Commit: 29d2ff7b31aef4fe490446e8a82fdc34021e2592
Author: Brecht Van Lommel
Date:   Thu Feb 8 16:14:04 2018 +0100
Branches: master
https://developer.blender.org/rB29d2ff7b31aef4fe490446e8a82fdc34021e2592

Cycles: unify OSL BSSRDF closure into a single bssrdf() closure with method.

This is similar to the upstream unified microfacet() closure, and makes it
easier to extend in the future.

===================================================================

M       intern/cycles/kernel/osl/osl_bssrdf.cpp
M       intern/cycles/kernel/osl/osl_closures.cpp
M       intern/cycles/kernel/osl/osl_closures.h
M       intern/cycles/kernel/shaders/node_principled_bsdf.osl
M       intern/cycles/kernel/shaders/node_subsurface_scattering.osl
M       intern/cycles/kernel/shaders/stdosl.h

===================================================================

diff --git a/intern/cycles/kernel/osl/osl_bssrdf.cpp 
b/intern/cycles/kernel/osl/osl_bssrdf.cpp
index 3e7905f26df..db6426f60e5 100644
--- a/intern/cycles/kernel/osl/osl_bssrdf.cpp
+++ b/intern/cycles/kernel/osl/osl_bssrdf.cpp
@@ -48,9 +48,38 @@ CCL_NAMESPACE_BEGIN
 
 using namespace OSL;
 
+static ustring u_cubic("cubic");
+static ustring u_gaussian("gaussian");
+static ustring u_burley("burley");
+static ustring u_principled("principled");
+
 class CBSSRDFClosure : public CClosurePrimitive {
 public:
        Bssrdf params;
+       ustring method;
+
+       CBSSRDFClosure()
+       {
+               params.texture_blur = 0.0f;
+               params.sharpness = 0.0f;
+               params.roughness = 0.0f;
+       }
+
+       void setup(ShaderData *sd, int path_flag, float3 weight)
+       {
+               if (method == u_cubic) {
+                       alloc(sd, path_flag, weight, CLOSURE_BSSRDF_CUBIC_ID);
+               }
+               else if (method == u_gaussian) {
+                       alloc(sd, path_flag, weight, 
CLOSURE_BSSRDF_GAUSSIAN_ID);
+               }
+               else if (method == u_burley) {
+                       alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
+               }
+               else if (method == u_principled) {
+                       alloc(sd, path_flag, weight, 
CLOSURE_BSSRDF_PRINCIPLED_ID);
+               }
+       }
 
        void alloc(ShaderData *sd, int path_flag, float3 weight, ClosureType 
type)
        {
@@ -76,105 +105,23 @@ public:
        }
 };
 
-/* Cubic */
-
-class CubicBSSRDFClosure : public CBSSRDFClosure {
-public:
-       void setup(ShaderData *sd, int path_flag, float3 weight)
-       {
-               alloc(sd, path_flag, weight, CLOSURE_BSSRDF_CUBIC_ID);
-       }
-};
-
-ClosureParam *closure_bssrdf_cubic_params()
-{
-       static ClosureParam params[] = {
-               CLOSURE_FLOAT3_PARAM(CubicBSSRDFClosure, params.N),
-               CLOSURE_FLOAT3_PARAM(CubicBSSRDFClosure, params.radius),
-               CLOSURE_FLOAT_PARAM(CubicBSSRDFClosure, params.texture_blur),
-               CLOSURE_FLOAT_PARAM(CubicBSSRDFClosure, params.sharpness),
-               CLOSURE_STRING_KEYPARAM(CubicBSSRDFClosure, label, "label"),
-               CLOSURE_FINISH_PARAM(CubicBSSRDFClosure)
-       };
-       return params;
-}
-
-CCLOSURE_PREPARE(closure_bssrdf_cubic_prepare, CubicBSSRDFClosure)
-
-/* Gaussian */
-
-class GaussianBSSRDFClosure : public CBSSRDFClosure {
-public:
-       void setup(ShaderData *sd, int path_flag, float3 weight)
-       {
-               alloc(sd, path_flag, weight, CLOSURE_BSSRDF_GAUSSIAN_ID);
-       }
-};
-
-ClosureParam *closure_bssrdf_gaussian_params()
-{
-       static ClosureParam params[] = {
-               CLOSURE_FLOAT3_PARAM(GaussianBSSRDFClosure, params.N),
-               CLOSURE_FLOAT3_PARAM(GaussianBSSRDFClosure, params.radius),
-               CLOSURE_FLOAT_PARAM(GaussianBSSRDFClosure, params.texture_blur),
-               CLOSURE_STRING_KEYPARAM(GaussianBSSRDFClosure, label, "label"),
-               CLOSURE_FINISH_PARAM(GaussianBSSRDFClosure)
-       };
-       return params;
-}
-
-CCLOSURE_PREPARE(closure_bssrdf_gaussian_prepare, GaussianBSSRDFClosure)
-
-/* Burley */
-
-class BurleyBSSRDFClosure : public CBSSRDFClosure {
-public:
-       void setup(ShaderData *sd, int path_flag, float3 weight)
-       {
-               alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID);
-       }
-};
-
-ClosureParam *closure_bssrdf_burley_params()
-{
-       static ClosureParam params[] = {
-               CLOSURE_FLOAT3_PARAM(BurleyBSSRDFClosure, params.N),
-               CLOSURE_FLOAT3_PARAM(BurleyBSSRDFClosure, params.radius),
-               CLOSURE_FLOAT_PARAM(BurleyBSSRDFClosure, params.texture_blur),
-               CLOSURE_FLOAT3_PARAM(BurleyBSSRDFClosure, params.albedo),
-               CLOSURE_STRING_KEYPARAM(BurleyBSSRDFClosure, label, "label"),
-               CLOSURE_FINISH_PARAM(BurleyBSSRDFClosure)
-       };
-       return params;
-}
-
-CCLOSURE_PREPARE(closure_bssrdf_burley_prepare, BurleyBSSRDFClosure)
-
-/* Disney principled */
-
-class PrincipledBSSRDFClosure : public CBSSRDFClosure {
-public:
-       void setup(ShaderData *sd, int path_flag, float3 weight)
-       {
-               alloc(sd, path_flag, weight, CLOSURE_BSSRDF_PRINCIPLED_ID);
-       }
-};
-
-ClosureParam *closure_bssrdf_principled_params()
+ClosureParam *closure_bssrdf_params()
 {
        static ClosureParam params[] = {
-               CLOSURE_FLOAT3_PARAM(PrincipledBSSRDFClosure, params.N),
-               CLOSURE_FLOAT3_PARAM(PrincipledBSSRDFClosure, params.radius),
-               CLOSURE_FLOAT_PARAM(PrincipledBSSRDFClosure, 
params.texture_blur),
-               CLOSURE_FLOAT3_PARAM(PrincipledBSSRDFClosure, params.albedo),
-               CLOSURE_FLOAT_PARAM(PrincipledBSSRDFClosure, params.roughness),
-               CLOSURE_STRING_KEYPARAM(PrincipledBSSRDFClosure, label, 
"label"),
-               CLOSURE_FINISH_PARAM(PrincipledBSSRDFClosure)
+               CLOSURE_STRING_PARAM(CBSSRDFClosure, method),
+               CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.N),
+               CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.radius),
+               CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.albedo),
+               CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.texture_blur, 
"texture_blur"),
+               CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.sharpness, 
"sharpness"),
+               CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.roughness, 
"roughness"),
+               CLOSURE_STRING_KEYPARAM(CBSSRDFClosure, label, "label"),
+               CLOSURE_FINISH_PARAM(CBSSRDFClosure)
        };
        return params;
 }
 
-CCLOSURE_PREPARE(closure_bssrdf_principled_prepare, PrincipledBSSRDFClosure)
+CCLOSURE_PREPARE(closure_bssrdf_prepare, CBSSRDFClosure)
 
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp 
b/intern/cycles/kernel/osl/osl_closures.cpp
index 8acab1ab558..d0c357580fd 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -316,14 +316,8 @@ void OSLShader::register_closures(OSLShadingSystem *ss_)
                closure_bsdf_diffuse_ramp_params(), 
closure_bsdf_diffuse_ramp_prepare);
        register_closure(ss, "phong_ramp", id++,
                closure_bsdf_phong_ramp_params(), 
closure_bsdf_phong_ramp_prepare);
-       register_closure(ss, "bssrdf_cubic", id++,
-               closure_bssrdf_cubic_params(), closure_bssrdf_cubic_prepare);
-       register_closure(ss, "bssrdf_gaussian", id++,
-               closure_bssrdf_gaussian_params(), 
closure_bssrdf_gaussian_prepare);
-       register_closure(ss, "bssrdf_burley", id++,
-               closure_bssrdf_burley_params(), closure_bssrdf_burley_prepare);
-       register_closure(ss, "bssrdf_principled", id++,
-               closure_bssrdf_principled_params(), 
closure_bssrdf_principled_prepare);
+       register_closure(ss, "bssrdf", id++,
+               closure_bssrdf_params(), closure_bssrdf_prepare);
 
        register_closure(ss, "hair_reflection", id++,
                bsdf_hair_reflection_params(), bsdf_hair_reflection_prepare);
diff --git a/intern/cycles/kernel/osl/osl_closures.h 
b/intern/cycles/kernel/osl/osl_closures.h
index 38943b77656..dca7e74f154 100644
--- a/intern/cycles/kernel/osl/osl_closures.h
+++ b/intern/cycles/kernel/osl/osl_closures.h
@@ -49,10 +49,7 @@ OSL::ClosureParam *closure_ambient_occlusion_params();
 OSL::ClosureParam *closure_bsdf_diffuse_ramp_params();
 OSL::ClosureParam *closure_bsdf_phong_ramp_params();
 OSL::ClosureParam *closure_bsdf_transparent_params();
-OSL::ClosureParam *closure_bssrdf_cubic_params();
-OSL::ClosureParam *closure_bssrdf_gaussian_params();
-OSL::ClosureParam *closure_bssrdf_burley_params();
-OSL::ClosureParam *closure_bssrdf_principled_params();
+OSL::ClosureParam *closure_bssrdf_params();
 OSL::ClosureParam *closure_absorption_params();
 OSL::ClosureParam *closure_henyey_greenstein_params();
 OSL::ClosureParam *closure_bsdf_microfacet_multi_ggx_params();
@@ -72,10 +69,7 @@ void closure_ambient_occlusion_prepare(OSL::RendererServices 
*, int id, void *da
 void closure_bsdf_diffuse_ramp_prepare(OSL::RendererServices *, int id, void 
*data);
 void closure_bsdf_phong_ramp_prepare(OSL::RendererServices *, int id, void 
*data);
 void closure_bsdf_transparent_prepare(OSL::RendererServices *, int id, void 
*data);
-void closure_bssrdf_cubic_prepare(OSL::RendererServices *, int id, void *data);
-void closure_bssrdf_gaussian_prepare(OSL::RendererServices *, int id, void 
*data);
-void closure_bssrdf_burley_prepare(OSL::RendererServices *, int id, void 
*data);
-void closure_bssrdf_principled_prepare(OSL::RendererServices *, int id, void 
*data);
+void closure_bssrdf_prepare(OSL::RendererServices *, int id, void *data);
 void closure_absorption_prepare(OSL::RendererServices *, int id, void *data);
 void closure_henyey_greenstein_prepare(OSL::RendererServices *, int id, void 
*data);
 void closure_bsdf_microfacet_multi_ggx_prepare(OSL::RendererServices *, int 
id, void *data);
diff --git a/intern/cycles/kernel/shaders/node_principled_bsdf.osl 
b/intern/cycles/kernel/shaders/node_principled_bsdf.osl
index 6870d479af3..0e31dcedee4 100644
--- a/intern/cycles/kernel/shaders/node_principled_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_principled_bsdf.osl
@@ -58,7 +58,7 @@ shader node_principled_bsdf(
        if (diffuse_weight > 1e-5) {
                if (Subsurface > 1e-5) {
                        color mixed_ss_base_color = SubsurfaceColor * 
Subsurface + BaseColor * (1.0 - Subsurface);
-                       BSDF = mixed_ss_base_color * bssrdf_principled(Normal, 
Subsurface * SubsurfaceRadius, 0.0, SubsurfaceColor, Roughness);
+                       BSDF = mixed_ss_base_color * bssrdf("principled", 
Normal, Subsurface * SubsurfaceRadius, SubsurfaceColor, "roughness", Roughness);
                } else {
                        BSDF = BaseColor * principled_diffuse(Normal, 
Roughness);
                }
diff --git a/intern/cycles/kernel/shaders/node_subsurface_scattering.osl 
b/intern/cycles/kernel/shaders/node_subsurface_scattering.osl
index 5ba8f34021d..c9983fcd5dd 100644
--- a/intern/cycles/kernel/shaders/node_subsurface_scattering.osl
+++ b/intern/cycles/kernel/shaders/node_subsurface_scattering.osl
@@ -27,10 +27,10 @@ shader node_subsurface_scattering(
        output closure color BSSRDF = 0)
 {
        if (falloff == "gaussian")
-               BSSRDF = Color * bssrdf_gaussian(Normal, Scale * Radius, 
TextureBlur);
+               BSSRDF = Color * bssrdf("gaussian", Normal, Scale * Radius, 
Color, "texture_blur", TextureBlur);
        else if (falloff == "cubic")
-               BSSRDF = Color * bssrdf_cubic(Normal, Scale * Radius, 
TextureBlur, Sharpness);
+               BSSRDF = Color * bssrdf("cubic", Normal, Scale * Radius, Color, 
"texture_blur", TextureBlur, "sharpness", Sharpness);
        else
-               BSSRDF = Color * bssrdf_burley(Normal, Scale * Radius, 
TextureBlur, Color);
+               BSSRDF = Color * bssrdf("burley", Normal, Scale * Radius, 
Color, "texture_blur", TextureBlur);
 }
 
diff --git a/intern/cycles/kernel/shaders/stdosl.h 
b/intern/cycles/kernel/shaders/stdosl.h
index c91d2918687..091ade4a60d 100644
--- a/intern/cycles/kernel/shaders/stdosl.h
+++ b/intern/cycles/kernel/shaders/stdosl.h
@@ -549,10 +549,7 @@ closure color principled_sheen(normal N) BUILTIN;
 closure color principled_clearcoat(normal N, float 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to