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

Change subsurface_bsdf radius from vector3 to color3 #1834

Merged
13 changes: 5 additions & 8 deletions libraries/bxdf/lama/lama_sss.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,20 @@
<nodegraph name="IMPL_lama_sss" nodedef="ND_lama_sss">

<!-- DMFP -->
<convert name="subsurface_radius_vector" type="vector3">
<input name="in" type="color3" interfacename="sssRadius" />
</convert>
<multiply name="subsurface_radius_scaled" type="vector3">
<input name="in1" type="vector3" nodename="subsurface_radius_vector" />
<multiply name="subsurface_radius_scaled" type="color3">
<input name="in1" type="color3" interfacename="sssRadius" />
<input name="in2" type="float" interfacename="sssScale" />
</multiply>
<multiply name="subsurface_multiply_unitlength" type="vector3">
<input name="in1" type="vector3" nodename="subsurface_radius_scaled" />
<multiply name="subsurface_multiply_unitlength" type="color3">
<input name="in1" type="color3" nodename="subsurface_radius_scaled" />
<input name="in2" type="float" interfacename="sssUnitLength" />
</multiply>

<!-- BRDF -->
<subsurface_bsdf name="subsurface_bsdf" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color" type="color3" interfacename="color" />
<input name="radius" type="vector3" nodename="subsurface_multiply_unitlength" />
<input name="radius" type="color3" nodename="subsurface_multiply_unitlength" />
<input name="anisotropy" type="float" interfacename="sssAnisotropy" />
<input name="normal" type="vector3" interfacename="normal" />
</subsurface_bsdf>
Expand Down
9 changes: 3 additions & 6 deletions libraries/bxdf/open_pbr_surface.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,13 @@
</mix>

<!-- Subsurface (non-thin-walled) -->
<convert name="subsurface_radius_vector" type="vector3">
<input name="in" type="color3" interfacename="subsurface_radius_scale" />
</convert>
<multiply name="subsurface_radius_scaled" type="vector3">
<input name="in1" type="vector3" nodename="subsurface_radius_vector" />
<multiply name="subsurface_radius_scaled" type="color3">
<input name="in1" type="color3" interfacename="subsurface_radius_scale" />
<input name="in2" type="float" interfacename="subsurface_radius" />
</multiply>
<subsurface_bsdf name="subsurface_bsdf" type="BSDF">
<input name="color" type="color3" nodename="subsurface_color_nonnegative" />
<input name="radius" type="vector3" nodename="subsurface_radius_scaled" />
<input name="radius" type="color3" nodename="subsurface_radius_scaled" />
<input name="anisotropy" type="float" interfacename="subsurface_scatter_anisotropy" />
<input name="normal" type="vector3" interfacename="geometry_normal" />
</subsurface_bsdf>
Expand Down
9 changes: 3 additions & 6 deletions libraries/bxdf/standard_surface.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,14 @@
<input name="color" type="color3" nodename="coat_affected_subsurface_color" />
<input name="normal" type="vector3" interfacename="normal" />
</translucent_bsdf>
<convert name="subsurface_radius_vector" type="vector3">
<input name="in" type="color3" interfacename="subsurface_radius" />
</convert>
<multiply name="subsurface_radius_scaled" type="vector3">
<input name="in1" type="vector3" nodename="subsurface_radius_vector" />
<multiply name="subsurface_radius_scaled" type="color3">
<input name="in1" type="color3" interfacename="subsurface_radius" />
<input name="in2" type="float" interfacename="subsurface_scale" />
</multiply>
<subsurface_bsdf name="subsurface_bsdf" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color" type="color3" nodename="coat_affected_subsurface_color" />
<input name="radius" type="vector3" nodename="subsurface_radius_scaled" />
<input name="radius" type="color3" nodename="subsurface_radius_scaled" />
<input name="anisotropy" type="float" interfacename="subsurface_anisotropy" />
<input name="normal" type="vector3" interfacename="normal" />
</subsurface_bsdf>
Expand Down
2 changes: 1 addition & 1 deletion libraries/pbrlib/genosl/legacy/mx_subsurface_bsdf.osl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void mx_subsurface_bsdf(float weight, color _color, vector radius, float anisotropy, normal N, output BSDF bsdf)
void mx_subsurface_bsdf(float weight, color _color, color radius, float anisotropy, normal N, output BSDF bsdf)
{
// TODO: Subsurface closure is not supported by vanilla OSL.
bsdf.response = _color * weight * diffuse(N);
Expand Down
2 changes: 1 addition & 1 deletion libraries/pbrlib/genosl/mx_subsurface_bsdf.osl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void mx_subsurface_bsdf(float weight, color _color, vector radius, float anisotropy, normal N, output BSDF bsdf)
void mx_subsurface_bsdf(float weight, color _color, color radius, float anisotropy, normal N, output BSDF bsdf)
{
// TODO: Subsurface closure is not supported by vanilla OSL.
bsdf = _color * weight * diffuse(N);
Expand Down
2 changes: 1 addition & 1 deletion libraries/pbrlib/pbrlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<nodedef name="ND_subsurface_bsdf" node="subsurface_bsdf" bsdf="R" nodegroup="pbr" doc="A subsurface scattering BSDF for true subsurface scattering.">
<input name="weight" type="float" value="1.0" uimin="0.0" uimax="1.0" />
<input name="color" type="color3" value="0.18, 0.18, 0.18" />
<input name="radius" type="vector3" value="1.0, 1.0, 1.0" />
<input name="radius" type="color3" value="1.0, 1.0, 1.0" />
<input name="anisotropy" type="float" value="0.0" />
<input name="normal" type="vector3" defaultgeomprop="Nworld" />
<output name="out" type="BSDF" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<subsurface_bsdf name="subsurface_brdf1" type="BSDF">
<input name="weight" type="float" value="1.0" />
<input name="color" type="color3" value="0.18, 0.18, 0.18" />
<input name="radius" type="vector3" value="1.0, 1.0, 1.0" />
<input name="radius" type="color3" value="1.0, 1.0, 1.0" />
<input name="anisotropy" type="float" value="0.0" />
<input name="normal" type="vector3" value="0.0, 0.0, 0.0" />
</subsurface_bsdf>
Expand Down
12 changes: 12 additions & 0 deletions source/MaterialXCore/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,18 @@ void Document::upgradeVersion()
unusedNodes.push_back(top);
}
}
else if (nodeCategory == "subsurface_bsdf")
{
InputPtr radiusInput = node->getInput("radius");
if (radiusInput && radiusInput->getType() == "vector3")
{
GraphElementPtr graph = node->getAncestorOfType<GraphElement>();
NodePtr convertNode = graph->addNode("convert", graph->createValidChildName("convert"), "color3");
copyInputWithBindings(node, "radius", convertNode, "in");
radiusInput->setConnectedNode(convertNode);
radiusInput->setType("color3");
}
}
else if (nodeCategory == "switch")
{
// Upgrade switch nodes from 5 to 10 inputs, handling the fallback behavior for
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXGenMdl/mdl/materialx/pbrlib_1_6.mdl
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export material mx_generalized_schlick_bsdf(
export material mx_subsurface_bsdf(
float mxp_weight = 1.0 [[ anno::unused() ]],
color mxp_color = color(0.18),
float3 mxp_radius = float3(1.0), // TODO: should probably be a color in MTLX Spec
color mxp_radius = color(1.0),
float mxp_anisotropy = 0.0,
float3 mxp_normal = state::normal() [[ anno::unused() ]]
) [[
Expand All @@ -357,7 +357,7 @@ export material mx_subsurface_bsdf(
color alpha =
(white - albedo_sq) / (white - mxp_anisotropy * albedo_sq);

color radius_inv = white/color(mxp_radius);
color radius_inv = white / mxp_radius;

color sigma_s = alpha * radius_inv;
color sigma_a = radius_inv - sigma_s;
Expand Down