Fix Cycles incorrect principled BSDF mixing with some parameter variatons.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 30 Jan 2018 11:40:05 +0000 (12:40 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Tue, 30 Jan 2018 14:05:47 +0000 (15:05 +0100)
Spotted by Ha Hyung-jin, thanks!

intern/cycles/kernel/closure/bsdf_microfacet.h
intern/cycles/kernel/osl/osl_closures.cpp
intern/cycles/kernel/svm/svm_closure.h

index 18b645e0ecbbe948506c10e639e323caf3eebc04..2dd59354058c896a72e1f91b3b01b47c124d1175 100644 (file)
@@ -336,7 +336,9 @@ ccl_device bool bsdf_microfacet_merge(const ShaderClosure *a, const ShaderClosur
               (bsdf_a->ior == bsdf_b->ior) &&
               ((bsdf_a->extra == NULL && bsdf_b->extra == NULL) ||
                ((bsdf_a->extra && bsdf_b->extra) &&
               (bsdf_a->ior == bsdf_b->ior) &&
               ((bsdf_a->extra == NULL && bsdf_b->extra == NULL) ||
                ((bsdf_a->extra && bsdf_b->extra) &&
-                (isequal_float3(bsdf_a->extra->color, bsdf_b->extra->color))));
+                (isequal_float3(bsdf_a->extra->color, bsdf_b->extra->color)) &&
+                (isequal_float3(bsdf_a->extra->cspec0, bsdf_b->extra->cspec0)) &&
+                (bsdf_a->extra->clearcoat == bsdf_b->extra->clearcoat)));
 }
 
 ccl_device int bsdf_microfacet_ggx_aniso_setup(MicrofacetBsdf *bsdf)
 }
 
 ccl_device int bsdf_microfacet_ggx_aniso_setup(MicrofacetBsdf *bsdf)
index 608e856e019d9544195a7ab28cf92d9d64a0aecb..c52230de86e91480ea45d5d34d550ad02aca86d3 100644 (file)
@@ -194,10 +194,12 @@ public:
                        return NULL;
                }
 
                        return NULL;
                }
 
+               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                bsdf->extra = extra;
                bsdf->ior = 1.5f;
                bsdf->alpha_x = clearcoat_roughness;
                bsdf->alpha_y = clearcoat_roughness;
                bsdf->extra = extra;
                bsdf->ior = 1.5f;
                bsdf->alpha_x = clearcoat_roughness;
                bsdf->alpha_y = clearcoat_roughness;
+               bsdf->extra->color = make_float3(0.0f, 0.0f, 0.0f);
                bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
                bsdf->extra->clearcoat = clearcoat;
                return bsdf;
                bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
                bsdf->extra->clearcoat = clearcoat;
                return bsdf;
@@ -379,6 +381,7 @@ public:
                bsdf->extra = extra;
                bsdf->extra->color = color;
                bsdf->extra->cspec0 = cspec0;
                bsdf->extra = extra;
                bsdf->extra->color = color;
                bsdf->extra->cspec0 = cspec0;
+               bsdf->extra->clearcoat = 0.0f;
                return bsdf;
        }
 };
                return bsdf;
        }
 };
@@ -388,6 +391,8 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
+               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
+               bsdf->alpha_y = bsdf->alpha_x;
                sd->flag |= (bsdf) ? bsdf_microfacet_ggx_fresnel_setup(bsdf, sd) : 0;
        }
 };
                sd->flag |= (bsdf) ? bsdf_microfacet_ggx_fresnel_setup(bsdf, sd) : 0;
        }
 };
@@ -462,6 +467,8 @@ public:
 
                bsdf->extra = extra;
                bsdf->extra->color = color;
 
                bsdf->extra = extra;
                bsdf->extra->color = color;
+               bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
+               bsdf->extra->clearcoat = 0.0f;
                return bsdf;
        }
 };
                return bsdf;
        }
 };
@@ -471,6 +478,9 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
+               bsdf->ior = 0.0f;
+               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
+               bsdf->alpha_y = bsdf->alpha_x;
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_setup(bsdf) : 0;
        }
 };
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_setup(bsdf) : 0;
        }
 };
@@ -493,6 +503,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
+               bsdf->ior = 0.0f;
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_aniso_setup(bsdf) : 0;
        }
 };
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_aniso_setup(bsdf) : 0;
        }
 };
@@ -519,6 +530,8 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
+               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
+               bsdf->alpha_y = bsdf->alpha_x;
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_setup(bsdf) : 0;
        }
 };
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_setup(bsdf) : 0;
        }
 };
@@ -568,6 +581,7 @@ public:
                bsdf->extra = extra;
                bsdf->extra->color = color;
                bsdf->extra->cspec0 = cspec0;
                bsdf->extra = extra;
                bsdf->extra->color = color;
                bsdf->extra->cspec0 = cspec0;
+               bsdf->extra->clearcoat = 0.0f;
                return bsdf;
        }
 };
                return bsdf;
        }
 };
@@ -577,6 +591,8 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
+               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
+               bsdf->alpha_y = bsdf->alpha_x;
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd) : 0;
        }
 };
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd) : 0;
        }
 };
@@ -629,6 +645,8 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
+               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
+               bsdf->alpha_y = bsdf->alpha_x;
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd) : 0;
        }
 };
                sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd) : 0;
        }
 };
index 5a5cf2db4013da42aca5891d71444fcebc07f897..7fc96f7e47f1b3a87b72035d7be396561396d75c 100644 (file)
@@ -268,6 +268,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                                        bsdf->extra->cspec0 = (specular * 0.08f * tmp_col) * (1.0f - metallic) + base_color * metallic;
                                        bsdf->extra->color = base_color;
 
                                        bsdf->extra->cspec0 = (specular * 0.08f * tmp_col) * (1.0f - metallic) + base_color * metallic;
                                        bsdf->extra->color = base_color;
+                                       bsdf->extra->clearcoat = 0.0f;
 
                                        /* setup bsdf */
                                        if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID || roughness <= 0.075f) /* use single-scatter GGX */
 
                                        /* setup bsdf */
                                        if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID || roughness <= 0.075f) /* use single-scatter GGX */
@@ -306,6 +307,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                                        }
 
                                                        bsdf->N = N;
                                                        }
 
                                                        bsdf->N = N;
+                                                       bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                                                        bsdf->extra = extra;
 
                                                        bsdf->alpha_x = refl_roughness * refl_roughness;
                                                        bsdf->extra = extra;
 
                                                        bsdf->alpha_x = refl_roughness * refl_roughness;
@@ -314,6 +316,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                                                        bsdf->extra->color = base_color;
                                                        bsdf->extra->cspec0 = cspec0;
 
                                                        bsdf->extra->color = base_color;
                                                        bsdf->extra->cspec0 = cspec0;
+                                                       bsdf->extra->clearcoat = 0.0f;
 
                                                        /* setup bsdf */
                                                        sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
 
                                                        /* setup bsdf */
                                                        sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
@@ -365,6 +368,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                                                bsdf->extra->color = base_color;
                                                bsdf->extra->cspec0 = cspec0;
 
                                                bsdf->extra->color = base_color;
                                                bsdf->extra->cspec0 = cspec0;
+                                               bsdf->extra->clearcoat = 0.0f;
 
                                                /* setup bsdf */
                                                sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
 
                                                /* setup bsdf */
                                                sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
@@ -390,12 +394,14 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                        }
 
                                        bsdf->N = clearcoat_normal;
                                        }
 
                                        bsdf->N = clearcoat_normal;
+                                       bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                                        bsdf->ior = 1.5f;
                                        bsdf->extra = extra;
 
                                        bsdf->alpha_x = clearcoat_roughness * clearcoat_roughness;
                                        bsdf->alpha_y = clearcoat_roughness * clearcoat_roughness;
 
                                        bsdf->ior = 1.5f;
                                        bsdf->extra = extra;
 
                                        bsdf->alpha_x = clearcoat_roughness * clearcoat_roughness;
                                        bsdf->alpha_y = clearcoat_roughness * clearcoat_roughness;
 
+                                       bsdf->extra->color = make_float3(0.0f, 0.0f, 0.0f);
                                        bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
                                        bsdf->extra->clearcoat = clearcoat;
 
                                        bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
                                        bsdf->extra->clearcoat = clearcoat;
 
@@ -460,6 +466,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                        }
 
                        bsdf->N = N;
                        }
 
                        bsdf->N = N;
+                       bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                        bsdf->alpha_x = param1;
                        bsdf->alpha_y = param1;
                        bsdf->ior = 0.0f;
                        bsdf->alpha_x = param1;
                        bsdf->alpha_y = param1;
                        bsdf->ior = 0.0f;
@@ -477,6 +484,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                bsdf->extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
                                if(bsdf->extra) {
                                        bsdf->extra->color = stack_load_float3(stack, data_node.z);
                                bsdf->extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
                                if(bsdf->extra) {
                                        bsdf->extra->color = stack_load_float3(stack, data_node.z);
+                                       bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
+                                       bsdf->extra->clearcoat = 0.0f;
                                        sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
                                }
                        }
                                        sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
                                }
                        }
@@ -498,6 +507,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                        if(bsdf) {
                                bsdf->N = N;
 
                        if(bsdf) {
                                bsdf->N = N;
+                               bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                                bsdf->extra = NULL;
 
                                float eta = fmaxf(param2, 1e-5f);
                                bsdf->extra = NULL;
 
                                float eta = fmaxf(param2, 1e-5f);
@@ -555,6 +565,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                                if(bsdf) {
                                        bsdf->N = N;
 
                                if(bsdf) {
                                        bsdf->N = N;
+                                       bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                                        bsdf->extra = NULL;
                                        svm_node_glass_setup(sd, bsdf, type, eta, roughness, false);
                                }
                                        bsdf->extra = NULL;
                                        svm_node_glass_setup(sd, bsdf, type, eta, roughness, false);
                                }
@@ -569,6 +580,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                                if(bsdf) {
                                        bsdf->N = N;
 
                                if(bsdf) {
                                        bsdf->N = N;
+                                       bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
                                        bsdf->extra = NULL;
                                        svm_node_glass_setup(sd, bsdf, type, eta, roughness, true);
                                }
                                        bsdf->extra = NULL;
                                        svm_node_glass_setup(sd, bsdf, type, eta, roughness, true);
                                }
@@ -603,6 +615,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                        kernel_assert(stack_valid(data_node.z));
                        bsdf->extra->color = stack_load_float3(stack, data_node.z);
 
                        kernel_assert(stack_valid(data_node.z));
                        bsdf->extra->color = stack_load_float3(stack, data_node.z);
+                       bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
+                       bsdf->extra->clearcoat = 0.0f;
 
                        /* setup bsdf */
                        sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
 
                        /* setup bsdf */
                        sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
@@ -656,6 +670,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                        bsdf->extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
                                        if(bsdf->extra) {
                                                bsdf->extra->color = stack_load_float3(stack, data_node.w);
                                        bsdf->extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
                                        if(bsdf->extra) {
                                                bsdf->extra->color = stack_load_float3(stack, data_node.w);
+                                               bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
+                                               bsdf->extra->clearcoat = 0.0f;
                                                sd->flag |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf);
                                        }
                                }
                                                sd->flag |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf);
                                        }
                                }