diff --git a/source/MaterialXGenOsl/OslShaderGenerator.cpp b/source/MaterialXGenOsl/OslShaderGenerator.cpp index b4edbee44b..a67c379454 100644 --- a/source/MaterialXGenOsl/OslShaderGenerator.cpp +++ b/source/MaterialXGenOsl/OslShaderGenerator.cpp @@ -266,7 +266,7 @@ ShaderPtr OslShaderGenerator::generate(const string& name, ElementPtr element, G emitLine("output closure color " + singleOutput->getVariable() + " = 0", stage, false); } #ifdef MATERIALX_OSL_LEGACY_CLOSURES - else if (isBsdfOutput) + else if (isBsdfOutput && context.getOptions().wrapBSDFAsClosureGraphOutput) { // Special case for having 'BSDF' as final output type. // For legacy closures this type is a struct internally (response, throughput, thickness, ior) @@ -330,7 +330,7 @@ ShaderPtr OslShaderGenerator::generate(const string& name, ElementPtr element, G emitScopeEnd(stage); } #ifdef MATERIALX_OSL_LEGACY_CLOSURES - else if (isBsdfOutput) + else if (isBsdfOutput && context.getOptions().wrapBSDFAsClosureGraphOutput) { // Special case for having 'BSDF' as final output type. // For legacy closures this type is a struct internally (response, throughput, thickness, ior) diff --git a/source/MaterialXGenShader/GenOptions.h b/source/MaterialXGenShader/GenOptions.h index d299bdcacc..2876d297f2 100644 --- a/source/MaterialXGenShader/GenOptions.h +++ b/source/MaterialXGenShader/GenOptions.h @@ -92,7 +92,8 @@ class MX_GENSHADER_API GenOptions hwWriteAlbedoTable(false), hwImplicitBitangents(true), emitColorTransforms(true), - elideConnectedConstants(true) + elideConnectedConstants(true), + wrapBSDFAsClosureGraphOutput(true) { } virtual ~GenOptions() { } @@ -186,6 +187,9 @@ class MX_GENSHADER_API GenOptions /// Enable eliding connected constants, setting this option to true /// breaks shader generation for arnold-usd. Defaults to true. bool elideConnectedConstants; + + // Enable exporting OSL BSDFs as closures in graph outputs + bool wrapBSDFAsClosureGraphOutput; }; MATERIALX_NAMESPACE_END