Skip to content

Commit

Permalink
Improvements to version upgrades
Browse files Browse the repository at this point in the history
- Add renderable examples of MaterialX 1.22 and 1.25 syntax, making it more straightforward to maintain older upgrade pathways over time.
- Improve the upgrade logic for legacy shader nodedefs, allowing blocks of special-case code to be removed from MaterialXView and MaterialXGraphEditor.
- Remove special-case unit tests for individual test documents, instead allowing these code paths to be covered by generic validation and shader generation for test suite materials.
- Increases the measured code coverage of MaterialX unit tests from 87.4% to 88.1%.
  • Loading branch information
jstone-lucasfilm committed Oct 5, 2023
1 parent 6bb5d1e commit 6982dd7
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 272 deletions.

This file was deleted.

This file was deleted.

70 changes: 70 additions & 0 deletions resources/Materials/TestSuite/stdlib/upgrade/syntax_1_22.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<materialx require="matopgraph" version="1.22">
<!--
Examples of MaterialX 1.22 syntax
-->

<opgraph name="carpaint_opgraph" colorspace="lin_rec709">
<constant name="base_constant" type="float">
<parameter name="color" type="float" value="0.5" />
</constant>
<constant name="base_color_constant" type="color3">
<parameter name="color" type="color3" value="0.1037792, 0.59212029, 0.85064936" />
</constant>
<constant name="specular_constant" type="float">
<parameter name="color" type="float" value="1.0" />
</constant>
<constant name="specular_color_constant" type="color3">
<parameter name="color" type="color3" value="1.0, 1.0, 1.0" />
</constant>
<constant name="specular_roughness_constant" type="float">
<parameter name="color" type="float" value="0.4" />
</constant>
<constant name="specular_anisotropy_constant" type="float">
<parameter name="color" type="float" value="0.5" />
</constant>
<constant name="coat_constant" type="float">
<parameter name="color" type="float" value="1.0" />
</constant>
<constant name="coat_roughness_constant" type="float">
<parameter name="color" type="float" value="0.0" />
</constant>
<output name="base_output" type="float">
<parameter name="in" type="opgraphnode" value="base_constant" />
</output>
<output name="base_color_output" type="color3">
<parameter name="in" type="opgraphnode" value="base_color_constant" />
</output>
<output name="specular_output" type="float">
<parameter name="in" type="opgraphnode" value="specular_constant" />
</output>
<output name="specular_color_output" type="color3">
<parameter name="in" type="opgraphnode" value="specular_color_constant" />
</output>
<output name="specular_roughness_output" type="float">
<parameter name="in" type="opgraphnode" value="specular_roughness_constant" />
</output>
<output name="specular_anisotropy_output" type="float">
<parameter name="in" type="opgraphnode" value="specular_anisotropy_constant" />
</output>
<output name="coat_output" type="float">
<parameter name="in" type="opgraphnode" value="coat_constant" />
</output>
<output name="coat_roughness_output" type="float">
<parameter name="in" type="opgraphnode" value="coat_roughness_constant" />
</output>
</opgraph>
<shader name="carpaint_shader" shadertype="surface" shadername="standard_surface">
<input name="base" graphoutput="base_output" graphname="carpaint_opgraph" type="float" />
<input name="base_color" graphoutput="base_color_output" graphname="carpaint_opgraph" type="color3" />
<input name="specular" graphoutput="specular_output" graphname="carpaint_opgraph" type="float" />
<input name="specular_color" graphoutput="specular_color_output" graphname="carpaint_opgraph" type="color3" />
<input name="specular_roughness" graphoutput="specular_roughness_output" graphname="carpaint_opgraph" type="float" />
<input name="specular_anisotropy" graphoutput="specular_anisotropy_output" graphname="carpaint_opgraph" type="float" />
<input name="coat" graphoutput="coat_output" graphname="carpaint_opgraph" type="float" />
<input name="coat_roughness" graphoutput="coat_roughness_output" graphname="carpaint_opgraph" type="float" />
</shader>
<material name="carpaint_material">
<shaderref name="carpaint_shader" shadertype="surface" />
</material>
</materialx>
28 changes: 28 additions & 0 deletions resources/Materials/TestSuite/stdlib/upgrade/syntax_1_25.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<materialx require="matopgraph" version="1.25" colorspace="lin_rec709">
<!--
Examples of MaterialX 1.25 syntax
-->

<shader name="standard_surface" shadertype="surface" shaderprogram="standard_surface">
<input name="base" type="float" value="1.0" publicname="base_public" />
<input name="base_color" type="color3" value="0.8, 0.8, 0.8" publicname="base_color_public" />
<input name="specular" type="float" value="1.0" publicname="specular_public" />
<input name="specular_color" type="color3" value="1.0, 1.0, 1.0" publicname="specular_color_public" />
<input name="specular_roughness" type="float" value="0.2" publicname="specular_roughness_public" />
<input name="specular_anisotropy" type="float" value="0.0" publicname="specular_anisotropy_public" />
<input name="coat" type="float" value="0.0" publicname="coat_public" />
<input name="coat_roughness" type="float" value="0.1" publicname="coat_roughness_public" />
</shader>
<material name="carpaint">
<shaderref name="standard_surface" shadertype="surface" />
<override name="base_public" type="float" value="0.5" />
<override name="base_color_public" type="color3" value="0.1037792, 0.59212029, 0.85064936" />
<override name="specular_public" type="float" value="1.0" />
<override name="specular_color_public" type="color3" value="1.0, 1.0, 1.0" />
<override name="specular_roughness_public" type="float" value="0.4" />
<override name="specular_anisotropy_public" type="float" value="0.5" />
<override name="coat_public" type="float" value="1.0" />
<override name="coat_roughness_public" type="float" value="0.0" />
</material>
</materialx>
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0"?>
<materialx version="1.36">
<!--
Upgrade path test from 1.36 to 1.37
Examples of MaterialX 1.36 syntax
-->

<!-- invert matrix to invertmatrix -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?xml version="1.0"?>
<materialx version="1.37">
<materialx version="1.37" colorspace="lin_rec709">
<!--
Examples of MaterialX 1.37 syntax
-->

<nodegraph name="atan2_graph">
<atan2 name="atan2_float" type="float">
<input name="in1" type="float" value="0.5" />
Expand Down Expand Up @@ -37,4 +41,24 @@
<input name="in2" type="float" value="1.0" />
</add>
</nodegraph>

<nodegraph name="NG_aiMixColor31">
<mix name="aiMixColor31" type="color3">
<input name="fg" type="color3" nodename="aiAbsvalColor31" />
<input name="bg" type="color3" nodename="aiAbsvalColor32" />
<input name="mix" type="float" value="0.5" />
</mix>
<absval name="aiAbsvalColor31" type="color3">
<input name="in" type="color3" value="1, 0, 0" />
</absval>
<absval name="aiAbsvalColor32" type="color3">
<input name="in" type="color3" value="0.671, 0.671, 0.671" />
</absval>
<output name="out" type="color3" nodename="aiMixColor31" />
</nodegraph>
<material name="my_surface">
<shaderref name="my_surface" node="standard_surface">
<bindinput name="base_color" type="color3" nodegraph="NG_aiMixColor31" output="out" />
</shaderref>
</material>
</materialx>
14 changes: 11 additions & 3 deletions source/MaterialXCore/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,10 @@ void Document::upgradeVersion()
if (nodeDef->hasAttribute("shadertype"))
{
nodeDef->setType(SURFACE_SHADER_TYPE_STRING);
nodeDef->removeAttribute("shadertype");
}
if (nodeDef->hasAttribute("shaderprogram"))
{
nodeDef->setNodeString(nodeDef->getAttribute("shaderprogram"));
nodeDef->removeAttribute("shaderprogram");
}
}
else if (child->getCategory() == "shaderref")
Expand Down Expand Up @@ -751,8 +749,18 @@ void Document::upgradeVersion()
// Remove legacy shader nodedefs.
for (NodeDefPtr nodeDef : getNodeDefs())
{
if (nodeDef->getType() == "surface")
if (nodeDef->hasAttribute("shadertype"))
{
for (ElementPtr mat : getChildrenOfType<Element>("material"))
{
for (ElementPtr shaderRef : mat->getChildrenOfType<Element>("shaderref"))
{
if (shaderRef->getAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE) == nodeDef->getName())
{
shaderRef->removeAttribute(InterfaceElement::NODE_DEF_ATTRIBUTE);
}
}
}
removeNodeDef(nodeDef->getName());
}
}
Expand Down
20 changes: 0 additions & 20 deletions source/MaterialXGraphEditor/RenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,6 @@ void applyModifiers(mx::DocumentPtr doc, const DocumentModifiers& modifiers)
}
}

// Remap references to unimplemented shader nodedefs.
for (mx::NodePtr materialNode : doc->getMaterialNodes())
{
for (mx::NodePtr shader : getShaderNodes(materialNode))
{
mx::NodeDefPtr nodeDef = shader->getNodeDef();
if (nodeDef && !nodeDef->getImplementation())
{
std::vector<mx::NodeDefPtr> altNodeDefs = doc->getMatchingNodeDefs(nodeDef->getNodeString());
for (mx::NodeDefPtr altNodeDef : altNodeDefs)
{
if (altNodeDef->getImplementation())
{
shader->setNodeDefString(altNodeDef->getName());
}
}
}
}
}

// Remap unsupported texture coordinate indices.
for (mx::ElementPtr elem : doc->traverseTree())
{
Expand Down
Loading

0 comments on commit 6982dd7

Please sign in to comment.