Skip to content

Commit

Permalink
HYDRA-1275 Prepare code and unit test for usd 24.11 (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk authored Nov 22, 2024
1 parent c52f7fe commit 64314ba
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 27 deletions.
17 changes: 0 additions & 17 deletions cmake/modules/FindUSD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,6 @@ find_library(USD_LIBRARY

get_filename_component(USD_LIBRARY_DIR ${USD_LIBRARY} DIRECTORY)

# Get the boost version from the one built with USD
if(USD_INCLUDE_DIR)
file(GLOB _USD_VERSION_HPP_FILE "${USD_INCLUDE_DIR}/boost-*/boost/version.hpp")
list(LENGTH _USD_VERSION_HPP_FILE found_one)
if(${found_one} STREQUAL "1")
list(GET _USD_VERSION_HPP_FILE 0 USD_VERSION_HPP)
file(STRINGS
"${USD_VERSION_HPP}"
_usd_tmp
REGEX "#define BOOST_VERSION .*$")
string(REGEX MATCH "[0-9]+" USD_BOOST_VERSION ${_usd_tmp})
unset(_usd_tmp)
unset(_USD_VERSION_HPP_FILE)
unset(USD_VERSION_HPP)
endif()
endif()

# See if MaterialX shaders with color4 inputs exist natively in Sdr:
# Not yet in a tagged USD version: https://github.com/PixarAnimationStudios/USD/pull/1894
set(USD_HAS_COLOR4_SDR_SUPPORT FALSE CACHE INTERNAL "USD.Sdr.PropertyTypes.Color4")
Expand Down
1 change: 0 additions & 1 deletion lib/mayaHydra/hydraExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ target_include_directories(${TARGET_NAME}
target_include_directories(${TARGET_NAME}
PUBLIC
${PYTHON_INCLUDE_DIR}
${BOOST_INCLUDE_DIR}
${CMAKE_BINARY_DIR}/include
PRIVATE
$<$<BOOL:${UFE_FOUND}>:${UFE_INCLUDE_DIR}>
Expand Down
15 changes: 13 additions & 2 deletions lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ VtValue MayaHydraLightAdapter::Get(const TfToken& key)
MFnLight mayaLight(GetDagPath());
GlfSimpleLight light;
const auto color = mayaLight.color();
const auto intensity = mayaLight.intensity();
auto intensity = mayaLight.intensity();
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
if( LightType() == HdPrimTypeTokens->simpleLight){
intensity /= M_PI;
}
#endif
MPoint pt(0.0, 0.0, 0.0, 1.0);
const auto inclusiveMatrix = GetDagPath().inclusiveMatrix();
const auto position = pt * inclusiveMatrix;
Expand Down Expand Up @@ -232,7 +237,13 @@ VtValue MayaHydraLightAdapter::GetLightParamValue(const TfToken& paramName)
const auto color = light.color();
return VtValue(GfVec3f(color.r, color.g, color.b));
} else if (paramName == HdLightTokens->intensity) {
return VtValue(light.intensity());
auto intensity = light.intensity();
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
if( LightType() == HdPrimTypeTokens->simpleLight){
intensity /= M_PI;
}
#endif
return VtValue(intensity);
} else if (paramName == HdLightTokens->exposure) {
return VtValue(0.0f);
} else if (paramName == HdLightTokens->normalize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ TfToken GetOutputName(const HdMaterialNode& material, SdfValueTypeName type)
auto addMatchingOutputs = [&](SdfValueTypeName matchingType) {
for (const auto& outName : outputNames) {
auto* sdrInfo = sdrNode->GetShaderOutput(outName);
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
if (sdrInfo && sdrInfo->GetTypeAsSdfType().GetSdfType() == matchingType) {
#else
if (sdrInfo && sdrInfo->GetTypeAsSdfType().first == matchingType) {
#endif
validOutputs.push_back(outName);
}
}
Expand Down Expand Up @@ -1246,7 +1250,12 @@ const MayaHydraShaderParams& MayaHydraMaterialNetworkConverter::GetPreviewShader
continue;
}
_previewShaderParams.emplace_back(
inputName, property->GetDefaultValue(), property->GetTypeAsSdfType().first);
inputName, property->GetDefaultValue(),
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
property->GetTypeAsSdfType().GetSdfType());
#else
property->GetTypeAsSdfType().first);
#endif
}
std::sort(
_previewShaderParams.begin(),
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ void MtohRenderOverride::_DetectMayaDefaultLighting(const MHWRender::MDrawContex

if (hasDirection && !hasPosition) {

#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
intensity /= M_PI;//Is a HdPrimTypeTokens->simpleLight
#endif

// Note for devs : if you update more parameters in the default light, don't forget
// to update MtohDefaultLightDelegate::SetDefaultLight and MayaHydraSceneIndex::SetDefaultLight, currently there are only 3 :
// position, diffuse, specular
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.
14 changes: 11 additions & 3 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testIsolateSelect.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class TestIsolateSelect(mtohUtils.MayaHydraBaseTestCase):

_requiredPlugins = ['mayaHydraCppTests', 'mayaHydraFlowViewportAPILocator']

imageVersion = None

@classmethod
def setUpClass(cls):
super(TestIsolateSelect, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

def setupScene(self):
proxyShapePathStr = mayaUsd_createStageWithNewLayer.createStageWithNewLayer()
stage = mayaUsd.lib.GetPrim(proxyShapePathStr).GetStage()
Expand Down Expand Up @@ -320,9 +328,9 @@ def test_isolateSelectMultiViewport(self):
cmds.select(clear=1)

cmds.refresh()

self.assertSnapshotClose("singleViewportIsolateSelectCylinder1.png", 0.1, 2)

#Has a different version for usd 24.11+
self.assertSnapshotClose("singleViewportIsolateSelectCylinder1.png", 0.1, 2, self.imageVersion)
# Switch to four-up viewport mode. Set the renderer in each new
# viewport to be Hydra Storm. Viewport 4 is already set.
cmds.FourViewLayout()
Expand Down
7 changes: 7 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/testUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <pxr/imaging/hd/tokens.h>
#include <pxr/imaging/hd/xformSchema.h>
#include <pxr/imaging/hd/filteringSceneIndex.h>
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
#include <pxr/imaging/hd/extComputationSchema.h>
#endif

#include <maya/MGlobal.h>
#include <maya/MMatrix.h>
Expand Down Expand Up @@ -240,7 +243,11 @@ void SceneIndexInspector::_WriteLeafDataSource(
= "SampledDataSource -> " + sampledDataSource->GetValue(0).GetTypeName();
} else if (
auto extComputationCallbackDataSource
#if defined(HD_API_VERSION) && HD_API_VERSION >= 74 // For USD 24.11+
= HdExtComputationCpuCallbackDataSource::Cast(dataSource)) {
#else
= HdExtComputationCallbackDataSource::Cast(dataSource)) {
#endif
dataSourceDescription = "ExtComputationCallbackDataSource";
} else {
dataSourceDescription = "Unidentified data source type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ def test_UsdKeepSelectionHighlighting(self):
self.assertSnapshotClose("Storm_Wireframe_AllSelected.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

#Switch to bounding box display mode, we should keep the selected items and their color
#For this snapshot and only for it, we need to modify the default lighting and reset it after the snapshot
cmds.modelEditor(panel, edit=True, displayAppearance="boundingBox")
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("Storm_BoundingBox_AllSelected.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityByUsdVersion()

#Switch to wireframe on shaded display mode, we should keep the selected items and their color
cmds.modelEditor(panel, edit=True, displayAppearance="smoothShaded")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,17 @@ def test_Authoring_Locator(self):
self.assertSnapshotClose("authoring_locator_visibility_off.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
# Check that updating a parent's visibility works after creation
cmds.setAttr(locatorGrandParent + ".visibility", True)
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("authoring_locator_visibility_on.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityByUsdVersion()

# Check that changing the visibility on the shape itself works
cmds.setAttr(locatorShape + ".visibility", False)
self.assertSnapshotClose("authoring_locator_visibility_off.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
# Restore visibility
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityByUsdVersion()
cmds.setAttr(locatorShape + ".visibility", True)
self.assertSnapshotClose("authoring_locator_visibility_on.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

Expand All @@ -91,12 +97,16 @@ def test_Authoring_Locator(self):
# Change the shape's transform directly
cmds.xform(cmds.listRelatives(locatorShape, parent=True)[0], translation=[-3,2,-1], rotation=[-15,10,-5], scale=[-2.5, 2.0, -1.5])
self.assertSnapshotClose("authoring_locator_shapeTransformChanged.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityByUsdVersion()

def test_Authoring_UsdStage(self):
self.setBasicCam(10)

stageParent, stageShape = self.usdStageSetup()

#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityByUsdVersion()

# Hide/unhide parent
cmds.select(clear=True)
self.assertSnapshotAndCompareVp2("usdStage_visibility_on.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
Expand All @@ -122,6 +132,7 @@ def test_Authoring_UsdStage(self):
cmds.xform(cmds.listRelatives(stageShape, parent=True)[0], translation=[-3,2,-1], rotation=[-15,10,-5], scale=[-2.5, 2.0, -1.5])
cmds.select(clear=True)
self.assertSnapshotAndCompareVp2("usdStage_shapeTransformChanged.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityByUsdVersion()

def test_Playback_Locator(self):
self.setBasicCam(10)
Expand All @@ -139,12 +150,15 @@ def test_Playback_Locator(self):
self.keyframeAttribute(locatorGrandParent, "translateX", 15)

cmds.currentTime(0)
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("locator_playback_initial.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

cmds.currentTime(2)
self.assertSnapshotClose("locator_playback_translated.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

cmds.currentTime(7)
self.resetDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("locator_playback_hidden.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

def test_Playback_UsdStage(self):
Expand All @@ -162,6 +176,9 @@ def test_Playback_UsdStage(self):
self.keyframeAttribute(stageParent, "visibility", False)
self.keyframeAttribute(stageParent, "translateX", 15)

#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityByUsdVersion()

cmds.currentTime(0)
self.assertSnapshotClose("usdStage_playback_initial.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

Expand All @@ -181,11 +198,14 @@ def test_Playback_UsdStage(self):

cmds.currentTime(7)
self.assertSnapshotSilhouetteClose("usdStage_playback_hidden.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.resetDefaultLightIntensityByUsdVersion()

def test_UsdStageAnimatedPrim(self):
self.setBasicCam(10)

stageParent, stageTransform = self.usdStageAnimatedPrimSetup()
#Is needed with usd 24.11 to keep the same images
self.modifyDefaultLightIntensityByUsdVersion()

cmds.currentTime(0)
self.keyframeAttribute(stageParent, "translateY", 0)
Expand All @@ -203,6 +223,8 @@ def test_UsdStageAnimatedPrim(self):
cmds.select(clear=True)
self.assertSnapshotClose("usdStageAnimatedPrim_t" + str(time) + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

self.resetDefaultLightIntensityByUsdVersion()

self.setViewport2Renderer()
for time in checkedTimes:
cmds.currentTime(time)
Expand Down
16 changes: 15 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testFlowViewportAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,26 @@ class TestFlowViewportAPI(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUti

IMAGE_DIFF_FAIL_THRESHOLD = 0.1
IMAGE_DIFF_FAIL_PERCENT = 2
imageVersion = None

@classmethod
def setUpClass(cls):
super(TestFlowViewportAPI, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

@classmethod
def tearDownClass(cls):
#Finish by a File New command to check that it's not crashing when cleaning up everything'
cmds.file(new=True, force=True)

#This function is called before each test is launched
def setUp(self):
#call parent function first
super(TestFlowViewportAPI, self).setUp()
#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityByUsdVersion()

def setupScene(self):
self.setHdStormRenderer()

Expand Down Expand Up @@ -184,7 +198,7 @@ def test_FilteringPrimitives(self):
self.setHdStormRenderer()
cmds.setAttr(sphereShape + '.subdivisionsAxis', 30) #Unfilter the prim
cmds.refresh()
self.assertSnapshotClose("filter_VP2AndThenBackToStorm_MovedSphereUnFiltered.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.assertSnapshotClose("filter_VP2AndThenBackToStorm_MovedSphereUnFiltered.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT, self.imageVersion)

#Test Cube grids parameters
def test_CubeGrid(self):
Expand Down
17 changes: 16 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testFootPrintNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ class TestFootPrintNode(mtohUtils.MayaHydraBaseTestCase): #Subclassing mtohUtils

IMAGE_DIFF_FAIL_THRESHOLD = 0.01
IMAGE_DIFF_FAIL_PERCENT = 0.1
imageVersion = None

@classmethod
def setUpClass(cls):
super(TestFootPrintNode, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

#This function is called before each test is launched
def setUp(self):
#call parent function first
super(TestFootPrintNode, self).setUp()
#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityByUsdVersion()

def tearDown(self):
#is called after each test : finish by a File New command to check that it's not crashing when cleaning up everything'
Expand Down Expand Up @@ -240,7 +254,8 @@ def test_Load(self):
"testFootPrintNode",
"testFootPrintNodeSaved.ma")
cmds.refresh()
self.assertSnapshotClose("loadingFootPrintScene.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
#using imageVersion as the color is different for this image under usd 24.11+
self.assertSnapshotClose("loadingFootPrintScene.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT, self.imageVersion)

if __name__ == '__main__':
fixturesUtils.runTests(globals())
10 changes: 9 additions & 1 deletion test/lib/mayaUsd/render/mayaToHydra/testMayaDefaultMaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class TestMayaDefaultMaterial(mtohUtils.MayaHydraBaseTestCase): #Subclassing mto

IMAGE_DIFF_FAIL_THRESHOLD = 0.05
IMAGE_DIFF_FAIL_PERCENT = 1.5
imageVersion = None

@classmethod
def setUpClass(cls):
super(TestMayaDefaultMaterial, cls).setUpClass()
if cls._usdVersion >= (0, 24, 11):
cls.imageVersion = 'usd_2411+'

def test_MayaDefaultMaterial(self):

Expand All @@ -39,7 +46,8 @@ def test_MayaDefaultMaterial(self):
cmds.refresh()
panel = mayaUtils.activeModelPanel()
if platform.system() != "Darwin": #Don't do the image comparison on OSX the flow viewport cubes have a lighter pixel look
self.assertSnapshotClose("sceneLoaded" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
#This image compare has a special version for usd 24.11+
self.assertSnapshotClose("sceneLoaded" + ".png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT, self.imageVersion)

#Use Default Material
cmds.modelEditor(panel, edit=True, useDefaultMaterial=True)
Expand Down
7 changes: 7 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testRefinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ class TestRefinement(mtohUtils.MayaHydraBaseTestCase):
IMAGEDIFF_FAIL_THRESHOLD = 0.01
IMAGEDIFF_FAIL_PERCENT = 0.1

#This function is called before each test is launched
def setUp(self):
#call parent function first
super(TestRefinement, self).setUp()
#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityByUsdVersion()

def verifySnapshot(self, imageName):
cmds.refresh()
self.assertSnapshotClose(imageName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def test_UsdStagePayloadsOnTheFly(self):
def test_UsdStagePayloadsFromScene(self):
from mayaUsd import lib as mayaUsdLib
self.loadUsdPayloadScene()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("payloadSceneLoadedPotA.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

#Change the variant
Expand All @@ -159,9 +160,11 @@ def test_UsdStagePayloadsFromScene(self):

def test_UsdStageReferences(self):
self.setUpReferenceScene()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("referencesSceneCreated.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

self.loadUsdReferencesScene()
self.modifyDefaultLightIntensityByUsdVersion()
self.assertSnapshotClose("referencesSceneLoaded.png", self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)

if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/testStageVariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def test_UsdStageVariants(self):
self.assertIsNotNone(modVariant)
self.assertEqual(modVariant.GetVariantSelection(), 'OneCube')

#modify light intensity for usd 24.11+
self.modifyDefaultLightIntensityByUsdVersion()

#Select the USD Cubes to see the selection highlight
cubesPath = ufe.Path([
mayaUtils.createUfePathSegment("|variants|variantsShape"),
Expand Down
Loading

0 comments on commit 64314ba

Please sign in to comment.