Skip to content

Commit

Permalink
Fix edge case in normalmap upgrade
Browse files Browse the repository at this point in the history
This changelist fixes an edge case in the upgrade of the `normalmap` node from version 1.38 to 1.39, adding support for node instances with explicit `nodedef` attributes.

An example of this usage has been added to the `TestSuite/stdlib/upgrade` folder for validation in unit testing.
  • Loading branch information
jstone-lucasfilm committed Feb 5, 2025
1 parent 1f4f5a1 commit 8b6417c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
19 changes: 19 additions & 0 deletions resources/Materials/TestSuite/stdlib/upgrade/syntax_1_38.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<materialx version="1.38">
<tiledimage name="N_tiledimage" type="vector3">
<input name="file" type="filename" value="resources/Images/mesh_wire_norm.png" />
<input name="uvtiling" type="vector2" value="8.0, 8.0" />
</tiledimage>
<normalmap name="N_normalmap" type="vector3" nodedef="ND_normalmap">
<input name="in" type="vector3" nodename="N_tiledimage" />
</normalmap>
<standard_surface name="N_surface" type="surfaceshader">
<input name="base_color" type="color3" value="1.0, 1.0, 1.0" />
<input name="specular_roughness" type="float" value="0" />
<input name="metalness" type="float" value="1" />
<input name="normal" type="vector3" nodename="N_normalmap" />
</standard_surface>
<surfacematerial name="N_material" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="N_surface" />
</surfacematerial>
</materialx>
13 changes: 9 additions & 4 deletions source/MaterialXCore/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,20 @@ void Document::upgradeVersion()
}
else if (nodeCategory == "normalmap")
{
// ND_normalmap was renamed to ND_normalmap_float
// The nodedef for scalar normal maps was renamed.
const string ORIG_SCALAR_NORMALMAP_ND = "ND_normalmap";
const string NEW_SCALAR_NORMALMAP_ND = "ND_normalmap_float";
NodeDefPtr nodeDef = getShaderNodeDef(node);
InputPtr scaleInput = node->getInput("scale");
if ((nodeDef && nodeDef->getName() == "ND_normalmap") ||
(scaleInput && scaleInput->getType() == "float"))
bool isScalarNormalMap = (nodeDef && nodeDef->getName() == ORIG_SCALAR_NORMALMAP_ND) ||
(node->getNodeDefString() == ORIG_SCALAR_NORMALMAP_ND) ||
(scaleInput && scaleInput->getType() == getTypeString<float>());
if (isScalarNormalMap)
{
node->setNodeDefString("ND_normalmap_float");
node->setNodeDefString(NEW_SCALAR_NORMALMAP_ND);
}

// The space input for normal maps was removed.
node->removeInput("space");

// If the normal or tangent inputs are set, the bitangent input should be normalize(cross(N, T))
Expand Down

0 comments on commit 8b6417c

Please sign in to comment.