Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<materialx version="1.39">
<nodedef name="ND_mixedoutput" node="mixedoutput">
<output name="surface" type="surfaceshader" />
<output name="weight" type="float" />
</nodedef>
<nodegraph name="NG_mixedoutput" nodedef="ND_mixedoutput">
<standard_surface name="surface_node" type="surfaceshader">
<input name="base_color" type="color3" value="1, 0, 0" />
</standard_surface>
<sin name="weight_node" type="float">
<input name="in" type="float" value="0.5" />
</sin>
<output name="surface" type="surfaceshader" nodename="surface_node" />
<output name="weight" type="float" nodename="weight_node" />
</nodegraph>
<mixedoutput name="source" type="multioutput" />
<standard_surface name="background" type="surfaceshader">
<input name="base_color" type="color3" value="0, 0, 1" />
</standard_surface>
<mix name="result" type="surfaceshader">
<input name="fg" type="surfaceshader" nodename="source" output="surface" />
<input name="bg" type="surfaceshader" nodename="background" />
<input name="mix" type="float" nodename="source" output="weight" />
</mix>
<surfacematerial name="mixedoutput_material" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="result" />
</surfacematerial>
</materialx>
30 changes: 30 additions & 0 deletions resources/Materials/TestSuite/pbrlib/multioutput/mixedoutput2.mtlx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<materialx version="1.39">
<!-- Scalar-first counterpart of mixedoutput.mtlx: both output orders must work. -->
<nodedef name="ND_mixedoutput2" node="mixedoutput2">
<output name="weight" type="float" />
<output name="surface" type="surfaceshader" />
</nodedef>
<nodegraph name="NG_mixedoutput2" nodedef="ND_mixedoutput2">
<standard_surface name="surface_node" type="surfaceshader">
<input name="base_color" type="color3" value="1, 0, 0" />
</standard_surface>
<sin name="weight_node" type="float">
<input name="in" type="float" value="0.5" />
</sin>
<output name="weight" type="float" nodename="weight_node" />
<output name="surface" type="surfaceshader" nodename="surface_node" />
</nodegraph>
<mixedoutput2 name="source" type="multioutput" />
<standard_surface name="background" type="surfaceshader">
<input name="base_color" type="color3" value="0, 0, 1" />
</standard_surface>
<mix name="result" type="surfaceshader">
<input name="fg" type="surfaceshader" nodename="source" output="surface" />
<input name="bg" type="surfaceshader" nodename="background" />
<input name="mix" type="float" nodename="source" output="weight" />
</mix>
<surfacematerial name="mixedoutput2_material" type="material">
<input name="surfaceshader" type="surfaceshader" nodename="result" />
</surfacematerial>
</materialx>
10 changes: 4 additions & 6 deletions source/MaterialXGenMdl/MdlShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions source/MaterialXGenMdl/Nodes/ClosureCompoundNodeMdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading