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

Fix display color not matching the source Lambert materials #2049

Merged
merged 2 commits into from
Feb 1, 2022
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
9 changes: 8 additions & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ void _getColorData(

infoMap[HdTokens->displayColor] = std::make_unique<PrimvarInfo>(
PrimvarSource(VtValue(colorArray), interpolation, PrimvarSource::CPUCompute), nullptr);
} else {
for (size_t i = 0; i < colorArray.size(); ++i) {
colorArray[i] = MayaUsd::utils::ConvertLinearToMaya(colorArray[i]);
}
}
}

Expand Down Expand Up @@ -1933,9 +1937,12 @@ void HdVP2Mesh::_UpdateDrawItem(
if ((colorInterp == HdInterpolationConstant || colorInterp == HdInterpolationInstance)
&& (alphaInterp == HdInterpolationConstant
|| alphaInterp == HdInterpolationInstance)) {
const GfVec3f& clr3f = MayaUsd::utils::ConvertLinearToMaya(colorArray[0]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved upstream. See line 376.

const GfVec3f& clr3f = colorArray[0];
const MColor color(clr3f[0], clr3f[1], clr3f[2], alphaArray[0]);
shader = _delegate->GetFallbackShader(color);
if (shader) {
shader->setParameter("diffuse", 1.0f);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already multiply the exported display color by the diffuse coefficient of 0.8. We need not apply it a second time.

}
// The color of the fallback shader is ignored when the interpolation is
// instance
} else {
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ inline const TfTokenVector& _SupportedBprimTypes()

const MString _diffuseColorParameterName = "diffuseColor"; //!< Shader parameter name
const MString _solidColorParameterName = "solidColor"; //!< Shader parameter name
const MString _diffuseParameterName = "diffuse"; //!< Shader parameter name
const MString _pointSizeParameterName = "pointSize"; //!< Shader parameter name
const MString _curveBasisParameterName = "curveBasis"; //!< Shader parameter name
const MString _structOutputName = "outSurfaceFinal"; //!< Output struct name of the fallback shader
Expand Down Expand Up @@ -181,6 +182,9 @@ class MShaderCache final
TF_VERIFY(_3dDefaultMaterialShader);

_3dCPVSolidShader = shaderMgr->getStockShader(MHWRender::MShaderManager::k3dCPVSolidShader);
if (TF_VERIFY(_3dCPVSolidShader)) {
_3dCPVSolidShader->setParameter(_diffuseParameterName, 1.0f);
}

TF_VERIFY(_3dCPVSolidShader);

Expand All @@ -204,6 +208,7 @@ class MShaderCache final
if (it != _curveBasisParameterValueMapping.end()) {
shader->setParameter(_curveBasisParameterName, it->second);
}
shader->setParameter(_diffuseParameterName, 1.0f);
}

_fallbackCPVShaders[i] = shader;
Expand Down
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set(TEST_SCRIPT_FILES "")

list(APPEND TEST_SCRIPT_FILES
testVP2RenderDelegateDisplayColors.py
testVP2RenderDelegateGeomSubset.py
testVP2RenderDelegatePointInstanceOrientation.py
)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/usr/bin/env mayapy
#
# Copyright 2022 Autodesk
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import fixturesUtils
import imageUtils
import mayaUtils
import usdUtils
import testUtils

from mayaUsd import lib as mayaUsdLib
from mayaUsd import ufe as mayaUsdUfe

from maya import cmds

import ufe

import os


class testVP2RenderDelegateDisplayColors(imageUtils.ImageDiffingTestCase):
"""
Tests imaging using the Viewport 2.0 render delegate when using per-instance
inherited data on instances.
"""

@classmethod
def setUpClass(cls):
# The test USD data is authored Z-up, so make sure Maya is configured
# that way too.
cmds.upAxis(axis='z')

inputPath = fixturesUtils.setUpClass(__file__,
initializeStandalone=False, loadPlugin=False)

cls._baselineDir = os.path.join(inputPath,
'VP2RenderDelegateDisplayColorsTest', 'baseline')

cls._testDir = os.path.abspath('.')

def assertSnapshotClose(self, imageName):
baselineImage = os.path.join(self._baselineDir, imageName)
snapshotImage = os.path.join(self._testDir, imageName)
imageUtils.snapshot(snapshotImage, width=960, height=540)
return self.assertImagesClose(baselineImage, snapshotImage)

def _StartTest(self, testName):
cmds.file(force=True, new=True)
mayaUtils.loadPlugin("mayaUsdPlugin")

self._testName = testName
testFile = testUtils.getTestScene("displayColors", self._testName + ".ma")

cmds.file(testFile, o=True)

exportedFile = os.path.join(self._testDir, "ColorTest.usda")
cmds.mayaUSDExport(mergeTransformAndShape=True,
file=exportedFile,
shadingMode='none',
exportDisplayColor=True)

shapeNode = mayaUtils.createProxyFromFile(exportedFile)[0]
cmds.move(0, 0, -1, shapeNode)

globalSelection = ufe.GlobalSelection.get()
globalSelection.clear()
self.assertSnapshotClose('%s_unselected.png' % self._testName)

def testPerInstanceInheritedData(self):
self._StartTest('ColorTest')



if __name__ == '__main__':
fixturesUtils.runTests(globals())
Loading