Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to double-sided materials for 1.39 #1866

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
2 changes: 1 addition & 1 deletion libraries/pbrlib/genosl/legacy/mx_surface.osl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void mx_surface(BSDF bsdf, EDF edf, float opacity, output surfaceshader result)
void mx_surface(BSDF bsdf, EDF edf, float opacity, int thin_walled, output surfaceshader result)
{
result.bsdf = bsdf.response;
result.edf = edf;
Expand Down
2 changes: 1 addition & 1 deletion libraries/pbrlib/genosl/mx_surface.osl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void mx_surface(BSDF bsdf, EDF edf, float opacity, output surfaceshader result)
void mx_surface(BSDF bsdf, EDF edf, float opacity, int thin_walled, output surfaceshader result)
{
result.bsdf = bsdf;
result.edf = edf;
Expand Down
1 change: 1 addition & 0 deletions libraries/pbrlib/pbrlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
<input name="bsdf" type="BSDF" value="" doc="Distribution function for surface scattering." />
<input name="edf" type="EDF" value="" doc="Distribution function for surface emission." />
<input name="opacity" type="float" value="1.0" doc="Surface cutout opacity" />
<input name="thin_walled" type="boolean" value="false" uniform="true" doc="Option to make the surface thin-walled." />
<output name="out" type="surfaceshader" />
</nodedef>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the old deprecated node thin_surface still remains below, and we can remove this in another PR.

I'm not sure if we need to add code for upgrading from thin_surface to surface with thin_walled enabled? The thin_surface node was never implemented in any backends, except maybe MDL, so I'm not sure if this was ever used by anyone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question, and my own sense is that the deprecated thin_surface node has not yet been used in real-world assets, because it's only been supported on a single target. So I'd say that it's likely safe to remove this node without an upgrade path in a future change.

Expand Down
1 change: 1 addition & 0 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<!-- Surface material -->
<nodedef name="ND_surfacematerial" node="surfacematerial" nodegroup="material">
<input name="surfaceshader" type="surfaceshader" value="" />
<input name="backsurfaceshader" type="surfaceshader" value="" />
<input name="displacementshader" type="displacementshader" value="" />
<output name="out" type="material" />
</nodedef>
Expand Down
3 changes: 2 additions & 1 deletion source/MaterialXGenMdl/mdl/materialx/pbrlib_1_6.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,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 bool mxp_thin_walled = false,
uniform float mxp_transmission_ior = 0.0 // extra parameter for setting transmission IOR
) [[
anno::usage( "materialx:surfaceshader")
Expand All @@ -555,7 +556,7 @@ export material mx_surface(
// we need to carry volume properties along for SSS
material_volume bsdf_volume = mxp_bsdf.volume;
} in material(
thin_walled: false,
thin_walled: mxp_thin_walled,
surface: material_surface(
scattering: bsdf_node,
emission: edf_node
Expand Down
5 changes: 3 additions & 2 deletions source/MaterialXGenMdl/mdl/materialx/stdlib_1_6.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ import .::hsv::*;

export material mx_surfacematerial(
material mxp_surfaceshader = material() [[ anno::usage( "materialx:surfaceshader") ]],
material mxp_backsurfaceshader = material() [[ anno::usage( "materialx:surfaceshader") ]],
material mxp_displacementshader = material() [[ anno::usage( "materialx:displacementshader") ]]
)
= material(
thin_walled: false,
thin_walled: mxp_surfaceshader.thin_walled || mxp_backsurfaceshader.thin_walled,
surface: mxp_surfaceshader.surface,
backface: mxp_surfaceshader.backface,
backface: mxp_backsurfaceshader.surface,
geometry: material_geometry(
cutout_opacity: mxp_surfaceshader.geometry.cutout_opacity,
displacement : mxp_displacementshader.geometry.displacement,
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenOsl/Nodes/MaterialNodeOsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ShaderNodeImplPtr MaterialNodeOsl::create()
void MaterialNodeOsl::emitFunctionDefinition(const ShaderNode&, GenContext& context, ShaderStage& stage) const
{
const static string FUNCTION_DEFINITION =
"MATERIAL mx_surfacematerial(surfaceshader surface, displacementshader disp)\n"
"MATERIAL mx_surfacematerial(surfaceshader surface, surfaceshader backsurface, displacementshader disp)\n"
"{\n"
" float opacity_weight = clamp(surface.opacity, 0.0, 1.0);\n"
" return (surface.bsdf + surface.edf) * opacity_weight + transparent() * (1.0 - opacity_weight);\n"
Expand Down