Rename any instance of scene layer or render layer in code with view layer
[blender.git] / source / blender / nodes / shader / node_shader_tree.c
index 67086d1f97d86609f5e2518610aae45ee909f1ab..dc48aa324b250ece6cc26177de7f96988a012c5a 100644 (file)
@@ -85,8 +85,8 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre
        SpaceNode *snode = CTX_wm_space_node(C);
        Scene *scene = CTX_data_scene(C);
        WorkSpace *workspace = CTX_wm_workspace(C);
-       SceneLayer *sl = CTX_data_scene_layer(C);
-       Object *ob = OBACT_NEW(sl);
+       ViewLayer *view_layer = CTX_data_view_layer(C);
+       Object *ob = OBACT(view_layer);
        ViewRender *view_render = BKE_viewrender_get(scene, workspace);
        
        if ((snode->shaderfrom == SNODE_SHADER_OBJECT) ||
@@ -439,7 +439,7 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree,
 static void ntree_shader_relink_displacement(bNodeTree *ntree,
                                              short compatibility)
 {
-       if (compatibility != NODE_NEW_SHADING) {
+       if ((compatibility & NODE_NEW_SHADING) == 0) {
                /* We can only deal with new shading system here. */
                return;
        }
@@ -511,7 +511,7 @@ static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *
  */
 static void ntree_shader_tag_ssr_node(bNodeTree *ntree, short compatibility)
 {
-       if (compatibility & NODE_NEWER_SHADING) {
+       if ((compatibility & NODE_NEWER_SHADING) == 0) {
                /* We can only deal with new shading system here. */
                return;
        }
@@ -523,8 +523,43 @@ static void ntree_shader_tag_ssr_node(bNodeTree *ntree, short compatibility)
        /* 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);
+       float lobe_id = 1;
+       nodeChainIter(ntree, output_node, ntree_tag_ssr_bsdf_cb, &lobe_id, true);
+}
+
+static bool ntree_tag_sss_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed))
+{
+       switch (fromnode->type) {
+               case SH_NODE_BSDF_PRINCIPLED:
+               case SH_NODE_SUBSURFACE_SCATTERING:
+                       fromnode->sss_id = (*(float *)userdata);
+                       (*(float *)userdata) += 1;
+                       break;
+               default:
+                       break;
+       }
+
+       return true;
+}
+
+/* EEVEE: Scan the ntree to set the Subsurface Scattering id of every SSS node.
+ */
+static void ntree_shader_tag_sss_node(bNodeTree *ntree, short compatibility)
+{
+       if ((compatibility & NODE_NEWER_SHADING) == 0) {
+               /* 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);
+
+       float sss_id = 1;
+       nodeChainIter(ntree, output_node, ntree_tag_sss_bsdf_cb, &sss_id, true);
 }
 
 /* EEVEE: Find which material domain are used (volume, surface ...).
@@ -568,6 +603,7 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibili
        ntree_shader_relink_displacement(localtree, compatibility);
 
        ntree_shader_tag_ssr_node(localtree, compatibility);
+       ntree_shader_tag_sss_node(localtree, compatibility);
 
        exec = ntreeShaderBeginExecTree(localtree);
        ntreeExecGPUNodes(exec, mat, 1, compatibility);