[Bf-blender-cvs] [32c9d2322cc] master: Fix T51408: Cycles - Principled BSDF Shader - Transparency is not working as expected

Pascal Schoen noreply at git.blender.org
Thu May 18 13:18:41 CEST 2017


Commit: 32c9d2322ccbf1bcfbe8a320d1e334d5e5d63d7b
Author: Pascal Schoen
Date:   Thu May 18 13:15:32 2017 +0200
Branches: master
https://developer.blender.org/rB32c9d2322ccbf1bcfbe8a320d1e334d5e5d63d7b

Fix T51408: Cycles - Principled BSDF Shader - Transparency is not working as expected

Renamed the "Transparency" input of the Principled BSDF to
"Transmission" and "Refraction Roughness" to "Transmission Roughness".

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

M	intern/cycles/kernel/shaders/node_principled_bsdf.osl
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/shaders/node_principled_bsdf.osl b/intern/cycles/kernel/shaders/node_principled_bsdf.osl
index 39c6c7e5fd9..57f40789d49 100644
--- a/intern/cycles/kernel/shaders/node_principled_bsdf.osl
+++ b/intern/cycles/kernel/shaders/node_principled_bsdf.osl
@@ -34,17 +34,17 @@ shader node_principled_bsdf(
 	float Clearcoat = 0.0,
 	float ClearcoatGloss = 1.0,
 	float IOR = 1.45,
-	float Transparency = 0.0,
-	float RefractionRoughness = 0.0,
+	float Transmission = 0.0,
+	float TransmissionRoughness = 0.0,
 	normal Normal = N,
 	normal ClearcoatNormal = N,
 	normal Tangent = normalize(dPdu),
 	output closure color BSDF = 0)
 {
 	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);
+	float diffuse_weight = (1.0 - clamp(Metallic, 0.0, 1.0)) * (1.0 - clamp(Transmission, 0.0, 1.0));
+	float final_transmission = clamp(Transmission, 0.0, 1.0) * (1.0 - clamp(Metallic, 0.0, 1.0));
+	float specular_weight = (1.0 - final_transmission);
 
 	vector T = Tangent;
 
@@ -90,7 +90,7 @@ shader node_principled_bsdf(
 		}
 	}
 
-	if (transp > 1e-5) {
+	if (final_transmission > 1e-5) {
 		color Cspec0 = BaseColor * SpecularTint + color(1.0, 1.0, 1.0) * (1.0 - SpecularTint);
 		float eta = backfacing() ? 1.0 / f : f;
 
@@ -98,18 +98,18 @@ shader node_principled_bsdf(
 			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 refl_roughness = Roughness;
+			if (Roughness <= 1e-2)
+				refl_roughness = 0.0;
 
-			float refraction_roughness = refl_roughness;
+			float transmission_roughness = refl_roughness;
 			if (distribution == "GGX")
-				refraction_roughness = 1.0 - (1.0 - refl_roughness) * (1.0 - RefractionRoughness);
+				transmission_roughness = 1.0 - (1.0 - refl_roughness) * (1.0 - TransmissionRoughness);
 
-			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));
+			BSDF = BSDF + final_transmission * (Fr * microfacet_ggx_fresnel(Normal, refl_roughness * refl_roughness, eta, BaseColor, Cspec0) +
+			       (1.0 - Fr) * BaseColor * microfacet_ggx_refraction(Normal, transmission_roughness * transmission_roughness, eta));
 		} else {
-			BSDF = BSDF + transp * microfacet_multi_ggx_glass_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0);
+			BSDF = BSDF + final_transmission * microfacet_multi_ggx_glass_fresnel(Normal, Roughness * Roughness, eta, BaseColor, Cspec0);
 		}
 	}
 
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
index 7918c640175..0e1aedf2918 100644
--- a/intern/cycles/kernel/svm/svm_closure.h
+++ b/intern/cycles/kernel/svm/svm_closure.h
@@ -79,14 +79,14 @@ 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, transparency_offset,
-				anisotropic_rotation_offset, refraction_roughness_offset;
+				sheen_tint_offset, clearcoat_offset, clearcoat_gloss_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_node2.x, &eta_offset, &transparency_offset, &anisotropic_rotation_offset, &refraction_roughness_offset);
+			decode_node_uchar4(data_node2.x, &eta_offset, &transmission_offset, &anisotropic_rotation_offset, &transmission_roughness_offset);
 
 			// get Disney principled parameters
 			float metallic = param1;
@@ -99,9 +99,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			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 transparency = stack_load_float(stack, transparency_offset);
+			float transmission = stack_load_float(stack, transmission_offset);
 			float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
-			float refraction_roughness = stack_load_float(stack, refraction_roughness_offset);
+			float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
 			float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
 
 			ClosureType distribution = stack_valid(data_node2.y) ? (ClosureType) data_node2.y : CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
@@ -118,10 +118,10 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 			float fresnel = fresnel_dielectric_cos(cosNO, ior);
 
 			// calculate weights of the diffuse and specular part
-			float diffuse_weight = (1.0f - saturate(metallic)) * (1.0f - saturate(transparency));
+			float diffuse_weight = (1.0f - saturate(metallic)) * (1.0f - saturate(transmission));
 			
-			float transp = saturate(transparency) * (1.0f - saturate(metallic));
-			float specular_weight = (1.0f - transp);
+			float final_transmission = saturate(transmission) * (1.0f - saturate(metallic));
+			float specular_weight = (1.0f - final_transmission);
 
 			// get the base color
 			uint4 data_base_color = read_node(kg, offset);
@@ -300,8 +300,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 #ifdef __CAUSTICS_TRICKS__
 			if(kernel_data.integrator.caustics_reflective || kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0) {
 #endif
-				if(transp > CLOSURE_WEIGHT_CUTOFF) {
-					float3 glass_weight = weight * transp;
+				if(final_transmission > CLOSURE_WEIGHT_CUTOFF) {
+					float3 glass_weight = weight * final_transmission;
 					float3 cspec0 = base_color * specular_tint + make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint);
 
 					if(roughness <= 5e-2f || distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) { /* use single-scatter GGX */
@@ -342,12 +342,12 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *
 								bsdf->N = N;
 
 								if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID)
-									refraction_roughness = 1.0f - (1.0f - refl_roughness) * (1.0f - refraction_roughness);
+									transmission_roughness = 1.0f - (1.0f - refl_roughness) * (1.0f - transmission_roughness);
 								else
-									refraction_roughness = refl_roughness;
+									transmission_roughness = refl_roughness;
 
-								bsdf->alpha_x = refraction_roughness * refraction_roughness;
-								bsdf->alpha_y = refraction_roughness * refraction_roughness;
+								bsdf->alpha_x = transmission_roughness * transmission_roughness;
+								bsdf->alpha_y = transmission_roughness * transmission_roughness;
 								bsdf->ior = ior;
 
 								/* setup bsdf */
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 9b565c3ede1..57b475e5cd0 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -2316,8 +2316,8 @@ NODE_DEFINE(PrincipledBsdfNode)
 	SOCKET_IN_FLOAT(clearcoat, "Clearcoat", 0.0f);
 	SOCKET_IN_FLOAT(clearcoat_gloss, "Clearcoat Gloss", 0.0f);
 	SOCKET_IN_FLOAT(ior, "IOR", 0.0f);
-	SOCKET_IN_FLOAT(transparency, "Transparency", 0.0f);
-	SOCKET_IN_FLOAT(refraction_roughness, "Refraction Roughness", 0.0f);
+	SOCKET_IN_FLOAT(transmission, "Transmission", 0.0f);
+	SOCKET_IN_FLOAT(transmission_roughness, "Transmission Roughness", 0.0f);
 	SOCKET_IN_FLOAT(anisotropic_rotation, "Anisotropic Rotation", 0.0f);
 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL);
 	SOCKET_IN_NORMAL(clearcoat_normal, "Clearcoat Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL);
@@ -2352,7 +2352,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_ior, ShaderInput *p_transparency, ShaderInput *p_anisotropic_rotation, ShaderInput *p_refraction_roughness)
+	ShaderInput *p_ior, ShaderInput *p_transmission, ShaderInput *p_anisotropic_rotation, ShaderInput *p_transmission_roughness)
 {
 	ShaderInput *base_color_in = input("Base Color");
 	ShaderInput *subsurface_color_in = input("Subsurface Color");
@@ -2376,8 +2376,8 @@ void PrincipledBsdfNode::compile(SVMCompiler& compiler, ShaderInput *p_metallic,
 	int clearcoat_offset = compiler.stack_assign(p_clearcoat);
 	int clearcoat_gloss_offset = compiler.stack_assign(p_clearcoat_gloss);
 	int ior_offset = compiler.stack_assign(p_ior);
-	int transparency_offset = compiler.stack_assign(p_transparency);
-	int refraction_roughness_offset = compiler.stack_assign(p_refraction_roughness);
+	int transmission_offset = compiler.stack_assign(p_transmission);
+	int transmission_roughness_offset = compiler.stack_assign(p_transmission_roughness);
 	int anisotropic_rotation_offset = compiler.stack_assign(p_anisotropic_rotation);
 	int subsurface_radius_offset = compiler.stack_assign(p_subsurface_radius);
 
@@ -2393,7 +2393,7 @@ void PrincipledBsdfNode::compile(SVMCompiler& compiler, ShaderInput *p_metallic,
 		compiler.encode_uchar4(specular_offset, roughness_offset, specular_tint_offset, anis

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list