File tree Expand file tree Collapse file tree 4 files changed +16
-5
lines changed
Expand file tree Collapse file tree 4 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,8 @@ class MX_GENSHADER_API GenOptions
9494 hwNormalizeUdimTexCoords (false ),
9595 hwWriteAlbedoTable (false ),
9696 hwWriteEnvPrefilter (false ),
97- hwImplicitBitangents (true )
97+ hwImplicitBitangents (true ),
98+ optReplaceBsdfMixWithLinearCombination (false )
9899 {
99100 }
100101 virtual ~GenOptions () { }
@@ -197,6 +198,10 @@ class MX_GENSHADER_API GenOptions
197198 // / Calculate fallback bitangents from existing normals and tangents
198199 // / inside the bitangent node.
199200 bool hwImplicitBitangents;
201+
202+ // / Analyse the graph of ShaderNodes and replace any ND_mix_bsdf nodes
203+ // / with a linear combination of their weighted inputs
204+ bool optReplaceBsdfMixWithLinearCombination;
200205};
201206
202207MATERIALX_NAMESPACE_END
Original file line number Diff line number Diff line change @@ -971,12 +971,15 @@ void ShaderGraph::optimize(GenContext& context)
971971 }
972972
973973 // we take a copy of the node list because we might modify it during the optimization
974- const vector<ShaderNode*> nodeList = getNodes ();
975- for (ShaderNode* node : nodeList)
974+ if (context.getOptions ().optReplaceBsdfMixWithLinearCombination )
976975 {
977- if (node->hasClassification (ShaderNode::Classification::MIX_BSDF))
976+ const vector<ShaderNode*> nodeList = getNodes ();
977+ for (ShaderNode* node : nodeList)
978978 {
979- optimizeMixBsdf (node, context);
979+ if (node->hasClassification (ShaderNode::Classification::MIX_BSDF))
980+ {
981+ optimizeMixBsdf (node, context);
982+ }
980983 }
981984 }
982985}
Original file line number Diff line number Diff line change @@ -162,6 +162,7 @@ RenderView::RenderView(mx::DocumentPtr doc,
162162 // Make sure all uniforms are added so value updates can
163163 // find the corresponding uniform.
164164 _genContext.getOptions ().shaderInterfaceType = mx::SHADER_INTERFACE_COMPLETE;
165+ _genContext.getOptions ().optReplaceBsdfMixWithLinearCombination = true ;
165166
166167 setDocument (doc);
167168 _stdLib = stdLib;
Original file line number Diff line number Diff line change @@ -255,6 +255,7 @@ Viewer::Viewer(const std::string& materialFilename,
255255 _genContext.getOptions ().fileTextureVerticalFlip = true ;
256256 _genContext.getOptions ().hwShadowMap = true ;
257257 _genContext.getOptions ().hwImplicitBitangents = false ;
258+ _genContext.getOptions ().optReplaceBsdfMixWithLinearCombination = true ;
258259
259260#ifdef MATERIALXVIEW_METAL_BACKEND
260261 _renderPipeline = MetalRenderPipeline::create (this );
@@ -267,6 +268,7 @@ Viewer::Viewer(const std::string& materialFilename,
267268 _genContextEssl.getOptions ().targetColorSpaceOverride = " lin_rec709" ;
268269 _genContextEssl.getOptions ().fileTextureVerticalFlip = false ;
269270 _genContextEssl.getOptions ().hwMaxActiveLightSources = 1 ;
271+ _genContextEssl.getOptions ().optReplaceBsdfMixWithLinearCombination = true ;
270272#endif
271273#if MATERIALX_BUILD_GEN_OSL
272274 // Set OSL generator options.
You can’t perform that action at this time.
0 commit comments