MaterialX icon indicating copy to clipboard operation
MaterialX copied to clipboard

Shader Translation fails to find upstream connections without explicit outputs

Open kwokcb opened this issue 2 years ago • 0 comments

If an upstream node on an input is connected, but that node does not have an explicit "output" child the current logic will fail. This code it appears is only looking for the upstream node and not the output so should be able to be changed though the input->output connection dictionary also needs to be maintained. See this code: https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/source/MaterialXGenShader/ShaderTranslator.cpp#L26-L44 or

OutputPtr connectedOutput = shaderInput->getConnectedOutput();
            if (connectedOutput)
            {
                NodePtr connectedNode = connectedOutput->getConnectedNode(); <-- This can be called directly to get the node

                // Nodes with world-space outputs are skipped, with translation being applied to
                // the node directly upstream.
                NodePtr worldSpaceNode = connectsToWorldSpaceNode(connectedOutput); <-- This signature would need to change to use the node directly
                if (worldSpaceNode)
                {
                    NodePtr upstreamNode = worldSpaceNode->getConnectedNode("in");
                    if (upstreamNode)
                    {
                        connectedNode = upstreamNode;
                    }
                }

                input->setConnectedNode(connectedNode);
                origOutputs.insert(connectedOutput); <-- Unknonw what to do here ?
            }

A workaround is to create all the explicit outputs on load (or after the fact). There are utilities to do this.

kwokcb avatar Jun 28 '22 13:06 kwokcb