Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a MaterialX v1.38.5 update for closures #2858

Merged
merged 2 commits into from
Feb 6, 2023
Merged
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
49 changes: 48 additions & 1 deletion lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,55 @@ ShaderPtr GlslFragmentGenerator::generate(
true);
}

// Add all function calls
// Add all function calls (varies greatly by MaterialX version)
seando-adsk marked this conversation as resolved.
Show resolved Hide resolved
#if MX_COMBINED_VERSION >= 13805
// 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);

// 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);
}
}
}
} else {
// No surface shader graph so just generate all
// function calls in order.
emitFunctionCalls(graph, context, pixelStage);
}
#elif MX_COMBINED_VERSION >= 13803
// 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);

// 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 {
// No surface shader graph so just generate all
// function calls in order.
emitFunctionCalls(graph, context, pixelStage);
}
#else
emitFunctionCalls(graph, context, pixelStage);
#endif

// Emit final result
//
Expand Down