[Bf-blender-cvs] [d4b814e] cycles_disney_brdf: Switched from a parameter struct for Disney parameters to ShaderClosure params

Pascal Schoen noreply at git.blender.org
Mon May 30 09:09:02 CEST 2016


Commit: d4b814e9304ebb44cc7c291cd83f7b7cdebcd152
Author: Pascal Schoen
Date:   Wed May 18 10:22:29 2016 +0200
Branches: cycles_disney_brdf
https://developer.blender.org/rBd4b814e9304ebb44cc7c291cd83f7b7cdebcd152

Switched from a parameter struct for Disney parameters to ShaderClosure params

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

M	intern/cycles/kernel/closure/bsdf_disney_clearcoat.h
M	intern/cycles/kernel/closure/bsdf_disney_diffuse.h
M	intern/cycles/kernel/closure/bsdf_disney_specular.h
M	intern/cycles/kernel/osl/bsdf_disney_clearcoat.cpp
M	intern/cycles/kernel/osl/bsdf_disney_diffuse.cpp
M	intern/cycles/kernel/osl/bsdf_disney_specular.cpp
M	intern/cycles/kernel/svm/svm_types.h

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

diff --git a/intern/cycles/kernel/closure/bsdf_disney_clearcoat.h b/intern/cycles/kernel/closure/bsdf_disney_clearcoat.h
index 0300c56..a96fc46 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_clearcoat.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_clearcoat.h
@@ -35,8 +35,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-/* structures */
-struct DisneyClearcoatBRDFParams {
+/*struct DisneyClearcoatBRDFParams {
     // brdf parameters
     float m_clearcoat;
     float m_clearcoatGloss;
@@ -49,21 +48,24 @@ struct DisneyClearcoatBRDFParams {
     }
 };
 
-typedef struct DisneyClearcoatBRDFParams DisneyClearcoatBRDFParams;
+typedef struct DisneyClearcoatBRDFParams DisneyClearcoatBRDFParams;*/
 
 
 ccl_device int bsdf_disney_clearcoat_setup(ShaderClosure *sc)
 {
+	/* clearcoat roughness */
+	sc->custom1 = mix(0.1f, 0.001f, sc->data1);
+
     sc->type = CLOSURE_BSDF_DISNEY_CLEARCOAT_ID;
     return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
 
 ccl_device float3 bsdf_disney_clearcoat_eval_reflect(const ShaderClosure *sc,
-    const DisneyClearcoatBRDFParams *params, const float3 I,
+    /*const DisneyClearcoatBRDFParams *params, */const float3 I,
     const float3 omega_in, float *pdf)
 {
-	if (params->m_clearcoat > 0.0f) {
-		float alpha = params->m_clearcoatRoughness;
+	if (sc->data0 > 0.0f) {
+		float alpha = sc->custom1;
 		float3 N = sc->N;
 
 		if (alpha <= 1e-4f)
@@ -100,7 +102,7 @@ ccl_device float3 bsdf_disney_clearcoat_eval_reflect(const ShaderClosure *sc,
 			float FH = schlick_fresnel(dot(omega_in, m));
 			float3 F = mix(make_float3(0.04f, 0.04f, 0.04f), make_float3(1.0f, 1.0f, 1.0f), FH);
 
-			float3 out = F * G * common * 0.25f * params->m_clearcoat;
+			float3 out = F * G * common * 0.25f * sc->data0;
 
 			/* eq. 2 in distribution of visible normals sampling
 			 * pm = Dw = G1o * dot(m, I) * D / dot(N, I); */
@@ -122,13 +124,13 @@ ccl_device float3 bsdf_disney_clearcoat_eval_transmit(const ShaderClosure *sc, c
     return make_float3(0.0f, 0.0f, 0.0f);
 }
 
-ccl_device int bsdf_disney_clearcoat_sample(const ShaderClosure *sc, const DisneyClearcoatBRDFParams *params,
+ccl_device int bsdf_disney_clearcoat_sample(const ShaderClosure *sc, /*const DisneyClearcoatBRDFParams *params,*/
     float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv,
     float3 *eval, float3 *omega_in, float3 *domega_in_dx,
     float3 *domega_in_dy, float *pdf)
 {
-	if (params->m_clearcoat > 0.0f) {
-		float alpha = params->m_clearcoatRoughness;
+	if (sc->data0 > 0.0f) {
+		float alpha = sc->custom1;
 		float3 N = sc->N;
 
 		float cosNO = dot(N, I);
@@ -189,7 +191,7 @@ ccl_device int bsdf_disney_clearcoat_sample(const ShaderClosure *sc, const Disne
 						float FH = schlick_fresnel(dot(*omega_in, m));
 						float3 F = mix(make_float3(0.04f, 0.04f, 0.04f), make_float3(1.0f, 1.0f, 1.0f), FH);
 
-						*eval = G1i * common * F * 0.25f * params->m_clearcoat;
+						*eval = G1i * common * F * 0.25f * sc->data0;
 					}
 
 #ifdef __RAY_DIFFERENTIALS__
diff --git a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
index 3e44277..85a5db4 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_diffuse.h
@@ -36,7 +36,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-struct DisneyDiffuseBRDFParams {
+/*struct DisneyDiffuseBRDFParams {
 	// brdf parameters
 	float3 m_base_color;
 	float m_subsurface;
@@ -45,23 +45,21 @@ struct DisneyDiffuseBRDFParams {
 	float m_sheen_tint;
 
 	// precomputed values
-	float3 m_cdlin, m_ctint, m_csheen;
-	float m_cdlum;
+	float3 m_csheen;
 
 	void precompute_values() {
-		m_cdlin = m_base_color;
-		m_cdlum = 0.3f * m_cdlin[0] + 0.6f * m_cdlin[1] + 0.1f * m_cdlin[2]; // luminance approx.
+		float m_cdlum = 0.3f * m_base_color[0] + 0.6f * m_base_color[1] + 0.1f * m_base_color[2]; // luminance approx.
 
-		m_ctint = m_cdlum > 0.0f ? m_cdlin / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
+		float3 m_ctint = m_cdlum > 0.0f ? m_base_color / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
 		m_csheen = mix(make_float3(1.0f, 1.0f, 1.0f), m_ctint, m_sheen_tint);
 	}
 };
 
-typedef struct DisneyDiffuseBRDFParams DisneyDiffuseBRDFParams;
+typedef struct DisneyDiffuseBRDFParams DisneyDiffuseBRDFParams;*/
 
 
 ccl_device float3 calculate_disney_diffuse_brdf(const ShaderClosure *sc,
-	const DisneyDiffuseBRDFParams *params, float3 N, float3 V, float3 L,
+	/*const DisneyDiffuseBRDFParams *params, */float3 N, float3 V, float3 L,
 	float3 H, float *pdf)
 {
 	float NdotL = dot(N, L);
@@ -77,27 +75,27 @@ ccl_device float3 calculate_disney_diffuse_brdf(const ShaderClosure *sc,
     float Fd = 0.0f;
 	float FL = schlick_fresnel(NdotL), FV = schlick_fresnel(NdotV);
 
-    if (params->m_subsurface != 1.0f) {
-	    const float Fd90 = 0.5f + 2.0f * LdotH*LdotH * params->m_roughness;
+	if (sc->data0 != 1.0f) {
+	    const float Fd90 = 0.5f + 2.0f * LdotH*LdotH * sc->data1;
 	    Fd = mix(1.0f, Fd90, FL) * mix(1.0f, Fd90, FV);
     }
 
-    if (params->m_subsurface > 0.0f) {
-	    float Fss90 = LdotH*LdotH * params->m_roughness;
+    if (sc->data0 > 0.0f) {
+	    float Fss90 = LdotH*LdotH * sc->data1;
 	    float Fss = mix(1.0f, Fss90, FL) * mix(1.0f, Fss90, FV);
 	    float ss = 1.25f * (Fss * (1.0f / (NdotL + NdotV) - 0.5f) + 0.5f);
-        Fd = mix(Fd, ss, params->m_subsurface);
+        Fd = mix(Fd, ss, sc->data0);
     }
 
-	float3 value = M_1_PI_F * Fd * params->m_cdlin;
+	float3 value = M_1_PI_F * Fd * sc->color0;
 
 	*pdf = M_1_PI_F * 0.5f;
 
 	// sheen component
-	if (params->m_sheen != 0.0f) {
+	if (sc->data2 != 0.0f) {
 		float FH = schlick_fresnel(LdotH);
 
-		value += FH * params->m_sheen * params->m_csheen;
+		value += FH * sc->data2 * sc->custom_color0;
 	}
 
 	value *= NdotL;
@@ -107,12 +105,19 @@ ccl_device float3 calculate_disney_diffuse_brdf(const ShaderClosure *sc,
 
 ccl_device int bsdf_disney_diffuse_setup(ShaderClosure *sc)
 {
+	float m_cdlum = 0.3f * sc->color0[0] + 0.6f * sc->color0[1] + 0.1f * sc->color0[2]; // luminance approx.
+
+	float3 m_ctint = m_cdlum > 0.0f ? sc->color0 / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
+
+	/* csheen0 */
+	sc->custom_color0 = mix(make_float3(1.0f, 1.0f, 1.0f), m_ctint, sc->data3);
+
 	sc->type = CLOSURE_BSDF_DISNEY_DIFFUSE_ID;
 	return SD_BSDF|SD_BSDF_HAS_EVAL;
 }
 
 ccl_device float3 bsdf_disney_diffuse_eval_reflect(const ShaderClosure *sc,
-	const DisneyDiffuseBRDFParams *params, const float3 I,
+	/*const DisneyDiffuseBRDFParams *params, */const float3 I,
 	const float3 omega_in, float *pdf)
 {
 	float3 N = normalize(sc->N);
@@ -121,7 +126,7 @@ ccl_device float3 bsdf_disney_diffuse_eval_reflect(const ShaderClosure *sc,
 	float3 H = normalize(L + V);
 
     if (dot(sc->N, omega_in) > 0.0f) {
-        float3 value = calculate_disney_diffuse_brdf(sc, params, N, V, L, H, pdf);
+        float3 value = calculate_disney_diffuse_brdf(sc, /*params, */N, V, L, H, pdf);
 
 		return value;
     }
@@ -136,7 +141,7 @@ ccl_device float3 bsdf_disney_diffuse_eval_transmit(const ShaderClosure *sc, con
 	return make_float3(0.0f, 0.0f, 0.0f);
 }
 
-ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc, const DisneyDiffuseBRDFParams *params,
+ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc, /*const DisneyDiffuseBRDFParams *params,*/
 	float3 Ng, float3 I, float3 dIdx, float3 dIdy, float randu, float randv,
 	float3 *eval, float3 *omega_in, float3 *domega_in_dx,
 	float3 *domega_in_dy, float *pdf)
@@ -148,7 +153,7 @@ ccl_device int bsdf_disney_diffuse_sample(const ShaderClosure *sc, const DisneyD
 	if (dot(Ng, *omega_in) > 0) {
 		float3 H = normalize(I + *omega_in);
 
-		*eval = calculate_disney_diffuse_brdf(sc, params, N, I, *omega_in, H, pdf);
+		*eval = calculate_disney_diffuse_brdf(sc, /*params, */N, I, *omega_in, H, pdf);
 
 #ifdef __RAY_DIFFERENTIALS__
 		// TODO: find a better approximation for the diffuse bounce
diff --git a/intern/cycles/kernel/closure/bsdf_disney_specular.h b/intern/cycles/kernel/closure/bsdf_disney_specular.h
index 904d0f2..44dd103 100644
--- a/intern/cycles/kernel/closure/bsdf_disney_specular.h
+++ b/intern/cycles/kernel/closure/bsdf_disney_specular.h
@@ -35,7 +35,7 @@
 
 CCL_NAMESPACE_BEGIN
 
-struct DisneySpecularBRDFParams {
+/*struct DisneySpecularBRDFParams {
     // brdf parameters
     float3 m_base_color;
     float m_metallic;
@@ -45,16 +45,15 @@ struct DisneySpecularBRDFParams {
     float m_anisotropic;
 
     // precomputed values
-    float3 m_cdlin, m_ctint, m_cspec0;
-    float m_cdlum;
+    float3 m_cspec0;
     float m_ax, m_ay;
     float m_roughg;
 
     void precompute_values() {
-        m_cdlin = m_base_color;
-        m_cdlum = 0.3f * m_cdlin[0] + 0.6f * m_cdlin[1] + 0.1f * m_cdlin[2]; // luminance approx.
+        float3 m_cdlin = m_base_color;
+        float m_cdlum = 0.3f * m_cdlin[0] + 0.6f * m_cdlin[1] + 0.1f * m_cdlin[2]; // luminance approx.
 
-        m_ctint = m_cdlum > 0.0f ? m_cdlin / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
+        float3 m_ctint = m_cdlum > 0.0f ? m_cdlin / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
 
 		m_cspec0 = mix(m_specular * 0.08f * mix(make_float3(1.0f, 1.0f, 1.0f),
 			m_ctint, m_specular_tint), m_cdlin, m_metallic);
@@ -68,21 +67,40 @@ struct DisneySpecularBRDFParams {
     }
 };
 
-typedef struct DisneySpecularBRDFParams DisneySpecularBRDFParams;
+typedef struct DisneySpecularBRDFParams DisneySpecularBRDFParams;*/
 
 
 ccl_device int bsdf_disney_specular_setup(ShaderClosure *sc)
 {
+	float m_cdlum = 0.3f * sc->color0[0] + 0.6f * sc->color0[1] + 0.1f * sc->color0[2]; // luminance approx.
+
+	float3 m_ctint = m_cdlum > 0.0f ? sc->color0 / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
+
+	sc->custom_color0 = mix(sc->data1 * 0.08f * mix(make_float3(1.0f, 1.0f, 1.0f),
+		m_ctint, sc->data2), sc->color0, sc->data0);
+
+	float aspect = sqrt(1.0f - sc->data4 * 0.9f);
+	float r2 = sqr(sc->data3);
+	
+	/* ax */
+	sc->custom1 = fmaxf(0.001f, r2 / aspect);
+
+	/* ay */
+	sc->custom2 = fmaxf(0.001f, r2 * aspect);
+
+	/* rough_g */
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list