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

GITHUB-3928 cast shadow code from csyching #3997

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
43 changes: 43 additions & 0 deletions lib/mayaUsd/render/vp2RenderDelegate/mayaPrimCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ static const InstancePrototypePath sVoidInstancePrototypePath { SdfPath(), kNati
namespace {
std::mutex sMayaMutex;
MayaUsdCustomData sMayaUsdCustomData;

bool getCastsShadows(HdVP2RenderDelegate* delegate, const SdfPath& rprimId, bool& isCastsShadows)
{
static const TfToken primvarVisCastsShadowsToken("primvars:visibility:castsShadows", TfToken::Immortal);
auto param = static_cast<HdVP2RenderParam*>(delegate->GetRenderParam());
auto value = param->GetDrawScene().GetUsdImagingDelegate()->Get(rprimId, primvarVisCastsShadowsToken);
if (!value.IsEmpty() && value.IsHolding<bool>()) {
isCastsShadows = value.UncheckedGet<bool>();
return true;
}
return false;
}

void setCastsShadows(HdVP2RenderDelegate* delegate, MHWRender::MRenderItem* renderItem, bool isCastsShadows)
{
const auto drawMode = renderItem->drawMode();
if (drawMode & MHWRender::MGeometry::kShaded || drawMode & MHWRender::MGeometry::kTextured) {
delegate->GetVP2ResourceRegistry().EnqueueCommit([renderItem, isCastsShadows]() {
renderItem->castsShadows(isCastsShadows);
renderItem->receivesShadows(isCastsShadows);
});
}
}

} // namespace

/* static */
Expand Down Expand Up @@ -442,6 +466,12 @@ void MayaUsdRPrim::_InitRenderItemCommon(MHWRender::MRenderItem* renderItem) con
#ifdef MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API
renderItem->setHideOnPlayback(_hideOnPlayback);
#endif

bool isCastsShadows = true;
if (getCastsShadows(_delegate, SdfPath(_rprimId.asChar()), isCastsShadows)) {
renderItem->castsShadows(isCastsShadows);
renderItem->receivesShadows(isCastsShadows);
}
}

HdVP2DrawItem::RenderItemData& MayaUsdRPrim::_AddRenderItem(
Expand Down Expand Up @@ -849,6 +879,19 @@ void MayaUsdRPrim::_SyncSharedData(
{
const SdfPath& id = refThis.GetId();

static const TfToken visCastsShadowsToken("visibility:castsShadows", TfToken::Immortal);
if (HdChangeTracker::IsPrimvarDirty(*dirtyBits, id, visCastsShadowsToken)) {
bool isCastsShadows = true;
if (getCastsShadows(_delegate, id, isCastsShadows)) {
RenderItemFunc setCastsShadowsFunc = [this, isCastsShadows](HdVP2DrawItem::RenderItemData& renderItemData) {
setCastsShadows(_delegate, renderItemData._renderItem, isCastsShadows);
};
for (const auto& repr : reprs) {
_ForEachRenderItemInRepr(repr.second, setCastsShadowsFunc);
}
}
}

if (HdChangeTracker::IsExtentDirty(*dirtyBits, id)) {
sharedData.bounds.SetRange(delegate->GetExtent(id));
}
Expand Down
4 changes: 4 additions & 0 deletions test/lib/ufe/testChildFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def testFilteredChildren(self):
self.assertEqual(6, len(children))
self.assertIn(ball3Item, children)

def testFilteredClassPrims(self):
# TODO
pass

def testProxyShapeFilteredChildren(self):
mayaUtils.openGroupBallsScene()
cmds.select(clear=True)
Expand Down