-
Notifications
You must be signed in to change notification settings - Fork 4
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-927 - Expose complexity settings in globalRenderSettings #106
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a47a5b
Implement global refinement level for USD primitives
vlasovi 7dc2057
Automated test for the feature
vlasovi 5cf138f
Merge branch 'public_dev' into vlasovi/HYDRA-927
vlasovi f098e53
Merge remote-tracking branch 'public/dev' into vlasovi/HYDRA-927
vlasovi 38a3a43
- Implement Fvp::DisplayStyleOverrideSceneIndex and use it to set glo…
vlasovi 97b5c16
Minor improvements requested by code review
vlasovi 57d44cc
Renaming mtohRefinementLevel to mayaHydraRefinementLevel
vlasovi 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
230 changes: 230 additions & 0 deletions
230
lib/flowViewport/sceneIndex/fvpDisplayStyleOverrideSceneIndex.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,230 @@ | ||
// 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. | ||
// | ||
|
||
#include "flowViewport/sceneIndex/fvpDisplayStyleOverrideSceneIndex.h" | ||
|
||
#include "pxr/imaging/hd/tokens.h" | ||
#include "pxr/imaging/hd/legacyDisplayStyleSchema.h" | ||
#include "pxr/imaging/hd/overlayContainerDataSource.h" | ||
#include "pxr/imaging/hd/sceneIndexPrimView.h" | ||
#include "pxr/imaging/hd/retainedDataSource.h" | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace DisplayStyleSceneIndex_Impl | ||
{ | ||
|
||
using OptionalInt = DisplayStyleOverrideSceneIndex::OptionalInt; | ||
|
||
struct _StyleInfo | ||
{ | ||
OptionalInt refineLevel; | ||
/// Retained data source storing refineLevel (or null ptr if empty optional | ||
/// value) to avoid allocating a data source for every prim. | ||
HdDataSourceBaseHandle refineLevelDs; | ||
}; | ||
|
||
/// Data source for locator displayStyle. | ||
class _DisplayStyleDataSource : public HdContainerDataSource | ||
{ | ||
public: | ||
HD_DECLARE_DATASOURCE(_DisplayStyleDataSource); | ||
|
||
HdDataSourceBaseHandle Get(const TfToken &name) override | ||
{ | ||
if (name == HdLegacyDisplayStyleSchemaTokens->refineLevel) { | ||
return _styleInfo->refineLevelDs; | ||
} | ||
return nullptr; | ||
} | ||
|
||
TfTokenVector GetNames() override | ||
{ | ||
static const TfTokenVector names = { | ||
HdLegacyDisplayStyleSchemaTokens->refineLevel | ||
}; | ||
|
||
return names; | ||
} | ||
|
||
private: | ||
_DisplayStyleDataSource(_StyleInfoSharedPtr const &styleInfo) | ||
: _styleInfo(styleInfo) | ||
{ | ||
} | ||
|
||
_StyleInfoSharedPtr _styleInfo; | ||
}; | ||
|
||
} // namespace DisplayStyleSceneIndex_Impl | ||
|
||
using namespace DisplayStyleSceneIndex_Impl; | ||
|
||
DisplayStyleOverrideSceneIndexRefPtr | ||
DisplayStyleOverrideSceneIndex::New( | ||
const HdSceneIndexBaseRefPtr &inputSceneIndex) | ||
{ | ||
return TfCreateRefPtr( | ||
new DisplayStyleOverrideSceneIndex( | ||
inputSceneIndex)); | ||
} | ||
|
||
DisplayStyleOverrideSceneIndex:: | ||
DisplayStyleOverrideSceneIndex( | ||
const HdSceneIndexBaseRefPtr &inputSceneIndex) | ||
: HdSingleInputFilteringSceneIndexBase(inputSceneIndex) | ||
, _styleInfo(std::make_shared<_StyleInfo>()) | ||
, _overlayDs( | ||
HdRetainedContainerDataSource::New( | ||
HdLegacyDisplayStyleSchemaTokens->displayStyle, | ||
_DisplayStyleDataSource::New(_styleInfo))) | ||
{ | ||
} | ||
|
||
HdSceneIndexPrim | ||
DisplayStyleOverrideSceneIndex::GetPrim( | ||
const SdfPath &primPath) const | ||
{ | ||
HdSceneIndexPrim prim = _GetInputSceneIndex()->GetPrim(primPath); | ||
if (prim.dataSource) { | ||
if (!isExcluded(primPath) && prim.primType == HdPrimTypeTokens->mesh) { | ||
prim.dataSource = | ||
HdOverlayContainerDataSource::New( | ||
_overlayDs, prim.dataSource); | ||
} | ||
} | ||
return prim; | ||
} | ||
|
||
SdfPathVector | ||
DisplayStyleOverrideSceneIndex::GetChildPrimPaths( | ||
const SdfPath &primPath) const | ||
{ | ||
return _GetInputSceneIndex()->GetChildPrimPaths(primPath); | ||
} | ||
|
||
void | ||
DisplayStyleOverrideSceneIndex::SetRefineLevel( | ||
const OptionalInt &refineLevel) | ||
{ | ||
if (refineLevel == _styleInfo->refineLevel) { | ||
return; | ||
} | ||
|
||
_styleInfo->refineLevel = refineLevel; | ||
_styleInfo->refineLevelDs = | ||
refineLevel | ||
? HdRetainedTypedSampledDataSource<int>::New(*refineLevel) | ||
: nullptr; | ||
|
||
static const HdDataSourceLocatorSet locators( | ||
HdLegacyDisplayStyleSchema::GetDefaultLocator() | ||
.Append(HdLegacyDisplayStyleSchemaTokens->refineLevel)); | ||
|
||
_DirtyAllPrims(locators); | ||
} | ||
|
||
void | ||
DisplayStyleOverrideSceneIndex::_DirtyAllPrims( | ||
const HdDataSourceLocatorSet &locators) | ||
{ | ||
if (!_IsObserved()) { | ||
return; | ||
} | ||
|
||
HdSceneIndexObserver::DirtiedPrimEntries entries; | ||
for (const SdfPath &path : HdSceneIndexPrimView(_GetInputSceneIndex())) { | ||
entries.push_back({path, locators}); | ||
} | ||
|
||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
void | ||
DisplayStyleOverrideSceneIndex::_PrimsAdded( | ||
const HdSceneIndexBase &sender, | ||
const HdSceneIndexObserver::AddedPrimEntries &entries) | ||
{ | ||
if (!_IsObserved()) { | ||
return; | ||
} | ||
|
||
_SendPrimsAdded(entries); | ||
} | ||
|
||
void | ||
DisplayStyleOverrideSceneIndex::_PrimsRemoved( | ||
const HdSceneIndexBase &sender, | ||
const HdSceneIndexObserver::RemovedPrimEntries &entries) | ||
{ | ||
if (!_IsObserved()) { | ||
return; | ||
} | ||
|
||
_SendPrimsRemoved(entries); | ||
} | ||
|
||
void | ||
DisplayStyleOverrideSceneIndex::_PrimsDirtied( | ||
const HdSceneIndexBase &sender, | ||
const HdSceneIndexObserver::DirtiedPrimEntries &entries) | ||
{ | ||
if (!_IsObserved()) { | ||
return; | ||
} | ||
|
||
_SendPrimsDirtied(entries); | ||
} | ||
|
||
void DisplayStyleOverrideSceneIndex::addExcludedSceneRoot( | ||
const PXR_NS::SdfPath& sceneRoot | ||
) | ||
{ | ||
_excludedSceneRoots.emplace(sceneRoot); | ||
} | ||
|
||
bool DisplayStyleOverrideSceneIndex::isExcluded( | ||
const PXR_NS::SdfPath& sceneRoot | ||
) const | ||
{ | ||
for (const auto& excluded : _excludedSceneRoots) { | ||
if (sceneRoot.HasPrefix(excluded)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool operator==( | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &a, | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &b) | ||
{ | ||
if (a.hasValue == false && b.hasValue == false) { | ||
return true; | ||
} | ||
|
||
return a.hasValue == b.hasValue && a.value == b.value; | ||
} | ||
|
||
bool operator!=( | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &a, | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &b) | ||
{ | ||
return !(a == b); | ||
} | ||
|
||
} //end of namespace FVP_NS_DEF |
124 changes: 124 additions & 0 deletions
124
lib/flowViewport/sceneIndex/fvpDisplayStyleOverrideSceneIndex.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,124 @@ | ||
// 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 FVP_DISPLAY_STYLE_OVERRIDE_SCENE_INDEX_H | ||
#define FVP_DISPLAY_STYLE_OVERRIDE_SCENE_INDEX_H | ||
|
||
#include "flowViewport/api.h" | ||
|
||
#include "pxr/imaging/hdsi/api.h" | ||
#include "pxr/imaging/hd/filteringSceneIndex.h" | ||
|
||
#include <set> | ||
|
||
namespace FVP_NS_DEF { | ||
|
||
namespace DisplayStyleSceneIndex_Impl | ||
{ | ||
struct _StyleInfo; | ||
using _StyleInfoSharedPtr = std::shared_ptr<_StyleInfo>; | ||
} | ||
|
||
class DisplayStyleOverrideSceneIndex; | ||
typedef PXR_NS::TfRefPtr<DisplayStyleOverrideSceneIndex> DisplayStyleOverrideSceneIndexRefPtr; | ||
typedef PXR_NS::TfRefPtr<const DisplayStyleOverrideSceneIndex> DisplayStyleOverrideSceneIndexConstRefPtr; | ||
|
||
/// | ||
/// \class DisplayStyleOverrideSceneIndex | ||
/// | ||
/// A scene index overriding the display style for each prim. | ||
/// | ||
class DisplayStyleOverrideSceneIndex : | ||
public PXR_NS::HdSingleInputFilteringSceneIndexBase | ||
{ | ||
public: | ||
FVP_API | ||
static DisplayStyleOverrideSceneIndexRefPtr | ||
New(const PXR_NS::HdSceneIndexBaseRefPtr &inputSceneIndex); | ||
|
||
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; | ||
|
||
/// A replacement for std::optional<int> that is not available until C++17. | ||
struct OptionalInt | ||
{ | ||
bool hasValue = false; | ||
int value = 0; | ||
|
||
operator bool() const { return hasValue; } | ||
int operator*() const { return value; } | ||
}; | ||
|
||
/// Sets the refine level (at data source locator displayStyle:refineLevel) | ||
/// for every prim in the input scene inedx. | ||
/// | ||
/// If an empty optional value is provided, a null data source will be | ||
/// returned for the data source locator. | ||
/// | ||
FVP_API | ||
void SetRefineLevel(const OptionalInt &refineLevel); | ||
|
||
FVP_API | ||
void addExcludedSceneRoot(const PXR_NS::SdfPath& sceneRoot); | ||
|
||
protected: | ||
FVP_API | ||
DisplayStyleOverrideSceneIndex( | ||
const PXR_NS::HdSceneIndexBaseRefPtr &inputSceneIndex); | ||
|
||
FVP_API | ||
void _PrimsAdded( | ||
const PXR_NS::HdSceneIndexBase &sender, | ||
const PXR_NS::HdSceneIndexObserver::AddedPrimEntries &entries) override; | ||
|
||
FVP_API | ||
void _PrimsRemoved( | ||
const PXR_NS::HdSceneIndexBase &sender, | ||
const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries &entries) override; | ||
|
||
FVP_API | ||
void _PrimsDirtied( | ||
const PXR_NS::HdSceneIndexBase &sender, | ||
const PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries &entries) override; | ||
|
||
private: | ||
void _DirtyAllPrims(const PXR_NS::HdDataSourceLocatorSet &locators); | ||
|
||
bool isExcluded(const PXR_NS::SdfPath& sceneRoot) const; | ||
|
||
std::set<PXR_NS::SdfPath> _excludedSceneRoots; | ||
|
||
DisplayStyleSceneIndex_Impl:: | ||
_StyleInfoSharedPtr const _styleInfo; | ||
|
||
/// Prim overlay data source. | ||
PXR_NS::HdContainerDataSourceHandle const _overlayDs; | ||
}; | ||
|
||
HDSI_API | ||
bool operator==( | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &a, | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &b); | ||
|
||
HDSI_API | ||
bool operator!=( | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &a, | ||
const DisplayStyleOverrideSceneIndex::OptionalInt &b); | ||
|
||
} //end of namespace FVP_NS_DEF | ||
|
||
#endif //FVP_DISPLAY_STYLE_OVERRIDE_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
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.
What about the refineLevel which is adapters, MayaHydraAdapter::GetDisplayStyle().refineLevel > 0)
Is what you do replaces this ? Or is this something else ?
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.
I assume the added one is the global refine level, while the one in DisplayStyle is per-primitive, but it's not enabled yet due to MRenderItem was already refined. HdsiLegacyDisplayStyleOverrideSceneIndex can be used to override the per-primitive one.
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.
As far as I understand MayaHydraAdapter is used only for Maya native prims. The new scene index is supposed to be used only for USD prims. I will add "addExcludedSceneRoot" to it in my next commit to exclude Maya prims