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

MAYA-125725 - Implement display layer's untextured mode for instanced geometry #2897

Merged
merged 1 commit into from
Feb 23, 2023
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
55 changes: 44 additions & 11 deletions lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,14 @@ HdReprSharedPtr MayaUsdRPrim::_InitReprCommon(

// Instanced primitives with instances in display layers use 'forced' representations to
// draw those specific instances, so the 'forced' representations should be inited alongside
if (reprToken != HdVP2ReprTokens->forcedBbox && reprToken != HdVP2ReprTokens->forcedWire) {
if (reprToken != HdVP2ReprTokens->forcedBbox && reprToken != HdVP2ReprTokens->forcedWire
&& reprToken != HdVP2ReprTokens->forcedUntextured) {
refThis.InitRepr(
drawScene.GetUsdImagingDelegate(), HdVP2ReprTokens->forcedBbox, dirtyBits);
refThis.InitRepr(
drawScene.GetUsdImagingDelegate(), HdVP2ReprTokens->forcedWire, dirtyBits);
refThis.InitRepr(
drawScene.GetUsdImagingDelegate(), HdVP2ReprTokens->forcedUntextured, dirtyBits);
}
} else {
// Sync display layer modes for non-instanced prims.
Expand Down Expand Up @@ -784,6 +787,8 @@ void MayaUsdRPrim::_SyncDisplayLayerModesInstanced(SdfPath const& id, unsigned i
_forcedReprFlags |= kForcedBBox;
} else if (displayLayerModes._reprOverride == kWire) {
_forcedReprFlags |= kForcedWire;
} else if (!displayLayerModes._texturing) {
_forcedReprFlags |= kForcedUntextured;
}

int requiredModFlags = 0;
Expand Down Expand Up @@ -1038,18 +1043,40 @@ bool MayaUsdRPrim::_FilterInstanceByDisplayLayer(
return true;
}

// Match item's bbox mode against instance's bbox mode
// Process draw mode overrides
const bool forcedBboxItem = (reprToken == HdVP2ReprTokens->forcedBbox);
const bool overrideBboxInstance = displayLayerModes._reprOverride == kBBox;
if (forcedBboxItem != overrideBboxInstance) {
return true;
}

// Match item's wire mode against instance's wire mode
const bool forcedWireItem = (reprToken == HdVP2ReprTokens->forcedWire);
const bool overrideWireInstance = displayLayerModes._reprOverride == kWire;
if (forcedWireItem != overrideWireInstance) {
return true;
const bool forcedUntexturedItem = (reprToken == HdVP2ReprTokens->forcedUntextured);
if (displayLayerModes._reprOverride == kNone) {
if (displayLayerModes._texturing) {
// In no-override mode, an instance should be drawn only by
// the non-forced reprs, so skip the forced ones.
if (forcedBboxItem || forcedWireItem || forcedUntexturedItem) {
return true;
}
} else {
// Untextured override cannot affect bbox and wire modes, so keep
// those reprs along with the forcedUntextured one.
// Also, since forcedUntextured repr doesn't have a dedicated highlight
// draw item, it is drawn by non-forced reprs.
bool bboxItem = reprToken == HdVP2ReprTokens->bbox;
bool wireItem = reprToken == HdReprTokens->wire;
if (!isDedicatedHighlightItem && !forcedUntexturedItem && !bboxItem && !wireItem) {
return true;
}
}
} else if (displayLayerModes._reprOverride == kWire) {
// Wire override cannot affect bbox mode so keep this repr
// along with the forcedWire one.
bool bboxItem = reprToken == HdVP2ReprTokens->bbox;
if (!forcedWireItem && !bboxItem) {
return true;
}
} else if (displayLayerModes._reprOverride == kBBox) {
// Bbox override affects all draw modes.
if (!forcedBboxItem) {
return true;
}
}

// Match item's hide-on-playback mode against that of the instance
Expand Down Expand Up @@ -1129,6 +1156,12 @@ void MayaUsdRPrim::_SyncForcedReprs(
} else {
_ForEachRenderItemInRepr(_FindRepr(reprs, HdVP2ReprTokens->forcedWire), hideDrawItem);
}

if (_forcedReprFlags & kForcedUntextured) {
refThis.Sync(delegate, renderParam, dirtyBits, HdVP2ReprTokens->forcedUntextured);
} else {
_ForEachRenderItemInRepr(_FindRepr(reprs, HdVP2ReprTokens->forcedUntextured), hideDrawItem);
}
}

PXR_NAMESPACE_CLOSE_SCOPE
3 changes: 2 additions & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class MayaUsdRPrim
enum ForcedReprFlags
{
kForcedBBox = 1 << 0,
kForcedWire = 1 << 1
kForcedWire = 1 << 1,
kForcedUntextured = 1 << 2
};

struct DisplayLayerModes
Expand Down
30 changes: 22 additions & 8 deletions lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,12 +1193,23 @@ void HdVP2Mesh::_InitRepr(const TfToken& reprToken, HdDirtyBits* dirtyBits)
}
}

HdVP2DrawItem* _FindMod(HdVP2DrawItem* baseItem, const int modFlags)
{
for (auto mod = baseItem; mod; mod = mod->GetMod()) {
if (mod->GetModFlags() == modFlags) {
return mod;
}
}

return nullptr;
}

void HdVP2Mesh::_AddNewRenderItem(
HdVP2DrawItem* drawItem,
const HdMeshReprDesc& desc,
const TfToken& reprToken,
MSubSceneContainer* subSceneContainer,
const bool shareHighlightItem)
const int modFlags)
{
const MString& renderItemName = drawItem->GetDrawItemName();

Expand Down Expand Up @@ -1237,9 +1248,7 @@ void HdVP2Mesh::_AddNewRenderItem(
|| reprToken == HdVP2ReprTokens->defaultMaterial) {
// Share selection highlight render item between hull reprs
bool foundShared = false;
for (auto it = _reprs.begin();
shareHighlightItem && (it != _reprs.end()) && !foundShared;
++it) {
for (auto it = _reprs.begin(); (it != _reprs.end()) && !foundShared; ++it) {
const HdReprSharedPtr& repr = it->second;
const auto& items = repr->GetDrawItems();
#if HD_API_VERSION < 35
Expand All @@ -1251,9 +1260,14 @@ void HdVP2Mesh::_AddNewRenderItem(
#endif
if (shDrawItem
&& shDrawItem->MatchesUsage(HdVP2DrawItem::kSelectionHighlight)) {
drawItem->ShareRenderItem(*shDrawItem);
foundShared = true;
break;
// We may only share items which properties correspond exactly,
// including 'hide-on-playback' and 'selectability'.
// Therefore, we must use only the corresponding mod.
if (auto sharedItem = _FindMod(shDrawItem, modFlags)) {
drawItem->ShareRenderItem(*sharedItem);
foundShared = true;
break;
}
}
}
}
Expand Down Expand Up @@ -1478,7 +1492,7 @@ void HdVP2Mesh::_UpdateMods(
newMod->SetModFlags(bitsetIndex);

// Add render items to the mod in the same way it is done for the original draw item
_AddNewRenderItem(newMod.get(), desc, reprToken, subSceneContainer, false);
_AddNewRenderItem(newMod.get(), desc, reprToken, subSceneContainer, bitsetIndex);
if (desc.geomStyle == HdMeshGeomStyleHull) {
if (newMod->GetRenderItems().size() == 0) {
_CreateSmoothHullRenderItems(*newMod, reprToken, *subSceneContainer);
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class HdVP2Mesh final
const HdMeshReprDesc& desc,
const TfToken& reprToken,
MSubSceneContainer* subSceneContainer,
const bool shareHighlightItem = true);
const int modFlags = 0);

void _UpdateMods(
HdRprim& refThis,
Expand Down
3 changes: 3 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ void _ConfigureReprs()
// Forced representations are used for instanced geometry with display layer overrides
HdMesh::ConfigureRepr(HdVP2ReprTokens->forcedBbox, reprDescEdge);
HdMesh::ConfigureRepr(HdVP2ReprTokens->forcedWire, reprDescWire);
// forcedUntextured repr doesn't use reprDescEdge descriptor because
// its selection highlight will be drawn through a non-forced repr
HdMesh::ConfigureRepr(HdVP2ReprTokens->forcedUntextured, reprDescHull);

// smooth hull for untextured display
HdBasisCurves::ConfigureRepr(
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ PXR_NAMESPACE_OPEN_SCOPE
(defaultMaterial) \
(smoothHullUntextured) \
(forcedBbox) \
(forcedWire)
(forcedWire) \
(forcedUntextured)

#define HDVP2_TOKENS \
(displayColorAndOpacity) \
Expand Down