[Bf-blender-cvs] [243a0e3] cycles_disney_brdf: Switching between OSL and SVM is more consistant now when using Disney BSDF.

Pascal Schoen noreply at git.blender.org
Thu Oct 20 11:11:58 CEST 2016


Commit: 243a0e3eb80ef82704d5ea2657384c3a4b9fb497
Author: Pascal Schoen
Date:   Thu Oct 20 10:01:45 2016 +0200
Branches: cycles_disney_brdf
https://developer.blender.org/rB243a0e3eb80ef82704d5ea2657384c3a4b9fb497

Switching between OSL and SVM is more consistant now when using Disney
BSDF.

There were some minor differences in the OSL implementation, e.g. the
refraction roughness was missing.

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

M	intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
M	intern/cycles/kernel/shaders/node_disney_bsdf.osl
M	intern/cycles/kernel/svm/svm_closure.h

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

diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h b/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
index 97af724..11f3525 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_multi_impl.h
@@ -276,7 +276,7 @@ ccl_device float3 MF_FUNCTION_FULL_NAME(mf_sample)(float3 wi, float3 *wo, const
 		float FH = (fresnel_dielectric_cos(dot(wi, normalize(wi + wr)), eta) - F0) * F0_norm; //schlick_fresnel(dot(wi, normalize(wi + wr))); //
 		throughput2 = cspec0 * (1.0f - FH) + make_float3(1.0f, 1.0f, 1.0f) * FH;
 	}
-#else defined(MF_MULTI_GLOSSY)
+#elif defined(MF_MULTI_GLOSSY)
 	float3 t_color = cspec0;
 	float3 throughput2 = make_float3(1.0f, 1.0f, 1.0f);
 	float F0 = fresnel_dielectric_cos(1.0f, eta);
diff --git a/intern/cycles/kernel/shaders/node_disney_bsdf.osl b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
index 5372948..ae1addd 100644
--- a/intern/cycles/kernel/shaders/node_disney_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
@@ -18,9 +18,9 @@
 #include "node_fresnel.h"
 
 shader node_disney_bsdf(
-	string distribution = "Multiscatter GGX",
-	color BaseColor = color(0.64555527, 0.41514809, 0.01698805),
-	color SubsurfaceColor = color(0.64555527, 0.41514809, 0.01698805),
+    string distribution = "Multiscatter GGX",
+    color BaseColor = color(0.64555527, 0.41514809, 0.01698805),
+    color SubsurfaceColor = color(0.64555527, 0.41514809, 0.01698805),
     float Metallic = 0.0,
     float Subsurface = 0.0,
     float Specular = 0.5,
@@ -33,16 +33,23 @@ shader node_disney_bsdf(
     float ClearcoatGloss = 1.0,
     float IOR = 1.45,
     float Transparency = 0.0,
+    float RefractionRoughness = 0.0,
     float AnisotropicRotation = 0.0,
-	normal Normal = N,
-	normal ClearcoatNormal = N,
-	normal Tangent = normalize(dPdu),
-	output closure color BSDF = 0)
+    normal Normal = N,
+    normal ClearcoatNormal = N,
+    normal Tangent = normalize(dPdu),
+    output closure color BSDF = 0)
 {
-	float f = max(IOR, 1e-5);
+    float f = max(IOR, 1e-5);
     float diffuse_weight = (1.0 - clamp(Metallic, 0.0, 1.0)) * (1.0 - clamp(Transparency, 0.0, 1.0));
     float transp = clamp(Transparency, 0.0, 1.0) * (1.0 - clamp(Metallic, 0.0, 1.0));
     float specular_weight = (1.0 - transp);
+
+    vector T = Tangent;
+
+    /* rotate tangent */
+    if (AnisotropicRotation != 0.0)
+        T = rotate(T, AnisotropicRotation * M_2PI, point(0.0, 0.0, 0.0), Normal);
     
     if (diffuse_weight > 1e-5) {
         if (Subsurface > 1e-5) {
@@ -51,7 +58,7 @@ shader node_disney_bsdf(
             BSDF = disney_diffuse(Normal, BaseColor, Roughness);
         }
         
-        if (Sheen != 0.0) {
+        if (Sheen > 1e-5) {
             BSDF = BSDF + disney_sheen(Normal, BaseColor, Sheen, SheenTint);
         }
         
@@ -71,10 +78,10 @@ shader node_disney_bsdf(
         
         color Cspec0 = (Specular * 0.08 * tmp_col) * (1.0 - Metallic) + BaseColor * Metallic;
         
-        if (distribution == "Multiscatter GGX") {
-            BSDF = BSDF + specular_weight * microfacet_multi_ggx_aniso_fresnel(Normal, Tangent, alpha_x, alpha_y, (2.0 / (1.0 - sqrt(0.08 * Specular))) - 1.0, BaseColor, Cspec0);
+        if (distribution == "GGX" || Roughness <= 0.075) {
+            BSDF = BSDF  + specular_weight * microfacet_ggx_aniso_fresnel(Normal, T, alpha_x, alpha_y, (2.0 / (1.0 - sqrt(0.08 * Specular))) - 1.0, BaseColor, Cspec0);
         } else {
-            BSDF = BSDF  + specular_weight * microfacet_ggx_aniso_fresnel(Normal, Tangent, alpha_x, alpha_y, (2.0 / (1.0 - sqrt(0.08 * Specular))) - 1.0, BaseColor, Cspec0);
+            BSDF = BSDF + specular_weight * microfacet_multi_ggx_aniso_fresnel(Normal, T, alpha_x, alpha_y, (2.0 / (1.0 - sqrt(0.08 * Specular))) - 1.0, BaseColor, Cspec0);
         }
     }
     
@@ -82,19 +89,27 @@ shader node_disney_bsdf(
         color Cspec0 = BaseColor * SpecularTint + color(1.0, 1.0, 1.0) * (1.0 - SpecularTint);
         float eta = backfacing() ? 1.0 / f : f;
         
-        if (distribution == "Multiscatter GGX") {
-            BSDF = BSDF + transp * microfacet_multi_ggx_glass_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0);
-        } else {
+        if (distribution == "GGX" || Roughness <= 5e-2) {
             float cosNO = dot(Normal, I);
             float Fr = fresnel_dielectric_cos(cosNO, eta);
+
+            float refl_roughness = Roughness;
+            if (Roughness <= 1e-2)
+                refl_roughness = 0.0;
+
+            float refraction_roughness = refl_roughness;
+            if (distribution == "GGX")
+                refraction_roughness = 1.0 - (1.0 - refl_roughness) * (1.0 - RefractionRoughness);
             
-            BSDF = BSDF + transp * (Fr * microfacet_ggx_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0) +
-		                (1.0 - Fr) * BaseColor * microfacet_ggx_refraction(Normal, Roughness * Roughness, eta));
+            BSDF = BSDF + transp * (Fr * microfacet_ggx_fresnel(Normal, refl_roughness * refl_roughness, eta, BaseColor, Cspec0) +
+                        (1.0 - Fr) * BaseColor * microfacet_ggx_refraction(Normal, refraction_roughness * refraction_roughness, eta));
+        } else {
+            BSDF = BSDF + transp * microfacet_multi_ggx_glass_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0);
         }
     }
     
     if (Clearcoat > 1e-5) {
-        BSDF = BSDF + 0.25 * Clearcoat * disney_clearcoat(Normal, Clearcoat, ClearcoatGloss);
+        BSDF = BSDF + 0.25 * Clearcoat * disney_clearcoat(ClearcoatNormal, Clearcoat, ClearcoatGloss);
     }
 }
 
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index 8aca266..a4536bb 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -153,7 +153,6 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 				/* diffuse */
 				if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF && fabsf(average(baseColor)) > CLOSURE_WEIGHT_CUTOFF) {
 					float3 diff_weight = weight * diffuse_weight;
-					float diff_sample_weight = fabsf(average(diff_weight));
 
 					DisneyDiffuseBsdf *bsdf = (DisneyDiffuseBsdf*)bsdf_alloc(sd, sizeof(DisneyDiffuseBsdf), diff_weight);
 
@@ -186,6 +185,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 					bssrdf->N = N;
 					bssrdf->baseColor = baseColor;
 					bssrdf->roughness = roughness;
+
+					/* setup bsdf */
 					ccl_fetch(sd, flag) |= bssrdf_setup(bssrdf, (ClosureType)CLOSURE_BSSRDF_DISNEY_ID);
 				}
 
@@ -199,6 +200,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 					bssrdf->N = N;
 					bssrdf->baseColor = baseColor;
 					bssrdf->roughness = roughness;
+
+					/* setup bsdf */
 					ccl_fetch(sd, flag) |= bssrdf_setup(bssrdf, (ClosureType)CLOSURE_BSSRDF_DISNEY_ID);
 				}
 
@@ -212,14 +215,15 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 					bssrdf->N = N;
 					bssrdf->baseColor = baseColor;
 					bssrdf->roughness = roughness;
+
+					/* setup bsdf */
 					ccl_fetch(sd, flag) |= bssrdf_setup(bssrdf, (ClosureType)CLOSURE_BSSRDF_DISNEY_ID);
 				}
 			}
 #else
 			/* diffuse */
-			if (diffuse_weight > 0.0f) {
+			if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
 				float3 diff_weight = weight * diffuse_weight;
-				float diff_sample_weight = fabsf(average(diff_weight));
 
 				DisneyDiffuseBsdf *bsdf = (DisneyDiffuseBsdf*)bsdf_alloc(sd, sizeof(DisneyDiffuseBsdf), diff_weight);
 
@@ -234,13 +238,11 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			}
 #endif
 
-			float sheen_diffuse_weight = diffuse_weight * 1.0f + (1.0f - diffuse_weight) * transp;
             /* sheen */
-			if (sheen_diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
-				float3 sheen_weight = weight * sheen_diffuse_weight;
-				float sheen_sample_weight = fabsf(average(sheen_weight));
+			if (diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
+				float3 sheen_weight = weight * diffuse_weight;
 
-				DisneySheenBsdf *bsdf = (DisneySheenBsdf*)bsdf_alloc(sd, sizeof(DisneySheenBsdf), weight);
+				DisneySheenBsdf *bsdf = (DisneySheenBsdf*)bsdf_alloc(sd, sizeof(DisneySheenBsdf), sheen_weight);
 
 				if (bsdf) {
 					bsdf->N = N;
@@ -258,7 +260,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			if (kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
 #endif
 				if (specular_weight > CLOSURE_WEIGHT_CUTOFF && (specular > CLOSURE_WEIGHT_CUTOFF || metallic > CLOSURE_WEIGHT_CUTOFF)) {
-					float3 spec_weight = weight * specular_weight/* * (specular * (1.0f - metallic) + metallic)*/;
+					float3 spec_weight = weight * specular_weight;
 
 					MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), spec_weight);
 					MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
@@ -279,14 +281,14 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 						float3 m_ctint = m_cdlum > 0.0f ? baseColor / m_cdlum : make_float3(0.0f, 0.0f, 0.0f); // normalize lum. to isolate hue+sat
 						float3 tmp_col = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specularTint) + m_ctint * specularTint;
 
-						bsdf->extra->cspec0 = (/*fresnel_dielectric_cos(1.0f, ior)*/specular * 0.08f * tmp_col) * (1.0f - metallic) + baseColor * metallic;
+						bsdf->extra->cspec0 = (specular * 0.08f * tmp_col) * (1.0f - metallic) + baseColor * metallic;
 						bsdf->extra->color = baseColor;
 
 						/* setup bsdf */
-						if (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID && roughness > 0.075f)
-							ccl_fetch(sd, flag) |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf, true);
-						else
+						if (distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID || roughness <= 0.075f) /* use single-scatter GGX */
 							ccl_fetch(sd, flag) |= bsdf_microfacet_ggx_aniso_setup(bsdf, true);
+						else /* use multi-scatter GGX */
+							ccl_fetch(sd, flag) |= 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list