diff --git a/source/MaterialXGenShader/OcioColorManagementSystem.cpp b/source/MaterialXGenShader/OcioColorManagementSystem.cpp index e280a18555..5b59d9f172 100644 --- a/source/MaterialXGenShader/OcioColorManagementSystem.cpp +++ b/source/MaterialXGenShader/OcioColorManagementSystem.cpp @@ -154,8 +154,35 @@ NodeDefPtr OcioColorManagementSystemImpl::getNodeDef(const ColorSpaceTransform& return {}; } + // Build a function name from the source/target color space names and the first + // six characters of the cache ID. Each name component is sanitized individually: + // invalid characters are replaced with underscores and consecutive underscores are + // collapsed to one so that OCIO's own identifier normalizer cannot produce a + // different name than the one we register on the node def. + auto sanitizeName = [](const string& s) -> string + { + string result = createValidName(s); + string collapsed; + bool prevUnderscore = false; + for (char c : result) + { + if (c == '_') + { + if (!prevUnderscore) + collapsed += c; + prevUnderscore = true; + } + else + { + collapsed += c; + prevUnderscore = false; + } + } + return collapsed; + }; static const auto NODE_NAME = string{ "ocio_color_conversion" }; - const auto functionName = NODE_NAME + "_" + processor->getCacheID(); + const string cacheID = processor->getCacheID(); + const auto functionName = NODE_NAME + "_" + sanitizeName(sourceColorSpace) + "_to_" + sanitizeName(targetColorSpace) + "_" + cacheID.substr(0, 6); const auto implName = OcioColorManagementSystem::IMPL_PREFIX + functionName + "_" + transform.type.getName(); const auto nodeDefName = ND_PREFIX + functionName + "_" + transform.type.getName(); auto nodeDef = document->getNodeDef(nodeDefName); diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp index b0f07c7d92..4e3510450f 100644 --- a/source/MaterialXGenShader/ShaderGraph.cpp +++ b/source/MaterialXGenShader/ShaderGraph.cpp @@ -12,7 +12,6 @@ #include -#include #include MATERIALX_NAMESPACE_BEGIN @@ -1227,8 +1226,8 @@ void ShaderGraph::populateColorTransformMap(ColorManagementSystemPtr colorManage } else { - std::cerr << "Unsupported color space transform from " << - sourceColorSpace << " to " << targetColorSpace << std::endl; + throw ExceptionShaderGenError("Unsupported color space transform from '" + + sourceColorSpace + "' to '" + targetColorSpace + "'."); } } } diff --git a/source/MaterialXTest/MaterialXGenMdl/GenMdl.h b/source/MaterialXTest/MaterialXGenMdl/GenMdl.h index 64b47caab9..0e16c37020 100644 --- a/source/MaterialXTest/MaterialXGenMdl/GenMdl.h +++ b/source/MaterialXTest/MaterialXGenMdl/GenMdl.h @@ -76,7 +76,8 @@ class MdlShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester // Ignore certain .mtlx files void addSkipFiles() override { - // no additional files are skipped + // ocio_color_management.mtlx uses color spaces which require OCIO and is not supported by MDL. + _skipFiles.insert("ocio_color_management.mtlx"); ShaderGeneratorTester::addSkipFiles(); } diff --git a/source/MaterialXTest/MaterialXGenMsl/GenMsl.h b/source/MaterialXTest/MaterialXGenMsl/GenMsl.h index 2371cfa5e9..af8cdf2d58 100644 --- a/source/MaterialXTest/MaterialXGenMsl/GenMsl.h +++ b/source/MaterialXTest/MaterialXGenMsl/GenMsl.h @@ -45,6 +45,7 @@ class MslShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester { // To skip specific files for this render target, add them as below: // _skipFiles.insert("example.mtlx"); + ParentClass::addSkipFiles(); } void setupDependentLibraries() override diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp index 166a18f691..79fff3da4e 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp @@ -741,6 +741,12 @@ void ShaderGeneratorTester::validate(const mx::GenOptions& generateOptions, cons context.getOptions().targetDistanceUnit = _defaultDistanceUnit; } + // Define target color space if required + if (context.getOptions().targetColorSpaceOverride.empty()) + { + context.getOptions().targetColorSpaceOverride = "lin_rec709"; + } + // Check if a binding context has been set. bool bindingContextUsed = _userData.count(mx::HW::USER_DATA_BINDING_CONTEXT) > 0; diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h index de58775eae..4ca7d7f34e 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h @@ -199,7 +199,13 @@ class ShaderGeneratorTester virtual void setTestStages() = 0; // Add files in to not examine - virtual void addSkipFiles() { }; + virtual void addSkipFiles() + { +#ifndef MATERIALX_BUILD_OCIO + // ocio_color_management.mtlx uses color spaces which require OCIO. + _skipFiles.insert("ocio_color_management.mtlx"); +#endif + }; // Add nodedefs to not examine virtual void addSkipNodeDefs() { }; diff --git a/source/MaterialXTest/MaterialXGenSlang/GenSlang.h b/source/MaterialXTest/MaterialXGenSlang/GenSlang.h index 453b891533..e47d29fa29 100644 --- a/source/MaterialXTest/MaterialXGenSlang/GenSlang.h +++ b/source/MaterialXTest/MaterialXGenSlang/GenSlang.h @@ -30,6 +30,13 @@ class SlangShaderGeneratorTester : public GenShaderUtil::ShaderGeneratorTester } // Ignore trying to create shader code for displacementshaders + void addSkipFiles() override + { + // ocio_color_management.mtlx uses color spaces which require OCIO and is not supported by Slang. + _skipFiles.insert("ocio_color_management.mtlx"); + ParentClass::addSkipFiles(); + } + void addSkipNodeDefs() override { _skipNodeDefs.insert("ND_displacement_float"); diff --git a/source/MaterialXTest/MaterialXRender/RenderUtil.h b/source/MaterialXTest/MaterialXRender/RenderUtil.h index 7002e3b1ae..7bedd49dcb 100644 --- a/source/MaterialXTest/MaterialXRender/RenderUtil.h +++ b/source/MaterialXTest/MaterialXRender/RenderUtil.h @@ -274,7 +274,13 @@ class ShaderRenderTester void addAdditionalTestStreams(mx::MeshPtr mesh); // Add any paths to explicitly skip here - virtual void addSkipFiles() {} + virtual void addSkipFiles() + { +#ifndef MATERIALX_BUILD_OCIO + // ocio_color_management.mtlx uses color spaces which require OCIO. + _skipFiles.insert("ocio_color_management.mtlx"); +#endif + } // Read test suite options and check if this target should run. bool loadOptions(const mx::FilePath& optionsFilePath, TestRunState& runState);