diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-22 06:31:31 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-22 12:48:17 +0300 |
commit | b102472551c351d8be8ebf96e3e44a5454f02d0a (patch) | |
tree | 1ccd80b94db736cd45f2c038c22e1c7b43642ded /source/blender/nodes/shader | |
parent | 735515a3f9e4c41738bf714d682b13db64adb638 (diff) |
Cleanup: style, use braces for nodes
Diffstat (limited to 'source/blender/nodes/shader')
24 files changed, 246 insertions, 115 deletions
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 816c56713d0..ed531a092ca 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -408,8 +408,9 @@ static void ntree_shader_unlink_hidden_value_sockets(bNode *group_node, bNodeSoc for (node = group_ntree->nodes.first; node; node = node->next) { for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { - if ((sock->flag & SOCK_HIDE_VALUE) == 0) + if ((sock->flag & SOCK_HIDE_VALUE) == 0) { continue; + } /* If socket is linked to a group input node and sockets id match. */ if (sock && sock->link && sock->link->fromnode->type == NODE_GROUP_INPUT) { if (STREQ(isock->identifier, sock->link->fromsock->identifier)) { @@ -439,16 +440,18 @@ static void ntree_shader_groups_expand_inputs(bNodeTree *localtree) for (group_node = localtree->nodes.first; group_node; group_node = group_node->next) { - if (!(ELEM(group_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) || group_node->id == NULL) + if (!(ELEM(group_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) || group_node->id == NULL) { continue; + } /* Do it recursively. */ ntree_shader_groups_expand_inputs((bNodeTree *)group_node->id); bNodeSocket *group_socket = group_node->inputs.first; for (; group_socket; group_socket = group_socket->next) { - if (group_socket->link != NULL) + if (group_socket->link != NULL) { continue; + } /* Detect the case where an input is plugged into a hidden value socket. * In this case we should just remove the link to trigger the socket default override. */ @@ -574,8 +577,9 @@ static void ntree_shader_link_builtin_group_normal(bNodeTree *ntree, /* Need to update tree so all node instances nodes gets proper sockets. */ bNode *group_input_node = ntreeFindType(group_ntree, NODE_GROUP_INPUT); node_group_verify(ntree, group_node, &group_ntree->id); - if (group_input_node) + if (group_input_node) { node_group_input_verify(group_ntree, group_input_node, &group_ntree->id); + } ntreeUpdateTree(G.main, group_ntree); /* Assumes sockets are always added at the end. */ bNodeSocket *group_node_normal_socket = group_node->inputs.last; @@ -849,8 +853,9 @@ bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, /* allocate the thread stack listbase array */ exec->threadstack = MEM_callocN(BLENDER_MAX_THREADS * sizeof(ListBase), "thread stack array"); - for (node = exec->nodetree->nodes.first; node; node = node->next) + for (node = exec->nodetree->nodes.first; node; node = node->next) { node->need_exec = 1; + } return exec; } @@ -863,8 +868,9 @@ bNodeTreeExec *ntreeShaderBeginExecTree(bNodeTree *ntree) /* XXX hack: prevent exec data from being generated twice. * this should be handled by the renderer! */ - if (ntree->execdata) + if (ntree->execdata) { return ntree->execdata; + } context.previews = ntree->previews; @@ -885,9 +891,11 @@ void ntreeShaderEndExecTree_internal(bNodeTreeExec *exec) if (exec->threadstack) { for (a = 0; a < BLENDER_MAX_THREADS; a++) { - for (nts = exec->threadstack[a].first; nts; nts = nts->next) - if (nts->stack) + for (nts = exec->threadstack[a].first; nts; nts = nts->next) { + if (nts->stack) { MEM_freeN(nts->stack); + } + } BLI_freelistN(&exec->threadstack[a]); } @@ -921,8 +929,9 @@ bool ntreeShaderExecTree(bNodeTree *ntree, int thread) /* ensure execdata is only initialized once */ if (!exec) { BLI_thread_lock(LOCK_NODES); - if (!ntree->execdata) + if (!ntree->execdata) { ntree->execdata = ntreeShaderBeginExecTree(ntree); + } BLI_thread_unlock(LOCK_NODES); exec = ntree->execdata; diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c index a29962843af..e75cb8a6642 100644 --- a/source/blender/nodes/shader/node_shader_util.c +++ b/source/blender/nodes/shader/node_shader_util.c @@ -49,10 +49,12 @@ void nodestack_get_vec(float *in, short type_in, bNodeStack *ns) const float *from = ns->vec; if (type_in == SOCK_FLOAT) { - if (ns->sockettype == SOCK_FLOAT) + if (ns->sockettype == SOCK_FLOAT) { *in = *from; - else + } + else { *in = (from[0] + from[1] + from[2]) / 3.0f; + } } else if (type_in == SOCK_VECTOR) { if (ns->sockettype == SOCK_FLOAT) { @@ -98,18 +100,24 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns) nodestack_get_vec(gs->vec, type, ns); gs->link = ns->data; - if (type == SOCK_FLOAT) + if (type == SOCK_FLOAT) { gs->type = GPU_FLOAT; - else if (type == SOCK_INT) + } + else if (type == SOCK_INT) { gs->type = GPU_FLOAT; /* HACK: Support as float. */ - else if (type == SOCK_VECTOR) + } + else if (type == SOCK_VECTOR) { gs->type = GPU_VEC3; - else if (type == SOCK_RGBA) + } + else if (type == SOCK_RGBA) { gs->type = GPU_VEC4; - else if (type == SOCK_SHADER) + } + else if (type == SOCK_SHADER) { gs->type = GPU_CLOSURE; - else + } + else { gs->type = GPU_NONE; + } gs->hasinput = ns->hasinput && ns->data; /* XXX Commented out the ns->data check here, as it seems it's not always set, @@ -133,8 +141,9 @@ static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeS bNodeSocket *sock; int i; - for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) + for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) { node_gpu_stack_from_data(&gs[i], sock->type, ns[i]); + } gs[i].end = true; } @@ -144,8 +153,9 @@ static void data_from_gpu_stack_list(ListBase *sockets, bNodeStack **ns, GPUNode bNodeSocket *sock; int i; - for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) + for (sock = sockets->first, i = 0; sock; sock = sock->next, i++) { node_data_from_gpu_stack(ns[i], &gs[i]); + } } bNode *nodeGetActiveTexture(bNodeTree *ntree) @@ -154,23 +164,28 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) bNode *node, *tnode, *inactivenode = NULL, *activetexnode = NULL, *activegroup = NULL; bool hasgroup = false; - if (!ntree) + if (!ntree) { return NULL; + } for (node = ntree->nodes.first; node; node = node->next) { if (node->flag & NODE_ACTIVE_TEXTURE) { activetexnode = node; /* if active we can return immediately */ - if (node->flag & NODE_ACTIVE) + if (node->flag & NODE_ACTIVE) { return node; + } } - else if (!inactivenode && node->typeinfo->nclass == NODE_CLASS_TEXTURE) + else if (!inactivenode && node->typeinfo->nclass == NODE_CLASS_TEXTURE) { inactivenode = node; + } else if (node->type == NODE_GROUP) { - if (node->flag & NODE_ACTIVE) + if (node->flag & NODE_ACTIVE) { activegroup = node; - else + } + else { hasgroup = true; + } } } @@ -178,20 +193,23 @@ bNode *nodeGetActiveTexture(bNodeTree *ntree) if (activegroup) { tnode = nodeGetActiveTexture((bNodeTree *)activegroup->id); /* active node takes priority, so ignore any other possible nodes here */ - if (tnode) + if (tnode) { return tnode; + } } - if (activetexnode) + if (activetexnode) { return activetexnode; + } if (hasgroup) { /* node active texture node in this tree, look inside groups */ for (node = ntree->nodes.first; node; node = node->next) { if (node->type == NODE_GROUP) { tnode = nodeGetActiveTexture((bNodeTree *)node->id); - if (tnode && ((tnode->flag & NODE_ACTIVE_TEXTURE) || !inactivenode)) + if (tnode && ((tnode->flag & NODE_ACTIVE_TEXTURE) || !inactivenode)) { return tnode; + } } } } @@ -218,8 +236,9 @@ void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node do_it = false; /* for groups, only execute outputs for edited group */ if (node->typeinfo->nclass == NODE_CLASS_OUTPUT) { - if ((output_node != NULL) && (node == output_node)) + if ((output_node != NULL) && (node == output_node)) { do_it = true; + } } else { do_it = true; @@ -230,8 +249,9 @@ void ntreeExecGPUNodes(bNodeTreeExec *exec, GPUMaterial *mat, bNode *output_node node_get_stack(node, stack, nsin, nsout); gpu_stack_from_data_list(gpuin, &node->inputs, nsin); gpu_stack_from_data_list(gpuout, &node->outputs, nsout); - if (node->typeinfo->gpufunc(mat, node, &nodeexec->data, gpuin, gpuout)) + if (node->typeinfo->gpufunc(mat, node, &nodeexec->data, gpuin, gpuout)) { data_from_gpu_stack_list(&node->outputs, nsout, gpuout); + } } } } @@ -261,7 +281,8 @@ void node_shader_gpu_tex_mapping(GPUMaterial *mat, GPU_link(mat, "mapping", in[0].link, tmat0, tmat1, tmat2, tmat3, tmin, tmax, &in[0].link); - if (texmap->type == TEXMAP_TYPE_NORMAL) + if (texmap->type == TEXMAP_TYPE_NORMAL) { GPU_link(mat, "texco_norm", in[0].link, &in[0].link); + } } } diff --git a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c index 84dda89c47d..f54d2563623 100644 --- a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c +++ b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c @@ -50,8 +50,9 @@ static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[2].link) + if (!in[2].link) { GPU_link(mat, "world_normals_get", &in[2].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c index dc92af5ee48..117c903a161 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c @@ -67,8 +67,9 @@ static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[4].link) + if (!in[4].link) { GPU_link(mat, "world_normals_get", &in[4].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c index 5ed02a275f1..5d1a8d0990a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c @@ -49,8 +49,9 @@ static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[2].link) + if (!in[2].link) { GPU_link(mat, "world_normals_get", &in[2].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c index 682fddc1f9d..ffeda75d366 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c @@ -55,8 +55,9 @@ static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[3].link) + if (!in[3].link) { GPU_link(mat, "world_normals_get", &in[3].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY | GPU_MATFLAG_REFRACT); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c index 97c1afbbee2..9200a6c468c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c @@ -54,11 +54,13 @@ static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[2].link) + if (!in[2].link) { GPU_link(mat, "world_normals_get", &in[2].link); + } - if (node->custom1 == SHD_GLOSSY_SHARP) + if (node->custom1 == SHD_GLOSSY_SHARP) { GPU_link(mat, "set_value_zero", &in[1].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_GLOSSY); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c index e0fda117648..b45249e11b2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c @@ -196,10 +196,12 @@ static void node_shader_update_principled(bNodeTree *UNUSED(ntree), bNode *node) for (sock = node->inputs.first; sock; sock = sock->next) { if (STREQ(sock->name, "Transmission Roughness")) { - if (distribution == SHD_GLOSSY_GGX) + if (distribution == SHD_GLOSSY_GGX) { sock->flag &= ~SOCK_UNAVAIL; - else + } + else { sock->flag |= SOCK_UNAVAIL; + } } } } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c index 2d740cab776..4d98c62f95c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c @@ -55,11 +55,13 @@ static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[3].link) + if (!in[3].link) { GPU_link(mat, "world_normals_get", &in[3].link); + } - if (node->custom1 == SHD_GLOSSY_SHARP) + if (node->custom1 == SHD_GLOSSY_SHARP) { GPU_link(mat, "set_value_zero", &in[1].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_REFRACT); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c index 8ec80be748e..b5faf1df913 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c @@ -50,8 +50,9 @@ static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[3].link) + if (!in[3].link) { GPU_link(mat, "world_normals_get", &in[3].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c index 6e2556d7446..993a5b3d945 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c @@ -48,8 +48,9 @@ static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[1].link) + if (!in[1].link) { GPU_link(mat, "world_normals_get", &in[1].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c index d4cb444cf08..97c2c9bc084 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c @@ -49,8 +49,9 @@ static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[2].link) + if (!in[2].link) { GPU_link(mat, "world_normals_get", &in[2].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE); diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c b/source/blender/nodes/shader/nodes/node_shader_common.c index 3f95d31841e..64dd2f28208 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.c +++ b/source/blender/nodes/shader/nodes/node_shader_common.c @@ -67,8 +67,9 @@ static void *group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanc bNodeTree *ngroup = (bNodeTree *)node->id; bNodeTreeExec *exec; - if (!ngroup) + if (!ngroup) { return NULL; + } /* initialize the internal node tree execution */ exec = ntreeShaderBeginExecTree_internal(context, ngroup, key); @@ -80,8 +81,9 @@ static void group_freeexec(void *nodedata) { bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata; - if (gexec) + if (gexec) { ntreeShaderEndExecTree_internal(gexec); + } } /* Copy inputs to the internal stack. @@ -98,8 +100,9 @@ static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack) if (node->type == NODE_GROUP_INPUT) { for (sock = node->outputs.first, a = 0; sock; sock = sock->next, ++a) { ns = node_get_socket_stack(gstack, sock); - if (ns) + if (ns) { copy_stack(ns, in[a]); + } } } } @@ -119,8 +122,9 @@ static void group_move_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstac if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) { for (sock = node->inputs.first, a = 0; sock; sock = sock->next, ++a) { ns = node_get_socket_stack(gstack, sock); - if (ns) + if (ns) { move_stack(out[a], ns); + } } break; /* only one active output node */ } @@ -137,16 +141,18 @@ static void group_execute(void *data, bNodeTreeExec *exec = execdata->data; bNodeThreadStack *nts; - if (!exec) + if (!exec) { return; + } /* XXX same behavior as trunk: all nodes inside group are executed. * it's stupid, but just makes it work. compo redesign will do this better. */ { bNode *inode; - for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) + for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) { inode->need_exec = 1; + } } nts = ntreeGetThreadStack(exec, thread); @@ -208,8 +214,9 @@ static int gpu_group_execute( { bNodeTreeExec *exec = execdata->data; - if (!node->id) + if (!node->id) { return 0; + } group_gpu_copy_inputs(node, in, exec->stack); ntreeExecGPUNodes(exec, mat, NULL); diff --git a/source/blender/nodes/shader/nodes/node_shader_invert.c b/source/blender/nodes/shader/nodes/node_shader_invert.c index 802d10def0a..4a17c3432de 100644 --- a/source/blender/nodes/shader/nodes/node_shader_invert.c +++ b/source/blender/nodes/shader/nodes/node_shader_invert.c @@ -48,10 +48,12 @@ static void node_shader_exec_invert(void *UNUSED(data), icol[2] = 1.0f - col[2]; /* if fac, blend result against original input */ - if (fac < 1.0f) + if (fac < 1.0f) { interp_v3_v3v3(out[0]->vec, col, icol, fac); - else + } + else { copy_v3_v3(out[0]->vec, icol); + } } static int gpu_shader_invert(GPUMaterial *mat, diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c index 5af0dd55083..eca0d96f2c8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_mapping.c +++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c @@ -60,24 +60,31 @@ static void node_shader_exec_mapping(void *UNUSED(data), mul_m4_v3(texmap->mat, vec); if (texmap->flag & TEXMAP_CLIP_MIN) { - if (vec[0] < texmap->min[0]) + if (vec[0] < texmap->min[0]) { vec[0] = texmap->min[0]; - if (vec[1] < texmap->min[1]) + } + if (vec[1] < texmap->min[1]) { vec[1] = texmap->min[1]; - if (vec[2] < texmap->min[2]) + } + if (vec[2] < texmap->min[2]) { vec[2] = texmap->min[2]; + } } if (texmap->flag & TEXMAP_CLIP_MAX) { - if (vec[0] > texmap->max[0]) + if (vec[0] > texmap->max[0]) { vec[0] = texmap->max[0]; - if (vec[1] > texmap->max[1]) + } + if (vec[1] > texmap->max[1]) { vec[1] = texmap->max[1]; - if (vec[2] > texmap->max[2]) + } + if (vec[2] > texmap->max[2]) { vec[2] = texmap->max[2]; + } } - if (texmap->type == TEXMAP_TYPE_NORMAL) + if (texmap->type == TEXMAP_TYPE_NORMAL) { normalize_v3(vec); + } } static void node_shader_init_mapping(bNodeTree *UNUSED(ntree), bNode *node) @@ -107,8 +114,9 @@ static int gpu_shader_mapping(GPUMaterial *mat, GPU_stack_link(mat, node, "mapping", in, out, tmat0, tmat1, tmat2, tmat3, tmin, tmax); - if (texmap->type == TEXMAP_TYPE_NORMAL) + if (texmap->type == TEXMAP_TYPE_NORMAL) { GPU_link(mat, "texco_norm", out[0].link, &out[0].link); + } return true; } diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c index 6e104066a58..f8d1617887e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_math.c +++ b/source/blender/nodes/shader/nodes/node_shader_math.c @@ -55,51 +55,66 @@ static void node_shader_exec_math(void *UNUSED(data), r = a * b; break; case NODE_MATH_DIVIDE: { - if (b == 0) /* We don't want to divide by zero. */ + if (b == 0) { /* We don't want to divide by zero. */ r = 0.0; - else + } + else { r = a / b; + } break; } case NODE_MATH_SIN: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = sinf(a); - else + } + else { r = sinf(b); + } break; } case NODE_MATH_COS: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = cosf(a); - else + } + else { r = cosf(b); + } break; } case NODE_MATH_TAN: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = tanf(a); - else + } + else { r = tanf(b); + } break; } case NODE_MATH_ASIN: { if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ /* Can't do the impossible... */ - if (a <= 1 && a >= -1) + if (a <= 1 && a >= -1) { r = asinf(a); - else + } + else { r = 0.0; + } } else { /* Can't do the impossible... */ - if (b <= 1 && b >= -1) + if (b <= 1 && b >= -1) { r = asinf(b); - else + } + else { r = 0.0; + } } break; } @@ -107,26 +122,33 @@ static void node_shader_exec_math(void *UNUSED(data), if (in[0]->hasinput || !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ /* Can't do the impossible... */ - if (a <= 1 && a >= -1) + if (a <= 1 && a >= -1) { r = acosf(a); - else + } + else { r = 0.0; + } } else { /* Can't do the impossible... */ - if (b <= 1 && b >= -1) + if (b <= 1 && b >= -1) { r = acosf(b); - else + } + else { r = 0.0; + } } break; } case NODE_MATH_ATAN: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = atan(a); - else + } + else { r = atan(b); + } break; } case NODE_MATH_POW: { @@ -150,53 +172,68 @@ static void node_shader_exec_math(void *UNUSED(data), } case NODE_MATH_LOG: { /* Don't want any imaginary numbers... */ - if (a > 0 && b > 0) + if (a > 0 && b > 0) { r = log(a) / log(b); - else + } + else { r = 0.0; + } break; } case NODE_MATH_MIN: { - if (a < b) + if (a < b) { r = a; - else + } + else { r = b; + } break; } case NODE_MATH_MAX: { - if (a > b) + if (a > b) { r = a; - else + } + else { r = b; + } break; } case NODE_MATH_ROUND: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = (a < 0) ? (int)(a - 0.5f) : (int)(a + 0.5f); - else + } + else { r = (b < 0) ? (int)(b - 0.5f) : (int)(b + 0.5f); + } break; } case NODE_MATH_LESS: { - if (a < b) + if (a < b) { r = 1.0f; - else + } + else { r = 0.0f; + } break; } case NODE_MATH_GREATER: { - if (a > b) + if (a > b) { r = 1.0f; - else + } + else { r = 0.0f; + } break; } case NODE_MATH_MOD: { - if (b == 0.0f) + if (b == 0.0f) { r = 0.0f; - else + } + else { r = fmod(a, b); + } break; } case NODE_MATH_ABS: { @@ -210,40 +247,54 @@ static void node_shader_exec_math(void *UNUSED(data), case NODE_MATH_FLOOR: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = floorf(a); - else + } + else { r = floorf(b); + } break; } case NODE_MATH_CEIL: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = ceilf(a); - else + } + else { r = ceilf(b); + } break; } case NODE_MATH_FRACT: { if (in[0]->hasinput || !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { r = a - floorf(a); - else + } + else { r = b - floorf(b); + } break; } case NODE_MATH_SQRT: { if (in[0]->hasinput || - !in[1]->hasinput) { /* This one only takes one input, so we've got to choose. */ - if (a > 0) + !in[1]->hasinput) /* This one only takes one input, so we've got to choose. */ + { + if (a > 0) { r = sqrt(a); - else + } + else { r = 0.0; + } } else { - if (b > 0) + if (b > 0) { r = sqrt(b); - else + } + else { r = 0.0; + } } break; } diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.c b/source/blender/nodes/shader/nodes/node_shader_normal_map.c index fcc64707642..d769a219fa0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c +++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c @@ -60,32 +60,37 @@ static int gpu_shader_normal_map(GPUMaterial *mat, float d[4] = {0, 0, 0, 0}; - if (in[0].link) + if (in[0].link) { strength = in[0].link; + } else if (node->original) { bNodeSocket *socket = BLI_findlink(&node->original->inputs, 0); bNodeSocketValueFloat *socket_data = socket->default_value; strength = GPU_uniform(&socket_data->value); } - else + else { strength = GPU_constant(in[0].vec); + } - if (in[1].link) + if (in[1].link) { realnorm = in[1].link; + } else if (node->original) { bNodeSocket *socket = BLI_findlink(&node->original->inputs, 1); bNodeSocketValueRGBA *socket_data = socket->default_value; realnorm = GPU_uniform(socket_data->value); } - else + else { realnorm = GPU_constant(in[1].vec); + } negnorm = GPU_builtin(GPU_VIEW_NORMAL); GPU_link(mat, "math_max", strength, GPU_constant(d), &strength); const char *color_to_normal_fnc_name = "color_to_normal_new_shading"; - if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD) + if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD) { color_to_normal_fnc_name = "color_to_blender_normal_new_shading"; + } switch (nm->space) { case SHD_SPACE_TANGENT: GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm); diff --git a/source/blender/nodes/shader/nodes/node_shader_script.c b/source/blender/nodes/shader/nodes/node_shader_script.c index 088272bbfb4..29d3fd3ba67 100644 --- a/source/blender/nodes/shader/nodes/node_shader_script.c +++ b/source/blender/nodes/shader/nodes/node_shader_script.c @@ -49,8 +49,9 @@ static void node_copy_script(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, bN NodeShaderScript *src_nss = src_node->storage; NodeShaderScript *dest_nss = MEM_dupallocN(src_nss); - if (src_nss->bytecode) + if (src_nss->bytecode) { dest_nss->bytecode = MEM_dupallocN(src_nss->bytecode); + } dest_node->storage = dest_nss; } diff --git a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c index a6a2edd5352..d590f229c1a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c +++ b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c @@ -57,8 +57,9 @@ static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[5].link) + if (!in[5].link) { GPU_link(mat, "world_normals_get", &in[5].link); + } GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS); @@ -83,10 +84,12 @@ static void node_shader_update_subsurface_scattering(bNodeTree *UNUSED(ntree), b for (sock = node->inputs.first; sock; sock = sock->next) { if (STREQ(sock->name, "Sharpness")) { - if (falloff == SHD_SUBSURFACE_CUBIC) + if (falloff == SHD_SUBSURFACE_CUBIC) { sock->flag &= ~SOCK_UNAVAIL; - else + } + else { sock->flag |= SOCK_UNAVAIL; + } } } } diff --git a/source/blender/nodes/shader/nodes/node_shader_tangent.c b/source/blender/nodes/shader/nodes/node_shader_tangent.c index 6af19503800..5512754d9a2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tangent.c +++ b/source/blender/nodes/shader/nodes/node_shader_tangent.c @@ -53,12 +53,15 @@ static int node_shader_gpu_tangent(GPUMaterial *mat, else { GPUNodeLink *orco = GPU_attribute(CD_ORCO, ""); - if (attr->axis == SHD_TANGENT_AXIS_X) + if (attr->axis == SHD_TANGENT_AXIS_X) { GPU_link(mat, "tangent_orco_x", orco, &orco); - else if (attr->axis == SHD_TANGENT_AXIS_Y) + } + else if (attr->axis == SHD_TANGENT_AXIS_Y) { GPU_link(mat, "tangent_orco_y", orco, &orco); - else + } + else { GPU_link(mat, "tangent_orco_z", orco, &orco); + } return GPU_stack_link(mat, node, diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c index 0105bea9550..c3b8bc8bfd0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c @@ -71,8 +71,9 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, int isdata = tex->color_space == SHD_COLORSPACE_NONE; GPUNodeLink *outalpha; - if (!ima) + if (!ima) { return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out); + } if (!in[0].link) { GPU_link(mat, "node_tex_environment_texco", GPU_builtin(GPU_VIEW_POSITION), &in[0].link); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c index 37a9247c1cc..d4dcb6857d2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c @@ -115,8 +115,9 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, int isdata = tex->color_space == SHD_COLORSPACE_NONE; float blend = tex->projection_blend; - if (!ima) + if (!ima) { return GPU_stack_link(mat, node, "node_tex_image_empty", in, out); + } ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL); if ((tex->color_space == SHD_COLORSPACE_COLOR) && ibuf && @@ -126,8 +127,9 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, } BKE_image_release_ibuf(ima, ibuf, NULL); - if (!in[0].link) + if (!in[0].link) { in[0].link = GPU_attribute(CD_MTFACE, ""); + } node_shader_gpu_tex_mapping(mat, node, in, out); diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c index 15db757a9a1..b1fb0cad4b2 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c @@ -62,8 +62,9 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat, GPUNodeStack *in, GPUNodeStack *out) { - if (!in[0].link) + if (!in[0].link) { in[0].link = GPU_attribute(CD_ORCO, ""); + } node_shader_gpu_tex_mapping(mat, node, in, out); diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c index 08a53c1d53d..fe0e7b1d638 100644 --- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c +++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c @@ -104,10 +104,12 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage; - if (in[0].hasinput) + if (in[0].hasinput) { inputlink = in[0].link; - else + } + else { inputlink = GPU_constant(in[0].vec); + } fromto = get_gpulink_matrix_from_to(nodeprop->convert_from, nodeprop->convert_to); @@ -125,11 +127,13 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, GPU_link(mat, "invert_z", out[0].link, &out[0].link); } } - else + else { GPU_link(mat, "set_rgb", inputlink, &out[0].link); + } - if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) + if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL) { GPU_link(mat, "vect_normalize", out[0].link, &out[0].link); + } return true; } |