diff --git a/intern/cycles/kernel/osl/shaders/node_principled_bsdf.osl b/intern/cycles/kernel/osl/shaders/node_principled_bsdf.osl index e5d3c66b498..777eeb42616 100644 --- a/intern/cycles/kernel/osl/shaders/node_principled_bsdf.osl +++ b/intern/cycles/kernel/osl/shaders/node_principled_bsdf.osl @@ -8,7 +8,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx", string subsurface_method = "random_walk", color BaseColor = color(0.8, 0.8, 0.8), - float Subsurface = 0.0, + float SubsurfaceWeight = 0.0, float SubsurfaceScale = 0.1, vector SubsurfaceRadius = vector(1.0, 1.0, 1.0), float SubsurfaceIOR = 1.4, @@ -19,15 +19,15 @@ shader node_principled_bsdf(string distribution = "multi_ggx", float Roughness = 0.5, float Anisotropic = 0.0, float AnisotropicRotation = 0.0, - float Sheen = 0.0, + float SheenWeight = 0.0, float SheenRoughness = 0.5, color SheenTint = 0.5, - float Coat = 0.0, + float CoatWeight = 0.0, float CoatRoughness = 0.03, float CoatIOR = 1.5, color CoatTint = color(1.0, 1.0, 1.0), float IOR = 1.45, - float Transmission = 0.0, + float TransmissionWeight = 0.0, color EmissionColor = 1.0, float EmissionStrength = 0.0, float Alpha = 1.0, @@ -53,7 +53,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx", T = rotate(T, AnisotropicRotation * M_2PI, point(0.0, 0.0, 0.0), Normal); } - if (Metallic < 1.0 && Transmission < 1.0) { + if (Metallic < 1.0 && TransmissionWeight < 1.0) { float eta = IOR; float f0 = F0_from_ior(eta); if (SpecularIORLevel != 0.5) { @@ -65,8 +65,8 @@ shader node_principled_bsdf(string distribution = "multi_ggx", } BSDF = BaseColor * diffuse(Normal); - if (Subsurface > 1e-5) { - float subsurface = min(Subsurface, 1.0); + if (SubsurfaceWeight > 1e-5) { + float subsurface_weight = min(SubsurfaceWeight, 1.0); vector radius = SubsurfaceScale * SubsurfaceRadius; float subsurface_ior = (subsurface_method == "random_walk_skin") ? SubsurfaceIOR : eta; closure color SubsurfBSDF = bssrdf(subsurface_method, @@ -79,7 +79,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx", subsurface_ior, "anisotropy", SubsurfaceAnisotropy); - BSDF = mix(BSDF, BaseColor * SubsurfBSDF, subsurface); + BSDF = mix(BSDF, BaseColor * SubsurfBSDF, subsurface_weight); } /* Apply specular tint */ @@ -93,7 +93,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx", } closure color TransmissionBSDF = 0; - if (Metallic < 1.0 && Transmission > 0.0) { + if (Metallic < 1.0 && TransmissionWeight > 0.0) { float eta = max(IOR, 1e-5); eta = backfacing() ? 1.0 / eta : eta; @@ -102,7 +102,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx", TransmissionBSDF = generalized_schlick_bsdf( Normal, vector(0.0), color(1.0), sqrt(BaseColor), r2, r2, F0, F90, -eta, distribution), - BSDF = mix(BSDF, TransmissionBSDF, clamp(Transmission, 0.0, 1.0)); + BSDF = mix(BSDF, TransmissionBSDF, clamp(TransmissionWeight, 0.0, 1.0)); } closure color MetallicBSDF = 0; @@ -117,25 +117,25 @@ shader node_principled_bsdf(string distribution = "multi_ggx", BSDF += EmissionStrength * EmissionColor * emission(); } - if (Coat > 1e-5) { + if (CoatWeight > 1e-5) { float coat_ior = max(CoatIOR, 1.0); if (CoatTint != color(1.0)) { float coat_neta = 1.0 / coat_ior; float cosNI = dot(I, CoatNormal); float cosNT = sqrt(1.0 - coat_neta * coat_neta * (1 - cosNI * cosNI)); - BSDF *= pow(CoatTint, Coat / cosNT); + BSDF *= pow(CoatTint, CoatWeight / cosNT); } float coat_r2 = clamp(CoatRoughness, 0.0, 1.0); coat_r2 = coat_r2 * coat_r2; closure color CoatBSDF = dielectric_bsdf( CoatNormal, vector(0.0), color(1.0), color(0.0), coat_r2, coat_r2, coat_ior, "ggx"); - BSDF = layer(clamp(Coat, 0.0, 1.0) * CoatBSDF, BSDF); + BSDF = layer(clamp(CoatWeight, 0.0, 1.0) * CoatBSDF, BSDF); } - if (Sheen > 1e-5) { + if (SheenWeight > 1e-5) { closure color SheenBSDF = sheen(Normal, clamp(SheenRoughness, 0.0, 1.0)); - BSDF = layer(clamp(Sheen, 0.0, 1.0) * SheenTint * SheenBSDF, BSDF); + BSDF = layer(clamp(SheenWeight, 0.0, 1.0) * SheenTint * SheenBSDF, BSDF); } BSDF = mix(transparent(), BSDF, clamp(Alpha, 0.0, 1.0)); diff --git a/intern/cycles/kernel/svm/closure.h b/intern/cycles/kernel/svm/closure.h index d480b3992b4..2467c7f5a85 100644 --- a/intern/cycles/kernel/svm/closure.h +++ b/intern/cycles/kernel/svm/closure.h @@ -75,8 +75,8 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, switch (type) { case CLOSURE_BSDF_PRINCIPLED_ID: { uint specular_ior_level_offset, roughness_offset, specular_tint_offset, anisotropic_offset, - sheen_offset, sheen_tint_offset, sheen_roughness_offset, coat_offset, - coat_roughness_offset, coat_ior_offset, eta_offset, transmission_offset, + sheen_weight_offset, sheen_tint_offset, sheen_roughness_offset, coat_weight_offset, + coat_roughness_offset, coat_ior_offset, eta_offset, transmission_weight_offset, anisotropic_rotation_offset, coat_tint_offset, coat_normal_offset, dummy, alpha_offset, emission_strength_offset, emission_offset, unused; uint4 data_node2 = read_node(kg, &offset); @@ -88,31 +88,34 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, &specular_tint_offset, &anisotropic_offset); svm_unpack_node_uchar4( - data_node.w, &sheen_offset, &sheen_tint_offset, &sheen_roughness_offset, &unused); + data_node.w, &sheen_weight_offset, &sheen_tint_offset, &sheen_roughness_offset, &unused); svm_unpack_node_uchar4(data_node2.x, &eta_offset, - &transmission_offset, + &transmission_weight_offset, &anisotropic_rotation_offset, &coat_normal_offset); - svm_unpack_node_uchar4( - data_node2.w, &coat_offset, &coat_roughness_offset, &coat_ior_offset, &coat_tint_offset); + svm_unpack_node_uchar4(data_node2.w, + &coat_weight_offset, + &coat_roughness_offset, + &coat_ior_offset, + &coat_tint_offset); // get Disney principled parameters float metallic = saturatef(param1); - float subsurface = saturatef(param2); + float subsurface_weight = saturatef(param2); float specular_ior_level = fmaxf(stack_load_float(stack, specular_ior_level_offset), 0.0f); float roughness = saturatef(stack_load_float(stack, roughness_offset)); Spectrum specular_tint = rgb_to_spectrum( max(stack_load_float3(stack, specular_tint_offset), zero_float3())); float anisotropic = saturatef(stack_load_float(stack, anisotropic_offset)); - float sheen = saturatef(stack_load_float(stack, sheen_offset)); + float sheen_weight = saturatef(stack_load_float(stack, sheen_weight_offset)); float3 sheen_tint = stack_load_float3(stack, sheen_tint_offset); float sheen_roughness = saturatef(stack_load_float(stack, sheen_roughness_offset)); - float coat = saturatef(stack_load_float(stack, coat_offset)); + float coat_weight = saturatef(stack_load_float(stack, coat_weight_offset)); float coat_roughness = saturatef(stack_load_float(stack, coat_roughness_offset)); float coat_ior = fmaxf(stack_load_float(stack, coat_ior_offset), 1.0f); float3 coat_tint = stack_load_float3(stack, coat_tint_offset); - float transmission = saturatef(stack_load_float(stack, transmission_offset)); + float transmission_weight = saturatef(stack_load_float(stack, transmission_weight_offset)); float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset); float ior = fmaxf(stack_load_float(stack, eta_offset), 1e-5f); @@ -176,9 +179,9 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, } /* First layer: Sheen */ - if (sheen > CLOSURE_WEIGHT_CUTOFF) { + if (sheen_weight > CLOSURE_WEIGHT_CUTOFF) { ccl_private SheenBsdf *bsdf = (ccl_private SheenBsdf *)bsdf_alloc( - sd, sizeof(SheenBsdf), sheen * rgb_to_spectrum(sheen_tint) * weight); + sd, sizeof(SheenBsdf), sheen_weight * rgb_to_spectrum(sheen_tint) * weight); if (bsdf) { bsdf->N = N; @@ -194,14 +197,14 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, } /* Second layer: Coat */ - if (coat > CLOSURE_WEIGHT_CUTOFF) { + if (coat_weight > CLOSURE_WEIGHT_CUTOFF) { float3 coat_normal = stack_valid(coat_normal_offset) ? stack_load_float3(stack, coat_normal_offset) : sd->N; coat_normal = maybe_ensure_valid_specular_reflection(sd, coat_normal); if (reflective_caustics) { ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc( - sd, sizeof(MicrofacetBsdf), coat * weight); + sd, sizeof(MicrofacetBsdf), coat_weight * weight); if (bsdf) { bsdf->N = coat_normal; @@ -244,7 +247,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, * TIR is no concern here since we're always coming from the outside. */ float cosNT = sqrtf(1.0f - sqr(1.0f / coat_ior) * (1 - sqr(cosNI))); float optical_depth = 1.0f / cosNT; - weight *= power(rgb_to_spectrum(coat_tint), coat * optical_depth); + weight *= power(rgb_to_spectrum(coat_tint), coat_weight * optical_depth); } } @@ -283,9 +286,9 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, } /* Transmission component */ - if (glass_caustics && transmission > CLOSURE_WEIGHT_CUTOFF) { + if (glass_caustics && transmission_weight > CLOSURE_WEIGHT_CUTOFF) { ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc( - sd, sizeof(MicrofacetBsdf), transmission * weight); + sd, sizeof(MicrofacetBsdf), transmission_weight * weight); ccl_private FresnelGeneralizedSchlick *fresnel = (bsdf != NULL) ? (ccl_private FresnelGeneralizedSchlick *)closure_alloc_extra( sd, sizeof(FresnelGeneralizedSchlick)) : @@ -310,7 +313,7 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, bsdf_microfacet_setup_fresnel_generalized_schlick(kg, bsdf, sd, fresnel, is_multiggx); /* Attenuate other components */ - weight *= (1.0f - transmission); + weight *= (1.0f - transmission_weight); } } @@ -360,8 +363,8 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, /* Diffuse/Subsurface component */ #ifdef __SUBSURFACE__ - ccl_private Bssrdf *bssrdf = bssrdf_alloc(sd, - rgb_to_spectrum(base_color) * subsurface * weight); + ccl_private Bssrdf *bssrdf = bssrdf_alloc( + sd, rgb_to_spectrum(base_color) * subsurface_weight * weight); if (bssrdf) { float3 subsurface_radius = stack_load_float3(stack, data_subsurf.y); float subsurface_scale = stack_load_float(stack, data_subsurf.z); @@ -380,11 +383,13 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg, sd->flag |= bssrdf_setup(sd, bssrdf, path_flag, subsurface_method); } #else - subsurface = 0.0f; + subsurface_weight = 0.0f; #endif ccl_private DiffuseBsdf *bsdf = (ccl_private DiffuseBsdf *)bsdf_alloc( - sd, sizeof(DiffuseBsdf), rgb_to_spectrum(base_color) * (1.0f - subsurface) * weight); + sd, + sizeof(DiffuseBsdf), + rgb_to_spectrum(base_color) * (1.0f - subsurface_weight) * weight); if (bsdf) { bsdf->N = N; diff --git a/intern/cycles/scene/shader_nodes.cpp b/intern/cycles/scene/shader_nodes.cpp index a7bbc39ffcc..fa6deab7420 100644 --- a/intern/cycles/scene/shader_nodes.cpp +++ b/intern/cycles/scene/shader_nodes.cpp @@ -2699,31 +2699,38 @@ NODE_DEFINE(PrincipledBsdfNode) SOCKET_IN_COLOR(base_color, "Base Color", make_float3(0.8f, 0.8f, 0.8f)) SOCKET_IN_FLOAT(metallic, "Metallic", 0.0f); - SOCKET_IN_FLOAT(subsurface, "Subsurface", 0.0f); + SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f); + SOCKET_IN_FLOAT(ior, "IOR", 0.0f); + SOCKET_IN_FLOAT(alpha, "Alpha", 1.0f); + SOCKET_IN_NORMAL(normal, "Normal", zero_float3(), SocketType::LINK_NORMAL); + + SOCKET_IN_FLOAT(subsurface_weight, "Subsurface Weight", 0.0f); SOCKET_IN_FLOAT(subsurface_scale, "Subsurface Scale", 0.1f); SOCKET_IN_VECTOR(subsurface_radius, "Subsurface Radius", make_float3(0.1f, 0.1f, 0.1f)); SOCKET_IN_FLOAT(subsurface_ior, "Subsurface IOR", 1.4f); SOCKET_IN_FLOAT(subsurface_anisotropy, "Subsurface Anisotropy", 0.0f); + SOCKET_IN_FLOAT(specular_ior_level, "Specular IOR Level", 0.0f); - SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f); SOCKET_IN_COLOR(specular_tint, "Specular Tint", one_float3()); SOCKET_IN_FLOAT(anisotropic, "Anisotropic", 0.0f); - SOCKET_IN_FLOAT(sheen, "Sheen", 0.0f); + SOCKET_IN_FLOAT(anisotropic_rotation, "Anisotropic Rotation", 0.0f); + SOCKET_IN_NORMAL(tangent, "Tangent", zero_float3(), SocketType::LINK_TANGENT); + + SOCKET_IN_FLOAT(transmission_weight, "Transmission Weight", 0.0f); + + SOCKET_IN_FLOAT(sheen_weight, "Sheen Weight", 0.0f); SOCKET_IN_FLOAT(sheen_roughness, "Sheen Roughness", 0.5f); SOCKET_IN_COLOR(sheen_tint, "Sheen Tint", one_float3()); - SOCKET_IN_FLOAT(coat, "Coat", 0.0f); + + SOCKET_IN_FLOAT(coat_weight, "Coat Weight", 0.0f); SOCKET_IN_FLOAT(coat_roughness, "Coat Roughness", 0.03f); SOCKET_IN_FLOAT(coat_ior, "Coat IOR", 1.5f); SOCKET_IN_COLOR(coat_tint, "Coat Tint", one_float3()); - SOCKET_IN_FLOAT(ior, "IOR", 0.0f); - SOCKET_IN_FLOAT(transmission, "Transmission", 0.0f); - SOCKET_IN_FLOAT(anisotropic_rotation, "Anisotropic Rotation", 0.0f); + SOCKET_IN_NORMAL(coat_normal, "Coat Normal", zero_float3(), SocketType::LINK_NORMAL); + SOCKET_IN_COLOR(emission_color, "Emission Color", one_float3()); SOCKET_IN_FLOAT(emission_strength, "Emission Strength", 0.0f); - SOCKET_IN_FLOAT(alpha, "Alpha", 1.0f); - SOCKET_IN_NORMAL(normal, "Normal", zero_float3(), SocketType::LINK_NORMAL); - SOCKET_IN_NORMAL(coat_normal, "Coat Normal", zero_float3(), SocketType::LINK_NORMAL); - SOCKET_IN_NORMAL(tangent, "Tangent", zero_float3(), SocketType::LINK_TANGENT); + SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); SOCKET_OUT_CLOSURE(BSDF, "BSDF"); @@ -2768,8 +2775,10 @@ bool PrincipledBsdfNode::has_surface_emission() bool PrincipledBsdfNode::has_surface_bssrdf() { - ShaderInput *subsurface_in = input("Subsurface"); - return (subsurface_in->link != NULL || subsurface > CLOSURE_WEIGHT_CUTOFF); + ShaderInput *subsurface_weight_in = input("Subsurface Weight"); + ShaderInput *subsurface_scale_in = input("Subsurface Scale"); + return (subsurface_weight_in->link != NULL || subsurface_weight > CLOSURE_WEIGHT_CUTOFF) && + (subsurface_scale_in->link != NULL || subsurface_scale != 0.0f); } void PrincipledBsdfNode::attributes(Shader *shader, AttributeRequestSet *attributes) @@ -2790,7 +2799,7 @@ void PrincipledBsdfNode::compile(SVMCompiler &compiler) ShaderInput *base_color_in = input("Base Color"); ShaderInput *p_metallic = input("Metallic"); - ShaderInput *p_subsurface = input("Subsurface"); + ShaderInput *p_subsurface_weight = input("Subsurface Weight"); ShaderInput *emission_strength_in = input("Emission Strength"); ShaderInput *alpha_in = input("Alpha"); @@ -2806,15 +2815,15 @@ void PrincipledBsdfNode::compile(SVMCompiler &compiler) int roughness_offset = compiler.stack_assign(input("Roughness")); int specular_tint_offset = compiler.stack_assign(input("Specular Tint")); int anisotropic_offset = compiler.stack_assign(input("Anisotropic")); - int sheen_offset = compiler.stack_assign(input("Sheen")); + int sheen_weight_offset = compiler.stack_assign(input("Sheen Weight")); int sheen_roughness_offset = compiler.stack_assign(input("Sheen Roughness")); int sheen_tint_offset = compiler.stack_assign(input("Sheen Tint")); - int coat_offset = compiler.stack_assign(input("Coat")); + int coat_weight_offset = compiler.stack_assign(input("Coat Weight")); int coat_roughness_offset = compiler.stack_assign(input("Coat Roughness")); int coat_ior_offset = compiler.stack_assign(input("Coat IOR")); int coat_tint_offset = compiler.stack_assign(input("Coat Tint")); int ior_offset = compiler.stack_assign(input("IOR")); - int transmission_offset = compiler.stack_assign(input("Transmission")); + int transmission_weight_offset = compiler.stack_assign(input("Transmission Weight")); int anisotropic_rotation_offset = compiler.stack_assign(input("Anisotropic Rotation")); int subsurface_radius_offset = compiler.stack_assign(input("Subsurface Radius")); int subsurface_scale_offset = compiler.stack_assign(input("Subsurface Scale")); @@ -2824,28 +2833,29 @@ void PrincipledBsdfNode::compile(SVMCompiler &compiler) int emission_strength_offset = compiler.stack_assign_if_linked(emission_strength_in); int emission_color_offset = compiler.stack_assign(input("Emission Color")); - compiler.add_node(NODE_CLOSURE_BSDF, - compiler.encode_uchar4(closure, - compiler.stack_assign(p_metallic), - compiler.stack_assign(p_subsurface), - compiler.closure_mix_weight_offset()), - __float_as_int((p_metallic) ? get_float(p_metallic->socket_type) : 0.0f), - __float_as_int((p_subsurface) ? get_float(p_subsurface->socket_type) : 0.0f)); + compiler.add_node( + NODE_CLOSURE_BSDF, + compiler.encode_uchar4(closure, + compiler.stack_assign(p_metallic), + compiler.stack_assign(p_subsurface_weight), + compiler.closure_mix_weight_offset()), + __float_as_int((p_metallic) ? get_float(p_metallic->socket_type) : 0.0f), + __float_as_int((p_subsurface_weight) ? get_float(p_subsurface_weight->socket_type) : 0.0f)); compiler.add_node( normal_offset, tangent_offset, compiler.encode_uchar4( specular_ior_level_offset, roughness_offset, specular_tint_offset, anisotropic_offset), - compiler.encode_uchar4(sheen_offset, sheen_tint_offset, sheen_roughness_offset)); + compiler.encode_uchar4(sheen_weight_offset, sheen_tint_offset, sheen_roughness_offset)); compiler.add_node( compiler.encode_uchar4( - ior_offset, transmission_offset, anisotropic_rotation_offset, coat_normal_offset), + ior_offset, transmission_weight_offset, anisotropic_rotation_offset, coat_normal_offset), distribution, subsurface_method, compiler.encode_uchar4( - coat_offset, coat_roughness_offset, coat_ior_offset, coat_tint_offset)); + coat_weight_offset, coat_roughness_offset, coat_ior_offset, coat_tint_offset)); float3 bc_default = get_float3(base_color_in->socket_type); diff --git a/intern/cycles/scene/shader_nodes.h b/intern/cycles/scene/shader_nodes.h index cb2909597ec..ac508f2c255 100644 --- a/intern/cycles/scene/shader_nodes.h +++ b/intern/cycles/scene/shader_nodes.h @@ -519,35 +519,35 @@ class PrincipledBsdfNode : public BsdfBaseNode { void simplify_settings(Scene *scene); NODE_SOCKET_API(float3, base_color) + NODE_SOCKET_API(float, metallic) + NODE_SOCKET_API(float, roughness) + NODE_SOCKET_API(float, ior) + NODE_SOCKET_API(float3, normal) + NODE_SOCKET_API(float, alpha) + NODE_SOCKET_API(ClosureType, subsurface_method) + NODE_SOCKET_API(float, subsurface_weight) NODE_SOCKET_API(float3, subsurface_radius) NODE_SOCKET_API(float, subsurface_scale) NODE_SOCKET_API(float, subsurface_ior) NODE_SOCKET_API(float, subsurface_anisotropy) - NODE_SOCKET_API(float, metallic) - NODE_SOCKET_API(float, subsurface) + NODE_SOCKET_API(ClosureType, distribution) NODE_SOCKET_API(float, specular_ior_level) - NODE_SOCKET_API(float, roughness) NODE_SOCKET_API(float3, specular_tint) NODE_SOCKET_API(float, anisotropic) - NODE_SOCKET_API(float, sheen) + NODE_SOCKET_API(float, anisotropic_rotation) + NODE_SOCKET_API(float3, tangent) + NODE_SOCKET_API(float, transmission_weight) + NODE_SOCKET_API(float, sheen_weight) NODE_SOCKET_API(float, sheen_roughness) NODE_SOCKET_API(float3, sheen_tint) - NODE_SOCKET_API(float, coat) + NODE_SOCKET_API(float, coat_weight) NODE_SOCKET_API(float, coat_roughness) NODE_SOCKET_API(float, coat_ior) NODE_SOCKET_API(float3, coat_tint) - NODE_SOCKET_API(float, ior) - NODE_SOCKET_API(float, transmission) - NODE_SOCKET_API(float, anisotropic_rotation) - NODE_SOCKET_API(float3, normal) NODE_SOCKET_API(float3, coat_normal) - NODE_SOCKET_API(float3, tangent) - NODE_SOCKET_API(float, surface_mix_weight) - NODE_SOCKET_API(ClosureType, distribution) - NODE_SOCKET_API(ClosureType, subsurface_method) NODE_SOCKET_API(float3, emission_color) NODE_SOCKET_API(float, emission_strength) - NODE_SOCKET_API(float, alpha) + NODE_SOCKET_API(float, surface_mix_weight) public: void attributes(Shader *shader, AttributeRequestSet *attributes); diff --git a/scripts/modules/bpy_extras/node_shader_utils.py b/scripts/modules/bpy_extras/node_shader_utils.py index 002b7cba5b9..2b0ea162552 100644 --- a/scripts/modules/bpy_extras/node_shader_utils.py +++ b/scripts/modules/bpy_extras/node_shader_utils.py @@ -412,13 +412,13 @@ class PrincipledBSDFWrapper(ShaderWrapper): def transmission_get(self): if not self.use_nodes or self.node_principled_bsdf is None: return 0.0 - return self.node_principled_bsdf.inputs["Transmission"].default_value + return self.node_principled_bsdf.inputs["Transmission Weight"].default_value @_set_check def transmission_set(self, value): value = values_clamp(value, 0.0, 1.0) if self.use_nodes and self.node_principled_bsdf is not None: - self.node_principled_bsdf.inputs["Transmission"].default_value = value + self.node_principled_bsdf.inputs["Transmission Weight"].default_value = value transmission = property(transmission_get, transmission_set) @@ -428,7 +428,7 @@ class PrincipledBSDFWrapper(ShaderWrapper): return None return ShaderImageTextureWrapper( self, self.node_principled_bsdf, - self.node_principled_bsdf.inputs["Transmission"], + self.node_principled_bsdf.inputs["Transmission Weight"], grid_row_diff=-1, colorspace_name='Non-Color', ) diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc index c54a3e42fc1..479be23f053 100644 --- a/source/blender/blenloader/intern/versioning_400.cc +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -697,6 +697,12 @@ static void version_principled_bsdf_rename_sockets(bNodeTree *ntree) { version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Emission", "Emission Color"); version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Specular", "Specular IOR Level"); + version_node_input_socket_name( + ntree, SH_NODE_BSDF_PRINCIPLED, "Subsurface", "Subsurface Weight"); + version_node_input_socket_name( + ntree, SH_NODE_BSDF_PRINCIPLED, "Transmission", "Transmission Weight"); + version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Coat", "Coat Weight"); + version_node_input_socket_name(ntree, SH_NODE_BSDF_PRINCIPLED, "Sheen", "Sheen Weight"); } /* Replace old Principled Hair BSDF as a variant in the new Principled Hair BSDF. */ diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl index 23e0d3b8364..c154a406d6f 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_principled.glsl @@ -10,7 +10,7 @@ vec3 tint_from_color(vec3 color) float principled_sheen(float NV, float rough) { - /* Empirical approximation (manual curve fitting) to the sheen albedo. Can be refined. */ + /* Empirical approximation (manual curve fitting) to the sheen_weight albedo. Can be refined. */ float den = 35.6694f * rough * rough - 24.4269f * rough * NV - 0.1405f * NV * NV + 6.1211f * rough + 0.28105f * NV - 0.1405f; float num = 58.5299f * rough * rough - 85.0941f * rough * NV + 9.8955f * NV * NV + @@ -28,11 +28,10 @@ void node_bsdf_principled(vec4 base_color, float metallic, float roughness, float ior, - float transmission, float alpha, vec3 N, float weight, - float subsurface, + float subsurface_weight, vec3 subsurface_radius, float subsurface_scale, float subsurface_ior, @@ -42,12 +41,13 @@ void node_bsdf_principled(vec4 base_color, float anisotropic, float anisotropic_rotation, vec3 T, - float coat, + float transmission_weight, + float coat_weight, float coat_roughness, float coat_ior, vec4 coat_tint, vec3 CN, - float sheen, + float sheen_weight, float sheen_roughness, vec4 sheen_tint, vec4 emission, @@ -63,16 +63,16 @@ void node_bsdf_principled(vec4 base_color, metallic = clamp(metallic, 0.0, 1.0); roughness = clamp(roughness, 0.0, 1.0); ior = max(ior, 1e-5); - transmission = clamp(transmission, 0.0, 1.0); - subsurface = clamp(subsurface, 0.0, 1.0); + transmission_weight = clamp(transmission_weight, 0.0, 1.0); + subsurface_weight = clamp(subsurface_weight, 0.0, 1.0); specular_ior_level = max(specular_ior_level, 0.0); specular_tint = max(specular_tint, vec4(0.0)); /* Not used by EEVEE */ /* anisotropic = clamp(anisotropic, 0.0, 1.0) */ - coat = clamp(coat, 0.0, 1.0); + coat_weight = clamp(coat_weight, 0.0, 1.0); coat_roughness = clamp(coat_roughness, 0.0, 1.0); coat_ior = max(coat_ior, 1.0); - sheen = clamp(sheen, 0.0, 1.0); + sheen_weight = clamp(sheen_weight, 0.0, 1.0); sheen_roughness = clamp(sheen_roughness, 0.0, 1.0); emission_strength = max(emission_strength, 0.0); alpha = clamp(alpha, 0.0, 1.0); @@ -92,9 +92,9 @@ void node_bsdf_principled(vec4 base_color, ClosureDiffuse diffuse_data; diffuse_data.N = N; - if (sheen > 0.0) { - /* TODO: Maybe sheen should be specular. */ - vec3 sheen_color = sheen * sheen_tint.rgb * principled_sheen(NV, sheen_roughness); + if (sheen_weight > 0.0) { + /* TODO: Maybe sheen_weight should be specular. */ + vec3 sheen_color = sheen_weight * sheen_tint.rgb * principled_sheen(NV, sheen_roughness); diffuse_data.color = weight * sheen_color; /* Attenuate lower layers */ weight *= (1.0 - max_v3(sheen_color)); @@ -109,18 +109,18 @@ void node_bsdf_principled(vec4 base_color, coat_data.roughness = coat_roughness; coat_data.color = vec3(1.0); - if (coat > 0.0) { + if (coat_weight > 0.0) { float coat_NV = dot(coat_data.N, V); float reflectance = bsdf_lut(coat_NV, coat_data.roughness, coat_ior, 0.0).x; - coat_data.weight = weight * coat * reflectance; + coat_data.weight = weight * coat_weight * reflectance; /* Attenuate lower layers */ - weight *= (1.0 - reflectance * coat); + weight *= (1.0 - reflectance * coat_weight); if (!all(equal(coat_tint.rgb, vec3(1.0)))) { float coat_neta = 1.0 / coat_ior; float NT = fast_sqrt(1.0 - coat_neta * coat_neta * (1 - NV * NV)); /* Tint lower layers. */ - coat_tint.rgb = pow(coat_tint.rgb, vec3(coat / NT)); + coat_tint.rgb = pow(coat_tint.rgb, vec3(coat_weight / NT)); } } else { @@ -158,19 +158,19 @@ void node_bsdf_principled(vec4 base_color, refraction_data.roughness = roughness; refraction_data.ior = ior; vec3 reflection_tint = specular_tint.rgb; - if (transmission > 0.0) { + if (transmission_weight > 0.0) { vec3 F0 = vec3(F0_from_ior(ior)) * reflection_tint; vec3 F90 = vec3(1.0); vec3 reflectance, transmittance; bsdf_lut( F0, F90, base_color.rgb, NV, roughness, ior, do_multiscatter, reflectance, transmittance); - reflection_data.color += weight * transmission * reflectance; + reflection_data.color += weight * transmission_weight * reflectance; - refraction_data.weight = weight * transmission; + refraction_data.weight = weight * transmission_weight; refraction_data.color = transmittance * coat_tint.rgb; /* Attenuate lower layers */ - weight *= (1.0 - transmission); + weight *= (1.0 - transmission_weight); } else { refraction_data.weight = 0.0; diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc index 4ab78c58171..0edf2cc392d 100644 --- a/source/blender/io/usd/intern/usd_reader_material.cc +++ b/source/blender/io/usd/intern/usd_reader_material.cc @@ -482,7 +482,7 @@ void USDMaterialReader::set_principled_node_inputs(bNode *principled, } if (pxr::UsdShadeInput coat_input = usd_shader.GetInput(usdtokens::clearcoat)) { - set_node_input(coat_input, principled, "Coat", ntree, column, &context); + set_node_input(coat_input, principled, "Coat Weight", ntree, column, &context); } if (pxr::UsdShadeInput coat_roughness_input = usd_shader.GetInput(usdtokens::clearcoatRoughness)) diff --git a/source/blender/io/usd/intern/usd_writer_material.cc b/source/blender/io/usd/intern/usd_writer_material.cc index cb98b8c2c90..584dbb847b6 100644 --- a/source/blender/io/usd/intern/usd_writer_material.cc +++ b/source/blender/io/usd/intern/usd_writer_material.cc @@ -301,7 +301,7 @@ static InputSpecMap &preview_surface_input_map() {"IOR", {usdtokens::ior, pxr::SdfValueTypeNames->Float, true}}, /* Note that for the Normal input set_default_value is false. */ {"Normal", {usdtokens::normal, pxr::SdfValueTypeNames->Float3, false}}, - {"Coat", {usdtokens::clearcoat, pxr::SdfValueTypeNames->Float, true}}, + {"Coat Weight", {usdtokens::clearcoat, pxr::SdfValueTypeNames->Float, true}}, {"Coat Roughness", {usdtokens::clearcoatRoughness, pxr::SdfValueTypeNames->Float, true}}, }; diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc index 29b480c41d9..535694f4a7b 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mtl.cc @@ -30,7 +30,7 @@ const char *tex_map_type_to_socket_id[] = { "Specular IOR Level", "Roughness", /* Map specular exponent to roughness. */ "Roughness", - "Sheen", + "Sheen Weight", "Metallic", /* Map reflection to metallic. */ "Emission Color", "Alpha", @@ -243,12 +243,12 @@ static void store_bsdf_properties(const bNode *bsdf_node, float aniso_rot = -1.0f; float transmission = -1.0f; if (bsdf_node) { - copy_property_from_node(SOCK_FLOAT, bsdf_node, "Sheen", {&sheen, 1}); - copy_property_from_node(SOCK_FLOAT, bsdf_node, "Coat", {&coat, 1}); + copy_property_from_node(SOCK_FLOAT, bsdf_node, "Sheen Weight", {&sheen, 1}); + copy_property_from_node(SOCK_FLOAT, bsdf_node, "Coat Weight", {&coat, 1}); copy_property_from_node(SOCK_FLOAT, bsdf_node, "Coat Roughness", {&coat_roughness, 1}); copy_property_from_node(SOCK_FLOAT, bsdf_node, "Anisotropic", {&aniso, 1}); copy_property_from_node(SOCK_FLOAT, bsdf_node, "Anisotropic Rotation", {&aniso_rot, 1}); - copy_property_from_node(SOCK_FLOAT, bsdf_node, "Transmission", {&transmission, 1}); + copy_property_from_node(SOCK_FLOAT, bsdf_node, "Transmission Weight", {&transmission, 1}); /* Clearcoat used to include an implicit 0.25 factor, so stay compatible to old versions. */ coat *= 4.0f; diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc index 6858b1d98de..a71780c5964 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mtl.cc @@ -324,11 +324,11 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial } if (mtl_mat.sheen >= 0) { - set_property_of_socket(SOCK_FLOAT, "Sheen", {mtl_mat.sheen}, bsdf); + set_property_of_socket(SOCK_FLOAT, "Sheen Weight", {mtl_mat.sheen}, bsdf); } if (mtl_mat.cc_thickness >= 0) { /* Clearcoat used to include an implicit 0.25 factor, so stay compatible to old versions. */ - set_property_of_socket(SOCK_FLOAT, "Coat", {0.25f * mtl_mat.cc_thickness}, bsdf); + set_property_of_socket(SOCK_FLOAT, "Coat Weight", {0.25f * mtl_mat.cc_thickness}, bsdf); } if (mtl_mat.cc_roughness >= 0) { set_property_of_socket(SOCK_FLOAT, "Coat Roughness", {mtl_mat.cc_roughness}, bsdf); @@ -345,7 +345,7 @@ static void set_bsdf_socket_values(bNode *bsdf, Material *mat, const MTLMaterial mtl_mat.transmit_color[2]) / 3; if (transmission >= 0) { - set_property_of_socket(SOCK_FLOAT, "Transmission", {transmission}, bsdf); + set_property_of_socket(SOCK_FLOAT, "Transmission Weight", {transmission}, bsdf); } } diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc index b4f28cf3b7f..14265488cd8 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc +++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.cc @@ -40,18 +40,12 @@ static void node_declare(NodeDeclarationBuilder &b) #define SOCK_ROUGHNESS_ID 2 b.add_input("IOR").default_value(1.45f).min(1.0f).max(1000.0f); #define SOCK_IOR_ID 3 - b.add_input("Transmission") - .default_value(0.0f) - .min(0.0f) - .max(1.0f) - .subtype(PROP_FACTOR); -#define SOCK_TRANSMISSION_ID 4 b.add_input("Alpha").default_value(1.0f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); -#define SOCK_ALPHA_ID 5 +#define SOCK_ALPHA_ID 4 b.add_input("Normal").hide_value(); -#define SOCK_NORMAL_ID 6 +#define SOCK_NORMAL_ID 5 b.add_input("Weight").unavailable(); -#define SOCK_WEIGHT_ID 7 +#define SOCK_WEIGHT_ID 6 /* Panel for Subsurface scattering settings. */ PanelDeclarationBuilder &sss = @@ -60,7 +54,7 @@ static void node_declare(NodeDeclarationBuilder &b) .draw_buttons([](uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) { uiItemR(layout, ptr, "subsurface_method", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE); }); - sss.add_input("Subsurface") + sss.add_input("Subsurface Weight") .default_value(0.0f) .min(0.0f) .max(1.0f) @@ -68,34 +62,34 @@ static void node_declare(NodeDeclarationBuilder &b) .description( "Blend between diffuse surface and subsurface scattering. " "Typically should be zero or one (either fully diffuse or subsurface)"); -#define SOCK_SUBSURFACE_ID 8 +#define SOCK_SUBSURFACE_WEIGHT_ID 7 sss.add_input("Subsurface Radius") .default_value({1.0f, 0.2f, 0.1f}) .min(0.0f) .max(100.0f) .compact() .description("Scattering radius to use for subsurface component (multiplied with Scale)"); -#define SOCK_SUBSURFACE_RADIUS_ID 9 +#define SOCK_SUBSURFACE_RADIUS_ID 8 sss.add_input("Subsurface Scale") .default_value(0.05f) .min(0.0f) .max(10.0f) .subtype(PROP_DISTANCE) .description("Scale of the subsurface scattering (multiplied with Radius)"); -#define SOCK_SUBSURFACE_SCALE_ID 10 +#define SOCK_SUBSURFACE_SCALE_ID 9 sss.add_input("Subsurface IOR") .default_value(1.4f) .min(1.01f) .max(3.8f) .subtype(PROP_FACTOR) .description("Index of refraction used for rays that enter the subsurface component"); -#define SOCK_SUBSURFACE_IOR_ID 11 +#define SOCK_SUBSURFACE_IOR_ID 10 sss.add_input("Subsurface Anisotropy") .default_value(0.0f) .min(0.0f) .max(1.0f) .subtype(PROP_FACTOR); -#define SOCK_SUBSURFACE_ANISOTROPY_ID 12 +#define SOCK_SUBSURFACE_ANISOTROPY_ID 11 /* Panel for Specular settings. */ PanelDeclarationBuilder &spec = @@ -113,31 +107,41 @@ static void node_declare(NodeDeclarationBuilder &b) "Adjustment to the IOR to increase or decrease specular intensity " "(0.5 means no adjustment, 0 removes all reflections, 1 doubles them at normal " "incidence)"); -#define SOCK_SPECULAR_ID 13 +#define SOCK_SPECULAR_ID 12 spec.add_input("Specular Tint") .default_value({1.0f, 1.0f, 1.0f, 1.0f}) .description( "Tint dielectric reflection at normal incidence for artistic control, and metallic " "reflection at near-grazing incidence to simulate complex index of refraction"); -#define SOCK_SPECULAR_TINT_ID 14 +#define SOCK_SPECULAR_TINT_ID 13 spec.add_input("Anisotropic") .default_value(0.0f) .min(0.0f) .max(1.0f) .subtype(PROP_FACTOR); -#define SOCK_ANISOTROPIC_ID 15 +#define SOCK_ANISOTROPIC_ID 14 spec.add_input("Anisotropic Rotation") .default_value(0.0f) .min(0.0f) .max(1.0f) .subtype(PROP_FACTOR); -#define SOCK_ANISOTROPIC_ROTATION_ID 16 +#define SOCK_ANISOTROPIC_ROTATION_ID 15 spec.add_input("Tangent").hide_value(); -#define SOCK_TANGENT_ID 17 +#define SOCK_TANGENT_ID 16 + + /* Panel for Transmission settings. */ + PanelDeclarationBuilder &transmission = b.add_panel("Transmission").default_closed(true); + transmission.add_input("Transmission Weight") + .default_value(0.0f) + .min(0.0f) + .max(1.0f) + .subtype(PROP_FACTOR) + .description("Blend between transmission and other base layer components"); +#define SOCK_TRANSMISSION_WEIGHT_ID 17 /* Panel for Coat settings. */ PanelDeclarationBuilder &coat = b.add_panel("Coat").default_closed(true); - coat.add_input("Coat") + coat.add_input("Coat Weight") .default_value(0.0f) .min(0.0f) .max(1.0f) @@ -145,7 +149,7 @@ static void node_declare(NodeDeclarationBuilder &b) .description( "Controls the intensity of the coat layer, both the reflection and the tinting. " "Typically should be zero or one for physically-based materials"); -#define SOCK_COAT_ID 18 +#define SOCK_COAT_WEIGHT_ID 18 coat.add_input("Coat Roughness") .default_value(0.03f) .min(0.0f) @@ -173,9 +177,12 @@ static void node_declare(NodeDeclarationBuilder &b) /* Panel for Sheen settings. */ PanelDeclarationBuilder &sheen = b.add_panel("Sheen").default_closed(true); - sheen.add_input("Sheen").default_value(0.0f).min(0.0f).max(1.0f).subtype( - PROP_FACTOR); -#define SOCK_SHEEN_ID 23 + sheen.add_input("Sheen Weight") + .default_value(0.0f) + .min(0.0f) + .max(1.0f) + .subtype(PROP_FACTOR); +#define SOCK_SHEEN_WEIGHT_ID 23 sheen.add_input("Sheen Roughness") .default_value(0.5f) .min(0.0f) @@ -228,12 +235,14 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, } #endif - bool use_diffuse = socket_not_zero(SOCK_SHEEN_ID) || - (socket_not_one(SOCK_METALLIC_ID) && socket_not_one(SOCK_TRANSMISSION_ID)); - bool use_subsurf = socket_not_zero(SOCK_SUBSURFACE_ID) && use_diffuse; - bool use_refract = socket_not_one(SOCK_METALLIC_ID) && socket_not_zero(SOCK_TRANSMISSION_ID); + bool use_diffuse = socket_not_zero(SOCK_SHEEN_WEIGHT_ID) || + (socket_not_one(SOCK_METALLIC_ID) && + socket_not_one(SOCK_TRANSMISSION_WEIGHT_ID)); + bool use_subsurf = socket_not_zero(SOCK_SUBSURFACE_WEIGHT_ID) && use_diffuse; + bool use_refract = socket_not_one(SOCK_METALLIC_ID) && + socket_not_zero(SOCK_TRANSMISSION_WEIGHT_ID); bool use_transparency = socket_not_one(SOCK_ALPHA_ID); - bool use_coat = socket_not_zero(SOCK_COAT_ID); + bool use_coat = socket_not_zero(SOCK_COAT_WEIGHT_ID); eGPUMaterialFlag flag = GPU_MATFLAG_GLOSSY; if (use_diffuse) {