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-121 - Use display color when texture mode is disabled #3272

Merged
4 changes: 3 additions & 1 deletion lib/mayaUsd/base/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ PXR_NAMESPACE_OPEN_SCOPE
/* Notice that only newly opened USD stage would be affected. */ \
((DisableAsyncTextureLoading, "mayaUsd_DisableAsyncTextureLoading")) \
/* option var to remember if the stage in the layer editor is pinned. */ \
((PinLayerEditorStage, "mayaUsd_PinLayerEditorStage"))
((PinLayerEditorStage, "mayaUsd_PinLayerEditorStage")) \
/* option var to remember if use display color when texture mode off */ \
((ShowDisplayColorTextureOff, "mayaUsd_ShowDisplayColorTextureOff"))
// clang-format on

TF_DECLARE_PUBLIC_TOKENS(MayaUsdOptionVars, MAYAUSD_CORE_PUBLIC, MAYA_USD_OPTIONVAR_TOKENS);
Expand Down
40 changes: 29 additions & 11 deletions lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "render_delegate.h"
#include "tokens.h"

#include <mayaUsd/base/tokens.h>
#include <mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.h>
#include <mayaUsd/utils/colorSpace.h>

Expand Down Expand Up @@ -891,7 +892,13 @@ void HdVP2Mesh::Sync(

auto addRequiredPrimvars = [&](const SdfPath& materialId) {
TfTokenVector requiredPrimvars;
if (!_GetMaterialPrimvars(renderIndex, materialId, requiredPrimvars)) {
if (!_GetMaterialPrimvars(renderIndex, materialId, requiredPrimvars)
|| ((reprToken == HdVP2ReprTokens->smoothHullUntextured)
&& (MGlobal::optionVarIntValue(
MayaUsdOptionVars->ShowDisplayColorTextureOff.GetText())
!= 0))) {
// if user selected present display color in untextured mode, use fallback shader as
// well
requiredPrimvars = sFallbackShaderPrimvars;
}

Expand Down Expand Up @@ -1746,16 +1753,27 @@ void HdVP2Mesh::_UpdateDrawItem(
renderIndex.GetSprim(HdPrimTypeTokens->material, materialId));

if (material) {
const HdCullStyle cullStyle = GetCullStyle(sceneDelegate);
MHWRender::MShaderInstance* shader = material->GetSurfaceShader(
_GetMaterialNetworkToken(reprToken), cullStyle == HdCullStyleBack);
if (shader != nullptr
&& (shader != drawItemData._shader || shader != stateToCommit._shader)) {
drawItemData._shader = shader;
drawItemData._shaderIsFallback = false;
stateToCommit._shader = shader;
stateToCommit._isTransparent
= shader->isTransparent() || renderItemData._transparent;
const MString optionVarName(
MayaUsdOptionVars->ShowDisplayColorTextureOff.GetText());

// if untextured mode with show display color specified, use fallback shader
if ((reprToken == HdVP2ReprTokens->smoothHullUntextured)
&& (MGlobal::optionVarIntValue(
MayaUsdOptionVars->ShowDisplayColorTextureOff.GetText())
!= 0)) {
drawItemData._shaderIsFallback = true;
} else {
const HdCullStyle cullStyle = GetCullStyle(sceneDelegate);
MHWRender::MShaderInstance* shader = material->GetSurfaceShader(
_GetMaterialNetworkToken(reprToken), cullStyle == HdCullStyleBack);
if (shader != nullptr
&& (shader != drawItemData._shader || shader != stateToCommit._shader)) {
drawItemData._shader = shader;
drawItemData._shaderIsFallback = false;
stateToCommit._shader = shader;
stateToCommit._isTransparent
= shader->isTransparent() || renderItemData._transparent;
}
}
} else {
drawItemData._shaderIsFallback = true;
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,13 @@ void ProxyRenderDelegate::_InitRenderDelegate()
{
TF_VERIFY(_proxyShapeData->ProxyShape());

// Initialize the optionVar ShowDisplayColorTextureOff, which will decide if display color will
// be used when untextured mode is selected
const MString optionVarName(MayaUsdOptionVars->ShowDisplayColorTextureOff.GetText());
if (!MGlobal::optionVarExists(optionVarName)) {
MGlobal::setOptionVarValue(optionVarName, 0);
}

// No need to run all the checks if we got till the end
if (_isInitialized())
return;
Expand Down