diff --git a/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp index edda7368e5..882186c527 100644 --- a/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp +++ b/source/MaterialXGenMdl/Nodes/CustomNodeMdl.cpp @@ -72,10 +72,11 @@ void CustomCodeNodeMdl::initializeForInlineSourceCode(const InterfaceElement& el NodeDefPtr nodeDef = impl.getNodeDef(); _inlineFunctionName = nodeDef->getName(); - _hash = std::hash{}(_inlineFunctionName); // make sure we emit the function definition only once const ShaderGenerator& shadergen = context.getShaderGenerator(); const MdlSyntax& syntax = static_cast(shadergen.getSyntax()); + syntax.makeValidName(_inlineFunctionName); + _hash = std::hash{}(_inlineFunctionName); // make sure we emit the function definition only once // Construct the function call template string initializeFunctionCallTemplateString(syntax, *nodeDef); // Collect information about output names and defaults @@ -248,7 +249,14 @@ void CustomCodeNodeMdl::emitFunctionDefinition(const ShaderNode& node, GenContex // User defined code shadergen.emitComment("inlined shader source code:", stage); - shadergen.emitLine(_inlineSourceCode, stage, false); + if (numOutputs == 1) + { + shadergen.emitLine(outputs.back().name + " = " + _inlineSourceCode, stage); + } + else + { + shadergen.emitLine(_inlineSourceCode, stage, false); + } // Output packing shadergen.emitComment("pack (in case of multiple outputs) and return outputs:", stage); diff --git a/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp b/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp index 2353703e7a..fadfdf84b4 100644 --- a/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp +++ b/source/MaterialXTest/MaterialXGenMdl/GenMdl.cpp @@ -242,6 +242,9 @@ void MdlShaderGeneratorTester::compileSource(const std::vector& so // avoid warning "C350: unused let temporary '...'" mdlcCommand += " -W \"350=off\""; + // avoid warning "C181: unused variable '...'" + mdlcCommand += " -W \"181=off\""; + // but treat all other warnings as errors mdlcCommand += " -W err";