Skip to content

Commit 5beba1a

Browse files
authored
Fix interpretation of subsurface weight in MDL (#2536)
The subsurface weight should not be applied to the expected color but instead enable/disable the effect in general. This means the semantic of the weight is meant for composition rather than turning down the volume absorption and scattering itself. With the performance optimizations for Standard Surface and OpenPBR this issue surfaced since weights are not 1.0 anymore.
1 parent 50cee47 commit 5beba1a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

source/MaterialXGenMdl/mdl/materialx/pbrlib_1_6.mdl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,16 @@ export material mx_subsurface_bsdf(
344344
color mxp_color = color(0.18),
345345
color mxp_radius = color(1.0),
346346
float mxp_anisotropy = 0.0,
347-
float3 mxp_normal = state::normal() [[ anno::unused() ]]
347+
float3 mxp_normal = state::normal()
348348
) [[
349349
anno::usage( "materialx:bsdf")
350350
]]
351351
= let {
352352
// https://blog.selfshadow.com/publications/s2017-shading-course/imageworks/s2017_pbs_imageworks_slides_v2.pdf
353353
// Phase function eccentricity 'g' has been omitted here since we pass that directly
354354
// to anisotropic_vdf(directional_bias: g).
355-
color C = math::saturate(mxp_weight) * mxp_color;
355+
float w = math::saturate(mxp_weight);
356+
color C = mxp_color;
356357
color albedo = color(4.09712) +
357358
(4.20863f * C) -
358359
math::sqrt(
@@ -364,7 +365,7 @@ export material mx_subsurface_bsdf(
364365
color white = color(1.0, 1.0, 1.0);
365366
color alpha = (white - albedo_sq) / (white - mxp_anisotropy * albedo_sq);
366367

367-
color radius_inv = white / math::max(color(0.001), mxp_radius);
368+
color radius_inv = white / math::max(0.00000001, mxp_radius);
368369

369370
color sigma_s = alpha * radius_inv;
370371
color sigma_a = radius_inv - sigma_s;
@@ -374,12 +375,16 @@ export material mx_subsurface_bsdf(
374375
scattering: df::anisotropic_vdf (
375376
directional_bias: mxp_anisotropy
376377
),
377-
scattering_coefficient: sigma_s,
378-
absorption_coefficient: sigma_a
378+
scattering_coefficient: w * sigma_s,
379+
absorption_coefficient: w * sigma_a
379380
),
380381

381382
surface: material_surface(
382-
scattering: df::diffuse_transmission_bsdf(tint: white)
383+
scattering: df::weighted_layer(
384+
weight: w,
385+
layer: df::diffuse_transmission_bsdf(tint: white),
386+
normal: mxp_normal
387+
)
383388
)
384389
);
385390

source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ void MdlShaderGeneratorTester::compileSource(const std::vector<mx::FilePath>& so
315315
if (renderArgs.empty())
316316
{
317317
// Assume MDL example DXR is being used and set reasonable arguments automatically
318-
renderCommand += " --nogui --res 512 512 --iterations 1024 --max_path_length 3 --noaux --no_firefly_clamp";
318+
renderCommand += " --nogui --res 512 512 --iterations 1024 --max_path_length 4 --noaux --no_firefly_clamp";
319319
renderCommand += " --background 0.073239 0.073239 0.083535";
320320
}
321321
else

0 commit comments

Comments
 (0)