Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion source/MaterialXGenShader/OcioColorManagementSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions source/MaterialXGenShader/ShaderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <MaterialXTrace/Tracing.h>

#include <iostream>
#include <queue>

MATERIALX_NAMESPACE_BEGIN
Expand Down Expand Up @@ -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 + "'.");
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion source/MaterialXTest/MaterialXGenMdl/GenMdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions source/MaterialXTest/MaterialXGenMsl/GenMsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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() { };
Expand Down
7 changes: 7 additions & 0 deletions source/MaterialXTest/MaterialXGenSlang/GenSlang.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 7 additions & 1 deletion source/MaterialXTest/MaterialXRender/RenderUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading