From b23de80a5e8e3cdf4b2ed5a5e12ced765c8b0125 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Thu, 17 Aug 2023 22:29:08 -0400 Subject: [PATCH] Add support for top level inputs (#1453) Fix so that top level inputs are parsed properly and values and path reflection data is correct (for uniform updates). --- .../stdlib/nodegraph_inputs/top_level_input.mtlx | 10 ++++++++++ source/MaterialXCore/Interface.cpp | 2 +- source/MaterialXGenShader/ShaderNode.cpp | 12 +++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx diff --git a/resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx new file mode 100644 index 0000000000..d92eae7f19 --- /dev/null +++ b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 3a93a384c2..b733d3a4c7 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -305,7 +305,7 @@ InputPtr Input::getInterfaceInput() const { if (hasInterfaceName()) { - ConstNodeGraphPtr graph = getAncestorOfType(); + ConstGraphElementPtr graph = getAncestorOfType(); if (graph) { return graph->getInput(getInterfaceName()); diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp index c923e4be57..3eb750f1ff 100644 --- a/source/MaterialXGenShader/ShaderNode.cpp +++ b/source/MaterialXGenShader/ShaderNode.cpp @@ -381,7 +381,17 @@ void ShaderNode::initialize(const Node& node, const NodeDef& nodeDef, GenContext ShaderInput* input = getInput(nodeValue->getName()); if (input) { - input->setPath(nodeValue->getNamePath()); + string path = nodeValue->getNamePath(); + InputPtr nodeInput = nodeValue->asA(); + if (nodeInput) + { + InputPtr interfaceInput = nodeInput->getInterfaceInput(); + if (interfaceInput) + { + path = interfaceInput->getNamePath(); + } + } + input->setPath(path); } }