Cycles: Expose diffuse and glossy depth to Light Path node
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 6 Dec 2016 15:15:36 +0000 (16:15 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 19 Jan 2017 14:09:58 +0000 (15:09 +0100)
Was a bit confusing to have transparent and translucent depth
exposed but no diffuse or glossy.

Reviewers: brecht

Subscribers: eyecandy

Differential Revision: https://developer.blender.org/D2399

intern/cycles/kernel/osl/osl_services.cpp
intern/cycles/kernel/osl/osl_services.h
intern/cycles/kernel/shaders/node_light_path.osl
intern/cycles/kernel/svm/svm_light_path.h
intern/cycles/kernel/svm/svm_types.h
intern/cycles/render/nodes.cpp
source/blender/nodes/shader/nodes/node_shader_light_path.c

index 2654386..eeccf9a 100644 (file)
@@ -102,6 +102,8 @@ ustring OSLRenderServices::u_curve_tangent_normal("geom:curve_tangent_normal");
 #endif
 ustring OSLRenderServices::u_path_ray_length("path:ray_length");
 ustring OSLRenderServices::u_path_ray_depth("path:ray_depth");
+ustring OSLRenderServices::u_path_diffuse_depth("path:diffuse_depth");
+ustring OSLRenderServices::u_path_glossy_depth("path:glossy_depth");
 ustring OSLRenderServices::u_path_transparent_depth("path:transparent_depth");
 ustring OSLRenderServices::u_path_transmission_depth("path:transmission_depth");
 ustring OSLRenderServices::u_trace("trace");
@@ -759,6 +761,24 @@ bool OSLRenderServices::get_background_attribute(KernelGlobals *kg, ShaderData *
                int f = state->bounce;
                return set_attribute_int(f, type, derivatives, val);
        }
+       else if(name == u_path_diffuse_depth) {
+               /* Diffuse Ray Depth */
+               PathState *state = sd->osl_path_state;
+               int f = state->diffuse_bounce;
+               return set_attribute_int(f, type, derivatives, val);
+       }
+       else if(name == u_path_glossy_depth) {
+               /* Glossy Ray Depth */
+               PathState *state = sd->osl_path_state;
+               int f = state->glossy_bounce;
+               return set_attribute_int(f, type, derivatives, val);
+       }
+       else if(name == u_path_transmission_depth) {
+               /* Transmission Ray Depth */
+               PathState *state = sd->osl_path_state;
+               int f = state->transmission_bounce;
+               return set_attribute_int(f, type, derivatives, val);
+       }
        else if(name == u_path_transparent_depth) {
                /* Transparent Ray Depth */
                PathState *state = sd->osl_path_state;
index 0f2e02c..ec34ca7 100644 (file)
@@ -165,6 +165,8 @@ public:
        static ustring u_curve_tangent_normal;
        static ustring u_path_ray_length;
        static ustring u_path_ray_depth;
+       static ustring u_path_diffuse_depth;
+       static ustring u_path_glossy_depth;
        static ustring u_path_transparent_depth;
        static ustring u_path_transmission_depth;
        static ustring u_trace;
index a021a40..64fe4c2 100644 (file)
@@ -27,6 +27,8 @@ shader node_light_path(
        output float IsVolumeScatterRay = 0.0,
        output float RayLength = 0.0,
        output float RayDepth = 0.0,
+       output float DiffuseDepth = 0.0,
+       output float GlossyDepth = 0.0,
        output float TransparentDepth = 0.0,
        output float TransmissionDepth = 0.0)
 {
@@ -45,6 +47,14 @@ shader node_light_path(
        getattribute("path:ray_depth", ray_depth);
        RayDepth = (float)ray_depth;
 
+       int diffuse_depth;
+       getattribute("path:diffuse_depth", diffuse_depth);
+       DiffuseDepth = (float)diffuse_depth;
+
+       int glossy_depth;
+       getattribute("path:glossy_depth", glossy_depth);
+       GlossyDepth = (float)glossy_depth;
+
        int transparent_depth;
        getattribute("path:transparent_depth", transparent_depth);
        TransparentDepth = (float)transparent_depth;
index f35ea05..04f6f62 100644 (file)
@@ -34,6 +34,8 @@ ccl_device void svm_node_light_path(ShaderData *sd, ccl_addr_space PathState *st
                case NODE_LP_backfacing: info = (ccl_fetch(sd, flag) & SD_BACKFACING)? 1.0f: 0.0f; break;
                case NODE_LP_ray_length: info = ccl_fetch(sd, ray_length); break;
                case NODE_LP_ray_depth: info = (float)state->bounce; break;
+               case NODE_LP_ray_diffuse: info = (float)state->diffuse_bounce; break;
+               case NODE_LP_ray_glossy: info = (float)state->glossy_bounce; break;
                case NODE_LP_ray_transparent: info = (float)state->transparent_bounce; break;
                case NODE_LP_ray_transmission: info = (float)state->transmission_bounce; break;
        }
index 5adf7d3..47209dd 100644 (file)
@@ -188,6 +188,8 @@ typedef enum NodeLightPath {
        NODE_LP_backfacing,
        NODE_LP_ray_length,
        NODE_LP_ray_depth,
+       NODE_LP_ray_diffuse,
+       NODE_LP_ray_glossy,
        NODE_LP_ray_transparent,
        NODE_LP_ray_transmission,
 } NodeLightPath;
index c7f37a1..1e4a9fd 100644 (file)
@@ -3027,6 +3027,8 @@ NODE_DEFINE(LightPathNode)
        SOCKET_OUT_FLOAT(is_volume_scatter_ray, "Is Volume Scatter Ray");
        SOCKET_OUT_FLOAT(ray_length, "Ray Length");
        SOCKET_OUT_FLOAT(ray_depth, "Ray Depth");
+       SOCKET_OUT_FLOAT(diffuse_depth, "Diffuse Depth");
+       SOCKET_OUT_FLOAT(glossy_depth, "Glossy Depth");
        SOCKET_OUT_FLOAT(transparent_depth, "Transparent Depth");
        SOCKET_OUT_FLOAT(transmission_depth, "Transmission Depth");
 
@@ -3093,6 +3095,16 @@ void LightPathNode::compile(SVMCompiler& compiler)
                compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_depth, compiler.stack_assign(out));
        }
 
+       out = output("Diffuse Depth");
+       if(!out->links.empty()) {
+               compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_diffuse, compiler.stack_assign(out));
+       }
+
+       out = output("Glossy Depth");
+       if(!out->links.empty()) {
+               compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_glossy, compiler.stack_assign(out));
+       }
+
        out = output("Transparent Depth");
        if(!out->links.empty()) {
                compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_transparent, compiler.stack_assign(out));
index b1001cd..052f2a6 100644 (file)
@@ -39,6 +39,8 @@ static bNodeSocketTemplate sh_node_light_path_out[] = {
        {       SOCK_FLOAT, 0, N_("Is Transmission Ray"),       0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
        {       SOCK_FLOAT, 0, N_("Ray Length"),                        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
        {       SOCK_FLOAT, 0, N_("Ray Depth"),                         0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 0, N_("Diffuse Depth"),     0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
+       {       SOCK_FLOAT, 0, N_("Glossy Depth"),      0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
        {       SOCK_FLOAT, 0, N_("Transparent Depth"),         0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
        {       SOCK_FLOAT, 0, N_("Transmission Depth"),        0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
        {       -1, 0, ""       }