Cycles: OSL oren_nayar_diffuse_bsdf compatibility for MaterialX

The oren_nayar_diffuse_bsdf closure in OSL had two issues:
- It broke when used with roughness of zero
- It only used the provided albedo for energy compensation, so it still
  required the user to multiply with the albedo

Therefore, this handles the zero roughness corner case and includes
the albedo in the closure weight.
This makes no difference when using the closure through the Diffuse
or Principled BSDF nodes, only for custom OSL shaders.

Pull Request: https://projects.blender.org/blender/blender/pulls/133597
This commit is contained in:
Alex
2025-01-27 17:58:20 +01:00
committed by Lukas Stockner
parent dd67b355ee
commit e39b2ee816
5 changed files with 7 additions and 4 deletions
@@ -45,6 +45,9 @@ ccl_device Spectrum bsdf_oren_nayar_get_intensity(const ccl_private ShaderClosur
{
const ccl_private OrenNayarBsdf *bsdf = (const ccl_private OrenNayarBsdf *)sc;
const float nl = max(dot(n, l), 0.0f);
if (bsdf->b <= 0.0f) {
return make_spectrum(nl * M_1_PI_F);
}
const float nv = max(dot(n, v), 0.0f);
float t = dot(l, v) - nl * nv;
+1 -1
View File
@@ -138,7 +138,7 @@ ccl_device void osl_closure_oren_nayar_diffuse_bsdf_setup(
}
ccl_private OrenNayarBsdf *bsdf = (ccl_private OrenNayarBsdf *)bsdf_alloc(
sd, sizeof(OrenNayarBsdf), rgb_to_spectrum(weight));
sd, sizeof(OrenNayarBsdf), rgb_to_spectrum(weight * closure->albedo));
if (!bsdf) {
return;
}
+1 -1
View File
@@ -29,7 +29,7 @@ OSL_CLOSURE_STRUCT_BEGIN(OrenNayarDiffuseBSDF, oren_nayar_diffuse_bsdf)
OSL_CLOSURE_STRUCT_MEMBER(OrenNayarDiffuseBSDF, VECTOR, packed_float3, N, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(OrenNayarDiffuseBSDF, VECTOR, packed_float3, albedo, nullptr)
OSL_CLOSURE_STRUCT_MEMBER(OrenNayarDiffuseBSDF, FLOAT, float, roughness, nullptr)
OSL_CLOSURE_STRUCT_END(OrenNayarDiffuseBSDF, oren_nayar)
OSL_CLOSURE_STRUCT_END(OrenNayarDiffuseBSDF, oren_nayar_diffuse_bsdf)
OSL_CLOSURE_STRUCT_BEGIN(Translucent, translucent)
OSL_CLOSURE_STRUCT_MEMBER(Translucent, VECTOR, packed_float3, N, nullptr)
@@ -12,5 +12,5 @@ shader node_diffuse_bsdf(color Color = 0.8,
if (Roughness == 0.0)
BSDF = Color * diffuse(Normal);
else
BSDF = Color * oren_nayar_diffuse_bsdf(Normal, clamp(Color, 0.0, 1.0), Roughness);
BSDF = oren_nayar_diffuse_bsdf(Normal, clamp(Color, 0.0, 1.0), Roughness);
}
@@ -80,7 +80,7 @@ shader node_principled_bsdf(string distribution = "multi_ggx",
}
if (diffuse_roughness > CLOSURE_WEIGHT_CUTOFF) {
BSDF = base_color * oren_nayar_diffuse_bsdf(Normal, base_color, diffuse_roughness);
BSDF = oren_nayar_diffuse_bsdf(Normal, base_color, diffuse_roughness);
}
else {
BSDF = base_color * diffuse(Normal);