1313#include < MaterialXGenShader/ShaderStage.h>
1414#include < MaterialXGenShader/TypeDesc.h>
1515
16-
1716MATERIALX_NAMESPACE_BEGIN
1817
1918const string OslShaderGenerator::TARGET = " genosl" ;
@@ -35,6 +34,12 @@ ShaderPtr OslShaderGenerator::generate(const string& name, ElementPtr element, G
3534 ScopedFloatFormatting fmt (Value::FloatFormatFixed);
3635
3736 ShaderGraph& graph = shader->getGraph ();
37+
38+ if (context.getOptions ().oslConnectCiWrapper )
39+ {
40+ addSetCiTerminalNode (graph, element->getDocument (), context);
41+ }
42+
3843 ShaderStage& stage = shader->getStage (Stage::PIXEL);
3944
4045 emitLibraryIncludes (stage, context);
@@ -224,8 +229,7 @@ ShaderPtr OslShaderGenerator::createShader(const string& name, ElementPtr elemen
224229 const auto & outputSockets = graph->getOutputSockets ();
225230 const auto * singleOutput = outputSockets.size () == 1 ? outputSockets[0 ] : NULL ;
226231
227- const bool isSurfaceShaderOutput = context.getOptions ().oslImplicitSurfaceShaderConversion
228- && singleOutput && singleOutput->getType () == Type::SURFACESHADER;
232+ const bool isSurfaceShaderOutput = context.getOptions ().oslImplicitSurfaceShaderConversion && singleOutput && singleOutput->getType () == Type::SURFACESHADER;
229233
230234 if (isSurfaceShaderOutput)
231235 {
@@ -404,10 +408,10 @@ void OslShaderGenerator::emitMetadata(const ShaderPort* port, ShaderStage& stage
404408{
405409 static const std::unordered_map<TypeDesc, ShaderMetadata, TypeDesc::Hasher> UI_WIDGET_METADATA =
406410 {
407- { Type::FLOAT, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" number" )) },
408- { Type::INTEGER, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" number" )) },
409- { Type::FILENAME, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" filename" )) },
410- { Type::BOOLEAN, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" checkBox" )) }
411+ { Type::FLOAT, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" number" )) },
412+ { Type::INTEGER, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" number" )) },
413+ { Type::FILENAME, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" filename" )) },
414+ { Type::BOOLEAN, ShaderMetadata (" widget" , Type::STRING, Type::STRING.createValueFromStrings (" checkBox" )) }
411415 };
412416
413417 static const std::set<TypeDesc> METADATA_TYPE_BLACKLIST =
@@ -466,6 +470,38 @@ void OslShaderGenerator::emitMetadata(const ShaderPort* port, ShaderStage& stage
466470 }
467471}
468472
473+
474+ void OslShaderGenerator::addSetCiTerminalNode (ShaderGraph& graph, ConstDocumentPtr document, GenContext& context) const
475+ {
476+ string setCiNodeDefName = " ND_osl_set_ci" ;
477+ NodeDefPtr setCiNodeDef = document->getNodeDef (setCiNodeDefName);
478+
479+ std::unordered_map<TypeDesc, ValuePtr, TypeDesc::Hasher> outputModeMap;
480+ int index = 0 ;
481+ for (auto input : setCiNodeDef->getInputs ())
482+ {
483+ string inputName = input->getName ();
484+ if (stringStartsWith (inputName, " input_" ))
485+ {
486+ TypeDesc inputType = _typeSystem->getType (input->getType ());
487+ outputModeMap[inputType] = std::make_shared<TypedValue<int >>(index++);
488+ }
489+ }
490+
491+ for (auto output : graph.getOutputSockets ())
492+ {
493+ auto outputType = output->getType ();
494+ string typeName = outputType.getName ();
495+ auto setCiNode = graph.inlineNodeBeforeOutput (output, " oslSetCi" , setCiNodeDefName, " input_" + typeName, " out_ci" , context);
496+ auto typeInput = setCiNode->getInput (" output_mode" );
497+
498+ auto outputModeValue = outputModeMap[outputType];
499+
500+ typeInput->setValue (outputModeValue);
501+ }
502+ }
503+
504+
469505namespace OSL
470506{
471507
0 commit comments