From f6355a66b635d11d20e75d0f2705fba728fb38ad Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Sat, 19 Oct 2024 14:57:43 -0400 Subject: [PATCH] Add defaultgeomprop support for nodegraph inputs (#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". --- .../defaultgeomprop/defaultgeomprop.mtlx | 41 +++++++++++++++++++ source/MaterialXCore/Interface.cpp | 2 +- source/MaterialXGenShader/ShaderGraph.cpp | 18 +++++++- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx diff --git a/resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx b/resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx new file mode 100644 index 0000000000..86bddc9650 --- /dev/null +++ b/resources/Materials/TestSuite/stdlib/defaultgeomprop/defaultgeomprop.mtlx @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 24d3ccfe0d..1c12e38ded 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -295,7 +295,7 @@ bool Input::validate(string* message) const if (hasDefaultGeomPropString()) { - validateRequire(parent->isA(), res, message, "Invalid defaultgeomprop on non-definition input"); + validateRequire(parent->isA() || parent->isA(), res, message, "Invalid defaultgeomprop on non-definition and non-nodegraph input"); validateRequire(getDefaultGeomProp() != nullptr, res, message, "Invalid defaultgeomprop string"); } if (parent->isA()) diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp index 0f39b46c32..e9a3b50b79 100644 --- a/source/MaterialXGenShader/ShaderGraph.cpp +++ b/source/MaterialXGenShader/ShaderGraph.cpp @@ -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(); if (!upstreamNode) { @@ -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 //