Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions resources/Materials/TestSuite/pbrlib/bsdf/generalized_schlick.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,51 @@
<input name="bsdf" type="BSDF" nodename="layer_RT" />
</surface>
<output name="layer_RT_out" type="surfaceshader" nodename="surface_layer_RT" />

<generalized_schlick_bsdf name="schlick_R2" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color0" type="color3" value="0.5, 0.0, 0.0" />
<input name="color90" type="color3" value="0.0, 1.0, 0.0" />
<input name="exponent" type="float" value="5.0" />
<input name="scatter_mode" type="string" value="R" />
</generalized_schlick_bsdf>
<surface name="surface_R2" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="schlick_R2" />
</surface>
<output name="R2_out" type="surfaceshader" nodename="surface_R2" />

<generalized_schlick_bsdf name="schlick_T2" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color0" type="color3" value="0.5, 0.0, 0.0" />
<input name="color90" type="color3" value="0.0, 1.0, 0.0" />
<input name="exponent" type="float" value="5.0" />
<input name="scatter_mode" type="string" value="T" />
</generalized_schlick_bsdf>
<surface name="surface_T2" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="schlick_T2" />
</surface>
<output name="T2_out" type="surfaceshader" nodename="surface_T2" />

<generalized_schlick_bsdf name="schlick_RT2" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color0" type="color3" value="0.5, 0.0, 0.0" />
<input name="color90" type="color3" value="0.0, 1.0, 0.0" />
<input name="exponent" type="float" value="5.0" />
<input name="scatter_mode" type="string" value="RT" />
</generalized_schlick_bsdf>
<surface name="surface_RT2" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="schlick_RT2" />
</surface>
<output name="RT2_out" type="surfaceshader" nodename="surface_RT2" />

<layer name="layer_RT2" type="BSDF">
<input name="top" type="BSDF" nodename="schlick_R2" />
<input name="base" type="BSDF" nodename="schlick_T2" />
</layer>
<surface name="surface_layer_RT2" type="surfaceshader">
<input name="bsdf" type="BSDF" nodename="layer_RT2" />
</surface>
<output name="layer_RT2_out" type="surfaceshader" nodename="surface_layer_RT2" />

</nodegraph>
</materialx>
83 changes: 54 additions & 29 deletions source/MaterialXGenMdl/mdl/materialx/pbrlib.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,16 @@ export material mx_dielectric_bsdf(
]]
= let {
float coatIor = mxp_thinfilm_ior <= 0.0 ? 1.0 : mxp_thinfilm_ior;
float grazing_refl = math::max((1.0 - math::average(mxp_roughness)), 0.0);
float root_r = (mxp_ior-1)/(mxp_ior+1);
bsdf bsdf_R = df::thin_film(
thickness: mxp_thinfilm_thickness,
ior: color(coatIor),
base: df::fresnel_layer(
ior: mxp_ior,
// fresnel layer has issues if base is a diffuse transmission, use custom curve for now
// this will break thin_film but improves standard_surface with diffuse transmission
base: df::custom_curve_layer(
normal_reflectivity: root_r*root_r,
grazing_reflectivity: grazing_refl,
weight: mxp_weight,
layer: df::microfacet_ggx_smith_bsdf(
roughness_u: mxp_roughness.x,
Expand All @@ -172,16 +177,16 @@ export material mx_dielectric_bsdf(
tangent_u: mxp_tangent,
mode: df::scatter_reflect),
base: mxp_base.surface.scattering,
normal: mxp_normal));
normal: mxp_normal));

bsdf bsdf_T = df::weighted_layer(
weight: mxp_weight,
layer: df::microfacet_ggx_smith_bsdf(
roughness_u: mxp_roughness.x,
roughness_v: mxp_roughness.y,
tint: mxp_tint,
tangent_u: mxp_tangent,
mode: df::scatter_transmit),
roughness_u: mxp_roughness.x,
roughness_v: mxp_roughness.y,
tint: mxp_tint,
tangent_u: mxp_tangent,
mode: df::scatter_transmit),
normal: mxp_normal);

bsdf bsdf_RT = df::weighted_layer(
Expand Down Expand Up @@ -255,7 +260,7 @@ export material mx_generalized_schlick_bsdf(
color mxp_color0 = color(1.0),
color mxp_color90 = color(1.0),
float mxp_exponent = 5.0,
float2 mxp_roughness = float2(0.0),
float2 mxp_roughness = float2(0.05),
float3 mxp_normal = state::normal(),
float3 mxp_tangent = state::texture_tangent_u(0),
uniform mx_distribution_type mxp_distribution = mx_distribution_type_ggx [[ anno::unused() ]],
Expand All @@ -268,31 +273,51 @@ export material mx_generalized_schlick_bsdf(
]]
= let {
float coatIor = mxp_thinfilm_ior <= 0.0 ? 1.0 : mxp_thinfilm_ior;
df::scatter_mode mode = ::mx_map_scatter_mode(mxp_scatter_mode);
bsdf ggx_model = df::microfacet_ggx_smith_bsdf(
roughness_u: mxp_roughness.x * mxp_roughness.x,
roughness_v: mxp_roughness.y * mxp_roughness.y,
float avgF0 = math::average(float3(mxp_color0));
bsdf ggx_model_R = df::microfacet_ggx_smith_bsdf(
roughness_u: mxp_roughness.x,
roughness_v: mxp_roughness.y,
tint: color(1.0),
tangent_u: mxp_tangent,
mode: df::scatter_reflect);

bsdf ggx_model_T = df::microfacet_ggx_smith_bsdf(
roughness_u: mxp_roughness.x,
roughness_v: mxp_roughness.y,
tint: color(1.0),
tangent_u: mxp_tangent,
mode: mode);
mode: df::scatter_transmit);
} in material(
surface: material_surface(
scattering: df::thin_film(
thickness: mxp_thinfilm_thickness,
ior: color(coatIor),
base: df::color_custom_curve_layer(
normal_reflectivity: mxp_color0,
grazing_reflectivity: mxp_color90,
exponent: mxp_exponent,
weight: color(mxp_weight),
layer: ggx_model,
base: mxp_base.surface.scattering,
normal: mxp_normal
)
scattering: df::weighted_layer(
weight: mxp_weight,
layer: mxp_scatter_mode == mx_scatter_mode_T
? df::color_custom_curve_layer(
normal_reflectivity: mxp_color0,
grazing_reflectivity: mxp_color90,
exponent: mxp_exponent,
layer: bsdf(),
base: ggx_model_T)
: df::thin_film(
thickness: mxp_thinfilm_thickness,
ior: color(coatIor),
base: df::color_custom_curve_layer(
normal_reflectivity: mxp_color0,
grazing_reflectivity: mxp_color90,
exponent: mxp_exponent,
layer: ggx_model_R,
base: mxp_scatter_mode == mx_scatter_mode_R
? mxp_base.surface.scattering
: ggx_model_T)),
base: mxp_base.surface.scattering,
normal: mxp_normal
)
),
// we can't use the computed ior here because it's varying
// assuming that we have something glass like when transmission is used
ior: color(1.5), // color(mx_f0_to_ior(avgF0))

// we need to carry volume properties along for SSS
ior: mxp_base.ior,
volume: mxp_base.volume
);

Expand Down Expand Up @@ -513,7 +538,7 @@ export material mx_surface(
material mxp_bsdf = material() [[ anno::usage( "materialx:bsdf") ]],
material mxp_edf = material() [[ anno::usage( "materialx:edf") ]],
float mxp_opacity = 1.0,
uniform float mxp_transmission_ior = 1.0 // extra parameter for setting transmission IOR
uniform float mxp_transmission_ior = 0.0 // extra parameter for setting transmission IOR
) [[
anno::usage( "materialx:surfaceshader")
]]
Expand All @@ -528,7 +553,7 @@ export material mx_surface(
scattering: bsdf_node,
emission: edf_node
),
ior: color(mxp_transmission_ior),
ior: mxp_transmission_ior > 0.0 ? color(mxp_transmission_ior) : mxp_bsdf.ior,
volume: bsdf_volume,
geometry: material_geometry(
cutout_opacity: mxp_opacity
Expand Down