From 777c45e0e482c59ba6262290fb8b755e8fab9912 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Fri, 20 Oct 2023 12:04:59 -0400 Subject: [PATCH 1/9] Nest nodegraphs. --- .../nodegraph_inputs/nested_nodegraph.mtlx | 45 +++++ source/MaterialXCore/Element.cpp | 8 + source/MaterialXCore/Element.h | 5 +- source/MaterialXCore/Interface.cpp | 189 +++++++++++++++--- 4 files changed, 213 insertions(+), 34 deletions(-) create mode 100644 resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph.mtlx diff --git a/resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph.mtlx b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph.mtlx new file mode 100644 index 0000000000..1a5861bc5a --- /dev/null +++ b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph.mtlx @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXCore/Element.cpp b/source/MaterialXCore/Element.cpp index 18d028efd3..99ba2f5566 100644 --- a/source/MaterialXCore/Element.cpp +++ b/source/MaterialXCore/Element.cpp @@ -548,6 +548,14 @@ bool ValueElement::validate(string* message) const if (decl) { ValueElementPtr valueElem = decl->getActiveValueElement(getInterfaceName()); + if (!valueElem) + { + nodeGraph = nodeGraph->getAncestorOfType(); + if (nodeGraph) + { + valueElem = nodeGraph->getActiveValueElement(getInterfaceName()); + } + } validateRequire(valueElem != nullptr, res, message, "Interface name not found in referenced declaration"); if (valueElem) { diff --git a/source/MaterialXCore/Element.h b/source/MaterialXCore/Element.h index 0e00bf596a..80ae56e636 100644 --- a/source/MaterialXCore/Element.h +++ b/source/MaterialXCore/Element.h @@ -586,10 +586,11 @@ class MX_CORE_API Element : public std::enable_shared_from_this /// pointer if no ancestor of this subclass is found. template shared_ptr getAncestorOfType() const { - for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent()) + ConstElementPtr self = getSelf(); + for (ConstElementPtr elem = self; elem; elem = elem->getParent()) { shared_ptr typedElem = elem->asA(); - if (typedElem) + if (typedElem && typedElem != self) { return typedElem; } diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 65570ab6b6..4cb5dd06a1 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -10,6 +10,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN const string PortElement::NODE_NAME_ATTRIBUTE = "nodename"; @@ -62,6 +64,8 @@ void PortElement::setConnectedNode(ConstNodePtr node) NodePtr PortElement::getConnectedNode() const { ConstGraphElementPtr graph = getAncestorOfType(); + //std::cout << "PortElement::getConnectedNode on graph: " << (graph ? graph->getNamePath() : "NONE") << + // std::endl; return graph ? graph->getNode(getNodeName()) : nullptr; } @@ -105,7 +109,11 @@ OutputPtr PortElement::getConnectedOutput() const NodeGraphPtr nodeGraph = resolveNameReference(getNodeGraphString(), scope); if (!nodeGraph) { - nodeGraph = resolveNameReference(getNodeGraphString()); + nodeGraph = resolveNameReference(getNodeGraphString(), parent); + if (!nodeGraph) + { + nodeGraph = resolveNameReference(getNodeGraphString()); + } } if (nodeGraph) { @@ -154,6 +162,10 @@ OutputPtr PortElement::getConnectedOutput() const { result = getDocument()->getOutput(outputString); } + + //if (result) + // std::cout << "getConnecfedOutput for: " << getNamePath() << " = " << result->getNamePath() + // << std::endl; return result; } @@ -161,42 +173,60 @@ bool PortElement::validate(string* message) const { bool res = true; - NodePtr connectedNode = getConnectedNode(); - if (hasNodeName() || hasOutputString()) + const string& outputString = getOutputString(); + InterfaceElementPtr connectedElement = nullptr; + NodePtr connectedNode = nullptr; + NodeGraphPtr connectedGraph = nullptr; + if (hasNodeName()) { - NodeGraphPtr nodeGraph = resolveNameReference(getNodeName()); - if (!nodeGraph) + connectedElement = connectedNode = getConnectedNode(); + //validateRequire(connectedNode != nullptr, res, message, + // "Node '" + getNodeName() + "' not found for connection"); + } + else if (hasNodeGraphString()) + { + const string& nodeGraphString = getNodeGraphString(); + connectedGraph = resolveNameReference(nodeGraphString); + if (!connectedGraph) { - validateRequire(connectedNode != nullptr, res, message, "Invalid port connection"); + if (getParent()) + { + connectedGraph = resolveNameReference(nodeGraphString, getParent()); + if (!connectedGraph) + { + connectedGraph = resolveNameReference(nodeGraphString, getParent()->getParent()); + } + } } + connectedElement = connectedGraph; + validateRequire(connectedGraph != nullptr, res, message, + "Nodegraph '" + nodeGraphString + "' not found for connection"); } - if (connectedNode) + + if (connectedElement) { - const string& outputString = getOutputString(); if (!outputString.empty()) { - OutputPtr output; - if (hasNodeName()) + OutputPtr output = nullptr; + if (connectedNode) { NodeDefPtr nodeDef = connectedNode->getNodeDef(); output = nodeDef ? nodeDef->getOutput(outputString) : OutputPtr(); if (output) { validateRequire(connectedNode->getType() == MULTI_OUTPUT_TYPE_STRING, res, message, - "Multi-output type expected in port connection"); + "Multi-output type expected in port connection'"); } } - else if (hasNodeGraphString()) + else if (connectedGraph) { - NodeGraphPtr nodeGraph = resolveNameReference(getNodeGraphString()); - if (nodeGraph) + output = connectedGraph->getOutput(outputString); + validateRequire(output != nullptr, res, message, + "Nodegraph output '" + outputString + "' not found for connection"); + if (connectedGraph->getNodeDef()) { - output = nodeGraph->getOutput(outputString); - if (nodeGraph->getNodeDef()) - { - validateRequire(nodeGraph->getOutputCount() > 1, res, message, - "Multi-output type expected in port connection"); - } + validateRequire(connectedGraph->getOutputCount() > 1, res, message, + "Multi-output type expected in port connection"); } } else @@ -215,18 +245,49 @@ bool PortElement::validate(string* message) const } else { - validateRequire(getType() == output->getType(), res, message, "Mismatched types in port connection"); + validateRequire(getType() == output->getType(), res, message, "Mismatched types in port connection:" + + getType() + " versus " + output->getType()); } } } - else if (hasChannels()) + else { - bool valid = validChannelsString(getChannels(), connectedNode->getType(), getType()); - validateRequire(valid, res, message, "Invalid channels string in port connection"); - } - else if (connectedNode->getType() != MULTI_OUTPUT_TYPE_STRING) - { - validateRequire(getType() == connectedNode->getType(), res, message, "Mismatched types in port connection"); + OutputPtr output = nullptr; + if (connectedNode) + { + NodeDefPtr nodeDef = connectedNode->getNodeDef(); + if (nodeDef) + { + std::vector outputs = nodeDef->getOutputs(); + if (!outputs.empty()) + { + output = outputs[0]; + } + } + } + else if (connectedGraph) + { + std::vector outputs = connectedGraph->getOutputs(); + if (!outputs.empty()) + { + output = outputs[0]; + } + } + + if (output) + { + const string& outputType = output->getType(); + if (hasChannels()) + { + bool valid = validChannelsString(getChannels(), outputType, getType()); + validateRequire(valid, res, message, "Invalid channels string in port connection"); + } + else if (connectedElement->getType() != MULTI_OUTPUT_TYPE_STRING) + { + validateRequire(getType() == outputType, res, message, "Mismatched types in port connection:" + + getType() + " versus " + outputType); + } + } } } return ValueElement::validate(message) && res; @@ -274,7 +335,13 @@ NodePtr Input::getConnectedNode() const InputPtr graphInput = getInterfaceInput(); if (graphInput && (graphInput->hasNodeName() || graphInput->hasNodeGraphString())) { - return graphInput->getConnectedNode(); + NodePtr result = graphInput->getConnectedNode(); + if (result) + { + //std::cout << "- START Look for node on input: " << getNamePath() << std::endl; + //std::cout << "-- return root node: " << result->getNamePath() << std::endl; + } + return result; } // Handle inputs of compound nodegraphs. @@ -283,6 +350,8 @@ NodePtr Input::getConnectedNode() const NodePtr rootNode = getDocument()->getNode(getNodeName()); if (rootNode) { + //std::cout << "- START Look for node on input: " << getNamePath() << std::endl; + //std::cout << "-- return root node: " << rootNode->getNamePath() << std::endl; return rootNode; } } @@ -294,8 +363,23 @@ NodePtr Input::getConnectedNode() const NodePtr node = output->getConnectedNode(); if (node) { + //std::cout << "- START Look for node on input: " << getNamePath() << std::endl; + //std::cout << "-- return node: " << node->getNamePath() << std::endl; return node; } + else if (output->hasNodeGraphString()) + { + OutputPtr childGraphOutput = output->getConnectedOutput(); + if (childGraphOutput) + { + NodePtr childGraphNode = childGraphOutput->getConnectedNode(); + if (childGraphNode) + { + //std::cout << "-- return child graph node: " << childGraphNode->getNamePath() << std::endl; + return childGraphNode; + } + } + } } return PortElement::getConnectedNode(); @@ -304,11 +388,52 @@ NodePtr Input::getConnectedNode() const InputPtr Input::getInterfaceInput() const { if (hasInterfaceName()) - { - ConstGraphElementPtr graph = getAncestorOfType(); + { + ConstNodeGraphPtr graph = getAncestorOfType(); + if (getParent() && getParent()->isA()) + { + graph = graph->getAncestorOfType(); + //std::cout << "Skip to parent graph: " << graph->getNamePath() << std::endl; + } if (graph) { - return graph->getInput(getInterfaceName()); + InputPtr returnVal = graph->getInput(getInterfaceName()); + if (returnVal) + { + if (returnVal->hasInterfaceName()) + { + //std::cout << "Continue input interface traversal:" << + // returnVal->getNamePath() << std::endl; + //graph = getAncestorOfType(); + //if (graph) + //{ + // std::cout << "-- go up to graph:" << graph->getNamePath() << std::endl; + //} + return returnVal->getInterfaceInput(); + } + else + { + //std::cout << "For input: " << getNamePath() << ". Get graph: " << graph->getName() + //<< ". Input:" << + // (returnVal ? returnVal->getName() : "FAILED") + // << "for interfacename: " << getInterfaceName() << std::endl; + return returnVal; + } + } + /* else + { + graph = graph->getAncestorOfType(); + returnVal = graph->getInput(getInterfaceName()); + if (returnVal) + { + std::cout << "For input: " << getNamePath() << ". Get graph: " << graph->getName() + << ". Input:" << + (returnVal ? returnVal->getName() : "FAILED") + << "for interfacename: " << getInterfaceName() << std::endl; + return returnVal; + } + + } */ } } return nullptr; From a95e89d9f4403517b0c979507b6bf651fc2ad14d Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Fri, 20 Oct 2023 12:37:44 -0400 Subject: [PATCH 2/9] Fix type check. --- source/MaterialXCore/Interface.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 4cb5dd06a1..4718e76261 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -12,6 +12,8 @@ #include +#pragma optimize( "", off ) + MATERIALX_NAMESPACE_BEGIN const string PortElement::NODE_NAME_ATTRIBUTE = "nodename"; @@ -253,17 +255,11 @@ bool PortElement::validate(string* message) const else { OutputPtr output = nullptr; + string outputType = EMPTY_STRING; + if (connectedNode) { - NodeDefPtr nodeDef = connectedNode->getNodeDef(); - if (nodeDef) - { - std::vector outputs = nodeDef->getOutputs(); - if (!outputs.empty()) - { - output = outputs[0]; - } - } + outputType = connectedNode->getType(); } else if (connectedGraph) { @@ -271,18 +267,18 @@ bool PortElement::validate(string* message) const if (!outputs.empty()) { output = outputs[0]; + outputType = output->getType(); } } - if (output) + if (!outputType.empty()) { - const string& outputType = output->getType(); if (hasChannels()) { bool valid = validChannelsString(getChannels(), outputType, getType()); validateRequire(valid, res, message, "Invalid channels string in port connection"); } - else if (connectedElement->getType() != MULTI_OUTPUT_TYPE_STRING) + else if (outputType != MULTI_OUTPUT_TYPE_STRING) { validateRequire(getType() == outputType, res, message, "Mismatched types in port connection:" + getType() + " versus " + outputType); From aa0b2d5f18072a6346b3cd3e867a4845b7997d5a Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Fri, 20 Oct 2023 14:44:23 -0400 Subject: [PATCH 3/9] Migraph nodegraph interface to GraphElement. Update unit tests. --- source/MaterialXCore/Document.h | 31 ----------- source/MaterialXCore/Interface.cpp | 54 +------------------ source/MaterialXCore/Node.h | 31 +++++++++++ source/MaterialXTest/MaterialXCore/Node.cpp | 48 +++++++++++++++++ .../MaterialXTest/MaterialXCore/Traversal.cpp | 13 ++++- .../PyMaterialXCore/PyDocument.cpp | 5 -- source/PyMaterialX/PyMaterialXCore/PyNode.cpp | 5 ++ 7 files changed, 98 insertions(+), 89 deletions(-) diff --git a/source/MaterialXCore/Document.h b/source/MaterialXCore/Document.h index 8f5abbf8fb..a23b5115c9 100644 --- a/source/MaterialXCore/Document.h +++ b/source/MaterialXCore/Document.h @@ -62,37 +62,6 @@ class MX_CORE_API Document : public GraphElement /// Get a list of source URI's referenced by the document StringSet getReferencedSourceUris() const; - /// @name NodeGraph Elements - /// @{ - - /// Add a NodeGraph to the document. - /// @param name The name of the new NodeGraph. - /// If no name is specified, then a unique name will automatically be - /// generated. - /// @return A shared pointer to the new NodeGraph. - NodeGraphPtr addNodeGraph(const string& name = EMPTY_STRING) - { - return addChild(name); - } - - /// Return the NodeGraph, if any, with the given name. - NodeGraphPtr getNodeGraph(const string& name) const - { - return getChildOfType(name); - } - - /// Return a vector of all NodeGraph elements in the document. - vector getNodeGraphs() const - { - return getChildrenOfType(); - } - - /// Remove the NodeGraph, if any, with the given name. - void removeNodeGraph(const string& name) - { - removeChildOfType(name); - } - /// Return a vector of all port elements that match the given node name. /// Port elements support spatially-varying upstream connections to /// nodes, and include both Input and Output elements. diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 4718e76261..eb554e53b8 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -12,8 +12,6 @@ #include -#pragma optimize( "", off ) - MATERIALX_NAMESPACE_BEGIN const string PortElement::NODE_NAME_ATTRIBUTE = "nodename"; @@ -66,8 +64,6 @@ void PortElement::setConnectedNode(ConstNodePtr node) NodePtr PortElement::getConnectedNode() const { ConstGraphElementPtr graph = getAncestorOfType(); - //std::cout << "PortElement::getConnectedNode on graph: " << (graph ? graph->getNamePath() : "NONE") << - // std::endl; return graph ? graph->getNode(getNodeName()) : nullptr; } @@ -165,9 +161,6 @@ OutputPtr PortElement::getConnectedOutput() const result = getDocument()->getOutput(outputString); } - //if (result) - // std::cout << "getConnecfedOutput for: " << getNamePath() << " = " << result->getNamePath() - // << std::endl; return result; } @@ -182,8 +175,6 @@ bool PortElement::validate(string* message) const if (hasNodeName()) { connectedElement = connectedNode = getConnectedNode(); - //validateRequire(connectedNode != nullptr, res, message, - // "Node '" + getNodeName() + "' not found for connection"); } else if (hasNodeGraphString()) { @@ -331,25 +322,13 @@ NodePtr Input::getConnectedNode() const InputPtr graphInput = getInterfaceInput(); if (graphInput && (graphInput->hasNodeName() || graphInput->hasNodeGraphString())) { - NodePtr result = graphInput->getConnectedNode(); - if (result) - { - //std::cout << "- START Look for node on input: " << getNamePath() << std::endl; - //std::cout << "-- return root node: " << result->getNamePath() << std::endl; - } - return result; + return graphInput->getConnectedNode(); } // Handle inputs of compound nodegraphs. if (getParent()->isA()) { - NodePtr rootNode = getDocument()->getNode(getNodeName()); - if (rootNode) - { - //std::cout << "- START Look for node on input: " << getNamePath() << std::endl; - //std::cout << "-- return root node: " << rootNode->getNamePath() << std::endl; - return rootNode; - } + return getDocument()->getNode(getNodeName()); } // Handle transitive connections via outputs. @@ -359,8 +338,6 @@ NodePtr Input::getConnectedNode() const NodePtr node = output->getConnectedNode(); if (node) { - //std::cout << "- START Look for node on input: " << getNamePath() << std::endl; - //std::cout << "-- return node: " << node->getNamePath() << std::endl; return node; } else if (output->hasNodeGraphString()) @@ -371,7 +348,6 @@ NodePtr Input::getConnectedNode() const NodePtr childGraphNode = childGraphOutput->getConnectedNode(); if (childGraphNode) { - //std::cout << "-- return child graph node: " << childGraphNode->getNamePath() << std::endl; return childGraphNode; } } @@ -389,7 +365,6 @@ InputPtr Input::getInterfaceInput() const if (getParent() && getParent()->isA()) { graph = graph->getAncestorOfType(); - //std::cout << "Skip to parent graph: " << graph->getNamePath() << std::endl; } if (graph) { @@ -398,38 +373,13 @@ InputPtr Input::getInterfaceInput() const { if (returnVal->hasInterfaceName()) { - //std::cout << "Continue input interface traversal:" << - // returnVal->getNamePath() << std::endl; - //graph = getAncestorOfType(); - //if (graph) - //{ - // std::cout << "-- go up to graph:" << graph->getNamePath() << std::endl; - //} return returnVal->getInterfaceInput(); } else { - //std::cout << "For input: " << getNamePath() << ". Get graph: " << graph->getName() - //<< ". Input:" << - // (returnVal ? returnVal->getName() : "FAILED") - // << "for interfacename: " << getInterfaceName() << std::endl; return returnVal; } } - /* else - { - graph = graph->getAncestorOfType(); - returnVal = graph->getInput(getInterfaceName()); - if (returnVal) - { - std::cout << "For input: " << getNamePath() << ". Get graph: " << graph->getName() - << ". Input:" << - (returnVal ? returnVal->getName() : "FAILED") - << "for interfacename: " << getInterfaceName() << std::endl; - return returnVal; - } - - } */ } } return nullptr; diff --git a/source/MaterialXCore/Node.h b/source/MaterialXCore/Node.h index 55846cf2e3..d09ccd2980 100644 --- a/source/MaterialXCore/Node.h +++ b/source/MaterialXCore/Node.h @@ -293,6 +293,37 @@ class MX_CORE_API GraphElement : public InterfaceElement removeChildOfType(name); } + /// @name NodeGraph Elements + /// @{ + + /// Add a NodeGraph to the document. + /// @param name The name of the new NodeGraph. + /// If no name is specified, then a unique name will automatically be + /// generated. + /// @return A shared pointer to the new NodeGraph. + NodeGraphPtr addNodeGraph(const string& name = EMPTY_STRING) + { + return addChild(name); + } + + /// Return the NodeGraph, if any, with the given name. + NodeGraphPtr getNodeGraph(const string& name) const + { + return getChildOfType(name); + } + + /// Return a vector of all NodeGraph elements in the document. + vector getNodeGraphs() const + { + return getChildrenOfType(); + } + + /// Remove the NodeGraph, if any, with the given name. + void removeNodeGraph(const string& name) + { + removeChildOfType(name); + } + /// @} /// @name Utility /// @{ diff --git a/source/MaterialXTest/MaterialXCore/Node.cpp b/source/MaterialXTest/MaterialXCore/Node.cpp index 655ec5b7fb..6037b4c2e5 100644 --- a/source/MaterialXTest/MaterialXCore/Node.cpp +++ b/source/MaterialXTest/MaterialXCore/Node.cpp @@ -613,6 +613,54 @@ TEST_CASE("Tokens", "[nodegraph]") } } +TEST_CASE("Nested Nodegraphs", "[nodegraph]") +{ + mx::DocumentPtr doc = mx::createDocument(); + + // Create 2 level nesting of graphs + mx::NodeGraphPtr level1 = doc->addNodeGraph("level1_graph"); + mx::NodeGraphPtr level2 = level1->addNodeGraph("level2_graph"); + REQUIRE(level2); + + // Add an input connection between the graph inputs at the 2 levels + // (An interface connection) + mx::InputPtr level1Input = level1->addInput("level1_input", "color3"); + mx::InputPtr level2Input = level2->addInput("level2_input", "color3"); + level2Input->setInterfaceName("level1_input"); + REQUIRE(level2Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); + + // Add output connection from child nodegraph to node inside nodegraph + mx::OutputPtr level2Output = level2->addOutput("level2_output", "color3"); + mx::NodePtr level1Multiply = level1->addNode("multiply", "color3"); + mx::InputPtr level1MultiplyInput = level1Multiply->addInput("in1", "color3"); + level1MultiplyInput->setNodeGraphString(level2->getName()); + level1MultiplyInput->setOutputString(level2Output->getName()); + mx::OutputPtr outputPtr = level1MultiplyInput->getConnectedOutput(); + REQUIRE(outputPtr->getNamePath() == level2Output->getNamePath()); + + // Check for connected node inside level2 + mx::NodePtr level2Add = level2->addNode("add", "color3"); + level2Output->setNodeName(level2Add->getName()); + mx::NodePtr connectedNode = level1MultiplyInput->getConnectedNode(); + REQUIRE(connectedNode->getNamePath() == level2Add->getNamePath()); + REQUIRE(outputPtr->getNamePath() == level2Output->getNamePath()); + + // Also connect to level 1 output + mx::OutputPtr leve1Output = level1->addOutput("leve1_output", "color3"); + leve1Output->setNodeGraphString(level2->getName()); + level1MultiplyInput->setOutputString(level2Output->getName()); + outputPtr = level1MultiplyInput->getConnectedOutput(); + REQUIRE(outputPtr->getNamePath() == level2Output->getNamePath()); + + std::string errors; + bool valid = doc->validate(&errors); + if (!valid) + { + INFO("Validation errors:" + errors); + } + REQUIRE(valid); +} + TEST_CASE("Node Definition Creation", "[nodedef]") { mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath(); diff --git a/source/MaterialXTest/MaterialXCore/Traversal.cpp b/source/MaterialXTest/MaterialXCore/Traversal.cpp index f65228c286..5f6bca320f 100644 --- a/source/MaterialXTest/MaterialXCore/Traversal.cpp +++ b/source/MaterialXTest/MaterialXCore/Traversal.cpp @@ -186,7 +186,18 @@ TEST_CASE("InterGraph Traversal", "[traversal]") { if (!interfaceInput->getNodeName().empty() || !interfaceInput->getNodeGraphString().empty()) { - REQUIRE(interfaceInput->getConnectedNode() != nullptr); + bool connectionFound = true; + mx::OutputPtr output = interfaceInput->getConnectedOutput(); + if (!output) + { + mx::NodePtr node = interfaceInput->getConnectedNode(); + if (!node) + { + connectionFound = false; + INFO("interface input has no connection:" + interfaceInput->getNamePath()); + } + } + CHECK(connectionFound); } } } diff --git a/source/PyMaterialX/PyMaterialXCore/PyDocument.cpp b/source/PyMaterialX/PyMaterialXCore/PyDocument.cpp index 101e1bea64..2e327ee9f2 100644 --- a/source/PyMaterialX/PyMaterialXCore/PyDocument.cpp +++ b/source/PyMaterialX/PyMaterialXCore/PyDocument.cpp @@ -19,11 +19,6 @@ void bindPyDocument(py::module& mod) .def("copy", &mx::Document::copy) .def("importLibrary", &mx::Document::importLibrary) .def("getReferencedSourceUris", &mx::Document::getReferencedSourceUris) - .def("addNodeGraph", &mx::Document::addNodeGraph, - py::arg("name") = mx::EMPTY_STRING) - .def("getNodeGraph", &mx::Document::getNodeGraph) - .def("getNodeGraphs", &mx::Document::getNodeGraphs) - .def("removeNodeGraph", &mx::Document::removeNodeGraph) .def("getMatchingPorts", &mx::Document::getMatchingPorts) .def("addGeomInfo", &mx::Document::addGeomInfo, py::arg("name") = mx::EMPTY_STRING, py::arg("geom") = mx::UNIVERSAL_GEOM_NAME) diff --git a/source/PyMaterialX/PyMaterialXCore/PyNode.cpp b/source/PyMaterialX/PyMaterialXCore/PyNode.cpp index 55448dee80..654eedeab3 100644 --- a/source/PyMaterialX/PyMaterialXCore/PyNode.cpp +++ b/source/PyMaterialX/PyMaterialXCore/PyNode.cpp @@ -45,6 +45,11 @@ void bindPyNode(py::module& mod) .def("getBackdrop", &mx::GraphElement::getBackdrop) .def("getBackdrops", &mx::GraphElement::getBackdrops) .def("removeBackdrop", &mx::GraphElement::removeBackdrop) + .def("addNodeGraph", &mx::GraphElement::addNodeGraph, + py::arg("name") = mx::EMPTY_STRING) + .def("getNodeGraph", &mx::GraphElement::getNodeGraph) + .def("getNodeGraphs", &mx::GraphElement::getNodeGraphs) + .def("removeNodeGraph", &mx::GraphElement::removeNodeGraph) .def("flattenSubgraphs", &mx::GraphElement::flattenSubgraphs, py::arg("target") = mx::EMPTY_STRING, py::arg("filter") = nullptr) .def("topologicalSort", &mx::GraphElement::topologicalSort) From 4420e4de1e08cd0e861779adf6631c84268ead8f Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Fri, 20 Oct 2023 16:10:48 -0400 Subject: [PATCH 4/9] Fix up ancestor nodegraph traversal. --- source/MaterialXCore/Element.cpp | 12 ++++-------- source/MaterialXCore/Element.h | 2 +- source/MaterialXCore/Interface.cpp | 10 ++++++++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/MaterialXCore/Element.cpp b/source/MaterialXCore/Element.cpp index 99ba2f5566..fc7f21fdeb 100644 --- a/source/MaterialXCore/Element.cpp +++ b/source/MaterialXCore/Element.cpp @@ -544,18 +544,14 @@ bool ValueElement::validate(string* message) const { validateRequire(isA() || isA(), res, message, "Only input and token elements support interface names"); ConstNodeGraphPtr nodeGraph = getAncestorOfType(); + if (getParent() && getParent()->isA()) + { + nodeGraph = nodeGraph->getParent()->getAncestorOfType(); + } ConstInterfaceElementPtr decl = nodeGraph ? nodeGraph->getDeclaration() : nullptr; if (decl) { ValueElementPtr valueElem = decl->getActiveValueElement(getInterfaceName()); - if (!valueElem) - { - nodeGraph = nodeGraph->getAncestorOfType(); - if (nodeGraph) - { - valueElem = nodeGraph->getActiveValueElement(getInterfaceName()); - } - } validateRequire(valueElem != nullptr, res, message, "Interface name not found in referenced declaration"); if (valueElem) { diff --git a/source/MaterialXCore/Element.h b/source/MaterialXCore/Element.h index 80ae56e636..0c09c736cd 100644 --- a/source/MaterialXCore/Element.h +++ b/source/MaterialXCore/Element.h @@ -590,7 +590,7 @@ class MX_CORE_API Element : public std::enable_shared_from_this for (ConstElementPtr elem = self; elem; elem = elem->getParent()) { shared_ptr typedElem = elem->asA(); - if (typedElem && typedElem != self) + if (typedElem) { return typedElem; } diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index eb554e53b8..8914a6cb6e 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -175,6 +175,8 @@ bool PortElement::validate(string* message) const if (hasNodeName()) { connectedElement = connectedNode = getConnectedNode(); + //validateRequire(connectedNode != nullptr, res, message, + // "Node '" + getNodeName() + "' not found for connection"); } else if (hasNodeGraphString()) { @@ -328,7 +330,11 @@ NodePtr Input::getConnectedNode() const // Handle inputs of compound nodegraphs. if (getParent()->isA()) { - return getDocument()->getNode(getNodeName()); + NodePtr rootNode = getDocument()->getNode(getNodeName()); + if (rootNode) + { + return rootNode; + } } // Handle transitive connections via outputs. @@ -364,7 +370,7 @@ InputPtr Input::getInterfaceInput() const ConstNodeGraphPtr graph = getAncestorOfType(); if (getParent() && getParent()->isA()) { - graph = graph->getAncestorOfType(); + graph = graph->getParent()->getAncestorOfType(); } if (graph) { From 93cedc08e18309fd8b7f33ba2a12b3822786287e Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Fri, 20 Oct 2023 16:34:04 -0400 Subject: [PATCH 5/9] Cleanup. --- source/MaterialXCore/Element.h | 3 +-- source/MaterialXTest/MaterialXCore/Traversal.cpp | 13 +------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/source/MaterialXCore/Element.h b/source/MaterialXCore/Element.h index 0c09c736cd..0e00bf596a 100644 --- a/source/MaterialXCore/Element.h +++ b/source/MaterialXCore/Element.h @@ -586,8 +586,7 @@ class MX_CORE_API Element : public std::enable_shared_from_this /// pointer if no ancestor of this subclass is found. template shared_ptr getAncestorOfType() const { - ConstElementPtr self = getSelf(); - for (ConstElementPtr elem = self; elem; elem = elem->getParent()) + for (ConstElementPtr elem = getSelf(); elem; elem = elem->getParent()) { shared_ptr typedElem = elem->asA(); if (typedElem) diff --git a/source/MaterialXTest/MaterialXCore/Traversal.cpp b/source/MaterialXTest/MaterialXCore/Traversal.cpp index 5f6bca320f..f65228c286 100644 --- a/source/MaterialXTest/MaterialXCore/Traversal.cpp +++ b/source/MaterialXTest/MaterialXCore/Traversal.cpp @@ -186,18 +186,7 @@ TEST_CASE("InterGraph Traversal", "[traversal]") { if (!interfaceInput->getNodeName().empty() || !interfaceInput->getNodeGraphString().empty()) { - bool connectionFound = true; - mx::OutputPtr output = interfaceInput->getConnectedOutput(); - if (!output) - { - mx::NodePtr node = interfaceInput->getConnectedNode(); - if (!node) - { - connectionFound = false; - INFO("interface input has no connection:" + interfaceInput->getNamePath()); - } - } - CHECK(connectionFound); + REQUIRE(interfaceInput->getConnectedNode() != nullptr); } } } From 32339823205b992c71027ede472ed5f4268a1360 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Fri, 20 Oct 2023 16:51:21 -0400 Subject: [PATCH 6/9] API update for JS. --- source/JsMaterialX/JsMaterialXCore/JsDocument.cpp | 4 ---- source/JsMaterialX/JsMaterialXCore/JsNode.cpp | 4 ++++ source/MaterialXCore/Interface.cpp | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/source/JsMaterialX/JsMaterialXCore/JsDocument.cpp b/source/JsMaterialX/JsMaterialXCore/JsDocument.cpp index 23901ecc0f..b3c0d57891 100644 --- a/source/JsMaterialX/JsMaterialXCore/JsDocument.cpp +++ b/source/JsMaterialX/JsMaterialXCore/JsDocument.cpp @@ -28,10 +28,6 @@ EMSCRIPTEN_BINDINGS(document) mx::StringSet set = self.getReferencedSourceUris(); return ems::val::array(set.begin(), set.end()); })) - BIND_MEMBER_FUNC("addNodeGraph", mx::Document, addNodeGraph, 0, 1, stRef) - .function("getNodeGraph", &mx::Document::getNodeGraph) - .function("getNodeGraphs", &mx::Document::getNodeGraphs) - .function("removeNodeGraph", &mx::Document::removeNodeGraph) .function("getMatchingPorts", &mx::Document::getMatchingPorts) BIND_MEMBER_FUNC("addGeomInfo", mx::Document, addGeomInfo, 0, 2, stRef, stRef) .function("getGeomInfo", &mx::Document::getGeomInfo) diff --git a/source/JsMaterialX/JsMaterialXCore/JsNode.cpp b/source/JsMaterialX/JsMaterialXCore/JsNode.cpp index 8878a219f5..13b83fb899 100644 --- a/source/JsMaterialX/JsMaterialXCore/JsNode.cpp +++ b/source/JsMaterialX/JsMaterialXCore/JsNode.cpp @@ -47,6 +47,10 @@ EMSCRIPTEN_BINDINGS(node) .function("getBackdrop", &mx::GraphElement::getBackdrop) .function("getBackdrops", &mx::GraphElement::getBackdrops) .function("removeBackdrop", &mx::GraphElement::removeBackdrop) + BIND_MEMBER_FUNC("addNodeGraph", mx::GraphElement, addNodeGraph, 0, 1, stRef) + .function("getNodeGraph", &mx::GraphElement::getNodeGraph) + .function("getNodeGraphs", &mx::GraphElement::getNodeGraphs) + .function("removeNodeGraph", &mx::GraphElement::removeNodeGraph) BIND_MEMBER_FUNC("flattenSubgraphs", mx::GraphElement, flattenSubgraphs, 0, 2, stRef, mx::NodePredicate) .function("topologicalSort", &mx::GraphElement::topologicalSort) .function("asStringDot", &mx::GraphElement::asStringDot); diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 8914a6cb6e..df1ab6b8cc 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -10,8 +10,6 @@ #include -#include - MATERIALX_NAMESPACE_BEGIN const string PortElement::NODE_NAME_ATTRIBUTE = "nodename"; @@ -175,8 +173,6 @@ bool PortElement::validate(string* message) const if (hasNodeName()) { connectedElement = connectedNode = getConnectedNode(); - //validateRequire(connectedNode != nullptr, res, message, - // "Node '" + getNodeName() + "' not found for connection"); } else if (hasNodeGraphString()) { From d4952ee14928c12f2fffdc7f0aecfd2b8dcc3623 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Mon, 30 Oct 2023 15:28:09 -0400 Subject: [PATCH 7/9] Refine getInterfaceInput() --- .../nodegraph_inputs/nested_nodegraph_3.mtlx | 41 +++++++++++++++++++ source/MaterialXCore/Interface.cpp | 28 +++++++++---- source/MaterialXTest/MaterialXCore/Node.cpp | 16 ++++++-- 3 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph_3.mtlx diff --git a/resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph_3.mtlx b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph_3.mtlx new file mode 100644 index 0000000000..f31d6031ca --- /dev/null +++ b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/nested_nodegraph_3.mtlx @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index df1ab6b8cc..1f028288a6 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -10,6 +10,8 @@ #include +#include + MATERIALX_NAMESPACE_BEGIN const string PortElement::NODE_NAME_ATTRIBUTE = "nodename"; @@ -362,26 +364,34 @@ NodePtr Input::getConnectedNode() const InputPtr Input::getInterfaceInput() const { if (hasInterfaceName()) - { - ConstNodeGraphPtr graph = getAncestorOfType(); - if (getParent() && getParent()->isA()) - { - graph = graph->getParent()->getAncestorOfType(); - } - if (graph) + { + const string& interfaceName = getInterfaceName(); + ConstElementPtr parent = getParent(); + parent = parent->getParent(); + ConstNodeGraphPtr graph = parent->asA(); + if (graph && !graph->getNodeDef()) { - InputPtr returnVal = graph->getInput(getInterfaceName()); + InputPtr returnVal = graph->getInput(interfaceName); if (returnVal) { if (returnVal->hasInterfaceName()) { - return returnVal->getInterfaceInput(); + InputPtr val = returnVal->getInterfaceInput(); + if (val) + { + returnVal = val; + } + return returnVal; } else { return returnVal; } } + else + { + throw Exception("Interface name cannot be found: '" + interfaceName + "'"); + } } } return nullptr; diff --git a/source/MaterialXTest/MaterialXCore/Node.cpp b/source/MaterialXTest/MaterialXCore/Node.cpp index 6037b4c2e5..3a14212856 100644 --- a/source/MaterialXTest/MaterialXCore/Node.cpp +++ b/source/MaterialXTest/MaterialXCore/Node.cpp @@ -613,7 +613,7 @@ TEST_CASE("Tokens", "[nodegraph]") } } -TEST_CASE("Nested Nodegraphs", "[nodegraph]") +TEST_CASE("Nested Nodegraphs", "[nodegraph1]") { mx::DocumentPtr doc = mx::createDocument(); @@ -621,13 +621,23 @@ TEST_CASE("Nested Nodegraphs", "[nodegraph]") mx::NodeGraphPtr level1 = doc->addNodeGraph("level1_graph"); mx::NodeGraphPtr level2 = level1->addNodeGraph("level2_graph"); REQUIRE(level2); + mx::NodeGraphPtr level3 = level2->addNodeGraph("level3_graph"); + REQUIRE(level3); - // Add an input connection between the graph inputs at the 2 levels + // Add an input connection between the graph inputs at the levels 1 and 2 // (An interface connection) mx::InputPtr level1Input = level1->addInput("level1_input", "color3"); mx::InputPtr level2Input = level2->addInput("level2_input", "color3"); level2Input->setInterfaceName("level1_input"); - REQUIRE(level2Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); + //REQUIRE(level2Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); + + // Add an input connection between the graphs inputs at level 1, 2 and 3 + mx::InputPtr level1Input2 = level1->addInput("level1_input2", "color3"); + mx::InputPtr level2Input2 = level2->addInput("level2_input2", "color3"); + level2Input2->setInterfaceName(level1Input2->getName()); + mx::InputPtr level3Input = level3->addInput("level3_input", "color3"); + level3Input->setInterfaceName(level2Input2->getName()); + REQUIRE(level3Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); // Add output connection from child nodegraph to node inside nodegraph mx::OutputPtr level2Output = level2->addOutput("level2_output", "color3"); From 45f27a5421387c32c66ce15e47182c12eb5c51e8 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Mon, 30 Oct 2023 16:21:02 -0400 Subject: [PATCH 8/9] Handle transitive outputs. --- source/MaterialXCore/Interface.cpp | 10 +++++-- source/MaterialXTest/MaterialXCore/Node.cpp | 31 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp index 1f028288a6..5293e670c6 100644 --- a/source/MaterialXCore/Interface.cpp +++ b/source/MaterialXCore/Interface.cpp @@ -10,8 +10,6 @@ #include -#include - MATERIALX_NAMESPACE_BEGIN const string PortElement::NODE_NAME_ATTRIBUTE = "nodename"; @@ -128,6 +126,12 @@ OutputPtr PortElement::getConnectedOutput() const } } } + + // Handl direct nodegraph -> nodegraph output connections + while (result && result->hasNodeGraphString()) + { + result = result->getConnectedOutput(); + } } // Look for a node output. else if (hasNodeName()) @@ -346,7 +350,7 @@ NodePtr Input::getConnectedNode() const } else if (output->hasNodeGraphString()) { - OutputPtr childGraphOutput = output->getConnectedOutput(); + OutputPtr childGraphOutput = output->getConnectedOutput(); if (childGraphOutput) { NodePtr childGraphNode = childGraphOutput->getConnectedNode(); diff --git a/source/MaterialXTest/MaterialXCore/Node.cpp b/source/MaterialXTest/MaterialXCore/Node.cpp index 3a14212856..004da21523 100644 --- a/source/MaterialXTest/MaterialXCore/Node.cpp +++ b/source/MaterialXTest/MaterialXCore/Node.cpp @@ -613,7 +613,7 @@ TEST_CASE("Tokens", "[nodegraph]") } } -TEST_CASE("Nested Nodegraphs", "[nodegraph1]") +TEST_CASE("Nested Nodegraphs", "[nodegraph]") { mx::DocumentPtr doc = mx::createDocument(); @@ -629,15 +629,16 @@ TEST_CASE("Nested Nodegraphs", "[nodegraph1]") mx::InputPtr level1Input = level1->addInput("level1_input", "color3"); mx::InputPtr level2Input = level2->addInput("level2_input", "color3"); level2Input->setInterfaceName("level1_input"); - //REQUIRE(level2Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); + REQUIRE(level2Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); // Add an input connection between the graphs inputs at level 1, 2 and 3 + // Recursive interfacename search mx::InputPtr level1Input2 = level1->addInput("level1_input2", "color3"); mx::InputPtr level2Input2 = level2->addInput("level2_input2", "color3"); level2Input2->setInterfaceName(level1Input2->getName()); mx::InputPtr level3Input = level3->addInput("level3_input", "color3"); level3Input->setInterfaceName(level2Input2->getName()); - REQUIRE(level3Input->getInterfaceInput()->getNamePath() == level1Input->getNamePath()); + REQUIRE(level3Input->getInterfaceInput()->getNamePath() == level1Input2->getNamePath()); // Add output connection from child nodegraph to node inside nodegraph mx::OutputPtr level2Output = level2->addOutput("level2_output", "color3"); @@ -662,6 +663,30 @@ TEST_CASE("Nested Nodegraphs", "[nodegraph1]") outputPtr = level1MultiplyInput->getConnectedOutput(); REQUIRE(outputPtr->getNamePath() == level2Output->getNamePath()); + // Check transitive outputs + mx::OutputPtr level3Output = level3->addOutput("level3_output", "color3"); + + mx::OutputPtr level2Output2 = level2->addOutput("level2_output2", "color3"); + level2Output2->setNodeGraphString(level3->getName()); + level2Output2->setOutputString(level3Output->getName()); + + mx::OutputPtr connectedOutput = level2Output2->getConnectedOutput(); + REQUIRE(connectedOutput); + REQUIRE(connectedOutput->getNamePath() == level3Output->getNamePath()); + + mx::OutputPtr level1Output2 = level1->addOutput("level1_output2", "color3"); + level1Output2->setNodeGraphString(level2->getName()); + level1Output2->setOutputString(level2Output2->getName()); + + connectedOutput = level1Output2->getConnectedOutput(); + REQUIRE(connectedOutput); + REQUIRE(connectedOutput->getNamePath() == level3Output->getNamePath()); + + mx::OutputPtr docOutput = doc->addOutput("doc_output", "color3"); + docOutput->setNodeGraphString(level1->getName()); + docOutput->setOutputString(level1Output2->getName()); + REQUIRE(connectedOutput->getNamePath() == level3Output->getNamePath()); + std::string errors; bool valid = doc->validate(&errors); if (!valid) From c105509f2b9cc33b90ea8719e9cf0fcea2699214 Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Thu, 18 Jan 2024 17:09:08 -0500 Subject: [PATCH 9/9] Merge update. (#48) * Improvements to noise implementations (#1653) - Leverage node graphs to share the conversion aspects of noise implementations across languages. - Simplify noise unit tests to cover only unique implementations. * Fix shader generation typos This changelist fixes a handful of minor typos in shader generation, introduced in #1355 and #1553. * Add frame capture to web viewer (#1636) Add frame capture code to trigger on 'f' key. This is the same key as used for the desktop viewer. * Document format updates This changelist applies the mxformat.py script to the libraries and resources folders in the repository, updating formatting for a handful of documents. --------- Co-authored-by: Jonathan Stone --- javascript/MaterialXView/source/index.js | 30 ++- libraries/bxdf/gltf_pbr.mtlx | 2 +- .../nprlib/genglsl/nprlib_genglsl_impl.mtlx | 2 +- .../nprlib/genmdl/nprlib_genmdl_impl.mtlx | 2 +- .../nprlib/genmsl/nprlib_genmsl_impl.mtlx | 2 +- .../genglsl/mx_fractal3d_fa_vector2.glsl | 7 - .../genglsl/mx_fractal3d_fa_vector3.glsl | 7 - .../genglsl/mx_fractal3d_fa_vector4.glsl | 7 - .../stdlib/genglsl/mx_noise2d_fa_vector2.glsl | 7 - .../stdlib/genglsl/mx_noise2d_fa_vector3.glsl | 7 - .../stdlib/genglsl/mx_noise2d_fa_vector4.glsl | 8 - .../stdlib/genglsl/mx_noise3d_fa_vector2.glsl | 7 - .../stdlib/genglsl/mx_noise3d_fa_vector3.glsl | 7 - .../stdlib/genglsl/mx_noise3d_fa_vector4.glsl | 8 - .../stdlib/genglsl/stdlib_genglsl_impl.mtlx | 21 -- .../stdlib/genmdl/stdlib_genmdl_impl.mtlx | 21 -- .../stdlib/genmsl/stdlib_genmsl_impl.mtlx | 27 +-- libraries/stdlib/genosl/mx_creatematrix.osl | 6 +- .../stdlib/genosl/mx_fractal3d_color3.osl | 5 - .../stdlib/genosl/mx_fractal3d_color4.osl | 5 - .../stdlib/genosl/mx_fractal3d_fa_color3.osl | 5 - .../stdlib/genosl/mx_fractal3d_fa_color4.osl | 5 - .../stdlib/genosl/mx_fractal3d_fa_vector2.osl | 5 - .../stdlib/genosl/mx_fractal3d_fa_vector3.osl | 5 - .../stdlib/genosl/mx_fractal3d_fa_vector4.osl | 5 - libraries/stdlib/genosl/mx_noise2d_color3.osl | 5 - libraries/stdlib/genosl/mx_noise2d_color4.osl | 5 - .../stdlib/genosl/mx_noise2d_fa_color3.osl | 5 - .../stdlib/genosl/mx_noise2d_fa_color4.osl | 5 - .../stdlib/genosl/mx_noise2d_fa_vector2.osl | 5 - .../stdlib/genosl/mx_noise2d_fa_vector3.osl | 5 - .../stdlib/genosl/mx_noise2d_fa_vector4.osl | 5 - libraries/stdlib/genosl/mx_noise3d_color3.osl | 5 - libraries/stdlib/genosl/mx_noise3d_color4.osl | 5 - .../stdlib/genosl/mx_noise3d_fa_color3.osl | 5 - .../stdlib/genosl/mx_noise3d_fa_color4.osl | 5 - .../stdlib/genosl/mx_noise3d_fa_vector2.osl | 5 - .../stdlib/genosl/mx_noise3d_fa_vector3.osl | 5 - .../stdlib/genosl/mx_noise3d_fa_vector4.osl | 5 - libraries/stdlib/genosl/mx_normalmap.osl | 2 +- .../stdlib/genosl/stdlib_genosl_impl.mtlx | 27 +-- libraries/stdlib/stdlib_ng.mtlx | 200 +++++++++++++++++- .../TestSuite/stdlib/noise/noise.mtlx | 105 --------- .../stdlib/procedural/tiledshape.mtlx | 2 +- .../TestSuite/stdlib/upgrade/syntax_1_37.mtlx | 2 +- 45 files changed, 241 insertions(+), 380 deletions(-) delete mode 100644 libraries/stdlib/genglsl/mx_fractal3d_fa_vector2.glsl delete mode 100644 libraries/stdlib/genglsl/mx_fractal3d_fa_vector3.glsl delete mode 100644 libraries/stdlib/genglsl/mx_fractal3d_fa_vector4.glsl delete mode 100644 libraries/stdlib/genglsl/mx_noise2d_fa_vector2.glsl delete mode 100644 libraries/stdlib/genglsl/mx_noise2d_fa_vector3.glsl delete mode 100644 libraries/stdlib/genglsl/mx_noise2d_fa_vector4.glsl delete mode 100644 libraries/stdlib/genglsl/mx_noise3d_fa_vector2.glsl delete mode 100644 libraries/stdlib/genglsl/mx_noise3d_fa_vector3.glsl delete mode 100644 libraries/stdlib/genglsl/mx_noise3d_fa_vector4.glsl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_color3.osl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_color4.osl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_fa_color3.osl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_fa_color4.osl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_fa_vector2.osl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_fa_vector3.osl delete mode 100644 libraries/stdlib/genosl/mx_fractal3d_fa_vector4.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_color3.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_color4.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_fa_color3.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_fa_color4.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_fa_vector2.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_fa_vector3.osl delete mode 100644 libraries/stdlib/genosl/mx_noise2d_fa_vector4.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_color3.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_color4.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_fa_color3.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_fa_color4.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_fa_vector2.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_fa_vector3.osl delete mode 100644 libraries/stdlib/genosl/mx_noise3d_fa_vector4.osl diff --git a/javascript/MaterialXView/source/index.js b/javascript/MaterialXView/source/index.js index d11ba9691e..d46bd2350f 100644 --- a/javascript/MaterialXView/source/index.js +++ b/javascript/MaterialXView/source/index.js @@ -21,6 +21,8 @@ let turntableEnabled = false; let turntableSteps = 360; let turntableStep = 0; +let captureRequested = false; + // Get URL options. Fallback to defaults if not specified. let materialFilename = new URLSearchParams(document.location.search).get("file"); if (!materialFilename) { @@ -31,6 +33,18 @@ let viewer = Viewer.create(); init(); viewer.getEditor().updateProperties(0.9); +// Capture the current frame and save an image file. +function captureFrame() +{ + let canvas = document.getElementById('webglcanvas'); + var url = canvas.toDataURL(); + var link = document.createElement('a'); + link.setAttribute('href', url); + link.setAttribute('target', '_blank'); + link.setAttribute('download', 'screenshot.png'); + link.click(); +} + function init() { let canvas = document.getElementById('webglcanvas'); @@ -82,9 +96,15 @@ function init() orbitControls = new OrbitControls(scene.getCamera(), renderer.domElement); orbitControls.addEventListener('change', () => { viewer.getScene().setUpdateTransforms(); - }) + }) - // Load model and shaders + // Add hotkey 'f' to capture the current frame and save an image file. + // See check inside the render loop when a capture can be performed. + document.addEventListener('keydown', (event) => { + if (event.key === 'f') { + captureRequested = true; + } + }); // Initialize editor viewer.getEditor().initialize(); @@ -160,6 +180,12 @@ function animate() composer.render(); viewer.getScene().updateTransforms(); + + if (captureRequested) + { + captureFrame(); + captureRequested = false; + } } function handleKeyEvents(event) diff --git a/libraries/bxdf/gltf_pbr.mtlx b/libraries/bxdf/gltf_pbr.mtlx index 6654e63454..b42054a185 100644 --- a/libraries/bxdf/gltf_pbr.mtlx +++ b/libraries/bxdf/gltf_pbr.mtlx @@ -359,7 +359,7 @@ - + diff --git a/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx b/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx index 7ddc4cee83..1a96f315e5 100644 --- a/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx +++ b/libraries/nprlib/genglsl/nprlib_genglsl_impl.mtlx @@ -12,6 +12,6 @@ - + diff --git a/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx b/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx index b6472e0c51..73a9d22945 100644 --- a/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx +++ b/libraries/nprlib/genmdl/nprlib_genmdl_impl.mtlx @@ -12,6 +12,6 @@ - + diff --git a/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx b/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx index b8f9a4e3aa..615e9d8ce0 100644 --- a/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx +++ b/libraries/nprlib/genmsl/nprlib_genmsl_impl.mtlx @@ -12,6 +12,6 @@ - + diff --git a/libraries/stdlib/genglsl/mx_fractal3d_fa_vector2.glsl b/libraries/stdlib/genglsl/mx_fractal3d_fa_vector2.glsl deleted file mode 100644 index 59dbbee127..0000000000 --- a/libraries/stdlib/genglsl/mx_fractal3d_fa_vector2.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_fractal3d_fa_vector2(float amplitude, int octaves, float lacunarity, float diminish, vec3 position, out vec2 result) -{ - vec2 value = mx_fractal_noise_vec2(position, octaves, lacunarity, diminish); - result = value * amplitude; -} diff --git a/libraries/stdlib/genglsl/mx_fractal3d_fa_vector3.glsl b/libraries/stdlib/genglsl/mx_fractal3d_fa_vector3.glsl deleted file mode 100644 index d0f30defd4..0000000000 --- a/libraries/stdlib/genglsl/mx_fractal3d_fa_vector3.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_fractal3d_fa_vector3(float amplitude, int octaves, float lacunarity, float diminish, vec3 position, out vec3 result) -{ - vec3 value = mx_fractal_noise_vec3(position, octaves, lacunarity, diminish); - result = value * amplitude; -} diff --git a/libraries/stdlib/genglsl/mx_fractal3d_fa_vector4.glsl b/libraries/stdlib/genglsl/mx_fractal3d_fa_vector4.glsl deleted file mode 100644 index b9c66c4465..0000000000 --- a/libraries/stdlib/genglsl/mx_fractal3d_fa_vector4.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_fractal3d_fa_vector4(float amplitude, int octaves, float lacunarity, float diminish, vec3 position, out vec4 result) -{ - vec4 value = mx_fractal_noise_vec4(position, octaves, lacunarity, diminish); - result = value * amplitude; -} diff --git a/libraries/stdlib/genglsl/mx_noise2d_fa_vector2.glsl b/libraries/stdlib/genglsl/mx_noise2d_fa_vector2.glsl deleted file mode 100644 index f5a81565d7..0000000000 --- a/libraries/stdlib/genglsl/mx_noise2d_fa_vector2.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_noise2d_fa_vector2(float amplitude, float pivot, vec2 texcoord, out vec2 result) -{ - vec3 value = mx_perlin_noise_vec3(texcoord); - result = value.xy * amplitude + pivot; -} diff --git a/libraries/stdlib/genglsl/mx_noise2d_fa_vector3.glsl b/libraries/stdlib/genglsl/mx_noise2d_fa_vector3.glsl deleted file mode 100644 index 0735965ca0..0000000000 --- a/libraries/stdlib/genglsl/mx_noise2d_fa_vector3.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_noise2d_fa_vector3(float amplitude, float pivot, vec2 texcoord, out vec3 result) -{ - vec3 value = mx_perlin_noise_vec3(texcoord); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genglsl/mx_noise2d_fa_vector4.glsl b/libraries/stdlib/genglsl/mx_noise2d_fa_vector4.glsl deleted file mode 100644 index 6d51a59e4a..0000000000 --- a/libraries/stdlib/genglsl/mx_noise2d_fa_vector4.glsl +++ /dev/null @@ -1,8 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_noise2d_fa_vector4(float amplitude, float pivot, vec2 texcoord, out vec4 result) -{ - vec3 xyz = mx_perlin_noise_vec3(texcoord); - float w = mx_perlin_noise_float(texcoord + vec2(19, 73)); - result = vec4(xyz, w) * amplitude + pivot; -} diff --git a/libraries/stdlib/genglsl/mx_noise3d_fa_vector2.glsl b/libraries/stdlib/genglsl/mx_noise3d_fa_vector2.glsl deleted file mode 100644 index 06d91f9135..0000000000 --- a/libraries/stdlib/genglsl/mx_noise3d_fa_vector2.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_noise3d_fa_vector2(float amplitude, float pivot, vec3 position, out vec2 result) -{ - vec3 value = mx_perlin_noise_vec3(position); - result = value.xy * amplitude + pivot; -} diff --git a/libraries/stdlib/genglsl/mx_noise3d_fa_vector3.glsl b/libraries/stdlib/genglsl/mx_noise3d_fa_vector3.glsl deleted file mode 100644 index 168bf572f1..0000000000 --- a/libraries/stdlib/genglsl/mx_noise3d_fa_vector3.glsl +++ /dev/null @@ -1,7 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_noise3d_fa_vector3(float amplitude, float pivot, vec3 position, out vec3 result) -{ - vec3 value = mx_perlin_noise_vec3(position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genglsl/mx_noise3d_fa_vector4.glsl b/libraries/stdlib/genglsl/mx_noise3d_fa_vector4.glsl deleted file mode 100644 index 680410f9d3..0000000000 --- a/libraries/stdlib/genglsl/mx_noise3d_fa_vector4.glsl +++ /dev/null @@ -1,8 +0,0 @@ -#include "lib/mx_noise.glsl" - -void mx_noise3d_fa_vector4(float amplitude, float pivot, vec3 position, out vec4 result) -{ - vec3 xyz = mx_perlin_noise_vec3(position); - float w = mx_perlin_noise_float(position + vec3(19, 73, 29)); - result = vec4(xyz, w) * amplitude + pivot; -} diff --git a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx index dc4f52e3b6..3cd3ae305d 100644 --- a/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx +++ b/libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx @@ -98,42 +98,21 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx index 96fd768e25..5250501320 100644 --- a/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx +++ b/libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx @@ -99,42 +99,21 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx index 1875c2b617..8526330d47 100644 --- a/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx +++ b/libraries/stdlib/genmsl/stdlib_genmsl_impl.mtlx @@ -97,42 +97,21 @@ - - - - - - - - - - - - - - - - - - - - - @@ -750,9 +729,9 @@ - - - + + + diff --git a/libraries/stdlib/genosl/mx_creatematrix.osl b/libraries/stdlib/genosl/mx_creatematrix.osl index 933dce00ba..3e567d3b5b 100644 --- a/libraries/stdlib/genosl/mx_creatematrix.osl +++ b/libraries/stdlib/genosl/mx_creatematrix.osl @@ -1,4 +1,4 @@ -void mx_creatematrix_vector3_matrix33(vector in1, vector in2, vector in3, out matrix result) +void mx_creatematrix_vector3_matrix33(vector in1, vector in2, vector in3, output matrix result) { result = matrix(in1.x, in1.y, in1.z, 0.0, in2.x, in2.y, in2.z, 0.0, @@ -6,7 +6,7 @@ void mx_creatematrix_vector3_matrix33(vector in1, vector in2, vector in3, out ma 0.0, 0.0, 0.0, 1.0); } -void mx_creatematrix_vector3_matrix44(vector3 in1, vector3 in2, vector3 in3, vector3 in4, out matrix result) +void mx_creatematrix_vector3_matrix44(vector in1, vector in2, vector in3, vector in4, output matrix result) { result = matrix(in1.x, in1.y, in1.z, 0.0, in2.x, in2.y, in2.z, 0.0, @@ -14,7 +14,7 @@ void mx_creatematrix_vector3_matrix44(vector3 in1, vector3 in2, vector3 in3, vec in4.x, in4.y, in4.z, 1.0); } -void mx_creatematrix_vector4_matrix44(vector4 in1, vector4 in2, vector4 in3, vector4 in4, out matrix result) +void mx_creatematrix_vector4_matrix44(vector4 in1, vector4 in2, vector4 in3, vector4 in4, output matrix result) { result = matrix(in1.x, in1.y, in1.z, in1.w, in2.x, in2.y, in2.z, in2.w, diff --git a/libraries/stdlib/genosl/mx_fractal3d_color3.osl b/libraries/stdlib/genosl/mx_fractal3d_color3.osl deleted file mode 100644 index bf1744890b..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_color3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_color3(vector amplitude, int octaves, float lacunarity, float diminish, vector position, output color result) -{ - color f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * amplitude; -} diff --git a/libraries/stdlib/genosl/mx_fractal3d_color4.osl b/libraries/stdlib/genosl/mx_fractal3d_color4.osl deleted file mode 100644 index 9943a92dfd..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_color4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_color4(vector4 amplitude, int octaves, float lacunarity, float diminish, vector position, output color4 result) -{ - color4 f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * color4(color(amplitude.x, amplitude.y, amplitude.z), amplitude.w); -} diff --git a/libraries/stdlib/genosl/mx_fractal3d_fa_color3.osl b/libraries/stdlib/genosl/mx_fractal3d_fa_color3.osl deleted file mode 100644 index 889848c692..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_fa_color3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_fa_color3(float amplitude, int octaves, float lacunarity, float diminish, vector position, output color result) -{ - color f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * amplitude; -} diff --git a/libraries/stdlib/genosl/mx_fractal3d_fa_color4.osl b/libraries/stdlib/genosl/mx_fractal3d_fa_color4.osl deleted file mode 100644 index d2a8f49291..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_fa_color4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_fa_color4(float amplitude, int octaves, float lacunarity, float diminish, vector position, output color4 result) -{ - color4 f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * amplitude; -} diff --git a/libraries/stdlib/genosl/mx_fractal3d_fa_vector2.osl b/libraries/stdlib/genosl/mx_fractal3d_fa_vector2.osl deleted file mode 100644 index c1266d473c..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_fa_vector2.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_fa_vector2(float amplitude, int octaves, float lacunarity, float diminish, vector position, output vector2 result) -{ - vector2 f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * amplitude; -} diff --git a/libraries/stdlib/genosl/mx_fractal3d_fa_vector3.osl b/libraries/stdlib/genosl/mx_fractal3d_fa_vector3.osl deleted file mode 100644 index 34f6515ca8..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_fa_vector3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_fa_vector3(float amplitude, int octaves, float lacunarity, float diminish, vector position, output vector result) -{ - vector f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * amplitude; -} diff --git a/libraries/stdlib/genosl/mx_fractal3d_fa_vector4.osl b/libraries/stdlib/genosl/mx_fractal3d_fa_vector4.osl deleted file mode 100644 index fb5a8c73d6..0000000000 --- a/libraries/stdlib/genosl/mx_fractal3d_fa_vector4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_fractal3d_fa_vector4(float amplitude, int octaves, float lacunarity, float diminish, vector position, output vector4 result) -{ - vector4 f = mx_fbm(position, octaves, lacunarity, diminish, "snoise"); - result = f * amplitude; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_color3.osl b/libraries/stdlib/genosl/mx_noise2d_color3.osl deleted file mode 100644 index 37421ee810..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_color3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_color3(vector amplitude, float pivot, vector2 texcoord, output color result) -{ - color value = noise("snoise", texcoord.x, texcoord.y); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_color4.osl b/libraries/stdlib/genosl/mx_noise2d_color4.osl deleted file mode 100644 index ec8064c577..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_color4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_color4(vector4 amplitude, float pivot, vector2 texcoord, output color4 result) -{ - color4 value = mx_noise("snoise", texcoord.x, texcoord.y); - result = value * color4(color(amplitude.x, amplitude.y, amplitude.z), amplitude.w) + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_fa_color3.osl b/libraries/stdlib/genosl/mx_noise2d_fa_color3.osl deleted file mode 100644 index 29c09c1ae2..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_fa_color3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_fa_color3(float amplitude, float pivot, vector2 texcoord, output color result) -{ - color value = noise("snoise", texcoord.x, texcoord.y); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_fa_color4.osl b/libraries/stdlib/genosl/mx_noise2d_fa_color4.osl deleted file mode 100644 index 35d3463ff7..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_fa_color4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_fa_color4(float amplitude, float pivot, vector2 texcoord, output color4 result) -{ - color4 value = mx_noise("snoise", texcoord.x, texcoord.y); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_fa_vector2.osl b/libraries/stdlib/genosl/mx_noise2d_fa_vector2.osl deleted file mode 100644 index b64dc6de7a..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_fa_vector2.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_fa_vector2(float amplitude, float pivot, vector2 texcoord, output vector2 result) -{ - vector2 value = mx_noise("snoise", texcoord.x, texcoord.y); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_fa_vector3.osl b/libraries/stdlib/genosl/mx_noise2d_fa_vector3.osl deleted file mode 100644 index c1f060a265..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_fa_vector3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_fa_vector3(float amplitude, float pivot, vector2 texcoord, output vector result) -{ - vector value = noise("snoise", texcoord.x, texcoord.y); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise2d_fa_vector4.osl b/libraries/stdlib/genosl/mx_noise2d_fa_vector4.osl deleted file mode 100644 index 9cb9f57c7c..0000000000 --- a/libraries/stdlib/genosl/mx_noise2d_fa_vector4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise2d_fa_vector4(float amplitude, float pivot, vector2 texcoord, output vector4 result) -{ - vector4 value = mx_noise("snoise", texcoord.x, texcoord.y); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_color3.osl b/libraries/stdlib/genosl/mx_noise3d_color3.osl deleted file mode 100644 index f4649a598a..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_color3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_color3(vector amplitude, float pivot, vector position, output color result) -{ - color value = noise("snoise", position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_color4.osl b/libraries/stdlib/genosl/mx_noise3d_color4.osl deleted file mode 100644 index c522f81493..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_color4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_color4(vector4 amplitude, float pivot, vector position, output color4 result) -{ - color4 value = mx_noise("snoise", position); - result = value * color4(color(amplitude.x, amplitude.y, amplitude.z), amplitude.w) + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_fa_color3.osl b/libraries/stdlib/genosl/mx_noise3d_fa_color3.osl deleted file mode 100644 index 83b777b2f2..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_fa_color3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_fa_color3(float amplitude, float pivot, vector position, output color result) -{ - color value = noise("snoise", position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_fa_color4.osl b/libraries/stdlib/genosl/mx_noise3d_fa_color4.osl deleted file mode 100644 index ee1a48ea0c..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_fa_color4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_fa_color4(float amplitude, float pivot, vector position, output color4 result) -{ - color4 value = mx_noise("snoise", position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_fa_vector2.osl b/libraries/stdlib/genosl/mx_noise3d_fa_vector2.osl deleted file mode 100644 index 9317d8933b..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_fa_vector2.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_fa_vector2(float amplitude, float pivot, vector position, output vector2 result) -{ - vector2 value = mx_noise("snoise", position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_fa_vector3.osl b/libraries/stdlib/genosl/mx_noise3d_fa_vector3.osl deleted file mode 100644 index 4e235febce..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_fa_vector3.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_fa_vector3(float amplitude, float pivot, vector position, output vector result) -{ - vector value = noise("snoise", position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_noise3d_fa_vector4.osl b/libraries/stdlib/genosl/mx_noise3d_fa_vector4.osl deleted file mode 100644 index 177fc3f286..0000000000 --- a/libraries/stdlib/genosl/mx_noise3d_fa_vector4.osl +++ /dev/null @@ -1,5 +0,0 @@ -void mx_noise3d_fa_vector4(float amplitude, float pivot, vector position, output vector4 result) -{ - vector4 value = mx_noise("snoise", position); - result = value * amplitude + pivot; -} diff --git a/libraries/stdlib/genosl/mx_normalmap.osl b/libraries/stdlib/genosl/mx_normalmap.osl index bf75781f51..79b31df69d 100644 --- a/libraries/stdlib/genosl/mx_normalmap.osl +++ b/libraries/stdlib/genosl/mx_normalmap.osl @@ -6,7 +6,7 @@ void mx_normalmap_vector2(vector value, string map_space, vector2 normal_scale, vector v = value * 2.0 - 1.0; vector T = normalize(U - dot(U, N) * N); vector B = normalize(cross(N, T)); - result = normalize(T * v[0] * normal_scale[0] + B * v[1] * normal_scale[1] + N * v[2]); + result = normalize(T * v[0] * normal_scale.x + B * v[1] * normal_scale.y + N * v[2]); } // Object space else diff --git a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx index ae3f6777cf..7268ee61dd 100644 --- a/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx +++ b/libraries/stdlib/genosl/stdlib_genosl_impl.mtlx @@ -99,42 +99,21 @@ - - - - - - - - - - - - - - - - - - - - - @@ -753,9 +732,9 @@ - - - + + + diff --git a/libraries/stdlib/stdlib_ng.mtlx b/libraries/stdlib/stdlib_ng.mtlx index 4983aaa477..b34dc71e5d 100644 --- a/libraries/stdlib/stdlib_ng.mtlx +++ b/libraries/stdlib/stdlib_ng.mtlx @@ -1309,6 +1309,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2479,7 +2673,7 @@ - + @@ -79,53 +44,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -136,53 +66,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resources/Materials/TestSuite/stdlib/procedural/tiledshape.mtlx b/resources/Materials/TestSuite/stdlib/procedural/tiledshape.mtlx index 69fd225f2c..fe6e414535 100644 --- a/resources/Materials/TestSuite/stdlib/procedural/tiledshape.mtlx +++ b/resources/Materials/TestSuite/stdlib/procedural/tiledshape.mtlx @@ -24,7 +24,7 @@ - + diff --git a/resources/Materials/TestSuite/stdlib/upgrade/syntax_1_37.mtlx b/resources/Materials/TestSuite/stdlib/upgrade/syntax_1_37.mtlx index 66dc69f668..7404b75575 100644 --- a/resources/Materials/TestSuite/stdlib/upgrade/syntax_1_37.mtlx +++ b/resources/Materials/TestSuite/stdlib/upgrade/syntax_1_37.mtlx @@ -58,7 +58,7 @@ - +