[Bf-blender-cvs] [d52d8f2] cycles_disney_brdf: Removed the color parameters from the diffuse and sheen shader and use them as closure weights instead.

Pascal Schoen noreply at git.blender.org
Wed Oct 26 09:07:48 CEST 2016


Commit: d52d8f2813d64363713f11160a6c725d4cafbcfa
Author: Pascal Schoen
Date:   Mon Oct 24 16:17:13 2016 +0200
Branches: cycles_disney_brdf
https://developer.blender.org/rBd52d8f2813d64363713f11160a6c725d4cafbcfa

Removed the color parameters from the diffuse and sheen shader and use
them as closure weights instead.

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

M	intern/cycles/kernel/closure/bsdf_disney_diffuse.h
M	intern/cycles/kernel/closure/bsdf_disney_sheen.h
M	intern/cycles/kernel/closure/bssrdf.h
M	intern/cycles/kernel/kernel_subsurface.h
M	intern/cycles/kernel/osl/osl_closures.cpp
M	intern/cycles/kernel/shaders/node_disney_bsdf.osl
M	intern/cycles/kernel/shaders/stdosl.h
M	intern/cycles/kernel/svm/svm_closure.h

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

diff --git a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
index 580c476..9262203 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
@@ -29,7 +29,6 @@ typedef ccl_addr_space struct DisneyDiffuseBsdf {
 
 	float roughness;
 	float3 N;
-	float3 base_color;
 } DisneyDiffuseBsdf;
 
 ccl_device float3 calculate_disney_diffuse_brdf(const DisneyDiffuseBsdf *bsdf,
@@ -49,13 +48,13 @@ ccl_device float3 calculate_disney_diffuse_brdf(const DisneyDiffuseBsdf *bsdf,
     const float Fd90 = 0.5f + 2.0f * LdotH*LdotH * bsdf->roughness;
 	float Fd = (1.0f * (1.0f - FL) + Fd90 * FL) * (1.0f * (1.0f - FV) + Fd90 * FV); //lerp(1.0f, Fd90, FL) * lerp(1.0f, Fd90, FV);
 
-	float3 value = M_1_PI_F * Fd * bsdf->base_color;
+	float value = M_1_PI_F * Fd;
 
 	*pdf = M_1_PI_F * 0.5f;
 
 	value *= NdotL;
 
-	return value;
+	return make_float3(value, value, value);
 }
 
 ccl_device int bsdf_disney_diffuse_setup(DisneyDiffuseBsdf *bsdf)
@@ -69,7 +68,7 @@ ccl_device float3 bsdf_disney_diffuse_eval_reflect(const ShaderClosure *sc, cons
 {
 	const DisneyDiffuseBsdf *bsdf = (const DisneyDiffuseBsdf *)sc;
 
-	float3 N = normalize(bsdf->N);
+	float3 N = bsdf->N;
 	float3 V = I; // outgoing
 	float3 L = omega_in; // incoming
 	float3 H = normalize(L + V);
@@ -98,7 +97,7 @@ ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc,
 {
 	const DisneyDiffuseBsdf *bsdf = (const DisneyDiffuseBsdf *)sc;
 
-	float3 N = normalize(bsdf->N);
+	float3 N = bsdf->N;
 
 	sample_uniform_hemisphere(N, randu, randv, omega_in, pdf);
 
diff --git a/intern/cycles/kernel/closure/bsdf_disney_sheen.h b/intern/cycles/kernel/closure/bsdf_disney_sheen.h
index 75a3426..7d3b438 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_sheen.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_sheen.h
@@ -26,10 +26,7 @@ CCL_NAMESPACE_BEGIN
 
 typedef ccl_addr_space struct DisneySheenBsdf {
 	SHADER_CLOSURE_BASE;
-
-	float sheen, sheen_tint;
 	float3 N;
-	float3 base_color, csheen0;
 } DisneySheenBsdf;
 
 ccl_device float3 calculate_disney_sheen_brdf(const DisneySheenBsdf *bsdf,
@@ -38,7 +35,7 @@ ccl_device float3 calculate_disney_sheen_brdf(const DisneySheenBsdf *bsdf,
 	float NdotL = dot(N, L);
 	float NdotV = dot(N, V);
 
-    if(NdotL < 0 || NdotV < 0 || bsdf->sheen == 0.0f) {
+    if(NdotL < 0 || NdotV < 0) {
         *pdf = 0.0f;
         return make_float3(0.0f, 0.0f, 0.0f);
     }
@@ -49,22 +46,15 @@ ccl_device float3 calculate_disney_sheen_brdf(const DisneySheenBsdf *bsdf,
 
 	float FH = schlick_fresnel(LdotH);
 
-	float3 value = FH * bsdf->sheen * bsdf->csheen0;
+	float value = FH;
 
 	value *= NdotL;
 
-	return value;
+	return make_float3(value, value, value);
 }
 
 ccl_device int bsdf_disney_sheen_setup(DisneySheenBsdf *bsdf)
 {
-	float m_cdlum = 0.3f * bsdf->base_color.x + 0.6f * bsdf->base_color.y + 0.1f * bsdf->base_color.z; // luminance approx.
-
-	float3 m_ctint = m_cdlum > 0.0f ? bsdf->base_color / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
-
-	/* csheen0 */
-	bsdf->csheen0 = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - bsdf->sheen_tint) + m_ctint * bsdf->sheen_tint;
-
 	bsdf->type = CLOSURE_BSDF_DISNEY_SHEEN_ID;
 	return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
@@ -74,7 +64,7 @@ ccl_device float3 bsdf_disney_sheen_eval_reflect(const ShaderClosure *sc, const
 {
 	const DisneySheenBsdf *bsdf = (const DisneySheenBsdf *)sc;
 
-	float3 N = normalize(bsdf->N);
+	float3 N = bsdf->N;
 	float3 V = I; // outgoing
 	float3 L = omega_in; // incoming
 	float3 H = normalize(L + V);
@@ -103,7 +93,7 @@ ccl_device int bsdf_disney_sheen_sample(const ShaderClosure *sc,
 {
 	const DisneySheenBsdf *bsdf = (const DisneySheenBsdf *)sc;
 
-	float3 N = normalize(bsdf->N);
+	float3 N = bsdf->N;
 
 	sample_uniform_hemisphere(N, randu, randv, omega_in, pdf);
 
diff --git a/intern/cycles/kernel/closure/bssrdf.h b/intern/cycles/kernel/closure/bssrdf.h
index 87707df..a5a5783 100644
--- a/intern/cycles/kernel/closure/bssrdf.h
+++ b/intern/cycles/kernel/closure/bssrdf.h
@@ -365,16 +365,14 @@ ccl_device int bssrdf_setup(Bssrdf *bssrdf, ClosureType type)
 		int flag;
 		if(type == CLOSURE_BSSRDF_DISNEY_ID) {
 			float roughness = bssrdf->roughness;
-			float3 base_color = bssrdf->base_color;
 			float3 N = bssrdf->N;
-			float3 weight = bssrdf->weight;
+			float3 weight = bssrdf->weight * bssrdf->base_color;
 			float sample_weight = bssrdf->sample_weight;
 
 			DisneyDiffuseBsdf *bsdf = (DisneyDiffuseBsdf*)bssrdf;
 
 			bsdf->N = N;
 			bsdf->roughness = roughness;
-			bsdf->base_color = base_color;
 			bsdf->weight = weight;
 			bsdf->sample_weight = sample_weight;
 			flag = bsdf_disney_diffuse_setup(bsdf);
diff --git a/intern/cycles/kernel/kernel_subsurface.h b/intern/cycles/kernel/kernel_subsurface.h
index 6de56ac..908c2d0 100644
--- a/intern/cycles/kernel/kernel_subsurface.h
+++ b/intern/cycles/kernel/kernel_subsurface.h
@@ -150,12 +150,11 @@ ccl_device void subsurface_scatter_setup_diffuse_bsdf(ShaderData *sd, ShaderClos
 	if(hit) {
 		Bssrdf *bssrdf = (Bssrdf *)sc;
 		if(bssrdf->type == CLOSURE_BSSRDF_DISNEY_ID) {
-			DisneyDiffuseBsdf *bsdf = (DisneyDiffuseBsdf*)bsdf_alloc(sd, sizeof(DisneyDiffuseBsdf), weight);
+			DisneyDiffuseBsdf *bsdf = (DisneyDiffuseBsdf*)bsdf_alloc(sd, sizeof(DisneyDiffuseBsdf), weight * bssrdf->base_color);
 
 			if(bsdf) {
 				bsdf->N = N;
 				bsdf->roughness = bssrdf->roughness;
-				bsdf->base_color = bssrdf->base_color;
 				sd->flag |= bsdf_disney_diffuse_setup(bsdf);
 
 				/* replace CLOSURE_BSDF_DISNEY_DIFFUSE_ID with this special ID so render passes
diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp
index df17988..55258db 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -179,15 +179,11 @@ VOLUME_CLOSURE_CLASS_END(VolumeAbsorption, absorption)
 
 BSDF_CLOSURE_CLASS_BEGIN(DisneyDiffuse, disney_diffuse, DisneyDiffuseBsdf, LABEL_DIFFUSE)
 	CLOSURE_FLOAT3_PARAM(DisneyDiffuseClosure, params.N),
-	CLOSURE_FLOAT3_PARAM(DisneyDiffuseClosure, params.base_color),
 	CLOSURE_FLOAT_PARAM(DisneyDiffuseClosure, params.roughness),
 BSDF_CLOSURE_CLASS_END(DisneyDiffuse, disney_diffuse)
 
 BSDF_CLOSURE_CLASS_BEGIN(DisneySheen, disney_sheen, DisneySheenBsdf, LABEL_DIFFUSE)
 	CLOSURE_FLOAT3_PARAM(DisneySheenClosure, params.N),
-	CLOSURE_FLOAT3_PARAM(DisneySheenClosure, params.base_color),
-	CLOSURE_FLOAT_PARAM(DisneySheenClosure, params.sheen),
-	CLOSURE_FLOAT_PARAM(DisneySheenClosure, params.sheen_tint),
 BSDF_CLOSURE_CLASS_END(DisneySheen, disney_sheen)
 
 /* DISNEY CLEARCOAT */
diff --git a/intern/cycles/kernel/shaders/node_disney_bsdf.osl b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
index b4a9722..8fe8245 100644
--- a/intern/cycles/kernel/shaders/node_disney_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
@@ -48,6 +48,9 @@ shader node_disney_bsdf(
 
     vector T = Tangent;
 
+    float m_cdlum = 0.3 * BaseColor[0] + 0.6 * BaseColor[1] + 0.1 * BaseColor[2]; // luminance approx.
+    color m_ctint = m_cdlum > 0.0 ? BaseColor / m_cdlum : color(0.0, 0.0, 0.0); // normalize lum. to isolate hue+sat
+
     /* rotate tangent */
     if (AnisotropicRotation != 0.0)
         T = rotate(T, AnisotropicRotation * M_2PI, point(0.0, 0.0, 0.0), Normal);
@@ -56,11 +59,13 @@ shader node_disney_bsdf(
         if (Subsurface > 1e-5) {
             BSDF = bssrdf_disney(Normal, Subsurface * SubsurfaceRadius, 0.0, BaseColor, SubsurfaceColor, Roughness);
         } else {
-            BSDF = disney_diffuse(Normal, BaseColor, Roughness);
+            BSDF = BaseColor * disney_diffuse(Normal, Roughness);
         }
         
         if (Sheen > 1e-5) {
-            BSDF = BSDF + disney_sheen(Normal, BaseColor, Sheen, SheenTint);
+            color csheen0 = color(1.0, 1.0, 1.0) * (1.0 - SheenTint) + m_ctint * SheenTint;
+
+            BSDF = BSDF + csheen0 * Sheen * disney_sheen(Normal);
         }
         
         BSDF = BSDF * diffuse_weight;
@@ -73,8 +78,6 @@ shader node_disney_bsdf(
         float alpha_x = max(0.001, r2 / aspect);
         float alpha_y = max(0.001, r2 * aspect);
         
-        float m_cdlum = 0.3 * BaseColor[0] + 0.6 * BaseColor[1] + 0.1 * BaseColor[2]; // luminance approx.
-        color m_ctint = m_cdlum > 0.0 ? BaseColor / m_cdlum : color(0.0, 0.0, 0.0); // normalize lum. to isolate hue+sat
         color tmp_col = color(1.0, 1.0, 1.0) * (1.0 - SpecularTint) + m_ctint * SpecularTint;
         
         color Cspec0 = (Specular * 0.08 * tmp_col) * (1.0 - Metallic) + BaseColor * Metallic;
diff --git a/intern/cycles/kernel/shaders/stdosl.h b/intern/cycles/kernel/shaders/stdosl.h
index f050300..a756229 100644
--- a/intern/cycles/kernel/shaders/stdosl.h
+++ b/intern/cycles/kernel/shaders/stdosl.h
@@ -545,8 +545,8 @@ closure color emission() BUILTIN;
 closure color background() BUILTIN;
 closure color holdout() BUILTIN;
 closure color ambient_occlusion() BUILTIN;
-closure color disney_diffuse(normal N, color base_color, float roughness) BUILTIN;
-closure color disney_sheen(normal N, color base_color, float sheen, float sheen_tint) BUILTIN;
+closure color disney_diffuse(normal N, float roughness) BUILTIN;
+closure color disney_sheen(normal N) BUILTIN;
 closure color disney_clearcoat(normal N, float clearcoat, float clearcoat_gloss) BUILTIN;
 
 // BSSRDF
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index a9ba922..c5ea40a 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -153,13 +153,12 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			if(subsurface < CLOSURE_WEIGHT_CUTOFF) {
 				/* diffuse */
 				if(diffuse_weight > CLOSURE_WEIGHT_CUTOFF && fabsf(average(base_color)) > CLOSURE_WEIGHT_CUTOFF) {
-					float3 diff_weight = weight * diffuse_weight;
+					float3 diff_weight = weight * base_color * diffuse_weight;
 
 					DisneyDiffuseBsdf *bsdf = (DisneyDiffuseBsdf*)bsdf_alloc(sd, sizeof(DisneyDiffuseBsdf), diff_weight);
 
 					if(bsdf) {
 						bsdf->N = N;
-						bsdf->base_color = base_color;
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list