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

HYDRA-1294 - fix doubleSided and CullStyle for MRenderItem #210

Merged
merged 4 commits into from
Nov 26, 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
10 changes: 10 additions & 0 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# MAYA_HAS_DISPLAY_LAYER_API Presence of MFnDisplayLayer
# MAYA_HAS_NEW_DISPLAY_LAYER_MESSAGING_API Presence of MDisplayLayerMemberChangedFunction
# MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API Presence of MRenderItem has HideOnPlayback API
# MAYA_HAS_RENDER_ITEM_CULL_MODE_API Presence of MRenderItem has CullMode API
# MAYA_HAS_VIEW_SELECTED_OBJECT_API Presence of M3dView::viewSelectedObject
# MAYA_LINUX_BUILT_WITH_CXX11_ABI Maya Linux was built with new cxx11 ABI.
# MAYA_MACOSX_BUILT_WITH_UB2 Maya OSX was built with Universal Binary 2.
Expand Down Expand Up @@ -404,6 +405,15 @@ if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
endif()
endif()

set(MAYA_HAS_RENDER_ITEM_CULL_MODE_API FALSE CACHE INTERNAL "hasRenderItemCullModeFunction")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h MAYA_HAS_API REGEX "cullMode")
if(MAYA_HAS_API)
set(MAYA_HAS_RENDER_ITEM_CULL_MODE_API TRUE CACHE INTERNAL "hasRenderItemCullModeFunction")
message(STATUS "MRenderItem has CullMode API")
endif()
endif()

set(MAYA_HAS_VIEW_SELECTED_OBJECT_API FALSE CACHE INTERNAL "hasViewSelectedObject")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/M3dView.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/M3dView.h MAYA_HAS_API REGEX "numViewSelectedObjects")
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaHydra/hydraExtensions/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ set(HEADERS
tokens.h
)

if (MAYA_HAS_RENDER_ITEM_CULL_MODE_API)
target_compile_definitions(${TARGET_NAME}
PRIVATE
MAYA_HAS_RENDER_ITEM_CULL_MODE_API=1
)
endif()

# -----------------------------------------------------------------------------
# promoted headers
# -----------------------------------------------------------------------------
Expand Down
32 changes: 28 additions & 4 deletions lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ MayaHydraRenderItemAdapter::MayaHydraRenderItemAdapter(
, _primitive(ri.primitive())
, _name(ri.name())
, _fastId(fastId)
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
, _cullMode(ri.cullMode())
#endif
{
_InsertRprim(this);
}
Expand Down Expand Up @@ -145,6 +148,18 @@ void MayaHydraRenderItemAdapter::UpdateFromDelta(const UpdateFromDeltaData& data

HdDirtyBits dirtyBits = 0;

#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
MRenderItem::CullMode cullMode = data._ri.cullMode();
if (cullMode != _cullMode) {
// MRenderItem uses CullNone to denote doubleSided
if (IsDoubleSided(_cullMode) || IsDoubleSided(cullMode)) {
dirtyBits |= HdChangeTracker::DirtyDoubleSided;
}
dirtyBits |= HdChangeTracker::DirtyCullStyle;
_cullMode = cullMode;
}
#endif

if (data._wireframeColor != _wireframeColor) {
_wireframeColor = data._wireframeColor;
dirtyBits |= HdChangeTracker::DirtyPrimvar; // displayColor primVar
Expand Down Expand Up @@ -545,10 +560,19 @@ void MayaHydraRenderItemAdapter::SetPlaybackChanged()

HdCullStyle MayaHydraRenderItemAdapter::GetCullStyle() const
{
// HdCullStyleNothing means no culling, HdCullStyledontCare means : let the renderer choose
// between back or front faces culling. We don't want culling, since we want to see the
// backfaces being unlit with MayaHydraSceneDelegate::GetDoubleSided returning false.
return _isArnoldSkyDomeLightTriangleShape ? HdCullStyleFront : HdCullStyleNothing;
if (_isArnoldSkyDomeLightTriangleShape) {
return HdCullStyleFront;
}
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
switch (_cullMode) {
case MRenderItem::CullNone: return HdCullStyleNothing;
case MRenderItem::CullFront: return HdCullStyleFront;
case MRenderItem::CullBack: return HdCullStyleBack;
default: return HdCullStyleNothing;
}
#else
return HdCullStyleNothing;
#endif
}

///////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 15 additions & 1 deletion lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ std::string kRenderItemTypeName = "renderItem";
static constexpr const char* kPointSize = "pointSize";

static const SdfPath kInvalidMaterial = SdfPath("InvalidMaterial");

#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
// Extract doubleSided attribute from CullMode as MRenderItem uses CullNone to denote doubleSided.
static bool IsDoubleSided(MRenderItem::CullMode cullMode) { return cullMode == MRenderItem::CullNone; }
#endif
} // namespace

using MayaHydraRenderItemAdapterPtr = std::shared_ptr<class MayaHydraRenderItemAdapter>;
Expand Down Expand Up @@ -81,7 +86,13 @@ class MayaHydraRenderItemAdapter : public MayaHydraAdapter
virtual bool IsSupported() const override;

MAYAHYDRALIB_API
bool GetDoubleSided() const override { return false; };
bool GetDoubleSided() const override {
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
return IsDoubleSided(_cullMode);
#else
return false;
#endif
};

MAYAHYDRALIB_API
GfBBox3d GetBoundingBox()const override { return _bounds; }
Expand Down Expand Up @@ -209,6 +220,9 @@ class MayaHydraRenderItemAdapter : public MayaHydraAdapter
bool _isHideOnPlayback = false;
bool _isArnoldSkyDomeLightTriangleShape = false;
GfBBox3d _bounds;//Bounding box
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
MRenderItem::CullMode _cullMode = MRenderItem::CullNone;
#endif
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
4 changes: 4 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ foreach(script ${INTERACTIVE_TEST_SCRIPT_FILES_DISABLE_VP2_RENDER_DELEGATE})
"LD_PRELOAD=${ADDITIONAL_LD_PRELOAD}"

"MAYAUSD_DISABLE_VP2_RENDER_DELEGATE=1"

"MAYA_HAS_RENDER_ITEM_CULL_MODE_API=${MAYA_HAS_RENDER_ITEM_CULL_MODE_API}"
)

# Assign a CTest label to these tests for easy filtering.
Expand Down Expand Up @@ -201,6 +203,8 @@ foreach(script ${INTERACTIVE_TEST_SCRIPT_FILES})

# Use standard surface as default for now
"MAYA_DEFAULT_SURFACE_SHADER=standardSurface"

"MAYA_HAS_RENDER_ITEM_CULL_MODE_API=${MAYA_HAS_RENDER_ITEM_CULL_MODE_API}"
)

# Add a ctest label to these tests for easy filtering.
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.
15 changes: 11 additions & 4 deletions test/lib/mayaUsd/render/mayaToHydra/testPolygonPrimitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import mtohUtils

import platform
import os

class TestPolygonPrimitives(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
Expand All @@ -25,10 +26,10 @@ class TestPolygonPrimitives(mtohUtils.MayaHydraBaseTestCase):
IMAGE_DIFF_FAIL_THRESHOLD = 0.05
IMAGE_DIFF_FAIL_PERCENT = 1.5

def compareSnapshot(self, referenceFilename, cameraDistance=15):
def compareSnapshot(self, referenceFilename, cameraDistance=15, imageVersion=None):
self.setBasicCam(cameraDistance)
cmds.refresh()
self.assertSnapshotClose(referenceFilename, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.assertSnapshotClose(referenceFilename, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT, imageVersion)

def setupScene(self, polygonCreationCallable):
self.setHdStormRenderer()
Expand Down Expand Up @@ -315,7 +316,10 @@ def test_PolygonSphericalHarmonics(self):
self.compareSnapshot("sphericalHarmonics_modified.png")

self.setupSuperShapeHelix(polyCreatorNodeName)
self.compareSnapshot("sphericalHarmonics_helix.png")
imageVersion = None
if(os.getenv('MAYA_HAS_RENDER_ITEM_CULL_MODE_API', 'NOT-FOUND') in ('1', 'TRUE')):
imageVersion = "RenderItemHasCullModeAPI"
self.compareSnapshot("sphericalHarmonics_helix.png", 15, imageVersion)

def test_PolygonUltra(self):
polyCreatorNodeName = self.setupScene(self.getSuperShapeCreationCallable("UltraShape"))
Expand Down Expand Up @@ -346,7 +350,10 @@ def test_PolygonUltra(self):
self.compareSnapshot("ultra_modified.png")

self.setupSuperShapeHelix(polyCreatorNodeName)
self.compareSnapshot("ultra_helix.png")
imageVersion = None
if(os.getenv('MAYA_HAS_RENDER_ITEM_CULL_MODE_API', 'NOT-FOUND') in ('1', 'TRUE')):
imageVersion = "RenderItemHasCullModeAPI"
self.compareSnapshot("ultra_helix.png", 15 , imageVersion)

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