Skip to content

Commit

Permalink
Adding a MaterialX v1.38.5 update for closures
Browse files Browse the repository at this point in the history
Shading graphs containing closures would fail to work with MaterialX
1.38.5.
  • Loading branch information
JGamache-autodesk committed Jan 31, 2023
1 parent 4bbc17f commit 90b7614
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,45 @@ ShaderPtr GlslFragmentGenerator::generate(
true);
}

// Add all function calls
// Add all function calls (varies greatly by MaterialX version)
#if MX_COMBINED_VERSION < 13803
emitFunctionCalls(graph, context, pixelStage);
#else
// Surface shaders need special handling.
if (graph.hasClassification(
ShaderNode::Classification::SHADER | ShaderNode::Classification::SURFACE)) {
// Emit all texturing nodes. These are inputs to any
// closure/shader nodes and need to be emitted first.
emitFunctionCalls(graph, context, pixelStage, ShaderNode::Classification::TEXTURE);

#if MX_COMBINED_VERSION < 13805
// Emit function calls for all surface shader nodes.
// These will internally emit their closure function calls.
emitFunctionCalls(
graph,
context,
pixelStage,
ShaderNode::Classification::SHADER | ShaderNode::Classification::SURFACE);
#else
// Emit function calls for "root" closure/shader nodes.
// These will internally emit function calls for any dependent closure nodes upstream.
for (ShaderGraphOutputSocket* socket : graph.getOutputSockets()) {
if (socket->getConnection()) {
const ShaderNode* upstream = socket->getConnection()->getNode();
if (upstream->getParent() == &graph
&& (upstream->hasClassification(ShaderNode::Classification::CLOSURE)
|| upstream->hasClassification(ShaderNode::Classification::SHADER))) {
emitFunctionCall(*upstream, context, pixelStage);
}
}
}
#endif
} else {
// No surface shader graph so just generate all
// function calls in order.
emitFunctionCalls(graph, context, pixelStage);
}
#endif

// Emit final result
//
Expand Down

0 comments on commit 90b7614

Please sign in to comment.