-
Notifications
You must be signed in to change notification settings - Fork 5
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-794 : Support maya lighting modes for USD and dome lights #167
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab152d0
HYDRA-794 : Support maya lighting modes for USD and dome lights (all …
lanierd-adsk a12da77
Fix tests
lanierd-adsk 0a2bab0
Fix maya lighting modes tests
lanierd-adsk 7fb34d6
Add a missing texture for tests
lanierd-adsk 856fe67
Remove grid from test.
lanierd-adsk 50302e4
Fix an issue in C++ code found by linux build
lanierd-adsk 311bf36
Fixes from code review
lanierd-adsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
lib/flowViewport/sceneIndex/fvpLightsManagementSceneIndex.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
//Local headers | ||
#include "fvpLightsManagementSceneIndex.h" | ||
|
||
//USD/Hydra headers | ||
#include <pxr/imaging/hd/tokens.h> | ||
#include <pxr/imaging/hd/retainedDataSource.h> | ||
#include <pxr/imaging/hd/overlayContainerDataSource.h> | ||
#include <pxr/imaging/hd/containerDataSourceEditor.h> | ||
#include <pxr/imaging/hd/sceneIndexPrimView.h> | ||
#include <pxr/imaging/hd/light.h> | ||
#include <pxr/imaging/hd/lightSchema.h> | ||
#include <pxr/imaging/glf/simpleLight.h> | ||
|
||
//ufe | ||
#include <ufe/globalSelection.h> | ||
#include <ufe/observableSelection.h> | ||
|
||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace { | ||
|
||
void _DisableLight(HdSceneIndexPrim& prim) | ||
{ | ||
HdContainerDataSourceEditor editor(prim.dataSource); | ||
//We don't set the intensity to 0 as for domelights this makes the geometry disappear | ||
for (const auto& t : { HdLightTokens->ambient, HdLightTokens->diffuse, HdLightTokens->specular }) { | ||
editor.Set( | ||
HdLightSchema::GetDefaultLocator().Append(t), | ||
HdRetainedTypedSampledDataSource<float>::New(0.0f)); | ||
} | ||
|
||
prim.dataSource = editor.Finish(); | ||
} | ||
|
||
} // end of anonymous namespace | ||
|
||
/// This is a filtering scene index that manages lights primitives | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
LightsManagementSceneIndex::LightsManagementSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const PathInterface& pathInterface, const SdfPath& defaultLightPath) | ||
: ParentClass(inputSceneIndex), | ||
InputSceneIndexUtils(inputSceneIndex) | ||
,_defaultLightPath(defaultLightPath) | ||
, _pathInterface(pathInterface) | ||
{ | ||
} | ||
|
||
void LightsManagementSceneIndex::SetLightingMode(LightingMode lightingMode) | ||
{ | ||
if (_lightingMode == lightingMode){ | ||
return; | ||
} | ||
|
||
_lightingMode = lightingMode; | ||
_DirtyAllLightsPrims(); | ||
} | ||
|
||
void LightsManagementSceneIndex::_DirtyAllLightsPrims() | ||
{ | ||
HdSceneIndexObserver::DirtiedPrimEntries entries; | ||
for (const SdfPath& path : HdSceneIndexPrimView(GetInputSceneIndex())) { | ||
auto primType = GetInputSceneIndex()->GetPrim(path).primType; | ||
if (HdPrimTypeIsLight(primType)) { | ||
entries.push_back({ path, HdLightSchema::GetDefaultLocator() }); | ||
} | ||
} | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
bool LightsManagementSceneIndex::_IsDefaultLight(const SdfPath& primPath)const | ||
{ | ||
return primPath == _defaultLightPath; | ||
} | ||
|
||
HdSceneIndexPrim LightsManagementSceneIndex::GetPrim(const SdfPath& primPath) const | ||
{ | ||
auto prim = GetInputSceneIndex()->GetPrim(primPath); | ||
auto primType = prim.primType; | ||
if (! HdPrimTypeIsLight(primType)) { | ||
return prim;//return any non light primitive | ||
} | ||
|
||
//This is a light | ||
switch (_lightingMode) { | ||
case LightingMode::kNoLighting: { | ||
_DisableLight(prim); | ||
return prim; | ||
} break; | ||
default: | ||
case LightingMode::kSceneLighting: { | ||
return prim; | ||
} break; | ||
case LightingMode::kDefaultLighting: { | ||
if (! _IsDefaultLight(primPath)){ | ||
_DisableLight(prim); | ||
} | ||
return prim; | ||
} break; | ||
case LightingMode::kSelectedLightsOnly: { | ||
const Ufe::Selection& ufeSelection = *Ufe::GlobalSelection::get(); | ||
if (ufeSelection.empty()) { | ||
// Nothing is selected | ||
_DisableLight(prim); | ||
return prim; | ||
} | ||
|
||
//Convert ufe selection to SdfPath | ||
SdfPathVector selectedLightsSdfPath; | ||
for (const auto& snItem : ufeSelection) { | ||
auto primSelections = _pathInterface.UfePathToPrimSelections(snItem->path()); | ||
for (const auto& primSelection : primSelections) { | ||
selectedLightsSdfPath.push_back(primSelection.primPath); | ||
} | ||
} | ||
const bool isSelected = selectedLightsSdfPath.end() | ||
!= std::find(selectedLightsSdfPath.begin(), | ||
selectedLightsSdfPath.end(), | ||
primPath); | ||
|
||
if (! isSelected) { | ||
_DisableLight(prim); | ||
} | ||
|
||
return prim; | ||
} break; | ||
} | ||
|
||
return prim; | ||
} | ||
|
||
}//end of namespace FVP_NS_DEF |
103 changes: 103 additions & 0 deletions
103
lib/flowViewport/sceneIndex/fvpLightsManagementSceneIndex.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef FLOW_VIEWPORT_SCENE_INDEX_FLOW_VIEWPORT_LIGHTS_MANAGEMENT_SCENE_INDEX_H | ||
#define FLOW_VIEWPORT_SCENE_INDEX_FLOW_VIEWPORT_LIGHTS_MANAGEMENT_SCENE_INDEX_H | ||
|
||
//Local headers | ||
#include "flowViewport/api.h" | ||
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h" | ||
#include "flowViewport/sceneIndex/fvpPathInterface.h" | ||
|
||
//Hydra headers | ||
#include <pxr/base/tf/declarePtrs.h> | ||
#include <pxr/imaging/hd/filteringSceneIndex.h> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
class LightsManagementSceneIndex; | ||
typedef PXR_NS::TfRefPtr<LightsManagementSceneIndex> LightsManagementSceneIndexRefPtr; | ||
typedef PXR_NS::TfRefPtr<const LightsManagementSceneIndex> LightsManagementSceneIndexConstRefPtr; | ||
|
||
/// \class LightsManagementSceneIndex | ||
/// | ||
/// This is a filtering scene index that manages lights primitives | ||
/// | ||
class LightsManagementSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBase | ||
, public Fvp::InputSceneIndexUtils<LightsManagementSceneIndex> | ||
{ | ||
public: | ||
using ParentClass = PXR_NS::HdSingleInputFilteringSceneIndexBase; | ||
using PXR_NS::HdSingleInputFilteringSceneIndexBase::_GetInputSceneIndex; | ||
|
||
FVP_API | ||
static LightsManagementSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const PathInterface& pathInterface, const PXR_NS::SdfPath& defaultLightPath){ | ||
return PXR_NS::TfCreateRefPtr(new LightsManagementSceneIndex(inputSceneIndex, pathInterface, defaultLightPath)); | ||
} | ||
|
||
// From HdSceneIndexBase | ||
FVP_API | ||
PXR_NS::HdSceneIndexPrim GetPrim(const PXR_NS::SdfPath& primPath) const override; | ||
|
||
FVP_API | ||
PXR_NS::SdfPathVector GetChildPrimPaths(const PXR_NS::SdfPath& primPath) const override{ | ||
return GetInputSceneIndex()->GetChildPrimPaths(primPath); | ||
} | ||
|
||
FVP_API | ||
~LightsManagementSceneIndex() override = default; | ||
|
||
enum class LightingMode{ | ||
kNoLighting, | ||
kSceneLighting,//All lights | ||
kDefaultLighting, | ||
kSelectedLightsOnly, | ||
}; | ||
|
||
FVP_API | ||
void SetLightingMode(LightingMode lightingMode); | ||
|
||
FVP_API | ||
LightingMode GetLightingMode()const {return _lightingMode;} | ||
|
||
protected: | ||
|
||
LightsManagementSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const PathInterface& pathInterface, const PXR_NS::SdfPath& defaultLightPath); | ||
|
||
//From HdSingleInputFilteringSceneIndexBase | ||
void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{ | ||
if (!_IsObserved())return; | ||
_SendPrimsAdded(entries); | ||
} | ||
void _PrimsRemoved(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries& entries)override{ | ||
if (!_IsObserved())return; | ||
_SendPrimsRemoved(entries); | ||
} | ||
void _PrimsDirtied(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries& entries)override{ | ||
if (!_IsObserved())return; | ||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
void _DirtyAllLightsPrims(); | ||
bool _IsDefaultLight(const PXR_NS::SdfPath& primPath)const; | ||
|
||
LightingMode _lightingMode = LightingMode::kSceneLighting; | ||
PXR_NS::SdfPath _defaultLightPath; | ||
const PathInterface& _pathInterface; | ||
}; | ||
|
||
}//end of namespace FVP_NS_DEF | ||
|
||
#endif //FLOW_VIEWPORT_SCENE_INDEX_FLOW_VIEWPORT_LIGHTS_MANAGEMENT_SCENE_INDEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me uncomfortable. Why are we treating Arnold lights in a special way, with a special conditional? Is there no way that our adapter infrastructure can handle this? What if another renderer has a different way of handling dome lights?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is specific to maya hydra, not specific to a renderer.