Skip to content

Commit

Permalink
Made versioned code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
JGamache-autodesk committed Feb 1, 2023
1 parent 90b7614 commit 4807c77
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,25 +386,14 @@ ShaderPtr GlslFragmentGenerator::generate(
}

// Add all function calls (varies greatly by MaterialX version)
#if MX_COMBINED_VERSION < 13803
emitFunctionCalls(graph, context, pixelStage);
#else
#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);

#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()) {
Expand All @@ -417,12 +406,33 @@ ShaderPtr GlslFragmentGenerator::generate(
}
}
}
#endif
} 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

0 comments on commit 4807c77

Please sign in to comment.