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-723 : Fix for Maya Lighting mode not working #30

Merged
merged 1 commit into from
Dec 20, 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
22 changes: 10 additions & 12 deletions lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,17 +690,17 @@ SdfPath MayaHydraSceneIndex::GetDelegateID(TfToken name)
}

MayaHydraSceneIndex::
LightDagPathMap MayaHydraSceneIndex::_GetActiveLightPaths() const
LightDagPathMap MayaHydraSceneIndex::_GetGlobalLightPaths() const
{
LightDagPathMap activeLightPaths;
activeLightPaths.reserve(_lightAdapters.size());
LightDagPathMap allLightPaths;
allLightPaths.reserve(_lightAdapters.size());
// By the time this function is called _lightAdapters should already have been populated
// with both Maya and Arnold light adapters. The adapters contain the DagPath information
// we store it here in unordered_map for fast retrieval
for(const auto& entry : _lightAdapters)
activeLightPaths.emplace(entry.second->GetDagPath().fullPathName().asChar(),
allLightPaths.emplace(entry.second->GetDagPath().fullPathName().asChar(),
entry.second->GetDagPath());
return activeLightPaths;
return allLightPaths;
}

void MayaHydraSceneIndex::PreFrame(const MHWRender::MDrawContext& context)
Expand Down Expand Up @@ -835,12 +835,13 @@ void MayaHydraSceneIndex::PreFrame(const MHWRender::MDrawContext& context)
return;
}

LightDagPathMap activeLightPaths = _GetActiveLightPaths();
LightDagPathMap globalLightPaths = _GetGlobalLightPaths();
LightDagPathMap activeLightPaths;
constexpr auto considerAllSceneLights = MHWRender::MDrawContext::kFilteredIgnoreLightLimit;
MStatus status;
const auto numLights = context.numberOfActiveLights(considerAllSceneLights, &status);

if ((!status || numLights == 0) && (0 == activeLightPaths.size())) {
if ((!status || numLights == 0) && (0 == globalLightPaths.size())) {
_MapAdapter<MayaHydraLightAdapter>(
[](MayaHydraLightAdapter* a) { a->SetLightingOn(false); },
_lightAdapters); // Turn off all lights
Expand All @@ -864,8 +865,8 @@ void MayaHydraSceneIndex::PreFrame(const MHWRender::MDrawContext& context)
}

// we do a fast look up here for any new lights that may have been added
auto found = activeLightPaths.find(lightPath.fullPathName().asChar());
if (found == activeLightPaths.end())
auto found = globalLightPaths.find(lightPath.fullPathName().asChar());
if (found != globalLightPaths.end())
activeLightPaths.emplace(lightPath.fullPathName().asChar(),
lightPath);

Expand Down Expand Up @@ -897,9 +898,6 @@ void MayaHydraSceneIndex::PreFrame(const MHWRender::MDrawContext& context)
}
},
_lightAdapters);
for(const auto& entry : activeLightPaths) {
CreateLightAdapter(entry.second);
}
}

void MayaHydraSceneIndex::PostFrame()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public
bool _CreateMaterial(const SdfPath& id, const MObject& obj);

using LightDagPathMap = std::unordered_map<std::string, MDagPath>;
LightDagPathMap _GetActiveLightPaths() const;
LightDagPathMap _GetGlobalLightPaths() const;
static VtValue CreateMayaDefaultMaterial();

using DirtyBitsToLocatorsFunc = std::function<void(TfToken const&, const HdDirtyBits, HdDataSourceLocatorSet*)>;
Expand Down