HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lightLinkingSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HDSI_LIGHT_LINKING_SCENE_INDEX_H
8 #define PXR_IMAGING_HDSI_LIGHT_LINKING_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdsi/api.h"
12 
14 #include "pxr/usd/sdf/path.h"
16 #include "pxr/base/tf/token.h"
17 #include "pxr/base/vt/array.h"
18 
19 #include <memory>
20 
22 
23 /// See documentation below for the use of these tokens.
24 ///
25 #define HDSI_LIGHT_LINKING_SCENE_INDEX_TOKENS \
26  (lightPrimTypes) \
27  (lightFilterPrimTypes) \
28  (geometryPrimTypes)
29 
30 TF_DECLARE_PUBLIC_TOKENS(HdsiLightLinkingSceneIndexTokens, HDSI_API,
32 
33 namespace HdsiLightLinkingSceneIndex_Impl
34 {
35  struct _Cache;
36  using _CacheSharedPtr = std::shared_ptr<_Cache>;
37 }
38 
40 
41 ///
42 /// \class HdsiLightLinkingSceneIndex
43 ///
44 /// Scene index that implements light linking semantics by:
45 /// - discovering light linking collections on lights and light filters; this
46 /// may be configured using the \p inputArgs c'tor argument by providing a
47 /// HdTokenArrayDataSourceHandle for \p lightPrimTypes and
48 /// \p lightFilterPrimTypes.
49 ///
50 /// - assigning a category ID token to each unique collection based on
51 /// its membership expression; in PRMan parlance, this is the value fed to
52 /// the "grouping:membership" attribute on the light/light filter.
53 /// Trivial collections that include all prims in the scene use the empty
54 /// token.
55 ///
56 /// - invalidating the categories locator on prims targeted (i.e. matched) by
57 /// the expression,
58 ///
59 /// - invalidating the light/light filter prim when the category ID for its
60 /// linking collection has changed, and
61 ///
62 /// - computing the categories that a (geometry) prim belong to; the list of
63 /// prim types affected by linking may be configured using the \p inputArgs
64 /// c'tor argument by providing a HdTokenArrayDataSourceHandle for
65 /// \p geometryPrimTypes.
66 ///
67 /// \note Current support for instancing is limited to linking non-nested
68 /// instance prims and non-nested point instancer prims.
69 // Linking to instance proxy prims, nested instances and
70 /// nested point instancers is not yet supported.
71 ///
72 /// \note For legacy scene delegates that implement light linking (e.g.
73 /// UsdImagingDelegate) and don't transport the light linking collections,
74 /// this scene index should leave the category(ies) unaffected on the
75 /// light, geometry prims and instancers.
76 ///
78 {
79 public:
80  HDSI_API
81  static HdSceneIndexBaseRefPtr
82  New(const HdSceneIndexBaseRefPtr &inputSceneIndex,
83  const HdContainerDataSourceHandle &inputArgs);
84 
85  HDSI_API
86  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
87 
88  HDSI_API
89  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
90 
91 protected:
92 
93  HDSI_API
95  const HdSceneIndexBaseRefPtr &inputSceneIndex,
96  const HdContainerDataSourceHandle &inputArgs);
97 
98  HDSI_API
99  void _PrimsAdded(
100  const HdSceneIndexBase &sender,
101  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
102 
103  HDSI_API
104  void _PrimsRemoved(
105  const HdSceneIndexBase &sender,
106  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
107 
108  HDSI_API
109  void _PrimsDirtied(
110  const HdSceneIndexBase &sender,
111  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
112 
113 private:
114  void _ProcessAddedLightOrFilter(
116  const TfTokenVector &collectionNames,
118 
119  bool _IsLight(const TfToken &primType) const;
120  bool _IsLightFilter(const TfToken &primType) const;
121  bool _IsGeometry(const TfToken &primType) const;
122 
123 private:
125 
126  // Track prims with light linking collections.
127  SdfPathSet _lightAndFilterPrimPaths;
128 
129  const VtArray<TfToken> _lightPrimTypes;
130  const VtArray<TfToken> _lightFilterPrimTypes;
131  const VtArray<TfToken> _geometryPrimTypes;
132 };
133 
135 
136 #endif
TF_DECLARE_REF_PTRS(HdsiLightLinkingSceneIndex)
static HDSI_API HdSceneIndexBaseRefPtr New(const HdSceneIndexBaseRefPtr &inputSceneIndex, const HdContainerDataSourceHandle &inputArgs)
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Definition: token.h:70
TF_DECLARE_PUBLIC_TOKENS(HdsiLightLinkingSceneIndexTokens, HDSI_API, HDSI_LIGHT_LINKING_SCENE_INDEX_TOKENS)
std::vector< class SdfPath > SdfPathVector
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
#define HDSI_API
Definition: api.h:23
HDSI_API void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries) override
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:192
HDSI_API HdsiLightLinkingSceneIndex(const HdSceneIndexBaseRefPtr &inputSceneIndex, const HdContainerDataSourceHandle &inputArgs)
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
std::shared_ptr< _Cache > _CacheSharedPtr
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define HDSI_LIGHT_LINKING_SCENE_INDEX_TOKENS
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDSI_API void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
HDSI_API void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries) override