[Bf-blender-cvs] [218202c] cycles_disney_brdf: Added an additional normal for the clearcoat

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


Commit: 218202c0905a4ec93ee19850360d1a39966d2c25
Author: Pascal Schoen
Date:   Mon May 30 15:08:18 2016 +0200
Branches: cycles_disney_brdf
https://developer.blender.org/rB218202c0905a4ec93ee19850360d1a39966d2c25

Added an additional normal for the clearcoat

With this normal one can simulate a thin layer of clearcoat by applying a
smoother normal map than the original to this input

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

M	intern/cycles/kernel/shaders/node_disney_bsdf.osl
M	intern/cycles/kernel/svm/svm_closure.h
M	intern/cycles/render/nodes.cpp
M	source/blender/nodes/shader/nodes/node_shader_bsdf_disney.c

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

diff --git a/intern/cycles/kernel/shaders/node_disney_bsdf.osl b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
index 8cd80d6..c6d75c4 100644
--- a/intern/cycles/kernel/shaders/node_disney_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_disney_bsdf.osl
@@ -29,6 +29,7 @@ shader node_disney_bsdf(
     float Clearcoat = 0.0,
     float ClearcoatGloss = 1.0,
 	normal Normal = N,
+	normal ClearcoatNormal = N,
 	normal Tangent = normalize(dPdu),
     //normal AnisotropicRotation = normal(0, 0, 0),
 	output closure color BSDF = 0)
@@ -44,7 +45,7 @@ shader node_disney_bsdf(
     }
 
     if (Clearcoat != 0.0) {
-        BSDF = BSDF + disney_clearcoat(Normal, Clearcoat, ClearcoatGloss);
+        BSDF = BSDF + disney_clearcoat(ClearcoatNormal, Clearcoat, ClearcoatGloss);
     }
 
 	/*if (Metallic == 1.0) {
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index 381e92a..fadddbc 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -156,6 +156,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			uint4 data_base_color = read_node(kg, offset);
 			float3 baseColor = stack_valid(data_base_color.x) ? stack_load_float3(stack, data_base_color.x) :
 				make_float3(__uint_as_float(data_base_color.y), __uint_as_float(data_base_color.z), __uint_as_float(data_base_color.w));
+
+			uint4 data_clearcoat_normal = read_node(kg, offset);
+			float3 CN = stack_valid(data_clearcoat_normal.x) ? stack_load_float3(stack, data_clearcoat_normal.x) : ccl_fetch(sd, N);
             
 			ShaderClosure *sc = ccl_fetch_array(sd, closure, ccl_fetch(sd, num_closure));
 			float3 weight = sc->weight;
@@ -304,7 +307,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 					sc = svm_node_closure_get_bsdf(sd, mix_weight/* * mix(0.333f, 0.5f, clamp(metallic, 0.0f, 1.0f))*/);
 
 					if (sc) {
-						sc->N = N;
+						sc->N = CN;
 
 						sc->data0 = clearcoat;
 						sc->data1 = clearcoatGloss;
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 239bf39..31f2664 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -2126,6 +2126,7 @@ DisneyBsdfNode::DisneyBsdfNode()
 	add_input("Clearcoat", SHADER_SOCKET_FLOAT, 0.0f);
 	add_input("ClearcoatGloss", SHADER_SOCKET_FLOAT, 1.0f);
 	add_input("Normal", SHADER_SOCKET_NORMAL, ShaderInput::NORMAL);
+	add_input("ClearcoatNormal", SHADER_SOCKET_NORMAL, ShaderInput::NORMAL);
 	add_input("Tangent", SHADER_SOCKET_VECTOR, ShaderInput::TANGENT);
 	add_input("SurfaceMixWeight", SHADER_SOCKET_FLOAT, 0.0f, ShaderInput::USE_SVM);
 
@@ -2138,6 +2139,7 @@ void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *metallic, Shade
 {
 	ShaderInput *base_color_in = input("BaseColor");
 	ShaderInput *normal_in = input("Normal");
+	ShaderInput *clearcoat_normal_in = input("ClearcoatNormal");
 	ShaderInput *tangent_in = input("Tangent");
 
 	float3 weight = make_float3(1.0f, 1.0f, 1.0f);
@@ -2149,6 +2151,7 @@ void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *metallic, Shade
 	compiler.add_node(NODE_CLOSURE_SET_WEIGHT, weight);
 
 	int normal_offset = compiler.stack_assign_if_linked(normal_in);
+	int clearcoat_normal_offset = compiler.stack_assign_if_linked(clearcoat_normal_in);
 	int tangent_offset = compiler.stack_assign_if_linked(tangent_in);
 	int specular_offset = compiler.stack_assign(specular);
 	int roughness_offset = compiler.stack_assign(roughness);
@@ -2170,11 +2173,11 @@ void DisneyBsdfNode::compile(SVMCompiler& compiler, ShaderInput *metallic, Shade
 	compiler.add_node(normal_offset, tangent_offset,
 		compiler.encode_uchar4(specular_offset, roughness_offset, specularTint_offset, anisotropic_offset),
 		compiler.encode_uchar4(sheen_offset, sheenTint_offset, clearcoat_offset, clearcoatGloss_offset));
-	//compiler.add_node(specularTint_offset, anisotropy_offset, sheen_offset, sheenTint_offset);
-	//compiler.add_node(clearcoat_offset, clearcoatGloss_offset, SVM_STACK_INVALID, SVM_STACK_INVALID);
 
 	compiler.add_node(((base_color_in->link) ? compiler.stack_assign(base_color_in) : SVM_STACK_INVALID),
 		__float_as_int(base_color_in->value.x), __float_as_int(base_color_in->value.y), __float_as_int(base_color_in->value.z));
+
+	compiler.add_node(clearcoat_normal_offset, SVM_STACK_INVALID, SVM_STACK_INVALID, SVM_STACK_INVALID);
 }
 
 void DisneyBsdfNode::compile(SVMCompiler& compiler)
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_disney.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_disney.c
index d2db4d9..9c46d20 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_disney.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_disney.c
@@ -41,7 +41,8 @@ static bNodeSocketTemplate sh_node_bsdf_disney_in[] = {
 	{	SOCK_FLOAT, 1, N_("SheenTint"),	            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_("ClearcoatGloss"),        1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
-	{	SOCK_VECTOR, 1, N_("Normal"),	            0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+	{   SOCK_VECTOR, 1, N_("Normal"),               0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+	{   SOCK_VECTOR, 1, N_("ClearcoatNormal"),      0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
 	{	SOCK_VECTOR, 1, N_("Tangent"),	            0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
 	//{	SOCK_VECTOR, 1, N_("AnisotropicRotation"),  0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
 	{	-1, 0, ""	}




More information about the Bf-blender-cvs mailing list