From 315c25bd8a90f8f57e3c3a1909581fc3d037591e Mon Sep 17 00:00:00 2001 From: Jerry Gamache Date: Wed, 13 Aug 2025 14:40:26 -0400 Subject: [PATCH] Add an option to toggle eliding constant nodes Editing this node in a real time MaterialX editing software leads to constant shader recompilation because the value gets burned inside the shader text. On complex shading models, this has a noticeable perfomance impact. Add an option to keep these as regular nodes that do not require recompiling the shader. --- source/MaterialXGenShader/GenOptions.h | 4 ++++ source/MaterialXGenShader/ShaderNode.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/source/MaterialXGenShader/GenOptions.h b/source/MaterialXGenShader/GenOptions.h index 51170c68de..7036ac7a4b 100644 --- a/source/MaterialXGenShader/GenOptions.h +++ b/source/MaterialXGenShader/GenOptions.h @@ -81,6 +81,7 @@ class MX_GENSHADER_API GenOptions addUpstreamDependencies(true), libraryPrefix("libraries"), emitColorTransforms(true), + elideConstantNodes(true), hwTransparency(false), hwSpecularEnvironmentMethod(SPECULAR_ENVIRONMENT_FIS), hwDirectionalAlbedoMethod(DIRECTIONAL_ALBEDO_ANALYTIC), @@ -134,6 +135,9 @@ class MX_GENSHADER_API GenOptions /// system is defined. Defaults to true. bool emitColorTransforms; + /// Enable eliding constant nodes. Defaults to true. + bool elideConstantNodes; + /// Sets if transparency is needed or not for HW shaders. /// If a surface shader has potential of being transparent /// this must be set to true, otherwise no transparency diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp index 73f56b17e6..cffacc85f9 100644 --- a/source/MaterialXGenShader/ShaderNode.cpp +++ b/source/MaterialXGenShader/ShaderNode.cpp @@ -292,7 +292,7 @@ ShaderNodePtr ShaderNode::create(const ShaderGraph* parent, const string& name, newNode->_classification = Classification::VDF | Classification::CLOSURE; } // Second, check for specific nodes types - else if (nodeDef.getNodeString() == CONSTANT) + else if (nodeDef.getNodeString() == CONSTANT && context.getOptions().elideConstantNodes) { newNode->_classification = Classification::TEXTURE | Classification::CONSTANT; }