Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMSUSD-1071 - Remember unknown color spaces #3652

Merged
merged 1 commit into from
Mar 7, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ const MString& ColorManagementPreferences::RenderingSpaceName()

const MString& ColorManagementPreferences::sRGBName() { return Get()._sRGBName; }

bool ColorManagementPreferences::isUnknownColorSpace(const std::string& colorSpace)
{
return Get()._unknownColorSpaces.count(colorSpace) > 0;
}

void ColorManagementPreferences::addUnknownColorSpace(const std::string& colorSpace)
{
InternalGet()._unknownColorSpaces.insert(colorSpace);
}

std::string ColorManagementPreferences::getFileRule(const std::string& path)
{
MString colorRuleCmd;
Expand Down Expand Up @@ -136,6 +146,7 @@ void ColorManagementPreferences::Refresh()
break;
}
}
_unknownColorSpaces.clear();
}

} // namespace MAYAUSD_NS_DEF
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <maya/MMessage.h>
#include <maya/MString.h>

#include <set>
#include <vector>

namespace MAYAUSD_NS_DEF {
Expand Down Expand Up @@ -50,6 +51,12 @@ class MAYAUSD_CORE_PUBLIC ColorManagementPreferences
*/
static const MString& sRGBName();

/*! \brief Prevent error spamming in the script editor by remembering failed requests
for a color management fragment.
*/
static bool isUnknownColorSpace(const std::string& colorSpace);
static void addUnknownColorSpace(const std::string& colorSpace);

/*! \brief Returns the OCIO color space name according to config file rules.

\param path The path of the file to be color managed.
Expand All @@ -73,6 +80,7 @@ class MAYAUSD_CORE_PUBLIC ColorManagementPreferences
bool _active = false;
MString _renderingSpaceName;
MString _sRGBName;
std::set<std::string> _unknownColorSpaces;
std::vector<MCallbackId> _mayaColorManagementCallbackIds;

void Refresh();
Expand Down
34 changes: 23 additions & 11 deletions lib/mayaUsd/render/vp2RenderDelegate/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,16 @@ void _AddColorManagementFragments(HdMaterialNetwork& net)
}

MString fragName, inputName, outputName;
MStatus status = fragmentManager->getColorManagementFragmentInfo(
colorSpace, fragName, inputName, outputName);
if (!status) {
if (!MayaUsd::ColorManagementPreferences::isUnknownColorSpace(colorSpace.asChar())) {
MStatus status = fragmentManager->getColorManagementFragmentInfo(
colorSpace, fragName, inputName, outputName);
if (!status) {
// Maya does not know about this color space. Remember that.
MayaUsd::ColorManagementPreferences::addUnknownColorSpace(colorSpace.asChar());
continue;
}
} else {
// Don't know how to handle that color space.
continue;
}

Expand Down Expand Up @@ -2700,14 +2707,19 @@ TfToken _RequiresColorManagement(
}

MString fragName, fragInput, fragOutput;
if (fragmentManager->getColorManagementFragmentInfo(
sourceColorSpace.c_str(), fragName, fragInput, fragOutput)) {
std::string untypedNodeDefId
= MaterialXMaya::OgsFragment::registerOCIOFragment(fragName.asChar());
if (!untypedNodeDefId.empty()) {
cmInputName = TfToken(fragInput.asChar());
cmOutputName = TfToken(fragOutput.asChar());
return TfToken((untypedNodeDefId + colorOutput->getType()));
if (!MayaUsd::ColorManagementPreferences::isUnknownColorSpace(sourceColorSpace)) {
if (fragmentManager->getColorManagementFragmentInfo(
sourceColorSpace.c_str(), fragName, fragInput, fragOutput)) {
std::string untypedNodeDefId
= MaterialXMaya::OgsFragment::registerOCIOFragment(fragName.asChar());
if (!untypedNodeDefId.empty()) {
cmInputName = TfToken(fragInput.asChar());
cmOutputName = TfToken(fragOutput.asChar());
return TfToken((untypedNodeDefId + colorOutput->getType()));
}
} else {
// Maya does not know about this color space. Remember that.
MayaUsd::ColorManagementPreferences::addUnknownColorSpace(sourceColorSpace);
}
}
#else
Expand Down