Skip to content

Commit 5a1a9f4

Browse files
committed
add subsurface bsdf tests and apply weight in MDL implementation
1 parent 0e6b5bf commit 5a1a9f4

2 files changed

Lines changed: 112 additions & 10 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0"?>
2+
<materialx version="1.39">
3+
<nodegraph name="subsurface_1_common">
4+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
5+
<input name="weight" type="float" value="1.0" />
6+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
7+
<input name="radius" type="color3" value="1.0, 1.0, 1.0" />
8+
<input name="anisotropy" type="float" value="0.0" />
9+
</subsurface_bsdf>
10+
<surface name="surface1" type="surfaceshader">
11+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
12+
<input name="opacity" type="float" value="1.0" />
13+
</surface>
14+
<output name="out" type="surfaceshader" nodename="surface1" />
15+
</nodegraph>
16+
17+
<!-- SSS radius of 1 cm assuming the scene units are in meters -->
18+
<nodegraph name="subsurface_2_radius_0_01">
19+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
20+
<input name="weight" type="float" value="1.0" />
21+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
22+
<input name="radius" type="color3" value="0.01, 0.01, 0.01" />
23+
<input name="anisotropy" type="float" value="0.0" />
24+
</subsurface_bsdf>
25+
<surface name="surface1" type="surfaceshader">
26+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
27+
<input name="opacity" type="float" value="1.0" />
28+
</surface>
29+
<output name="out" type="surfaceshader" nodename="surface1" />
30+
</nodegraph>
31+
32+
<!-- SSS radius of 2.5 cm assuming the scene units are in meters -->
33+
<nodegraph name="subsurface_2_radius_0_025">
34+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
35+
<input name="weight" type="float" value="1.0" />
36+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
37+
<input name="radius" type="color3" value="0.025, 0.025, 0.025" />
38+
<input name="anisotropy" type="float" value="0.0" />
39+
</subsurface_bsdf>
40+
<surface name="surface1" type="surfaceshader">
41+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
42+
<input name="opacity" type="float" value="1.0" />
43+
</surface>
44+
<output name="out" type="surfaceshader" nodename="surface1" />
45+
</nodegraph>
46+
47+
<!-- SSS radius of 5 m (thin gas) assuming the scene units are in meters -->
48+
<nodegraph name="subsurface_2_radius_5_0">
49+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
50+
<input name="weight" type="float" value="1.0" />
51+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
52+
<input name="radius" type="color3" value="5.0, 5.0, 5.0" />
53+
<input name="anisotropy" type="float" value="0.0" />
54+
</subsurface_bsdf>
55+
<surface name="surface1" type="surfaceshader">
56+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
57+
<input name="opacity" type="float" value="1.0" />
58+
</surface>
59+
<output name="out" type="surfaceshader" nodename="surface1" />
60+
</nodegraph>
61+
62+
<nodegraph name="subsurface_3_weighted">
63+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
64+
<input name="weight" type="float" value="0.25" />
65+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
66+
<input name="radius" type="color3" value="1.0, 1.0, 1.0" />
67+
<input name="anisotropy" type="float" value="0.0" />
68+
</subsurface_bsdf>
69+
<surface name="surface1" type="surfaceshader">
70+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
71+
<input name="opacity" type="float" value="1.0" />
72+
</surface>
73+
<output name="out" type="surfaceshader" nodename="surface1" />
74+
</nodegraph>
75+
76+
<nodegraph name="subsurface_4_forward">
77+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
78+
<input name="weight" type="float" value="1.0" />
79+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
80+
<input name="radius" type="color3" value="1.0, 1.0, 1.0" />
81+
<input name="anisotropy" type="float" value="0.9" />
82+
</subsurface_bsdf>
83+
<surface name="surface1" type="surfaceshader">
84+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
85+
<input name="opacity" type="float" value="1.0" />
86+
</surface>
87+
<output name="out" type="surfaceshader" nodename="surface1" />
88+
</nodegraph>
89+
90+
<nodegraph name="subsurface_4_backward">
91+
<subsurface_bsdf name="subsurface_bsdf1" type="BSDF">
92+
<input name="weight" type="float" value="1.0" />
93+
<input name="color" type="color3" value="0.816, 0.140, 0.124" />
94+
<input name="radius" type="color3" value="1.0, 1.0, 1.0" />
95+
<input name="anisotropy" type="float" value="-0.9" />
96+
</subsurface_bsdf>
97+
<surface name="surface1" type="surfaceshader">
98+
<input name="bsdf" type="BSDF" nodename="subsurface_bsdf1" />
99+
<input name="opacity" type="float" value="1.0" />
100+
</surface>
101+
<output name="out" type="surfaceshader" nodename="surface1" />
102+
</nodegraph>
103+
104+
</materialx>

source/MaterialXGenMdl/mdl/materialx/pbrlib_1_6.mdl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export material mx_generalized_schlick_bsdf(
340340
);
341341

342342
export material mx_subsurface_bsdf(
343-
float mxp_weight = 1.0 [[ anno::unused() ]],
343+
float mxp_weight = 1.0,
344344
color mxp_color = color(0.18),
345345
color mxp_radius = color(1.0),
346346
float mxp_anisotropy = 0.0,
@@ -351,22 +351,20 @@ export material mx_subsurface_bsdf(
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
354-
// to anisotropic_vdf(directional_bias: g).
354+
// to anisotropic_vdf(directional_bias: g).
355+
color C = math::saturate(mxp_weight) * mxp_color;
355356
color albedo = color(4.09712) +
356-
(4.20863f * mxp_color) -
357+
(4.20863f * C) -
357358
math::sqrt(
358359
9.59217f +
359-
41.6808f * mxp_color +
360-
17.7126f * mxp_color * mxp_color);
360+
41.6808f * C +
361+
17.7126f * C * C);
361362

362363
color albedo_sq = albedo * albedo;
363-
364364
color white = color(1.0, 1.0, 1.0);
365+
color alpha = (white - albedo_sq) / (white - mxp_anisotropy * albedo_sq);
365366

366-
color alpha =
367-
(white - albedo_sq) / (white - mxp_anisotropy * albedo_sq);
368-
369-
color radius_inv = white / mxp_radius;
367+
color radius_inv = white / math::max(color(0.001), mxp_radius);
370368

371369
color sigma_s = alpha * radius_inv;
372370
color sigma_a = radius_inv - sigma_s;

0 commit comments

Comments
 (0)