HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
renderSettings.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 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_HD_RENDER_SETTINGS_H
8 #define PXR_IMAGING_HD_RENDER_SETTINGS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/bprim.h"
13 
14 #include "pxr/base/vt/array.h"
15 #include "pxr/base/vt/dictionary.h"
16 #include "pxr/base/gf/vec2i.h"
17 #include "pxr/base/gf/vec2f.h"
18 #include "pxr/base/gf/vec2d.h"
19 #include "pxr/base/gf/range2f.h"
20 
21 #include <vector>
22 
24 
25 ///
26 /// Hydra prim backing render settings scene description.
27 /// While it is a state prim (Sprim) in spirit, it is made to be a Bprim to
28 /// ensure that it is sync'd prior to Sprims and Rprims to allow render setting
29 /// opinions to be discovered and inform the sync process of those prims.
30 ///
31 /// \note Hydra has several "render settings" concepts as of this writing, which
32 /// can be confusing. We have:
33 /// - HdRenderSettingsMap: A dictionary of token-value pairs that is provided
34 /// as an argument for render delegate construction.
35 /// - HdRenderSettingsDescriptorList: A mechanism to discover and update
36 /// render settings on the render delegate.
37 /// - Render task params: This currently captures opinions such as the camera to
38 /// use, the AOV outputs, etc.
39 ///
40 /// We aim to transition away from the API and task based render settings
41 /// opinions above to using render settings scene description to drive
42 /// rendering in Hydra.
43 ///
44 /// \sa HdRenderSettingsPrimTokens (defined in hd/tokens.h) for tokens
45 /// permitted in (legacy) scene delegate queries via Get(...).
46 ///
47 /// \sa HdRenderSettingsSchema for querying locators and building container
48 /// data sources when using scene indices.
49 ///
50 class HdRenderSettings : public HdBprim
51 {
52 public:
53  // Change tracking for HdRenderSettings.
55  Clean = 0,
56  DirtyActive = 1 << 1,
63  DirtyFrameNumber = 1 << 8,
72  };
73 
74  // Parameters that may be queried and invalidated.
75  //
76  // \note This mirrors UsdRender except that the render products and vars
77  // are "flattened out" similar to UsdRenderSpec.
78  struct RenderProduct {
79  struct RenderVar {
82  std::string sourceName;
85  };
86 
87  /// Identification & output information
88  //
89  // Path to product prim in scene description.
91  // The type of product, ex: "raster".
93  // The name of the product, which uniquely identifies it.
95  // The pixel resolution of the product.
97  // The render vars that the product is comprised of.
98  std::vector<RenderVar> renderVars;
99 
100  /// Camera and framing
101  //
102  // Path to the camera to use for this product.
104  // The pixel aspect ratio as adjusted by aspectRatioConformPolicy.
106  // The policy that was applied to conform aspect ratio
107  // mismatches between the aperture and image.
109  // The camera aperture size as adjusted by aspectRatioConformPolicy.
111  // The data window, in NDC terms relative to the aperture.
112  // (0,0) corresponds to bottom-left and (1,1) corresponds to
113  // top-right. Note that the data window can partially cover
114  // or extend beyond the unit range, for representing overscan
115  // or cropped renders.
117 
118  /// Settings overrides
119  //
123  };
124 
125  using RenderProducts = std::vector<RenderProduct>;
127 
128  HD_API
129  ~HdRenderSettings() override;
130 
131  // ------------------------------------------------------------------------
132  // Public API
133  // ------------------------------------------------------------------------
134  HD_API
135  bool IsActive() const;
136 
137  HD_API
138  bool IsValid() const;
139 
140  HD_API
142 
143  HD_API
144  const RenderProducts& GetRenderProducts() const;
145 
146  HD_API
147  const VtArray<TfToken>& GetIncludedPurposes() const;
148 
149  HD_API
151 
152  HD_API
153  const TfToken& GetRenderingColorSpace() const;
154 
155  // XXX Using VtValue in a std::optional (C++17) sense.
156  HD_API
157  const VtValue& GetShutterInterval() const;
158 
159  /// Returns whether the render products were invalidated since the last
160  /// time this function was called.
161  ///
162  /// \note Due to the lack of fine-grained invalidation in the dirty bits
163  /// above, *any* change to to the targeted product(s) and their
164  /// associated render var(s) would mark the products are dirty.
165  ///
166  HD_API
168 
169  // ------------------------------------------------------------------------
170  // Satisfying HdBprim
171  // ------------------------------------------------------------------------
172  HD_API
173  void
174  Sync(HdSceneDelegate *sceneDelegate,
175  HdRenderParam *renderParam,
176  HdDirtyBits *dirtyBits) override final;
177 
178  HD_API
180  GetInitialDirtyBitsMask() const override;
181 
182 protected:
183  HD_API
184  HdRenderSettings(SdfPath const& id);
185 
186  // ------------------------------------------------------------------------
187  // Virtual API
188  // ------------------------------------------------------------------------
189  // This is called during Sync after dirty processing and before clearing the
190  // dirty bits.
191  virtual void
192  _Sync(HdSceneDelegate *sceneDelegate,
193  HdRenderParam *renderParam,
194  const HdDirtyBits *dirtyBits);
195 
196 
197 private:
198  // Class cannot be default constructed or copied.
199  HdRenderSettings() = delete;
200  HdRenderSettings(const HdRenderSettings &) = delete;
201  HdRenderSettings &operator =(const HdRenderSettings &) = delete;
202 
203  bool _active;
204  bool _dirtyProducts;
205  NamespacedSettings _namespacedSettings;
206  RenderProducts _products;
207  VtArray<TfToken> _includedPurposes;
208  VtArray<TfToken> _materialBindingPurposes;
209  TfToken _renderingColorSpace;
210  VtValue _vShutterInterval;
211 };
212 
213 // VtValue requirements
214 HD_API
216 
217 HD_API
218 std::ostream& operator<<(
219  std::ostream& out, const HdRenderSettings::RenderProduct&);
220 
221 HD_API
224 HD_API
227 HD_API
228 std::ostream& operator<<(
229  std::ostream& out, const HdRenderSettings::RenderProduct::RenderVar&);
230 
231 HD_API
234 HD_API
237 
238 
240 
241 #endif // PXR_IMAGING_HD_RENDER_SETTINGS_H
HD_API bool IsActive() const
HD_API const VtArray< TfToken > & GetIncludedPurposes() const
Definition: vec2i.h:43
HD_API const NamespacedSettings & GetNamespacedSettings() const
std::vector< RenderProduct > RenderProducts
bool disableMotionBlur
Settings overrides.
uint32_t HdDirtyBits
Definition: types.h:143
HD_API const RenderProducts & GetRenderProducts() const
#define HD_API
Definition: api.h:23
HD_API const VtArray< TfToken > & GetMaterialBindingPurposes() const
HD_API bool IsValid() const
virtual void _Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, const HdDirtyBits *dirtyBits)
HD_API size_t hash_value(HdRenderSettings::RenderProduct const &rp)
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
SdfPath productPath
Identification & output information.
HD_API bool GetAndResetHasDirtyProducts()
Definition: token.h:70
HD_API ~HdRenderSettings() override
HD_API const VtValue & GetShutterInterval() const
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
Definition: path.h:273
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) overridefinal
HD_API const TfToken & GetRenderingColorSpace() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::vector< RenderVar > renderVars
Definition: vec2f.h:45
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Definition: bprim.h:39
SdfPath cameraPath
Camera and framing.
HD_API std::ostream & operator<<(std::ostream &out, const HdRenderSettings::RenderProduct &)
Definition: value.h:146
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542