diff options
Diffstat (limited to 'source/blender/nodes')
4 files changed, 48 insertions, 4 deletions
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index b5d77e99328..52e9ed35a2e 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -475,6 +475,48 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree, ntreeUpdateTree(G.main, ntree); } +static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed)) +{ + switch (fromnode->type) { + case SH_NODE_BSDF_ANISOTROPIC: + case SH_NODE_EEVEE_METALLIC: + case SH_NODE_EEVEE_SPECULAR: + case SH_NODE_BSDF_PRINCIPLED: + case SH_NODE_BSDF_GLOSSY: + fromnode->ssr_id = (*(float *)userdata); + (*(float *)userdata) += 1; + break; + default: + /* We could return false here but since we (will) + * allow the use of Closure as RGBA, we can have + * Bsdf nodes linked to other Bsdf nodes. */ + break; + } + + return true; +} + +/* EEVEE: Scan the ntree to set the Screen Space Reflection + * layer id of every specular node. + */ +static void ntree_shader_tag_ssr_node(bNodeTree *ntree, short compatibility) +{ + if (compatibility != NODE_NEWER_SHADING) { + /* We can only deal with new shading system here. */ + return; + } + + bNode *output_node = ntree_shader_output_node(ntree); + if (output_node == NULL) { + return; + } + /* Make sure sockets links pointers are correct. */ + ntreeUpdateTree(G.main, ntree); + + int lobe_count = 0; + nodeChainIter(ntree, output_node, ntree_tag_ssr_bsdf_cb, &lobe_count, true); +} + void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibility) { /* localize tree to create links for reroute and mute */ @@ -486,6 +528,8 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibili */ ntree_shader_relink_displacement(localtree, compatibility); + ntree_shader_tag_ssr_node(localtree, compatibility); + exec = ntreeShaderBeginExecTree(localtree); ntreeExecGPUNodes(exec, mat, 1, compatibility); ntreeShaderEndExecTree(exec); 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 4ae0474d685..1ec77bc9189 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c @@ -100,10 +100,10 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeE /* Only use complex versions when needed. */ if (!in[12].link && (in[12].vec[0] == 0.0f)) { - return GPU_stack_link(mat, node, "node_bsdf_principled_simple", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, node, "node_bsdf_principled_simple", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&node->ssr_id)); } else { - return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION)); + return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&node->ssr_id)); } } diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c b/source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c index 2a8a3a44f39..071486493fa 100644 --- a/source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c +++ b/source/blender/nodes/shader/nodes/node_shader_eevee_metallic.c @@ -68,7 +68,7 @@ static int node_shader_gpu_eevee_metallic(GPUMaterial *mat, bNode *node, bNodeEx GPU_link(mat, "set_value", GPU_uniform(&one), &in[10].link); } - return GPU_stack_link(mat, node, "node_eevee_metallic", in, out); + return GPU_stack_link(mat, node, "node_eevee_metallic", in, out, GPU_uniform(&node->ssr_id)); } diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c index 954f9b3ee4a..c249e77c17a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c +++ b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c @@ -67,7 +67,7 @@ static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *node, bNodeEx GPU_link(mat, "set_value", GPU_uniform(&one), &in[9].link); } - return GPU_stack_link(mat, node, "node_eevee_specular", in, out); + return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_uniform(&node->ssr_id)); } |