Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Mon, 26 Jun 2017 03:27:54 +0000 (13:27 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 26 Jun 2017 03:27:54 +0000 (13:27 +1000)
19 files changed:
intern/cycles/kernel/closure/bsdf_microfacet.h
intern/cycles/kernel/closure/bsdf_microfacet_multi.h
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
release/scripts/startup/keyingsets_builtins.py
source/blender/blenlib/BLI_rect.h
source/blender/blenlib/intern/rct.c
source/blender/editors/gpencil/gpencil_paint.c
source/blender/editors/interface/interface.c
source/blender/editors/screen/screen_ops.c
source/blender/gpu/shaders/gpu_shader_material.glsl
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/composite/nodes/node_composite_switchview.c
source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
source/blender/windowmanager/intern/wm_draw.c

index 30cc8b903304fb1e93570f621c077a9e8ef14a50..b12e248f0a3fc94a9b5bf6cbe1b920108c5fad24 100644 (file)
@@ -288,12 +288,16 @@ ccl_device int bsdf_microfacet_ggx_setup(MicrofacetBsdf *bsdf)
        return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
 
-ccl_device int bsdf_microfacet_ggx_fresnel_setup(MicrofacetBsdf *bsdf)
+ccl_device int bsdf_microfacet_ggx_fresnel_setup(MicrofacetBsdf *bsdf, const ShaderData *sd)
 {
        bsdf->extra->cspec0.x = saturate(bsdf->extra->cspec0.x);
        bsdf->extra->cspec0.y = saturate(bsdf->extra->cspec0.y);
        bsdf->extra->cspec0.z = saturate(bsdf->extra->cspec0.z);
 
+       float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+       float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
+       bsdf->sample_weight *= F;
+
        bsdf->alpha_x = saturate(bsdf->alpha_x);
        bsdf->alpha_y = bsdf->alpha_x;
 
@@ -302,12 +306,16 @@ ccl_device int bsdf_microfacet_ggx_fresnel_setup(MicrofacetBsdf *bsdf)
        return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
 
-ccl_device int bsdf_microfacet_ggx_clearcoat_setup(MicrofacetBsdf *bsdf)
+ccl_device int bsdf_microfacet_ggx_clearcoat_setup(MicrofacetBsdf *bsdf, const ShaderData *sd)
 {
        bsdf->extra->cspec0.x = saturate(bsdf->extra->cspec0.x);
        bsdf->extra->cspec0.y = saturate(bsdf->extra->cspec0.y);
        bsdf->extra->cspec0.z = saturate(bsdf->extra->cspec0.z);
 
+       float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+       float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
+       bsdf->sample_weight *= 0.25f * bsdf->extra->clearcoat * F;
+
        bsdf->alpha_x = saturate(bsdf->alpha_x);
        bsdf->alpha_y = bsdf->alpha_x;
 
@@ -343,12 +351,16 @@ ccl_device int bsdf_microfacet_ggx_aniso_setup(MicrofacetBsdf *bsdf)
        return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
 
-ccl_device int bsdf_microfacet_ggx_aniso_fresnel_setup(MicrofacetBsdf *bsdf)
+ccl_device int bsdf_microfacet_ggx_aniso_fresnel_setup(MicrofacetBsdf *bsdf, const ShaderData *sd)
 {
        bsdf->extra->cspec0.x = saturate(bsdf->extra->cspec0.x);
        bsdf->extra->cspec0.y = saturate(bsdf->extra->cspec0.y);
        bsdf->extra->cspec0.z = saturate(bsdf->extra->cspec0.z);
 
+       float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+       float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
+       bsdf->sample_weight *= F;
+
        bsdf->alpha_x = saturate(bsdf->alpha_x);
        bsdf->alpha_y = saturate(bsdf->alpha_y);
 
index b07b515c405f302953c5fb83d6d6b1e24ef5ae1f..22d0092093a27f343d726dc6190a0c9198d0dd4d 100644 (file)
@@ -245,35 +245,69 @@ ccl_device_forceinline float mf_ggx_albedo(float r)
        return saturate(albedo);
 }
 
+ccl_device_inline float mf_ggx_transmission_albedo(float a, float ior)
+{
+       if(ior < 1.0f) {
+               ior = 1.0f/ior;
+       }
+       a = saturate(a);
+       ior = clamp(ior, 1.0f, 3.0f);
+       float I_1 = 0.0476898f*expf(-0.978352f*(ior-0.65657f)*(ior-0.65657f)) - 0.033756f*ior + 0.993261f;
+       float R_1 = (((0.116991f*a - 0.270369f)*a + 0.0501366f)*a - 0.00411511f)*a + 1.00008f;
+       float I_2 = (((-2.08704f*ior + 26.3298f)*ior - 127.906f)*ior + 292.958f)*ior - 287.946f + 199.803f/(ior*ior) - 101.668f/(ior*ior*ior);
+       float R_2 = ((((5.3725f*a -24.9307f)*a + 22.7437f)*a - 3.40751f)*a + 0.0986325f)*a + 0.00493504f;
+
+       return saturate(1.0f + I_2*R_2*0.0019127f - (1.0f - I_1)*(1.0f - R_1)*9.3205f);
+}
+
 ccl_device_forceinline float mf_ggx_pdf(const float3 wi, const float3 wo, const float alpha)
 {
        float D = D_ggx(normalize(wi+wo), alpha);
        float lambda = mf_lambda(wi, make_float2(alpha, alpha));
+       float singlescatter = 0.25f * D / max((1.0f + lambda) * wi.z, 1e-7f);
+
+       float multiscatter = wo.z * M_1_PI_F;
+
        float albedo = mf_ggx_albedo(alpha);
-       return 0.25f * D / max((1.0f + lambda) * wi.z, 1e-7f) + (1.0f - albedo) * wo.z;
+       return albedo*singlescatter + (1.0f - albedo)*multiscatter;
 }
 
 ccl_device_forceinline float mf_ggx_aniso_pdf(const float3 wi, const float3 wo, const float2 alpha)
 {
-       return 0.25f * D_ggx_aniso(normalize(wi+wo), alpha) / ((1.0f + mf_lambda(wi, alpha)) * wi.z) + (1.0f - mf_ggx_albedo(sqrtf(alpha.x*alpha.y))) * wo.z;
+       float D = D_ggx_aniso(normalize(wi+wo), alpha);
+       float lambda = mf_lambda(wi, alpha);
+       float singlescatter = 0.25f * D / max((1.0f + lambda) * wi.z, 1e-7f);
+
+       float multiscatter = wo.z * M_1_PI_F;
+
+       float albedo = mf_ggx_albedo(sqrtf(alpha.x*alpha.y));
+       return albedo*singlescatter + (1.0f - albedo)*multiscatter;
 }
 
 ccl_device_forceinline float mf_glass_pdf(const float3 wi, const float3 wo, const float alpha, const float eta)
 {
-       float3 wh;
-       float fresnel;
-       if(wi.z*wo.z > 0.0f) {
-               wh = normalize(wi + wo);
-               fresnel = fresnel_dielectric_cos(dot(wi, wh), eta);
-       }
-       else {
-               wh = normalize(wi + wo*eta);
-               fresnel = 1.0f - fresnel_dielectric_cos(dot(wi, wh), eta);
-       }
+       bool reflective = (wi.z*wo.z > 0.0f);
+
+       float wh_len;
+       float3 wh = normalize_len(wi + (reflective? wo : (wo*eta)), &wh_len);
        if(wh.z < 0.0f)
                wh = -wh;
        float3 r_wi = (wi.z < 0.0f)? -wi: wi;
-       return fresnel * max(0.0f, dot(r_wi, wh)) * D_ggx(wh, alpha) / ((1.0f + mf_lambda(r_wi, make_float2(alpha, alpha))) * r_wi.z) + fabsf(wo.z);
+       float lambda = mf_lambda(r_wi, make_float2(alpha, alpha));
+       float D = D_ggx(wh, alpha);
+       float fresnel = fresnel_dielectric_cos(dot(r_wi, wh), eta);
+
+       float multiscatter = fabsf(wo.z * M_1_PI_F);
+       if(reflective) {
+               float singlescatter = 0.25f * D / max((1.0f + lambda) * r_wi.z, 1e-7f);
+               float albedo = mf_ggx_albedo(alpha);
+               return fresnel * (albedo*singlescatter + (1.0f - albedo)*multiscatter);
+       }
+       else {
+               float singlescatter = fabsf(dot(r_wi, wh)*dot(wo, wh) * D * eta*eta / max((1.0f + lambda) * r_wi.z * wh_len*wh_len, 1e-7f));
+               float albedo = mf_ggx_transmission_albedo(alpha, eta);
+               return (1.0f - fresnel) * (albedo*singlescatter + (1.0f - albedo)*multiscatter);
+       }
 }
 
 /* === Actual random walk implementations, one version of mf_eval and mf_sample per phase function. === */
@@ -326,13 +360,17 @@ ccl_device int bsdf_microfacet_multi_ggx_aniso_setup(MicrofacetBsdf *bsdf)
        return bsdf_microfacet_multi_ggx_common_setup(bsdf);
 }
 
-ccl_device int bsdf_microfacet_multi_ggx_aniso_fresnel_setup(MicrofacetBsdf *bsdf)
+ccl_device int bsdf_microfacet_multi_ggx_aniso_fresnel_setup(MicrofacetBsdf *bsdf, const ShaderData *sd)
 {
        if(is_zero(bsdf->T))
                bsdf->T = make_float3(1.0f, 0.0f, 0.0f);
 
        bsdf->type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID;
 
+       float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+       float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
+       bsdf->sample_weight *= F;
+
        return bsdf_microfacet_multi_ggx_common_setup(bsdf);
 }
 
@@ -345,12 +383,16 @@ ccl_device int bsdf_microfacet_multi_ggx_setup(MicrofacetBsdf *bsdf)
        return bsdf_microfacet_multi_ggx_common_setup(bsdf);
 }
 
-ccl_device int bsdf_microfacet_multi_ggx_fresnel_setup(MicrofacetBsdf *bsdf)
+ccl_device int bsdf_microfacet_multi_ggx_fresnel_setup(MicrofacetBsdf *bsdf, const ShaderData *sd)
 {
        bsdf->alpha_y = bsdf->alpha_x;
 
        bsdf->type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID;
 
+       float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+       float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
+       bsdf->sample_weight *= F;
+
        return bsdf_microfacet_multi_ggx_common_setup(bsdf);
 }
 
@@ -455,7 +497,7 @@ ccl_device int bsdf_microfacet_multi_ggx_glass_setup(MicrofacetBsdf *bsdf)
        return SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_NEEDS_LCG;
 }
 
-ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(MicrofacetBsdf *bsdf)
+ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(MicrofacetBsdf *bsdf, const ShaderData *sd)
 {
        bsdf->alpha_x = clamp(bsdf->alpha_x, 1e-4f, 1.0f);
        bsdf->alpha_y = bsdf->alpha_x;
@@ -469,6 +511,10 @@ ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(MicrofacetBsdf *bsd
 
        bsdf->type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID;
 
+       float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+       float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
+       bsdf->sample_weight *= F;
+
        return SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_NEEDS_LCG;
 }
 
index 5b66793a05da22f79ce2263f468c972cedd4340c..2f0897434ecbd6fcf8e3484dea8db7806cee060c 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;
@@ -217,7 +217,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
-               sd->flag |= (bsdf) ? bsdf_microfacet_ggx_clearcoat_setup(bsdf) : 0;
+               sd->flag |= (bsdf) ? bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd) : 0;
        }
 };
 
@@ -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)
        };
@@ -389,7 +389,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
-               sd->flag |= (bsdf) ? bsdf_microfacet_ggx_fresnel_setup(bsdf) : 0;
+               sd->flag |= (bsdf) ? bsdf_microfacet_ggx_fresnel_setup(bsdf, sd) : 0;
        }
 };
 
@@ -413,7 +413,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
-               sd->flag |= (bsdf) ? bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf) : 0;
+               sd->flag |= (bsdf) ? bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf, sd) : 0;
        }
 };
 
@@ -566,7 +566,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
-               sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_fresnel_setup(bsdf) : 0;
+               sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_fresnel_setup(bsdf, sd) : 0;
        }
 };
 
@@ -590,7 +590,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
-               sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf) : 0;
+               sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf, sd) : 0;
        }
 };
 
@@ -618,7 +618,7 @@ public:
        void setup(ShaderData *sd, int path_flag, float3 weight)
        {
                MicrofacetBsdf *bsdf = alloc(sd, path_flag, weight);
-               sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf) : 0;
+               sd->flag |= (bsdf) ? bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd) : 0;
        }
 };
 
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..844245ee2d41a82b392496c5062fe67e4aeceb8e 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);
@@ -292,9 +292,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 
                                                /* setup bsdf */
                                                if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID || roughness <= 0.075f) /* use single-scatter GGX */
-                                                       sd->flag |= bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf);
+                                                       sd->flag |= bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf, sd);
                                                else /* use multi-scatter GGX */
-                                                       sd->flag |= bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf);
+                                                       sd->flag |= bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf, sd);
                                        }
                                }
 #ifdef __CAUSTICS_TRICKS__
@@ -332,7 +332,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                                                bsdf->extra->cspec0 = cspec0;
 
                                                                /* setup bsdf */
-                                                               sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf);
+                                                               sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
                                                        }
                                                }
 
@@ -377,7 +377,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
                                                        bsdf->extra->cspec0 = cspec0;
 
                                                        /* setup bsdf */
-                                                       sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf);
+                                                       sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
                                                }
                                        }
                                }
@@ -398,14 +398,14 @@ 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;
 
                                                /* setup bsdf */
-                                               sd->flag |= bsdf_microfacet_ggx_clearcoat_setup(bsdf);
+                                               sd->flag |= bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd);
                                        }
                                }
 #ifdef __CAUSTICS_TRICKS__
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 ce0b1b62d444bbb244bd4ef6842c72ee13994afc..f62e3602bb9cbf1c8e0ff7fce716fa1eacdfd60c 100644 (file)
@@ -643,26 +643,29 @@ class BUILTIN_KSI_DeltaScale(KeyingSetInfo):
 
 ###############################
 
+# Note that this controls order of options in 'insert keyframe' menu.
+# Better try to keep some logical order here beyond mere alphabetical one, also because of menu entries shortcut.
+# See also T51867.
 classes = (
     BUILTIN_KSI_Available,
-    BUILTIN_KSI_BendyBones,
-    BUILTIN_KSI_DeltaLocation,
-    BUILTIN_KSI_DeltaRotation,
-    BUILTIN_KSI_DeltaScale,
+    BUILTIN_KSI_Location,
+    BUILTIN_KSI_Rotation,
+    BUILTIN_KSI_Scaling,
     BUILTIN_KSI_LocRot,
     BUILTIN_KSI_LocRotScale,
     BUILTIN_KSI_LocScale,
-    BUILTIN_KSI_Location,
     BUILTIN_KSI_RotScale,
-    BUILTIN_KSI_Rotation,
-    BUILTIN_KSI_Scaling,
+    BUILTIN_KSI_DeltaLocation,
+    BUILTIN_KSI_DeltaRotation,
+    BUILTIN_KSI_DeltaScale,
     BUILTIN_KSI_VisualLoc,
+    BUILTIN_KSI_VisualRot,
+    BUILTIN_KSI_VisualScaling,
     BUILTIN_KSI_VisualLocRot,
     BUILTIN_KSI_VisualLocRotScale,
     BUILTIN_KSI_VisualLocScale,
-    BUILTIN_KSI_VisualRot,
     BUILTIN_KSI_VisualRotScale,
-    BUILTIN_KSI_VisualScaling,
+    BUILTIN_KSI_BendyBones,
     BUILTIN_KSI_WholeCharacter,
     BUILTIN_KSI_WholeCharacterSelected,
 )
index 041679ef8764db1e9e13c391ebb6e1f54d362c9d..21b9c75ac35d6b18d12cb27a17f19dfa128a7ced 100644 (file)
@@ -97,6 +97,7 @@ void BLI_rctf_union(struct rctf *rctf1, const struct rctf *rctf2);
 void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src);
 void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src);
 void BLI_rcti_rctf_copy_floor(struct rcti *dst, const struct rctf *src);
+void BLI_rcti_rctf_copy_round(struct rcti *dst, const struct rctf *src);
 
 void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, const float angle);
 
index fd24a00156d90114d26adecb488e13da8a80b473..e0c4cbe999055bf572fc0dc849c02c5fc291c231 100644 (file)
@@ -693,6 +693,14 @@ void BLI_rcti_rctf_copy_floor(rcti *dst, const rctf *src)
        dst->ymax = floorf(src->ymax);
 }
 
+void BLI_rcti_rctf_copy_round(rcti *dst, const rctf *src)
+{
+       dst->xmin = floorf(src->xmin + 0.5f);
+       dst->xmax = floorf(src->xmax + 0.5f);
+       dst->ymin = floorf(src->ymin + 0.5f);
+       dst->ymax = floorf(src->ymax + 0.5f);
+}
+
 void BLI_rctf_rcti_copy(rctf *dst, const rcti *src)
 {
        dst->xmin = src->xmin;
index 1b2f35b3fb102fb9cb9e96021297525c0bf363bc..b46095d3abb2a89da327d1dd490cc4f02f7eeac4 100644 (file)
@@ -165,6 +165,8 @@ typedef struct tGPsdata {
        bGPDbrush *brush; /* current drawing brush */
        short straight[2];   /* 1: line horizontal, 2: line vertical, other: not defined, second element position */
        int lock_axis;       /* lock drawing to one axis */
+
+       short keymodifier;   /* key used for invoking the operator */
 } tGPsdata;
 
 /* ------ */
@@ -1958,7 +1960,7 @@ static void gpencil_draw_cancel(bContext *C, wmOperator *op)
 /* ------------------------------- */
 
 
-static int gpencil_draw_init(bContext *C, wmOperator *op)
+static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
 {
        tGPsdata *p;
        eGPencil_PaintModes paintmode = RNA_enum_get(op->ptr, "mode");
@@ -1977,6 +1979,13 @@ static int gpencil_draw_init(bContext *C, wmOperator *op)
                gpencil_draw_exit(C, op);
                return 0;
        }
+
+       if (event != NULL) {
+               p->keymodifier = event->keymodifier;
+       }
+       else {
+               p->keymodifier = -1;
+       }
        
        /* everything is now setup ok */
        return 1;
@@ -2218,7 +2227,7 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
        /* printf("GPencil - Starting Re-Drawing\n"); */
        
        /* try to initialize context data needed while drawing */
-       if (!gpencil_draw_init(C, op)) {
+       if (!gpencil_draw_init(C, op, NULL)) {
                if (op->customdata) MEM_freeN(op->customdata);
                /* printf("\tGP - no valid data\n"); */
                return OPERATOR_CANCELLED;
@@ -2293,7 +2302,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
                printf("GPencil - Starting Drawing\n");
        
        /* try to initialize context data needed while drawing */
-       if (!gpencil_draw_init(C, op)) {
+       if (!gpencil_draw_init(C, op, event)) {
                if (op->customdata)
                        MEM_freeN(op->customdata);
                if (G.debug & G_DEBUG)
@@ -2456,7 +2465,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
                         *   is essential for ensuring that they can quickly return to that view
                         */
                }
-               else if ((ELEM(event->type, DKEY)) && (event->val == KM_RELEASE)) {
+               else if ((ELEM(event->type, p->keymodifier)) && (event->val == KM_RELEASE)) {
                        /* enable continuous if release D key in mid drawing */
                        p->scene->toolsettings->gpencil_flags |= GP_TOOL_FLAG_PAINTSESSIONS_ON;
                }
index d667a26cc89e9ac6159aabf12d9b7cb3ff589b4f..8a16b3077d58f5effabedb1d024125d948d6770f 100644 (file)
@@ -1338,7 +1338,7 @@ static void ui_but_to_pixelrect(rcti *rect, const ARegion *ar, uiBlock *block, u
        rctf rectf;
 
        ui_block_to_window_rctf(ar, block, &rectf, (but) ? &but->rect : &block->rect);
-       BLI_rcti_rctf_copy(rect, &rectf);
+       BLI_rcti_rctf_copy_round(rect, &rectf);
        BLI_rcti_translate(rect, -ar->winrct.xmin, -ar->winrct.ymin);
 }
 
index b5bf60e92c5668828156542cc48cd703dc52d02c..b8fa16117a992a38d6111c95bcb9bfd9ee6857e4 100644 (file)
@@ -3724,7 +3724,7 @@ static int screen_animation_cancel_exec(bContext *C, wmOperator *op)
        bScreen *screen = ED_screen_animation_playing(CTX_wm_manager(C));
 
        if (screen) {
-               if (RNA_boolean_get(op->ptr, "restore_frame")) {
+               if (RNA_boolean_get(op->ptr, "restore_frame") && screen->animtimer) {
                        ScreenAnimData *sad = screen->animtimer->customdata;
                        Scene *scene = CTX_data_scene(C);
 
index 28a94f8d78d00299693b33b71b7599c9d6039e65..889741485058f39351a65d272c2ddefd71e0d393 100644 (file)
@@ -2648,7 +2648,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
@@ -2657,7 +2657,7 @@ void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_rad
        float eta = (2.0 / (1.0 - sqrt(0.08 * specular))) - 1.0;
 
        /* set the viewing vector */
-       vec3 V = -normalize(I);
+       vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? -normalize(I) : vec3(0.0, 0.0, 1.0);
 
        /* get the tangent */
        vec3 Tangent = T;
@@ -2752,7 +2752,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 22d07d739cdf102b3fe92832c4d568b4a1e4f1e4..10422c8557954d3a83be97cc1bebc08ecb8c6e9c 100644 (file)
@@ -6320,14 +6320,8 @@ static void def_cmp_switch(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
-static void def_cmp_switch_view(StructRNA *srna)
+static void def_cmp_switch_view(StructRNA *UNUSED(srna))
 {
-       PropertyRNA *prop;
-
-       prop = RNA_def_property(srna, "check", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "custom1", 0);
-       RNA_def_property_ui_text(prop, "Switch", "Off: first socket, On: second socket");
-       RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
 static void def_cmp_colorcorrection(StructRNA *srna)
index d805cf4d87fa82fa036ab7f8b69770a2e80f157c..e0d9fa33f136ce900ea504eba04b1f8edd5a3d97 100644 (file)
@@ -137,7 +137,6 @@ static void init_switch_view(const bContext *C, PointerRNA *ptr)
        cmp_node_switch_view_sanitycheck(ntree, node);
 }
 
-/* custom1 = mix type */
 void register_node_type_cmp_switch_view(void)
 {
        static bNodeType ntype;
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},
index 7aaed4086ed87795c009993805a0de5ca3d6e717..7cff598e6ad4eae61fe2da8ab37a0414ea3f00ac 100644 (file)
@@ -930,15 +930,14 @@ void wm_draw_update(bContext *C)
        
        for (win = wm->windows.first; win; win = win->next) {
 #ifdef WIN32
-               if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
-                       GHOST_TWindowState state = GHOST_GetWindowState(win->ghostwin);
-
-                       if (state == GHOST_kWindowStateMinimized) {
-                               /* do not update minimized windows, it gives issues on intel drivers (see [#33223])
-                                * anyway, it seems logical to skip update for invisible windows
-                                */
-                               continue;
-                       }
+               GHOST_TWindowState state = GHOST_GetWindowState(win->ghostwin);
+
+               if (state == GHOST_kWindowStateMinimized) {
+                       /* do not update minimized windows, gives issues on Intel (see T33223)
+                        * and AMD (see T50856). it seems logical to skip update for invisible
+                        * window anyway.
+                        */
+                       continue;
                }
 #endif
                if (win->drawmethod != U.wmdrawmethod) {