Skip to content

Commit

Permalink
Add defaultgeomprop support for nodegraph inputs (AcademySoftwareFoun…
Browse files Browse the repository at this point in the history
…dation#2076)

This PR makes it so that defaultgeomprop values can be used with nodegraph inputs as opposed to solely used on nodedef inputs. Includes a test file that is a nodegraph version of a checkerboard nodegraph implementation. The nodegraph exposes a defaultgeomprop value on the nodegraph's texcoord input of "UV0".
  • Loading branch information
feldstj authored Oct 19, 2024
1 parent bec073b commit f6355a6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0"?>
<materialx version="1.39">
<surfacematerial name="defaultgeomprop" type="material" nodedef="ND_surfacematerial">
<input name="surfaceshader" type="surfaceshader" nodename="standard_surface1" />
</surfacematerial>
<standard_surface name="standard_surface1" type="surfaceshader" nodedef="ND_standard_surface_surfaceshader">
<input name="base_color" type="color3" output="out" nodegraph="checkerboard1" />
</standard_surface>
<nodegraph name="checkerboard1">
<input name="color1" type="color3" uiname="Color 1" value="1, 1, 1" doc="The first color used in the checkerboard pattern." />
<input name="color2" type="color3" uiname="Color 2" value="0.0, 0.0, 0.0" doc="The second color used in the checkerboard pattern." />
<input name="uvtiling" type="vector2" uiname="UV Tiling" value="8, 8" doc="The tiling of the checkerboard pattern along each axis, with higher values producing smaller squares. Default is (8, 8)." />
<input name="uvoffset" type="vector2" uiname="UV Offset" value="0, 0" doc="The offset of the checkerboard pattern along each axis. Default is (0, 0)." />
<input name="texcoord" type="vector2" defaultgeomprop="UV0" uiname="Texture Coordinates" doc="The input 2d space. Default is the first texture coordinates." />
<multiply name="N_mtlxmult" type="vector2">
<input name="in1" type="vector2" interfacename="texcoord" />
<input name="in2" type="vector2" interfacename="uvtiling" />
</multiply>
<subtract name="N_mtlxsubtract" type="vector2">
<input name="in1" type="vector2" nodename="N_mtlxmult" />
<input name="in2" type="vector2" interfacename="uvoffset" />
</subtract>
<floor name="N_mtlxfloor" type="vector2">
<input name="in" type="vector2" nodename="N_mtlxsubtract" />
</floor>
<dotproduct name="N_mtlxdotproduct" type="float">
<input name="in1" type="vector2" nodename="N_mtlxfloor" />
<input name="in2" type="vector2" value="1, 1" />
</dotproduct>
<modulo name="N_modulo" type="float">
<input name="in1" type="float" nodename="N_mtlxdotproduct" />
<input name="in2" type="float" value="2" />
</modulo>
<mix name="N_mtlxmix" type="color3">
<input name="bg" type="color3" interfacename="color2" />
<input name="fg" type="color3" interfacename="color1" />
<input name="mix" type="float" nodename="N_modulo" />
</mix>
<output name="out" type="color3" nodename="N_mtlxmix" />
</nodegraph>
</materialx>
2 changes: 1 addition & 1 deletion source/MaterialXCore/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ bool Input::validate(string* message) const

if (hasDefaultGeomPropString())
{
validateRequire(parent->isA<NodeDef>(), res, message, "Invalid defaultgeomprop on non-definition input");
validateRequire(parent->isA<NodeDef>() || parent->isA<NodeGraph>(), res, message, "Invalid defaultgeomprop on non-definition and non-nodegraph input");
validateRequire(getDefaultGeomProp() != nullptr, res, message, "Invalid defaultgeomprop string");
}
if (parent->isA<Node>())
Expand Down
18 changes: 17 additions & 1 deletion source/MaterialXGenShader/ShaderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement,
ElementPtr connectingElement,
GenContext& context)
{
// Create the node if it doesn't exists
// Create the node if it doesn't exist.
NodePtr upstreamNode = upstreamElement->asA<Node>();
if (!upstreamNode)
{
Expand All @@ -95,6 +95,22 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement,
newNode = createNode(upstreamNode, context);
}

// Handle interface inputs with default geometric properties.
for (InputPtr activeInput : upstreamNode->getActiveInputs())
{
if (!activeInput->hasInterfaceName() || activeInput->getConnectedNode())
{
continue;
}

InputPtr graphInput = activeInput->getInterfaceInput();
if (graphInput && graphInput->hasDefaultGeomPropString())
{
ShaderInput* shaderInput = getNode(upstreamNode->getName())->getInput(activeInput->getName());
addDefaultGeomNode(shaderInput, *graphInput->getDefaultGeomProp(), context);
}
}

//
// Make connections
//
Expand Down

0 comments on commit f6355a6

Please sign in to comment.