Shader: Adjust Coat Tint Color intensity based on Coat Weight
The previous formula for adjusting Coat Tint intensity resulted in strong tints and sudden colour changes when using a low coat weight. This commit fixes these issues by mixing between a white tint (no tint) and the chosen tint based on the Coat Weight. Pull Request: https://projects.blender.org/blender/blender/pulls/113468
This commit is contained in:
@@ -121,18 +121,19 @@ shader node_principled_bsdf(string distribution = "multi_ggx",
|
||||
|
||||
if (CoatWeight > 1e-5) {
|
||||
float coat_ior = max(CoatIOR, 1.0);
|
||||
float coat_weight = clamp(CoatWeight, 0.0, 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, CoatWeight / cosNT);
|
||||
BSDF *= mix(color(1.0), pow(CoatTint, 1.0 / cosNT), coat_weight);
|
||||
}
|
||||
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(CoatWeight, 0.0, 1.0) * CoatBSDF, BSDF);
|
||||
BSDF = layer(coat_weight * CoatBSDF, BSDF);
|
||||
}
|
||||
|
||||
if (SheenWeight > 1e-5) {
|
||||
|
||||
@@ -257,7 +257,7 @@ ccl_device
|
||||
* 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_weight * optical_depth);
|
||||
weight *= mix(one_spectrum(), power(rgb_to_spectrum(coat_tint), optical_depth), coat_weight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ void node_bsdf_principled(vec4 base_color,
|
||||
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_weight / NT));
|
||||
coat_tint.rgb = mix(vec3(1.0), pow(coat_tint.rgb, vec3(1.0 / NT)), coat_weight);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user