Skip to content

Commit

Permalink
Add support for geompropvalueuniform node (#2092)
Browse files Browse the repository at this point in the history
Adds a string-/filename-friendly primvar/geompropvalue node, as was proposed for 1.39.
  • Loading branch information
crydalch authored Dec 14, 2024
1 parent b1b94b6 commit 81ed31d
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 27 deletions.
6 changes: 0 additions & 6 deletions documents/Specification/MaterialX.Proposals.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ In #1201 it was decided that separate periodic versions of all of the noises is

* **`bump`**: Existing node, proposal to add a vector3 `bitangent` input

<a id="node-geompropvalueuniform"> </a>

* **`geompropvalueuniform`**: the value of the specified uniform geometric property (defined using &lt;geompropdef>) of the currently-bound geometry. This node's type must match that of the referenced geomprop.
* `geomprop` (uniform string): the geometric property to be referenced.
* `default` (same type as the geomprop's value): a value to return if the specified `geomprop` is not defined on the current geometry.

Note: when &lt;geompropvalueuniform> is added, the text in the first paragraph of the Specification about Node Inputs should be revised to include "&lt;geompropvalueuniform>" as an example of "or any other node whose output is explicitly declared to be uniform".


Expand Down
6 changes: 6 additions & 0 deletions documents/Specification/MaterialX.Specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,12 @@ Standard Geometric nodes:
* `geomprop` (uniform string): the geometric property to be referenced.
* `default` (same type as the geomprop's value): a value to return if the specified `geomprop` is not defined on the current geometry.

<a id="node-geompropvalueuniform"> </a>

* **`geompropvalueuniform`**: the value of the specified uniform geometric property (defined using &lt;geompropdef>) of the currently-bound geometry. This node's type must match that of the referenced geomprop.
* `geomprop` (uniform string): the geometric property to be referenced.
* `default` (same type as the geomprop's value): a value to return if the specified `geomprop` is not defined on the current geometry.

Additionally, the `geomcolor` and `geompropvalue` nodes for color3/color4-type properties can take a `colorspace` attribute to declare what colorspace the color property value is in; the default is "none" for no colorspace declaration (and hence no colorspace conversion).


Expand Down
22 changes: 17 additions & 5 deletions libraries/bxdf/usd_preview_surface.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@
</nodedef>
<nodedef name="ND_UsdPrimvarReader_string" nodegroup="geometric" node="UsdPrimvarReader">
<input name="varname" type="string" value="" uniform="true" />
<input name="fallback" type="string" value="" />
<output name="out" type="string" />
<input name="fallback" type="string" value="" uniform="true" />
<output name="out" type="string" uniform="true"/>
</nodedef>
<nodedef name="ND_UsdPrimvarReader_filename" nodegroup="geometric" node="UsdPrimvarReader">
<input name="varname" type="string" value="" uniform="true" />
<input name="fallback" type="filename" value="" uniform="true" />
<output name="out" type="filename" uniform="true"/>
</nodedef>
<nodedef name="ND_UsdPrimvarReader_float" nodegroup="geometric" node="UsdPrimvarReader">
<input name="varname" type="string" value="" uniform="true" />
Expand Down Expand Up @@ -359,11 +364,18 @@
<output name="out" type="boolean" nodename="primvar" />
</nodegraph>
<nodegraph name="IMP_UsdPrimvarReader_string" nodedef="ND_UsdPrimvarReader_string">
<geompropvalue name="primvar" type="string">
<geompropvalueuniform name="primvar" type="string">
<input name="geomprop" type="string" interfacename="varname" />
<input name="default" type="string" interfacename="fallback" />
</geompropvalue>
<output name="out" type="string" nodename="primvar" />
</geompropvalueuniform>
<output name="out" type="string" nodename="primvar" uniform="true" />
</nodegraph>
<nodegraph name="IMP_UsdPrimvarReader_filename" nodedef="ND_UsdPrimvarReader_filename">
<geompropvalueuniform name="primvar" type="filename">
<input name="geomprop" type="string" interfacename="varname" />
<input name="default" type="filename" interfacename="fallback" />
</geompropvalueuniform>
<output name="out" type="filename" nodename="primvar" uniform="true" />
</nodegraph>
<nodegraph name="IMP_UsdPrimvarReader_float" nodedef="ND_UsdPrimvarReader_float">
<geompropvalue name="primvar" type="float">
Expand Down
5 changes: 4 additions & 1 deletion libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,17 @@
<!-- <geompropvalue> -->
<implementation name="IM_geompropvalue_integer_genglsl" nodedef="ND_geompropvalue_integer" function="mx_geompropvalue_int" target="genglsl" />
<implementation name="IM_geompropvalue_boolean_genglsl" nodedef="ND_geompropvalue_boolean" function="mx_geompropvalue_bool" target="genglsl" />
<implementation name="IM_geompropvalue_string_genglsl" nodedef="ND_geompropvalue_string" function="mx_geompropvalue_string" target="genglsl" />
<implementation name="IM_geompropvalue_float_genglsl" nodedef="ND_geompropvalue_float" function="mx_geompropvalue_float" target="genglsl" />
<implementation name="IM_geompropvalue_color3_genglsl" nodedef="ND_geompropvalue_color3" function="mx_geompropvalue_color" target="genglsl" />
<implementation name="IM_geompropvalue_color4_genglsl" nodedef="ND_geompropvalue_color4" function="mx_geompropvalue_color4" target="genglsl" />
<implementation name="IM_geompropvalue_vector2_genglsl" nodedef="ND_geompropvalue_vector2" function="mx_geompropvalue_vector2" target="genglsl" />
<implementation name="IM_geompropvalue_vector3_genglsl" nodedef="ND_geompropvalue_vector3" function="mx_geompropvalue_vector" target="genglsl" />
<implementation name="IM_geompropvalue_vector4_genglsl" nodedef="ND_geompropvalue_vector4" function="mx_geompropvalue_vector4" target="genglsl" />

<!-- <geompropvalueuniform> -->
<implementation name="IM_geompropvalue_string_genglsl" nodedef="ND_geompropvalueuniform_string" function="mx_geompropvalue_string" target="genglsl" />
<implementation name="IM_geompropvalue_filename_genglsl" nodedef="ND_geompropvalueuniform_filename" function="mx_geompropvalue_string" target="genglsl" />

<!-- ======================================================================== -->
<!-- Application nodes -->
<!-- ======================================================================== -->
Expand Down
5 changes: 4 additions & 1 deletion libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,17 @@
<!-- <geompropvalue> -->
<implementation name="IM_geompropvalue_integer_genmdl" nodedef="ND_geompropvalue_integer" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_integer(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_boolean_genmdl" nodedef="ND_geompropvalue_boolean" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_boolean(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_string_genmdl" nodedef="ND_geompropvalue_string" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_string(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_float_genmdl" nodedef="ND_geompropvalue_float" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_float(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_color3_genmdl" nodedef="ND_geompropvalue_color3" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_color3(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_color4_genmdl" nodedef="ND_geompropvalue_color4" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_color4(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_vector2_genmdl" nodedef="ND_geompropvalue_vector2" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_vector2(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_vector3_genmdl" nodedef="ND_geompropvalue_vector3" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_vector3(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_vector4_genmdl" nodedef="ND_geompropvalue_vector4" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_vector4(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />

<!-- <geompropvalueuniform> -->
<implementation name="IM_geompropvalue_string_genmdl" nodedef="ND_geompropvalueuniform_string" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_string(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />
<implementation name="IM_geompropvalue_filename_genmdl" nodedef="ND_geompropvalueuniform_filename" sourcecode="materialx::stdlib_{{MDL_VERSION_SUFFIX}}::mx_geompropvalue_string(mxp_geomprop:{{geomprop}}, mxp_default:{{default}})" target="genmdl" />

<!-- ======================================================================== -->
<!-- Application nodes -->
<!-- ======================================================================== -->
Expand Down
5 changes: 4 additions & 1 deletion libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@
<!-- <geompropvalue> -->
<implementation name="IM_geompropvalue_integer_genmsl" nodedef="ND_geompropvalue_integer" function="mx_geompropvalue_int" target="genmsl" />
<implementation name="IM_geompropvalue_boolean_genmsl" nodedef="ND_geompropvalue_boolean" function="mx_geompropvalue_bool" target="genmsl" />
<implementation name="IM_geompropvalue_string_genmsl" nodedef="ND_geompropvalue_string" function="mx_geompropvalue_string" target="genmsl" />
<implementation name="IM_geompropvalue_float_genmsl" nodedef="ND_geompropvalue_float" function="mx_geompropvalue_float" target="genmsl" />
<implementation name="IM_geompropvalue_color3_genmsl" nodedef="ND_geompropvalue_color3" function="mx_geompropvalue_color" target="genmsl" />
<implementation name="IM_geompropvalue_color4_genmsl" nodedef="ND_geompropvalue_color4" function="mx_geompropvalue_color4" target="genmsl" />
<implementation name="IM_geompropvalue_vector2_genmsl" nodedef="ND_geompropvalue_vector2" function="mx_geompropvalue_vector2" target="genmsl" />
<implementation name="IM_geompropvalue_vector3_genmsl" nodedef="ND_geompropvalue_vector3" function="mx_geompropvalue_vector" target="genmsl" />
<implementation name="IM_geompropvalue_vector4_genmsl" nodedef="ND_geompropvalue_vector4" function="mx_geompropvalue_vector4" target="genmsl" />

<!-- <geompropvalueuniform> -->
<implementation name="IM_geompropvalue_string_genmsl" nodedef="ND_geompropvalueuniform_string" function="mx_geompropvalue_string" target="genmsl" />
<implementation name="IM_geompropvalue_filename_genmsl" nodedef="ND_geompropvalueuniform_filename" function="mx_geompropvalue_string" target="genmsl" />

<!-- ======================================================================== -->
<!-- Application nodes -->
<!-- ======================================================================== -->
Expand Down
5 changes: 4 additions & 1 deletion libraries/stdlib/genosl/stdlib_genosl_impl.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,17 @@
<!-- <geompropvalue> -->
<implementation name="IM_geompropvalue_integer_genosl" nodedef="ND_geompropvalue_integer" file="mx_geompropvalue_integer.osl" function="mx_geompropvalue_integer" target="genosl" />
<implementation name="IM_geompropvalue_boolean_genosl" nodedef="ND_geompropvalue_boolean" file="mx_geompropvalue_boolean.osl" function="mx_geompropvalue_boolean" target="genosl" />
<implementation name="IM_geompropvalue_string_genosl" nodedef="ND_geompropvalue_string" file="mx_geompropvalue_string.osl" function="mx_geompropvalue_string" target="genosl" />
<implementation name="IM_geompropvalue_float_genosl" nodedef="ND_geompropvalue_float" file="mx_geompropvalue_float.osl" function="mx_geompropvalue_float" target="genosl" />
<implementation name="IM_geompropvalue_color3_genosl" nodedef="ND_geompropvalue_color3" file="mx_geompropvalue_color3.osl" function="mx_geompropvalue_color" target="genosl" />
<implementation name="IM_geompropvalue_color4_genosl" nodedef="ND_geompropvalue_color4" file="mx_geompropvalue_color4.osl" function="mx_geompropvalue_color4" target="genosl" />
<implementation name="IM_geompropvalue_vector2_genosl" nodedef="ND_geompropvalue_vector2" file="mx_geompropvalue_vector2.osl" function="mx_geompropvalue_vector2" target="genosl" />
<implementation name="IM_geompropvalue_vector3_genosl" nodedef="ND_geompropvalue_vector3" file="mx_geompropvalue_vector3.osl" function="mx_geompropvalue_vector" target="genosl" />
<implementation name="IM_geompropvalue_vector4_genosl" nodedef="ND_geompropvalue_vector4" file="mx_geompropvalue_vector4.osl" function="mx_geompropvalue_vector4" target="genosl" />

<!-- <geompropvalueuniform> -->
<implementation name="IM_geompropvalue_string_genosl" nodedef="ND_geompropvalueuniform_string" file="mx_geompropvalue_string.osl" function="mx_geompropvalue_string" target="genosl" />
<implementation name="IM_geompropvalue_filename_genosl" nodedef="ND_geompropvalueuniform_filename" file="mx_geompropvalue_string.osl" function="mx_geompropvalue_string" target="genosl" />

<!-- ======================================================================== -->
<!-- Application nodes -->
<!-- ======================================================================== -->
Expand Down
21 changes: 16 additions & 5 deletions libraries/stdlib/stdlib_defs.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -1355,11 +1355,6 @@
<input name="default" type="boolean" value="false" />
<output name="out" type="boolean" default="false" />
</nodedef>
<nodedef name="ND_geompropvalue_string" node="geompropvalue" nodegroup="geometric">
<input name="geomprop" type="string" value="" uniform="true" />
<input name="default" type="string" value="" uniform="true" />
<output name="out" type="string" default="" />
</nodedef>
<nodedef name="ND_geompropvalue_float" node="geompropvalue" nodegroup="geometric">
<input name="geomprop" type="string" value="" uniform="true" />
<input name="default" type="float" value="0.0" />
Expand Down Expand Up @@ -1391,6 +1386,22 @@
<output name="out" type="vector4" default="0.0, 0.0, 0.0, 0.0" />
</nodedef>

<!--
Node: <geompropvalueuniform>
The uniform, non-varying value of the specified geometric property for the current geometry.
-->
<nodedef name="ND_geompropvalueuniform_string" node="geompropvalueuniform" nodegroup="geometric">
<input name="geomprop" type="string" value="" uniform="true" />
<input name="default" type="string" value="" uniform="true" />
<output name="out" type="string" default="" uniform="true" />
</nodedef>
<nodedef name="ND_geompropvalueuniform_filename" node="geompropvalueuniform" nodegroup="geometric">
<input name="geomprop" type="string" value="" uniform="true" />
<input name="default" type="filename" value="" uniform="true" />
<output name="out" type="filename" default="" uniform="true" />
</nodedef>


<!--
Node: <bump>
Offset the surface normal by a scalar value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<geompropvalue name="geompropvalue_boolean" type="boolean">
<input name="geomprop" type="string" value="geompropvalue_bool" />
</geompropvalue>
<output name="geompropvalue_string_out" type="color3" nodename="swizzle1" />
<output name="geompropvalueuniform_string_out" type="color3" nodename="swizzle1" />
<constant name="swizzle1" type="color3">
<input name="value" type="color3" value="0.5, 0.5, 0.5" />
</constant>
<geompropvalue name="geompropvalue_string" type="string">
<input name="geomprop" type="string" value="geompropvalue_string" />
</geompropvalue>
<geompropvalueuniform name="geompropvalueuniform_string" type="string">
<input name="geomprop" type="string" value="geompropvalueuniform_string" />
</geompropvalueuniform>
<output name="geompropvalue_float_out" type="float" nodename="geompropvalue_float" />
<geompropvalue name="geompropvalue_float" type="float">
<input name="geomprop" type="string" value="geompropvalue_float" />
Expand Down
1 change: 1 addition & 0 deletions source/MaterialXGenGlsl/GlslShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ GlslShaderGenerator::GlslShaderGenerator() :
registerImplementation(elementNames, GeomPropValueNodeGlsl::create);
registerImplementation("IM_geompropvalue_boolean_" + GlslShaderGenerator::TARGET, GeomPropValueNodeGlslAsUniform::create);
registerImplementation("IM_geompropvalue_string_" + GlslShaderGenerator::TARGET, GeomPropValueNodeGlslAsUniform::create);
registerImplementation("IM_geompropvalue_filename_" + GlslShaderGenerator::TARGET, GeomPropValueNodeGlslAsUniform::create);

// <!-- <frame> -->
registerImplementation("IM_frame_float_" + GlslShaderGenerator::TARGET, HwFrameNode::create);
Expand Down
2 changes: 2 additions & 0 deletions source/MaterialXGenMsl/MslShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ MslShaderGenerator::MslShaderGenerator() :
registerImplementation(elementNames, GeomPropValueNodeMsl::create);
registerImplementation("IM_geompropvalue_boolean_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create);
registerImplementation("IM_geompropvalue_string_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create);
registerImplementation("IM_geompropvalue_filename_" + MslShaderGenerator::TARGET, GeomPropValueNodeMslAsUniform::create);


// <!-- <frame> -->
registerImplementation("IM_frame_float_" + MslShaderGenerator::TARGET, HwFrameNode::create);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXTest/MaterialXGenGlsl/GenGlsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GlslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester
whiteList =
{
"volumeshader", "volumematerial",
"IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string",
"IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string", "IM_geompropvalue_filename",
"IM_light_", "IM_point_light_", "IM_spot_light_", "IM_directional_light_"
};
ShaderGeneratorTester::getImplementationWhiteList(whiteList);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXTest/MaterialXGenMsl/GenMsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class MslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester
whiteList =
{
"displacementshader", "volumeshader", "surfacematerial", "volumematerial",
"IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string",
"IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue_boolean", "IM_geompropvalue_string", "IM_geompropvalue_filename",
"IM_light_", "IM_point_light_", "IM_spot_light_", "IM_directional_light_",
"ND_surfacematerial", "ND_volumematerial"
};
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXTest/MaterialXGenOsl/GenOsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class OslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester
whiteList =
{
"displacementshader", "volumeshader",
"IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue"
"IM_constant_", "IM_dot_", "IM_angle", "IM_geompropvalue", "IM_geompropvalueuniform"
};
ShaderGeneratorTester::getImplementationWhiteList(whiteList);
}
Expand Down

0 comments on commit 81ed31d

Please sign in to comment.