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/imaging/hd/api.h"
11 #include "pxr/imaging/hd/bprim.h"
12 #include "pxr/imaging/hd/types.h"
13 
14 #include "pxr/usd/sdf/path.h"
15 
16 #include "pxr/base/gf/range2f.h"
17 #include "pxr/base/gf/vec2f.h"
18 #include "pxr/base/gf/vec2i.h"
19 #include "pxr/base/tf/token.h"
20 #include "pxr/base/vt/array.h"
21 #include "pxr/base/vt/dictionary.h"
22 #include "pxr/base/vt/value.h"
23 
24 #include "pxr/pxr.h"
25 
26 #include <cstddef>
27 #include <ostream>
28 #include <string>
29 #include <vector>
30 
32 
33 ///
34 /// Hydra prim backing render settings scene description.
35 /// While it is a state prim (Sprim) in spirit, it is made to be a Bprim to
36 /// ensure that it is sync'd prior to Sprims and Rprims to allow render setting
37 /// opinions to be discovered and inform the sync process of those prims.
38 ///
39 /// \note Hydra has several "render settings" concepts as of this writing, which
40 /// can be confusing. We have:
41 /// - HdRenderSettingsMap: A dictionary of token-value pairs that is provided
42 /// as an argument for render delegate construction.
43 /// - HdRenderSettingsDescriptorList: A mechanism to discover and update
44 /// render settings on the render delegate.
45 /// - Render task params: This currently captures opinions such as the camera to
46 /// use, the AOV outputs, etc.
47 ///
48 /// We aim to transition away from the API and task based render settings
49 /// opinions above to using render settings scene description to drive
50 /// rendering in Hydra.
51 ///
52 /// \sa HdRenderSettingsPrimTokens (defined in hd/tokens.h) for tokens
53 /// permitted in (legacy) scene delegate queries via Get(...).
54 ///
55 /// \sa HdRenderSettingsSchema for querying locators and building container
56 /// data sources when using scene indices.
57 ///
58 class HdRenderSettings : public HdBprim
59 {
60 public:
61  // Change tracking for HdRenderSettings.
63  Clean = 0,
64  DirtyActive = 1 << 1,
71  DirtyFrameNumber = 1 << 8,
72  DirtyCamera = 1 << 9,
83  | DirtyCamera
86  };
87 
88  HD_API
89  static std::string
91 
92  // Parameters that may be queried and invalidated.
93  //
94  // \note This mirrors UsdRender except that the render products and vars
95  // are "flattened out" similar to UsdRenderSpec.
96  struct RenderProduct {
97  struct RenderVar {
100  std::string sourceName;
103  };
104 
105  /// Identification & output information
106  //
107  // Path to product prim in scene description.
109  // The type of product, ex: "raster".
111  // The name of the product, which uniquely identifies it.
113  // The pixel resolution of the product.
115  // The render vars that the product is comprised of.
116  std::vector<RenderVar> renderVars;
117 
118  /// Camera and framing
119  //
120  // Path to the camera to use for this product.
122  // The pixel aspect ratio as adjusted by aspectRatioConformPolicy.
124  // The policy that was applied to conform aspect ratio
125  // mismatches between the aperture and image.
127  // The camera aperture size as adjusted by aspectRatioConformPolicy.
129  // The data window, in NDC terms relative to the aperture.
130  // (0,0) corresponds to bottom-left and (1,1) corresponds to
131  // top-right. Note that the data window can partially cover
132  // or extend beyond the unit range, for representing overscan
133  // or cropped renders.
135 
136  /// Settings overrides
137  //
141  };
142 
143  using RenderProducts = std::vector<RenderProduct>;
145 
146  HD_API
147  ~HdRenderSettings() override;
148 
149  // ------------------------------------------------------------------------
150  // Public API
151  // ------------------------------------------------------------------------
152  HD_API
153  bool IsActive() const;
154 
155  HD_API
156  bool IsValid() const;
157 
158  HD_API
160 
161  HD_API
162  const RenderProducts& GetRenderProducts() const;
163 
164  HD_API
165  const VtArray<TfToken>& GetIncludedPurposes() const;
166 
167  HD_API
169 
170  HD_API
171  const TfToken& GetRenderingColorSpace() const;
172 
173  // XXX: Using VtValue in a std::optional (C++17) sense.
174  HD_API
175  const VtValue& GetUnionedSamplingInterval() const;
176 
177  // XXX: Using VtValue in a std::optional (C++17) sense.
178  HD_API
179  const VtValue& GetCamera() const;
180 
181  HD_API
182  bool GetDisableDepthOfField() const;
183 
184  HD_API
185  bool GetDisableMotionBlur() const;
186 
187  /// Returns whether the render products were invalidated since the last
188  /// time this function was called.
189  ///
190  /// \note Due to the lack of fine-grained invalidation in the dirty bits
191  /// above, *any* change to to the targeted product(s) and their
192  /// associated render var(s) would mark the products are dirty.
193  ///
194  HD_API
196 
197  // ------------------------------------------------------------------------
198  // Satisfying HdBprim
199  // ------------------------------------------------------------------------
200  HD_API
201  void
202  Sync(HdSceneDelegate *sceneDelegate,
203  HdRenderParam *renderParam,
204  HdDirtyBits *dirtyBits) final;
205 
206  HD_API
208  GetInitialDirtyBitsMask() const override;
209 
210 protected:
211  HD_API
212  HdRenderSettings(SdfPath const& id);
213 
214  // ------------------------------------------------------------------------
215  // Virtual API
216  // ------------------------------------------------------------------------
217  // This is called during Sync after dirty processing and before clearing the
218  // dirty bits.
219  virtual void
220  _Sync(HdSceneDelegate *sceneDelegate,
221  HdRenderParam *renderParam,
222  const HdDirtyBits *dirtyBits);
223 
224 
225 private:
226  // Class cannot be default constructed or copied.
227  HdRenderSettings() = delete;
228  HdRenderSettings(const HdRenderSettings &) = delete;
229  HdRenderSettings &operator =(const HdRenderSettings &) = delete;
230 
231  bool _active;
232  bool _dirtyProducts;
233  NamespacedSettings _namespacedSettings;
234  RenderProducts _products;
235  VtArray<TfToken> _includedPurposes;
236  VtArray<TfToken> _materialBindingPurposes;
237  TfToken _renderingColorSpace;
238  VtValue _vUnionedSamplingInterval;
239  VtValue _vCamera;
240  bool _disableDepthOfField;
241  bool _disableMotionBlur;
242 };
243 
244 // VtValue requirements
245 HD_API
247 
248 HD_API
249 std::ostream& operator<<(
250  std::ostream& out, const HdRenderSettings::RenderProduct&);
251 
252 HD_API
255 HD_API
258 HD_API
259 std::ostream& operator<<(
260  std::ostream& out, const HdRenderSettings::RenderProduct::RenderVar&);
261 
262 HD_API
265 HD_API
268 
269 
271 
272 #endif // PXR_IMAGING_HD_RENDER_SETTINGS_H
HD_API bool IsActive() const
HD_API const VtArray< TfToken > & GetIncludedPurposes() const
HD_API bool GetDisableMotionBlur() 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
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
HD_API const RenderProducts & GetRenderProducts() const
#define HD_API
Definition: api.h:23
HD_API const VtValue & GetUnionedSamplingInterval() const
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
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
HD_API const VtValue & GetCamera() const
Definition: path.h:280
HD_API const TfToken & GetRenderingColorSpace() const
std::vector< RenderVar > renderVars
static HD_API std::string StringifyDirtyBits(HdDirtyBits dirtyBits)
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 &)
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) final
HD_API bool GetDisableDepthOfField() const
Definition: value.h:89
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542