Skip to content

Commit

Permalink
Merge pull request #2049 from Autodesk/t_gamaj/fix_display_color_too_…
Browse files Browse the repository at this point in the history
…dark

Fix display color not matching the source Lambert materials
  • Loading branch information
Krystian Ligenza authored Feb 1, 2022
2 parents a11054a + 5510e1d commit 0dc8929
Show file tree
Hide file tree
Showing 101 changed files with 951 additions and 1 deletion.
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]);
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);
}
// 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

0 comments on commit 0dc8929

Please sign in to comment.