[Bf-blender-cvs] [14ea0c5fccf] master: Fix T51849: change Cycles clearcoat gloss to roughness.

Brecht Van Lommel noreply at git.blender.org
Wed Jun 21 21:36:13 CEST 2017


Commit: 14ea0c5fccfdbd8d244758709185160e45222dc3
Author: Brecht Van Lommel
Date:   Wed Jun 21 19:24:57 2017 +0200
Branches: master
https://developer.blender.org/rB14ea0c5fccfdbd8d244758709185160e45222dc3

Fix T51849: change Cycles clearcoat gloss to roughness.

This is compatible with UE4 and more consistent with specular and transmission
roughness, even if it deviates from the original Disney BRDF.

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

M	intern/cycles/kernel/osl/osl_closures.cpp
M	intern/cycles/kernel/shaders/node_principled_bsdf.osl
M	intern/cycles/kernel/shaders/stdosl.h
M	intern/cycles/kernel/svm/svm_closure.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	source/blender/gpu/shaders/gpu_shader_material.glsl
M	source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c

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

diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp
index 5b66793a05d..f76fc0d6fea 100644
--- a/intern/cycles/kernel/osl/osl_closures.cpp
+++ b/intern/cycles/kernel/osl/osl_closures.cpp
@@ -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;
@@ -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)
 	};
diff --git a/intern/cycles/kernel/shaders/node_principled_bsdf.osl b/intern/cycles/kernel/shaders/node_principled_bsdf.osl
index 9d85d56ba78..2bb981c3918 100644
--- a/intern/cycles/kernel/shaders/node_principled_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_principled_bsdf.osl
@@ -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);
 	}
 }
 
diff --git a/intern/cycles/kernel/shaders/stdosl.h b/intern/cycles/kernel/shaders/stdosl.h
index 289d1091b0a..c91d2918687 100644
--- a/intern/cycles/kernel/shaders/stdosl.h
+++ b/intern/cycles/kernel/shaders/stdosl.h
@@ -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;
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index f3bbd7a7dac..c05da61ba5a 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -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);
@@ -398,8 +398,8 @@ 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;
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 57b475e5cd0..166156f7ac3 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -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"));
 }
 
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 687a86e3223..c6ab47fcc84 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -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,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list