Skip to content

Commit 41ec46d

Browse files
authored
MDL 1.7 dielectric and generalized schlick improvements (#1321)
- Change the `Dielectric` MDL implementation to use custom curve instead of Fresnel because of issues with diffuse transmission. This comes with limited thin_film support, which will be restored by MDL 1.8 - Improve `Generalized Schlick` MDL implementation so Reflect, Transmit and ReflectTransmit are more plausible. The OSL backend produces very similar results.
1 parent 975c24f commit 41ec46d

2 files changed

Lines changed: 100 additions & 29 deletions

File tree

resources/Materials/TestSuite/pbrlib/bsdf/generalized_schlick.mtlx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,51 @@
4545
<input name="bsdf" type="BSDF" nodename="layer_RT" />
4646
</surface>
4747
<output name="layer_RT_out" type="surfaceshader" nodename="surface_layer_RT" />
48+
49+
<generalized_schlick_bsdf name="schlick_R2" type="BSDF">
50+
<input name="weight" type="float" value="1.0" />
51+
<input name="color0" type="color3" value="0.5, 0.0, 0.0" />
52+
<input name="color90" type="color3" value="0.0, 1.0, 0.0" />
53+
<input name="exponent" type="float" value="5.0" />
54+
<input name="scatter_mode" type="string" value="R" />
55+
</generalized_schlick_bsdf>
56+
<surface name="surface_R2" type="surfaceshader">
57+
<input name="bsdf" type="BSDF" nodename="schlick_R2" />
58+
</surface>
59+
<output name="R2_out" type="surfaceshader" nodename="surface_R2" />
60+
61+
<generalized_schlick_bsdf name="schlick_T2" type="BSDF">
62+
<input name="weight" type="float" value="1.0" />
63+
<input name="color0" type="color3" value="0.5, 0.0, 0.0" />
64+
<input name="color90" type="color3" value="0.0, 1.0, 0.0" />
65+
<input name="exponent" type="float" value="5.0" />
66+
<input name="scatter_mode" type="string" value="T" />
67+
</generalized_schlick_bsdf>
68+
<surface name="surface_T2" type="surfaceshader">
69+
<input name="bsdf" type="BSDF" nodename="schlick_T2" />
70+
</surface>
71+
<output name="T2_out" type="surfaceshader" nodename="surface_T2" />
72+
73+
<generalized_schlick_bsdf name="schlick_RT2" type="BSDF">
74+
<input name="weight" type="float" value="1.0" />
75+
<input name="color0" type="color3" value="0.5, 0.0, 0.0" />
76+
<input name="color90" type="color3" value="0.0, 1.0, 0.0" />
77+
<input name="exponent" type="float" value="5.0" />
78+
<input name="scatter_mode" type="string" value="RT" />
79+
</generalized_schlick_bsdf>
80+
<surface name="surface_RT2" type="surfaceshader">
81+
<input name="bsdf" type="BSDF" nodename="schlick_RT2" />
82+
</surface>
83+
<output name="RT2_out" type="surfaceshader" nodename="surface_RT2" />
84+
85+
<layer name="layer_RT2" type="BSDF">
86+
<input name="top" type="BSDF" nodename="schlick_R2" />
87+
<input name="base" type="BSDF" nodename="schlick_T2" />
88+
</layer>
89+
<surface name="surface_layer_RT2" type="surfaceshader">
90+
<input name="bsdf" type="BSDF" nodename="layer_RT2" />
91+
</surface>
92+
<output name="layer_RT2_out" type="surfaceshader" nodename="surface_layer_RT2" />
93+
4894
</nodegraph>
4995
</materialx>

source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,16 @@ export material mx_dielectric_bsdf(
159159
]]
160160
= let {
161161
float coatIor = mxp_thinfilm_ior <= 0.0 ? 1.0 : mxp_thinfilm_ior;
162+
float grazing_refl = math::max((1.0 - math::average(mxp_roughness)), 0.0);
163+
float root_r = (mxp_ior-1)/(mxp_ior+1);
162164
bsdf bsdf_R = df::thin_film(
163165
thickness: mxp_thinfilm_thickness,
164166
ior: color(coatIor),
165-
base: df::fresnel_layer(
166-
ior: mxp_ior,
167+
// fresnel layer has issues if base is a diffuse transmission, use custom curve for now
168+
// this will break thin_film but improves standard_surface with diffuse transmission
169+
base: df::custom_curve_layer(
170+
normal_reflectivity: root_r*root_r,
171+
grazing_reflectivity: grazing_refl,
167172
weight: mxp_weight,
168173
layer: df::microfacet_ggx_smith_bsdf(
169174
roughness_u: mxp_roughness.x,
@@ -172,16 +177,16 @@ export material mx_dielectric_bsdf(
172177
tangent_u: mxp_tangent,
173178
mode: df::scatter_reflect),
174179
base: mxp_base.surface.scattering,
175-
normal: mxp_normal));
180+
normal: mxp_normal));
176181

177182
bsdf bsdf_T = df::weighted_layer(
178183
weight: mxp_weight,
179184
layer: df::microfacet_ggx_smith_bsdf(
180-
roughness_u: mxp_roughness.x,
181-
roughness_v: mxp_roughness.y,
182-
tint: mxp_tint,
183-
tangent_u: mxp_tangent,
184-
mode: df::scatter_transmit),
185+
roughness_u: mxp_roughness.x,
186+
roughness_v: mxp_roughness.y,
187+
tint: mxp_tint,
188+
tangent_u: mxp_tangent,
189+
mode: df::scatter_transmit),
185190
normal: mxp_normal);
186191

187192
bsdf bsdf_RT = df::weighted_layer(
@@ -255,7 +260,7 @@ export material mx_generalized_schlick_bsdf(
255260
color mxp_color0 = color(1.0),
256261
color mxp_color90 = color(1.0),
257262
float mxp_exponent = 5.0,
258-
float2 mxp_roughness = float2(0.0),
263+
float2 mxp_roughness = float2(0.05),
259264
float3 mxp_normal = state::normal(),
260265
float3 mxp_tangent = state::texture_tangent_u(0),
261266
uniform mx_distribution_type mxp_distribution = mx_distribution_type_ggx [[ anno::unused() ]],
@@ -268,31 +273,51 @@ export material mx_generalized_schlick_bsdf(
268273
]]
269274
= let {
270275
float coatIor = mxp_thinfilm_ior <= 0.0 ? 1.0 : mxp_thinfilm_ior;
271-
df::scatter_mode mode = ::mx_map_scatter_mode(mxp_scatter_mode);
272-
bsdf ggx_model = df::microfacet_ggx_smith_bsdf(
273-
roughness_u: mxp_roughness.x * mxp_roughness.x,
274-
roughness_v: mxp_roughness.y * mxp_roughness.y,
276+
float avgF0 = math::average(float3(mxp_color0));
277+
bsdf ggx_model_R = df::microfacet_ggx_smith_bsdf(
278+
roughness_u: mxp_roughness.x,
279+
roughness_v: mxp_roughness.y,
280+
tint: color(1.0),
281+
tangent_u: mxp_tangent,
282+
mode: df::scatter_reflect);
283+
284+
bsdf ggx_model_T = df::microfacet_ggx_smith_bsdf(
285+
roughness_u: mxp_roughness.x,
286+
roughness_v: mxp_roughness.y,
275287
tint: color(1.0),
276288
tangent_u: mxp_tangent,
277-
mode: mode);
289+
mode: df::scatter_transmit);
278290
} in material(
279291
surface: material_surface(
280-
scattering: df::thin_film(
281-
thickness: mxp_thinfilm_thickness,
282-
ior: color(coatIor),
283-
base: df::color_custom_curve_layer(
284-
normal_reflectivity: mxp_color0,
285-
grazing_reflectivity: mxp_color90,
286-
exponent: mxp_exponent,
287-
weight: color(mxp_weight),
288-
layer: ggx_model,
289-
base: mxp_base.surface.scattering,
290-
normal: mxp_normal
291-
)
292+
scattering: df::weighted_layer(
293+
weight: mxp_weight,
294+
layer: mxp_scatter_mode == mx_scatter_mode_T
295+
? df::color_custom_curve_layer(
296+
normal_reflectivity: mxp_color0,
297+
grazing_reflectivity: mxp_color90,
298+
exponent: mxp_exponent,
299+
layer: bsdf(),
300+
base: ggx_model_T)
301+
: df::thin_film(
302+
thickness: mxp_thinfilm_thickness,
303+
ior: color(coatIor),
304+
base: df::color_custom_curve_layer(
305+
normal_reflectivity: mxp_color0,
306+
grazing_reflectivity: mxp_color90,
307+
exponent: mxp_exponent,
308+
layer: ggx_model_R,
309+
base: mxp_scatter_mode == mx_scatter_mode_R
310+
? mxp_base.surface.scattering
311+
: ggx_model_T)),
312+
base: mxp_base.surface.scattering,
313+
normal: mxp_normal
292314
)
293315
),
316+
// we can't use the computed ior here because it's varying
317+
// assuming that we have something glass like when transmission is used
318+
ior: color(1.5), // color(mx_f0_to_ior(avgF0))
319+
294320
// we need to carry volume properties along for SSS
295-
ior: mxp_base.ior,
296321
volume: mxp_base.volume
297322
);
298323

@@ -513,7 +538,7 @@ export material mx_surface(
513538
material mxp_bsdf = material() [[ anno::usage( "materialx:bsdf") ]],
514539
material mxp_edf = material() [[ anno::usage( "materialx:edf") ]],
515540
float mxp_opacity = 1.0,
516-
uniform float mxp_transmission_ior = 1.0 // extra parameter for setting transmission IOR
541+
uniform float mxp_transmission_ior = 0.0 // extra parameter for setting transmission IOR
517542
) [[
518543
anno::usage( "materialx:surfaceshader")
519544
]]
@@ -528,7 +553,7 @@ export material mx_surface(
528553
scattering: bsdf_node,
529554
emission: edf_node
530555
),
531-
ior: color(mxp_transmission_ior),
556+
ior: mxp_transmission_ior > 0.0 ? color(mxp_transmission_ior) : mxp_bsdf.ior,
532557
volume: bsdf_volume,
533558
geometry: material_geometry(
534559
cutout_opacity: mxp_opacity

0 commit comments

Comments
 (0)