HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_RenderSettings.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * NAME: XUSD_RenderSettings.h (karma Library, C++)
17  *
18  * COMMENTS:
19  */
20 
21 #ifndef __XUSD_RenderSettings__
22 #define __XUSD_RenderSettings__
23 
24 #include "HUSD_API.h"
25 #include <PXL/PXL_Common.h>
26 #include <UT/UT_Array.h>
27 #include <UT/UT_NonCopyable.h>
28 #include <UT/UT_Rect.h>
29 #include <UT/UT_StringHolder.h>
30 #include <UT/UT_UniquePtr.h>
31 #include <SYS/SYS_Types.h>
32 #include <pxr/pxr.h>
33 #include <pxr/imaging/hd/aov.h>
37 #include <pxr/usd/usdRender/var.h>
38 
39 #include <string>
40 
41 class UT_JSONWriter;
42 
44 
45 class XUSD_RenderProduct;
47 
49  : public UT_NonCopyable
50 {
51 public:
53  virtual ~XUSD_RenderSettingsContext();
54 
55  /// Update any settings from the render settings primitive. This allows
56  /// the context to look at custom attributes on the RenderSettings.
57  ///
58  /// This function will always be called - even if there are no settings.
59  virtual void initFromUSD(UsdRenderSettings &settings) { }
60 
61  /// Return the name of the render delegate
62  virtual TfToken renderer() const = 0;
63 
64  /// Override the path to the camera
65  virtual SdfPath overrideCamera() const
66  {
67  return SdfPath();
68  }
69 
70  /// Return the default resolution for rendering products
71  virtual GfVec2i defaultResolution() const = 0;
72 
73  /// Optionally override the resolution of the product
74  virtual GfVec2i overrideResolution(const GfVec2i &res) const
75  {
76  return res;
77  }
78 
79  /// Optionally, override the pixel aspect ratio.
80  virtual fpreal overridePixelAspect(fpreal pa) const { return pa; }
81 
82  /// Optionally, override the data window
83  virtual GfVec4f overrideDataWindow(const GfVec4f &w) const { return w; }
84 
85  /// Optionally, override the disableMotionBlur
86  virtual bool overrideDisableMotionBlur(bool v) const { return v; }
87 
88  /// Return if there's an overridden purpose for the render
89  virtual const char *overridePurpose() const { return nullptr; }
90 
91  /// Return the default purpose (this is a comma separated list)
92  virtual const char *defaultPurpose() const
93  {
94  const char *p = overridePurpose();
95  if (!p)
96  p = "geometry,render";
97  return p;
98  }
99 
100  /// Start frame for a render sequence
101  virtual fpreal startFrame() const = 0;
102 
103  /// Frame increment, when computing sequences
104  virtual fpreal frameInc() const { return 1; }
105 
106  /// Return the number of frames being rendered
107  virtual int frameCount() const { return 1; }
108 
109  /// Return the fps
110  virtual fpreal fps() const { return 24; }
111 
112  /// Current frame in the render sequence
113  virtual UsdTimeCode evalTime() const = 0;
114 
115  /// Get a default rendering descriptor for a given AOV
116  virtual HdAovDescriptor defaultAovDescriptor(const TfToken &aov) const
117  {
118  return HdAovDescriptor();
119  }
120 
121  /// Default product name
122  virtual const char *defaultProductName() const { return nullptr; }
123 
124  /// Return a product name override
125  virtual const char *overrideProductName(const XUSD_RenderProduct &p,
126  int pidx) const
127  {
128  return nullptr;
129  }
130 
131  /// Optionally, override the path to the snapshots
132  virtual const char *overrideSnapshotPath(const XUSD_RenderProduct &p,
133  int pidx) const
134  {
135  return nullptr;
136  }
137  /// Optionally, override the suffix on snapshots
138  virtual const char *overrideSnapshotSuffix(const XUSD_RenderProduct &p,
139  int pidx) const
140  {
141  return "_part";
142  }
143 
144 
145  /// Get the tile suffix, if there is one
146  virtual const char *tileSuffix() const { return nullptr; }
147 
148  /// Get the tile index, defaults to 0
149  virtual int tileIndex() const { return 0; }
150 
151  /// Build initial render settings map
152  virtual void setDefaultSettings(const XUSD_RenderSettings &rset,
153  HdRenderSettingsMap &settings) const
154  { }
155 
156  /// After the products have been loaded, apply any overrides
157  virtual void overrideSettings(const XUSD_RenderSettings &rset,
158  HdRenderSettingsMap &settings) const
159  { }
160 
161  /// Allow render options to be applied without a camera present.
162  virtual bool allowCameraless() const { return false; }
163 };
164 
166  : public UT_NonCopyable
167 {
168 public:
169  XUSD_RenderVar();
170  virtual ~XUSD_RenderVar();
171 
172  bool loadFrom(const UsdRenderVar &prim,
173  const XUSD_RenderSettingsContext &ctx);
174  bool resolveFrom(const UsdRenderVar &prim,
175  const XUSD_RenderSettingsContext &ctx);
176  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
177 
178  virtual UT_UniquePtr<XUSD_RenderVar> clone() const;
179 
180  const std::string &aovName() const { return myAovName; }
181  const TfToken &aovToken() const { return myAovToken; }
182  const TfToken &dataType() const;
183  const std::string &sourceName() const;
184  const TfToken &sourceType() const;
185 
186  const HdAovDescriptor &desc() const { return myHdDesc; }
187  PXL_DataFormat pxlFormat() const { return myDataFormat; }
188  PXL_Packing pxlPacking() const { return myPacking; }
189 
190  /// Print out the settings
191  void dump(UT_JSONWriter &w) const;
192 
193 protected:
199 };
200 
202  : public UT_NonCopyable
203 {
204 public:
207 
209  virtual ~XUSD_RenderProduct();
210 
211  bool loadFrom(const UsdStageRefPtr &usd,
212  const UsdRenderProduct &prim,
213  const XUSD_RenderSettingsContext &ctx);
214  bool resolveFrom(const UsdStageRefPtr &usd,
215  const UsdRenderProduct &prim,
216  const XUSD_RenderSettingsContext &ctx);
217  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
218  bool buildDummyRaster(const XUSD_RenderSettingsContext &ctx,
219  const XUSD_RenderProduct &src);
220 
221  void updateSettings(const UsdStageRefPtr &use,
222  const UsdRenderProduct &prim,
223  const XUSD_RenderSettingsContext &ctx);
224 
225  const TfToken &productType() const;
226  TfToken productName(int frame = 0) const;
227 
228  bool isRaster() const;
229 
230  // Current output filename (with all variables expanded)
231  const UT_StringHolder &outputName() const { return myFilename; }
232 
233  const RenderVarList &vars() const { return myVars; }
234 
235  /// @{
236  /// Properties that can override settings defined on a render settings
237  /// primitive The functions return true if they are authored on the
238  /// product.
239  template <typename T>
241  {
242  void clear() { myAuthored = false; }
243  bool import(T &val) const
244  {
245  if (myAuthored)
246  {
247  val = myValue;
248  return true;
249  }
250  return false;
251  }
253  bool myAuthored = false;
254  };
255  bool cameraPath(SdfPath &val) const
256  {
257  if (myCameraPath.IsEmpty())
258  return false;
259  val = myCameraPath;
260  return true;
261  }
262  bool shutter(GfVec2d &val) const { return myShutter.import(val); }
263  bool res(GfVec2i &val) const { return myRes.import(val); }
264  bool pixelAspect(float &val) const { return myPixelAspect.import(val); }
265  bool dataWindow(GfVec4f &val) const { return myDataWindowF.import(val); }
266  bool disableMotionBlur(bool &val) const;
267  /// @}
268 
269  /// @{
270  /// Test whether the product list has a specific value for the given
271  /// attribute. If so, overwrite the value with the value of the product
272  /// list. Note, all products must author the attribute and have the same
273  /// value.
275  static bool specificRes(GfVec2i &val, const ProductList &products);
276  static bool specificPixelAspect(float &val, const ProductList &products);
277  static bool specificDataWindow(GfVec4f &val, const ProductList &products);
278  static bool specificDisableMotionBlur(bool &val, const ProductList &products);
279  /// @}
280 
281  const SdfPath &cameraPath() const { return myCameraPath; }
282 
283  const_iterator begin() const { return myVars.begin(); }
284  const_iterator end() const { return myVars.end(); }
285 
286  /// Expand product name variables. Returns false if there are multiple
287  /// frames, but no frame expansion. The @c product_index is -1 for
288  /// non-raster products or the offset into the list of raster products.
289  bool expandProduct(const XUSD_RenderSettingsContext &opts,
290  int product_index, int frame);
291  bool collectAovs(TfTokenVector &aovs, HdAovDescriptorList &descs) const;
292 
293  /// User settings for this product
294  const HdAovSettingsMap &settings() const { return mySettings; }
295 
296  /// Print out the settings
297  void dump(UT_JSONWriter &w) const;
298 
299  bool isDefault() const { return myIsDefault; }
300  void setIsDefault() { myIsDefault = true; }
301 
302 protected:
303  /// If you have a sub-class of XUSD_RenderVar, you can create it here
305  {
306  return UTmakeUnique<XUSD_RenderVar>();
307  }
308 
309  // Member data
315 
316  // Override values
324 
325 };
326 
327 /// XUSD_RenderSettings contains the HdRenderSettings for the render
329  : public UT_NonCopyable
330 {
331 public:
336 
338  virtual ~XUSD_RenderSettings();
339 
340  static void findCameras(UT_Array<SdfPath> &list, UsdPrim prim);
341 
342  /// Since the settings primitive may specify values used by the render
343  /// settings context (like frame count, etc.) we pass in a
344  /// non-const @c context so the initialization process so we can call
345  /// initFromUSD() once we've found the render settings.
346  bool init(const UsdStageRefPtr &usd,
347  const SdfPath &settings_path,
349  /// Alternative initialization with a string path
350  bool init(const UsdStageRefPtr &usd,
351  const UT_StringHolder &settings_path,
353 
354  /// Update the frame
355  bool updateFrame(const UsdStageRefPtr &usd,
357  bool create_dummy_raster_product);
358 
359  /// Resolve products/vars
360  bool resolveProducts(const UsdStageRefPtr &usd,
361  const XUSD_RenderSettingsContext &ctx,
362  bool create_dummy_raster_product);
363 
364  /// Get the render settings
365  UsdPrim prim() const { return myUsdSettings.GetPrim(); }
366 
367  /// Rendering head
368  const TfToken &renderer() const { return myRenderer; }
369 
370  /// Properties from the render settings which cannot be overridden per
371  /// product.
372  const VtArray<TfToken> &purpose() const { return myPurpose; }
373 
374  /// Properties which a render product might override
375  SdfPath cameraPath(const XUSD_RenderProduct *p) const;
376  double shutterOpen(const XUSD_RenderProduct *p) const;
377  double shutterClose(const XUSD_RenderProduct *p) const;
378  int xres(const XUSD_RenderProduct *p) const;
379  int yres(const XUSD_RenderProduct *p) const;
380  GfVec2i res(const XUSD_RenderProduct *p) const;
381  float pixelAspect(const XUSD_RenderProduct *p) const;
382  GfVec4f dataWindowF(const XUSD_RenderProduct *p) const;
383  UT_DimRect dataWindow(const XUSD_RenderProduct *p) const;
384  bool disableMotionBlur(const XUSD_RenderProduct *p) const;
385  UT_StringHolder outputName(int product_group) const;
386 
387  const HdRenderSettingsMap &renderSettings() const { return mySettings; }
388 
389  /// @{
390  /// Render Products
391  const ProductGroupList &productGroups() const { return myProductGroups; }
392  const ProductList &products() const { return myProducts; }
393  const_iterator begin() const { return myProducts.begin(); }
394  const_iterator end() const { return myProducts.end(); }
395  /// @}
396 
397  /// Expand product name variables
398  bool expandProducts(const XUSD_RenderSettingsContext &ctx,
399  int frame,
400  int product_group);
401 
402  /// Print out the settings to UT_ErrorLog
403  void printSettings() const;
404  void dump() const; // Dump for a debug build
405  void dump(UT_JSONWriter &w) const;
406 
407  bool collectAovs(TfTokenVector &aovs,
408  HdAovDescriptorList &descs) const;
409 
411  {
412  INVALID = -1,
413  EXPAND_APERTURE,
414  CROP_APERTURE,
415  ADJUST_HAPERTURE,
416  ADJUST_VAPERTURE,
417  ADJUST_PIXEL_ASPECT,
418  DEFAULT = EXPAND_APERTURE
419  };
420  static HUSD_AspectConformPolicy conformPolicy(const TfToken &t);
421  static const TfToken &conformPolicy(HUSD_AspectConformPolicy policy);
422 
423  // Helper function for calculating a UT_DimRect consistently based on
424  // floating point reoslution and datawindow fractional values.
425  static UT_InclusiveRect computeDataWindow(const GfVec2i &res,
426  const GfVec4f &win);
427 
428  /// When the camera aspect ratio doesn't match the image aspect ratio, USD
429  /// specifies five different approatches to resolving this difference.
430  /// HoudiniGL and Karma only use the vertical aperture and thus have a
431  /// fixed way to resolve aspect ratio differences. This method will adjust
432  /// the vertical aspect or pixel aspect ratio to fit with the five
433  /// different methods described in USD. The method returns true if values
434  /// were changed. The method is templated on single/double precision
435  template <typename T>
436  static bool aspectConform(HUSD_AspectConformPolicy conform,
437  T &vaperture, T &pixel_aspect,
438  T cam_aspect, T img_aspect);
439 
440  /// This method assumes you have render settings defined
441  template <typename T>
442  bool aspectConform(const XUSD_RenderSettingsContext &ctx,
443  T &vaperture, T &pixel_aspect,
444  T cam_aspect, T img_aspect) const;
445 
446  HUSD_AspectConformPolicy conformPolicy(
447  const XUSD_RenderSettingsContext &c) const;
448 
449  // Return a VtValue for all non-raster render products for the delegate
450  // render product interface.
451  VtValue delegateRenderProducts(int product_group) const;
452 
453  virtual bool supportedDelegate(const TfToken &name) const;
454 protected:
456  {
457  return UTmakeUnique<XUSD_RenderProduct>();
458  }
459  void partitionProducts();
460  void computeImageWindows(const UsdStageRefPtr &usd,
461  const XUSD_RenderSettingsContext &ctx);
462  void setDefaults(const UsdStageRefPtr &usd,
463  const XUSD_RenderSettingsContext &ctx);
464  bool loadFromPrim(const UsdStageRefPtr &usd,
465  const XUSD_RenderSettingsContext &ctx);
466  bool loadFromOptions(const UsdStageRefPtr &usd,
467  const XUSD_RenderSettingsContext &ctx);
468  void buildRenderSettings(const UsdStageRefPtr &usd,
469  const XUSD_RenderSettingsContext &ctx);
470  bool isDefaultProduct() const
471  {
472  return myProducts.size() >= 1 && myProducts[0]->isDefault();
473  }
474  /// Check to see whether there have been any unexpected products added (as
475  /// in the mplay monitor or the dummy raster product). Returns true if the
476  /// path list size matches.
477  bool accountForExtraProducts(const SdfPathVector &paths) const;
478 
495 };
496 
498 
499 #endif
const_iterator end() const
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
Definition: vec2i.h:60
const RenderVarList & vars() const
const TfToken & renderer() const
Rendering head.
SettingOverride< bool > myDisableMotionBlur
virtual SdfPath overrideCamera() const
Override the path to the camera.
UsdRenderSettings myUsdSettings
PXL_DataFormat pxlFormat() const
const VtArray< TfToken > & purpose() const
const GLdouble * v
Definition: glcorearb.h:837
XUSD_RenderSettings contains the HdRenderSettings for the render.
virtual void setDefaultSettings(const XUSD_RenderSettings &rset, HdRenderSettingsMap &settings) const
Build initial render settings map.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual const char * overrideSnapshotPath(const XUSD_RenderProduct &p, int pidx) const
Optionally, override the path to the snapshots.
bool cameraPath(SdfPath &val) const
ProductGroupList myProductGroups
int64 exint
Definition: SYS_Types.h:125
#define HUSD_API
Definition: HUSD_API.h:32
virtual GfVec2i overrideResolution(const GfVec2i &res) const
Optionally override the resolution of the product.
bool pixelAspect(float &val) const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
const SdfPath & cameraPath() const
const UT_StringHolder & outputName() const
const_iterator begin() const
SettingOverride< GfVec4f > myDataWindowF
Definition: vec2d.h:62
virtual const char * defaultPurpose() const
Return the default purpose (this is a comma separated list)
virtual bool overrideDisableMotionBlur(bool v) const
Optionally, override the disableMotionBlur.
SettingOverride< GfVec2d > myShutter
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
const TfToken & aovToken() const
virtual const char * overrideProductName(const XUSD_RenderProduct &p, int pidx) const
Return a product name override.
virtual UT_UniquePtr< XUSD_RenderVar > newRenderVar() const
If you have a sub-class of XUSD_RenderVar, you can create it here.
virtual void overrideSettings(const XUSD_RenderSettings &rset, HdRenderSettingsMap &settings) const
After the products have been loaded, apply any overrides.
virtual const char * defaultProductName() const
Default product name.
Definition: token.h:87
PXL_DataFormat myDataFormat
const_iterator begin() const
simple inheritance: W = L * pW
PXR_NAMESPACE_OPEN_SCOPE typedef TfHashMap< TfToken, VtValue, TfToken::HashFunctor > HdAovSettingsMap
Definition: aov.h:38
bool isDefaultProduct() const
HdAovSettingsMap mySettings
const HdAovDescriptor & desc() const
virtual HdAovDescriptor defaultAovDescriptor(const TfToken &aov) const
Get a default rendering descriptor for a given AOV.
const_iterator end() const
const HdAovSettingsMap & settings() const
User settings for this product.
UT_StringHolder myFilename
const HdRenderSettingsMap & renderSettings() const
PXL_Packing
Definition: PXL_Common.h:32
Definition: prim.h:135
std::vector< HdAovDescriptor > HdAovDescriptorList
Definition: aov.h:79
virtual const char * overrideSnapshotSuffix(const XUSD_RenderProduct &p, int pidx) const
Optionally, override the suffix on snapshots.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
GLuint const GLchar * name
Definition: glcorearb.h:786
PXL_DataFormat
Definition: PXL_Common.h:20
virtual GfVec4f overrideDataWindow(const GfVec4f &w) const
Optionally, override the data window.
Definition: path.h:291
HdAovDescriptor myHdDesc
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
virtual bool allowCameraless() const
Allow render options to be applied without a camera present.
const ProductList & products() const
GLdouble t
Definition: glad.h:2397
bool res(GfVec2i &val) const
PXL_Packing pxlPacking() const
VtArray< TfToken > myPurpose
Definition: vec4f.h:62
const ProductGroupList & productGroups() const
UT_StringHolder myPartname
SettingOverride< GfVec2i > myRes
bool dataWindow(GfVec4f &val) const
UsdPrim GetPrim() const
Definition: prim.h:2610
const std::string & aovName() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
virtual void initFromUSD(UsdRenderSettings &settings)
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual const char * overridePurpose() const
Return if there's an overridden purpose for the render.
virtual UT_UniquePtr< XUSD_RenderProduct > newRenderProduct() const
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual const char * tileSuffix() const
Get the tile suffix, if there is one.
HdRenderSettingsMap mySettings
virtual fpreal frameInc() const
Frame increment, when computing sequences.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
HUSD_API const char * productType()
SettingOverride< bool > myInstantaneousShutter
UsdPrim prim() const
Get the render settings.
SettingOverride< float > myPixelAspect
virtual fpreal fps() const
Return the fps.
virtual int tileIndex() const
Get the tile index, defaults to 0.
HUSD_API const char * dataType()
Definition: value.h:167
HUSD_API const char * productName()
bool shutter(GfVec2d &val) const
virtual fpreal overridePixelAspect(fpreal pa) const
Optionally, override the pixel aspect ratio.
virtual int frameCount() const
Return the number of frames being rendered.
HUSD_API const char * disableMotionBlur()
GLenum src
Definition: glcorearb.h:1793