diff --git a/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx new file mode 100644 index 0000000000..07909137e4 --- /dev/null +++ b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx new file mode 100644 index 0000000000..c57d502dfd --- /dev/null +++ b/resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/MaterialXGenMdl/MdlShaderGenerator.cpp b/source/MaterialXGenMdl/MdlShaderGenerator.cpp index d0987aea35..36a6430d14 100644 --- a/source/MaterialXGenMdl/MdlShaderGenerator.cpp +++ b/source/MaterialXGenMdl/MdlShaderGenerator.cpp @@ -379,13 +379,11 @@ ShaderNodeImplPtr MdlShaderGenerator::createShaderNodeImplForNodeGraph(const Nod throw ExceptionShaderGenError("NodeGraph '" + nodegraph.getName() + "' has no outputs defined"); } - const TypeDesc outputType = _typeSystem->getType(outputs[0]->getType()); - - ShaderNodeImplPtr impl; - // Use a compound implementation. - if (outputType.isClosure()) + // Any closure output requires the emitter that handles mixed output types. + for (OutputPtr output : outputs) { - return ClosureCompoundNodeMdl::create(); + if (_typeSystem->getType(output->getType()).isClosure()) + return ClosureCompoundNodeMdl::create(); } return CompoundNodeMdl::create(); } diff --git a/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp index 822fd5406a..9a65e6c3bf 100644 --- a/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp @@ -101,6 +101,7 @@ void ClosureCompoundNodeMdl::emitFunctionDefinition(const ShaderNode& node, GenC { const string result = shadergen.getUpstreamResult(outputSocket, context); shadergen.emitLine("return " + result, stage); + shadergen.emitScopeEnd(stage); } shadergen.emitLineBreak(stage);