Fix T51849: change Cycles clearcoat gloss to roughness.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 21 Jun 2017 17:24:57 +0000 (19:24 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 21 Jun 2017 17:55:20 +0000 (19:55 +0200)
This is compatible with UE4 and more consistent with specular and transmission
roughness, even if it deviates from the original Disney BRDF.

intern/cycles/kernel/osl/osl_closures.cpp
intern/cycles/kernel/shaders/node_principled_bsdf.osl
intern/cycles/kernel/shaders/stdosl.h
intern/cycles/kernel/svm/svm_closure.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c

index 5b66793a05da22f79ce2263f468c972cedd4340c..f76fc0d6fea15d84a711fc1b83c7b5dcb4652616 100644 (file)
@@ -191,7 +191,7 @@ BSDF_CLOSURE_CLASS_END(PrincipledSheen, principled_sheen)
 class PrincipledClearcoatClosure : public CBSDFClosure {
 public:
        MicrofacetBsdf params;
-       float clearcoat, clearcoat_gloss;
+       float clearcoat, clearcoat_roughness;
 
        MicrofacetBsdf *alloc(ShaderData *sd, int path_flag, float3 weight)
        {
@@ -202,8 +202,8 @@ public:
 
                        bsdf->ior = 1.5f;
 
-                       bsdf->alpha_x = 0.1f * (1.0f - clearcoat_gloss) + 0.001f * clearcoat_gloss;
-                       bsdf->alpha_y = 0.1f * (1.0f - clearcoat_gloss) + 0.001f * clearcoat_gloss;
+                       bsdf->alpha_x = clearcoat_roughness;
+                       bsdf->alpha_y = clearcoat_roughness;
 
                        bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
                        bsdf->extra->clearcoat = clearcoat;
@@ -226,7 +226,7 @@ ClosureParam *closure_bsdf_principled_clearcoat_params()
        static ClosureParam params[] = {
                CLOSURE_FLOAT3_PARAM(PrincipledClearcoatClosure, params.N),
                CLOSURE_FLOAT_PARAM(PrincipledClearcoatClosure, clearcoat),
-               CLOSURE_FLOAT_PARAM(PrincipledClearcoatClosure, clearcoat_gloss),
+               CLOSURE_FLOAT_PARAM(PrincipledClearcoatClosure, clearcoat_roughness),
                CLOSURE_STRING_KEYPARAM(PrincipledClearcoatClosure, label, "label"),
                CLOSURE_FINISH_PARAM(PrincipledClearcoatClosure)
        };
index 9d85d56ba78d7ba6c69243022cf6e3b7f456471f..2bb981c39183fd6f59c47b90c9816f449c560651 100644 (file)
@@ -32,7 +32,7 @@ shader node_principled_bsdf(
        float Sheen = 0.0,
        float SheenTint = 0.5,
        float Clearcoat = 0.0,
-       float ClearcoatGloss = 1.0,
+       float ClearcoatRoughness = 0.03,
        float IOR = 1.45,
        float Transmission = 0.0,
        float TransmissionRoughness = 0.0,
@@ -114,7 +114,7 @@ shader node_principled_bsdf(
        }
 
        if (Clearcoat > 1e-5) {
-               BSDF = BSDF + principled_clearcoat(ClearcoatNormal, Clearcoat, ClearcoatGloss);
+               BSDF = BSDF + principled_clearcoat(ClearcoatNormal, Clearcoat, ClearcoatRoughness * ClearcoatRoughness);
        }
 }
 
index 289d1091b0a1160dca80101c2fc38637b5699a8c..c91d29186879d20a5b67fee73b7a070ec7047e9b 100644 (file)
@@ -546,7 +546,7 @@ closure color holdout() BUILTIN;
 closure color ambient_occlusion() BUILTIN;
 closure color principled_diffuse(normal N, float roughness) BUILTIN;
 closure color principled_sheen(normal N) BUILTIN;
-closure color principled_clearcoat(normal N, float clearcoat, float clearcoat_gloss) BUILTIN;
+closure color principled_clearcoat(normal N, float clearcoat, float clearcoat_roughness) BUILTIN;
 
 // BSSRDF
 closure color bssrdf_cubic(normal N, vector radius, float texture_blur, float sharpness) BUILTIN;
index f3bbd7a7dacf8b58342fffcbf3c5fd5e915c696e..c05da61ba5ad2921d289412cd82cf0066387b823 100644 (file)
@@ -79,13 +79,13 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 #ifdef __PRINCIPLED__
                case CLOSURE_BSDF_PRINCIPLED_ID: {
                        uint specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset, sheen_offset,
-                               sheen_tint_offset, clearcoat_offset, clearcoat_gloss_offset, eta_offset, transmission_offset,
+                               sheen_tint_offset, clearcoat_offset, clearcoat_roughness_offset, eta_offset, transmission_offset,
                                anisotropic_rotation_offset, transmission_roughness_offset;
                        uint4 data_node2 = read_node(kg, offset);
 
                        float3 T = stack_load_float3(stack, data_node.y);
                        decode_node_uchar4(data_node.z, &specular_offset, &roughness_offset, &specular_tint_offset, &anisotropic_offset);
-                       decode_node_uchar4(data_node.w, &sheen_offset, &sheen_tint_offset, &clearcoat_offset, &clearcoat_gloss_offset);
+                       decode_node_uchar4(data_node.w, &sheen_offset, &sheen_tint_offset, &clearcoat_offset, &clearcoat_roughness_offset);
                        decode_node_uchar4(data_node2.x, &eta_offset, &transmission_offset, &anisotropic_rotation_offset, &transmission_roughness_offset);
 
                        // get Disney principled parameters
@@ -98,7 +98,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                        float sheen = stack_load_float(stack, sheen_offset);
                        float sheen_tint = stack_load_float(stack, sheen_tint_offset);
                        float clearcoat = stack_load_float(stack, clearcoat_offset);
-                       float clearcoat_gloss = stack_load_float(stack, clearcoat_gloss_offset);
+                       float clearcoat_roughness = stack_load_float(stack, clearcoat_roughness_offset);
                        float transmission = stack_load_float(stack, transmission_offset);
                        float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
                        float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
@@ -398,8 +398,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                                bsdf->ior = 1.5f;
                                                bsdf->extra = extra;
 
-                                               bsdf->alpha_x = 0.1f * (1.0f - clearcoat_gloss) + 0.001f * clearcoat_gloss;
-                                               bsdf->alpha_y = 0.1f * (1.0f - clearcoat_gloss) + 0.001f * clearcoat_gloss;
+                                               bsdf->alpha_x = clearcoat_roughness * clearcoat_roughness;
+                                               bsdf->alpha_y = clearcoat_roughness * clearcoat_roughness;
 
                                                bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
                                                bsdf->extra->clearcoat = clearcoat;
index 57b475e5cd00f9b9f149d919d57f99662d3af038..166156f7ac3525b1ba590bbe2631967e47ac765c 100644 (file)
@@ -2308,13 +2308,13 @@ NODE_DEFINE(PrincipledBsdfNode)
        SOCKET_IN_FLOAT(subsurface, "Subsurface", 0.0f);
        SOCKET_IN_VECTOR(subsurface_radius, "Subsurface Radius", make_float3(0.1f, 0.1f, 0.1f));
        SOCKET_IN_FLOAT(specular, "Specular", 0.0f);
-       SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f);
+       SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
        SOCKET_IN_FLOAT(specular_tint, "Specular Tint", 0.0f);
        SOCKET_IN_FLOAT(anisotropic, "Anisotropic", 0.0f);
        SOCKET_IN_FLOAT(sheen, "Sheen", 0.0f);
        SOCKET_IN_FLOAT(sheen_tint, "Sheen Tint", 0.0f);
        SOCKET_IN_FLOAT(clearcoat, "Clearcoat", 0.0f);
-       SOCKET_IN_FLOAT(clearcoat_gloss, "Clearcoat Gloss", 0.0f);
+       SOCKET_IN_FLOAT(clearcoat_roughness, "Clearcoat Roughness", 0.03f);
        SOCKET_IN_FLOAT(ior, "IOR", 0.0f);
        SOCKET_IN_FLOAT(transmission, "Transmission", 0.0f);
        SOCKET_IN_FLOAT(transmission_roughness, "Transmission Roughness", 0.0f);
@@ -2351,7 +2351,7 @@ void PrincipledBsdfNode::attributes(Shader *shader, AttributeRequestSet *attribu
 
 void PrincipledBsdfNode::compile(SVMCompiler& compiler, ShaderInput *p_metallic, ShaderInput *p_subsurface, ShaderInput *p_subsurface_radius,
        ShaderInput *p_specular, ShaderInput *p_roughness, ShaderInput *p_specular_tint, ShaderInput *p_anisotropic,
-       ShaderInput *p_sheen, ShaderInput *p_sheen_tint, ShaderInput *p_clearcoat, ShaderInput *p_clearcoat_gloss,
+       ShaderInput *p_sheen, ShaderInput *p_sheen_tint, ShaderInput *p_clearcoat, ShaderInput *p_clearcoat_roughness,
        ShaderInput *p_ior, ShaderInput *p_transmission, ShaderInput *p_anisotropic_rotation, ShaderInput *p_transmission_roughness)
 {
        ShaderInput *base_color_in = input("Base Color");
@@ -2374,7 +2374,7 @@ void PrincipledBsdfNode::compile(SVMCompiler& compiler, ShaderInput *p_metallic,
        int sheen_offset = compiler.stack_assign(p_sheen);
        int sheen_tint_offset = compiler.stack_assign(p_sheen_tint);
        int clearcoat_offset = compiler.stack_assign(p_clearcoat);
-       int clearcoat_gloss_offset = compiler.stack_assign(p_clearcoat_gloss);
+       int clearcoat_roughness_offset = compiler.stack_assign(p_clearcoat_roughness);
        int ior_offset = compiler.stack_assign(p_ior);
        int transmission_offset = compiler.stack_assign(p_transmission);
        int transmission_roughness_offset = compiler.stack_assign(p_transmission_roughness);
@@ -2391,7 +2391,7 @@ void PrincipledBsdfNode::compile(SVMCompiler& compiler, ShaderInput *p_metallic,
 
        compiler.add_node(normal_offset, tangent_offset,
                compiler.encode_uchar4(specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset),
-               compiler.encode_uchar4(sheen_offset, sheen_tint_offset, clearcoat_offset, clearcoat_gloss_offset));
+               compiler.encode_uchar4(sheen_offset, sheen_tint_offset, clearcoat_offset, clearcoat_roughness_offset));
 
        compiler.add_node(compiler.encode_uchar4(ior_offset, transmission_offset, anisotropic_rotation_offset, transmission_roughness_offset),
                distribution, SVM_STACK_INVALID, SVM_STACK_INVALID);
@@ -2419,7 +2419,7 @@ void PrincipledBsdfNode::compile(SVMCompiler& compiler)
 {
        compile(compiler, input("Metallic"), input("Subsurface"), input("Subsurface Radius"), input("Specular"),
                input("Roughness"), input("Specular Tint"), input("Anisotropic"), input("Sheen"), input("Sheen Tint"),
-               input("Clearcoat"), input("Clearcoat Gloss"), input("IOR"), input("Transmission"),
+               input("Clearcoat"), input("Clearcoat Roughness"), input("IOR"), input("Transmission"),
                input("Anisotropic Rotation"), input("Transmission Roughness"));
 }
 
index 687a86e322320d11a3cabdbc33888bb1f252d66e..c6ab47fcc84d46c049e61ebbd903d1625d06e92f 100644 (file)
@@ -378,13 +378,13 @@ public:
        bool has_bssrdf_bump();
        void compile(SVMCompiler& compiler, ShaderInput *metallic, ShaderInput *subsurface, ShaderInput *subsurface_radius,
                ShaderInput *specular, ShaderInput *roughness, ShaderInput *specular_tint, ShaderInput *anisotropic,
-               ShaderInput *sheen, ShaderInput *sheen_tint, ShaderInput *clearcoat, ShaderInput *clearcoat_gloss,
+               ShaderInput *sheen, ShaderInput *sheen_tint, ShaderInput *clearcoat, ShaderInput *clearcoat_roughness,
                ShaderInput *ior, ShaderInput *transmission, ShaderInput *anisotropic_rotation, ShaderInput *transmission_roughness);
 
        float3 base_color;
        float3 subsurface_color, subsurface_radius;
        float metallic, subsurface, specular, roughness, specular_tint, anisotropic,
-               sheen, sheen_tint, clearcoat, clearcoat_gloss, ior, transmission,
+               sheen, sheen_tint, clearcoat, clearcoat_roughness, ior, transmission,
                anisotropic_rotation, transmission_roughness;
        float3 normal, clearcoat_normal, tangent;
        float surface_mix_weight;
index f6b39d77dc7d9c4fd2dea7a4a694c8dc8b51ed47..a7ff8c1529f67bdc06f1ce2648e18d6bb977d8de 100644 (file)
@@ -2621,7 +2621,7 @@ void node_bsdf_toon(vec4 color, float size, float tsmooth, vec3 N, out vec4 resu
 
 void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
        float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
-       float clearcoat_gloss, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, out vec4 result)
+       float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, out vec4 result)
 {
        /* ambient light */
        // TODO: set ambient light to an appropriate value
@@ -2725,7 +2725,7 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad
                        //float FH = schlick_fresnel(LdotH);
 
                        // clearcoat (ior = 1.5 -> F0 = 0.04)
-                       float Dr = GTR1(CNdotH, mix(0.1, 0.001, clearcoat_gloss));
+                       float Dr = GTR1(CNdotH, sqr(clearcoat_roughness));
                        float Fr = fresnel_dielectric_cos(LdotH, 1.5); //mix(0.04, 1.0, FH);
                        float Gr = smithG_GGX(CNdotL, 0.25) * smithG_GGX(CNdotV, 0.25);
 
index 44288db182ac4ca770eb036f70764ae905d7f2bd..e0330d110ca162306efe666e8830550d2bb90759 100644 (file)
@@ -43,7 +43,7 @@ static bNodeSocketTemplate sh_node_bsdf_principled_in[] = {
        {       SOCK_FLOAT, 1, N_("Sheen"),                                     0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
        {       SOCK_FLOAT, 1, N_("Sheen Tint"),                        0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
        {       SOCK_FLOAT, 1, N_("Clearcoat"),                         0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-       {       SOCK_FLOAT, 1, N_("Clearcoat Gloss"),           1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+       {       SOCK_FLOAT, 1, N_("Clearcoat Roughness"),       0.03f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
        {       SOCK_FLOAT, 1, N_("IOR"),                                       1.45f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f},
        {       SOCK_FLOAT, 1, N_("Transmission"),                      0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
        {       SOCK_FLOAT, 1, N_("Transmission Roughness"),0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},