diff --git a/lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp b/lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp index 028c1fb646..23cd2f9443 100644 --- a/lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp +++ b/lib/mayaUsd/render/MaterialXGenOgsXml/GlslFragmentGenerator.cpp @@ -386,9 +386,7 @@ 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)) { @@ -396,15 +394,6 @@ ShaderPtr GlslFragmentGenerator::generate( // 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()) { @@ -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