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 "HUSD_Utils.h"
26 #include <PXL/PXL_Common.h>
27 #include <UT/UT_Array.h>
28 #include <UT/UT_NonCopyable.h>
29 #include <UT/UT_Rect.h>
30 #include <UT/UT_StringHolder.h>
31 #include <UT/UT_UniquePtr.h>
32 #include <SYS/SYS_Types.h>
33 #include <pxr/pxr.h>
34 #include <pxr/imaging/hd/aov.h>
38 #include <pxr/usd/usdRender/var.h>
39 
40 #include <string>
41 
42 class UT_JSONWriter;
43 
45 
46 class XUSD_RenderProduct;
48 
50  : public UT_NonCopyable
51 {
52 public:
54  virtual ~XUSD_RenderSettingsContext();
55 
56  /// Update any settings from the render settings primitive. This allows
57  /// the context to look at custom attributes on the RenderSettings.
58  ///
59  /// This function will always be called - even if there are no settings.
60  virtual void initFromUSD(UsdRenderSettings &settings) { }
61 
62  /// Return the name of the render delegate
63  virtual TfToken renderer() const = 0;
64 
65  /// Override the path to the camera
66  virtual SdfPath overrideCamera() const
67  {
68  return SdfPath();
69  }
70 
71  /// Return the default resolution for rendering products
72  virtual GfVec2i defaultResolution() const = 0;
73 
74  /// Optionally override the resolution of the product
75  virtual GfVec2i overrideResolution(const GfVec2i &res) const
76  {
77  return res;
78  }
79 
80  /// Optionally, override the pixel aspect ratio.
81  virtual fpreal overridePixelAspect(fpreal pa) const { return pa; }
82 
83  /// Optionally, override the data window
84  virtual GfVec4f overrideDataWindow(const GfVec4f &w) const { return w; }
85 
86  /// Optionally, override the disableMotionBlur
87  virtual bool overrideDisableMotionBlur(bool v) const { return v; }
88 
89  /// Return if there's an overridden purpose for the render
90  virtual const char *overridePurpose() const { return nullptr; }
91 
92  /// Return the default purpose (this is a comma separated list)
93  virtual const char *defaultPurpose() const
94  {
95  const char *p = overridePurpose();
96  if (!p)
97  p = "geometry,render";
98  return p;
99  }
100 
101  /// Start frame for a render sequence
102  virtual fpreal startFrame() const = 0;
103 
104  /// Frame increment, when computing sequences
105  virtual fpreal frameInc() const { return 1; }
106 
107  /// Return the number of frames being rendered
108  virtual int frameCount() const { return 1; }
109 
110  /// Start frame for a render sequence
111  virtual const std::vector<fpreal> *frameList() const { return nullptr; }
112 
113  /// Return the fps
114  virtual fpreal fps() const { return 24; }
115 
116  /// Current frame in the render sequence
117  virtual UsdTimeCode evalTime() const = 0;
118 
119  /// Get a default rendering descriptor for a given AOV
120  virtual HdAovDescriptor defaultAovDescriptor(const TfToken &aov) const
121  {
122  return HdAovDescriptor();
123  }
124 
125  /// Default product name
126  virtual const char *defaultProductName() const { return nullptr; }
127 
128  /// Return a product name override
129  virtual const char *overrideProductName(const XUSD_RenderProduct &p,
130  int pidx) const
131  {
132  return nullptr;
133  }
134 
135  /// Optionally, override the path to the snapshots
136  virtual const char *overrideSnapshotPath(const XUSD_RenderProduct &p,
137  int pidx) const
138  {
139  return nullptr;
140  }
141  /// Optionally, override the suffix on snapshots
142  virtual const char *overrideSnapshotSuffix(const XUSD_RenderProduct &p,
143  int pidx) const
144  {
145  return "_part";
146  }
147 
148 
149  /// Get the tile suffix, if there is one
150  virtual const char *tileSuffix() const { return nullptr; }
151 
152  /// Get the tile index, defaults to 0
153  virtual int tileIndex() const { return 0; }
154 
155  /// Build initial render settings map
156  virtual void setDefaultSettings(const XUSD_RenderSettings &rset,
157  HdRenderSettingsMap &settings) const
158  { }
159 
160  /// After the products have been loaded, apply any overrides
161  virtual void overrideSettings(const XUSD_RenderSettings &rset,
162  HdRenderSettingsMap &settings) const
163  { }
164 
165  /// Allow render options to be applied without a camera present.
166  virtual bool allowCameraless() const { return false; }
167 };
168 
170  : public UT_NonCopyable
171 {
172 public:
173  XUSD_RenderVar();
174  virtual ~XUSD_RenderVar();
175 
176  bool loadFrom(const UsdRenderVar &prim,
177  const XUSD_RenderSettingsContext &ctx);
178  bool resolveFrom(const UsdRenderVar &prim,
179  const XUSD_RenderSettingsContext &ctx);
180  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
181 
182  virtual UT_UniquePtr<XUSD_RenderVar> clone() const;
183 
184  const std::string &aovName() const { return myAovName; }
185  const TfToken &aovToken() const { return myAovToken; }
186  const TfToken &dataType() const;
187  const std::string &sourceName() const;
188  const TfToken &sourceType() const;
189 
190  const HdAovDescriptor &desc() const { return myHdDesc; }
191  PXL_DataFormat pxlFormat() const { return myDataFormat; }
192  PXL_Packing pxlPacking() const { return myPacking; }
193 
194  /// Print out the settings
195  void dump(UT_JSONWriter &w) const;
196 
197 protected:
203 };
204 
206  : public UT_NonCopyable
207 {
208 public:
211 
213  virtual ~XUSD_RenderProduct();
214 
215  bool loadFrom(const UsdStageRefPtr &usd,
216  const UsdRenderProduct &prim,
217  const XUSD_RenderSettingsContext &ctx);
218  bool resolveFrom(const UsdStageRefPtr &usd,
219  const UsdRenderProduct &prim,
220  const XUSD_RenderSettingsContext &ctx);
221  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
222  bool buildDummyRaster(const XUSD_RenderSettingsContext &ctx,
223  const XUSD_RenderProduct &src);
224 
225  void updateSettings(const UsdStageRefPtr &use,
226  const UsdRenderProduct &prim,
227  const XUSD_RenderSettingsContext &ctx);
228 
229  const TfToken &productType() const;
230  TfToken productName(int frame = 0) const;
231 
232  bool isRaster() const;
233 
234  // Current output filename (with all variables expanded)
235  const UT_StringHolder &outputName() const { return myFilename; }
236 
237  const RenderVarList &vars() const { return myVars; }
238 
239  /// @{
240  /// Properties that can override settings defined on a render settings
241  /// primitive The functions return true if they are authored on the
242  /// product.
243  template <typename T>
245  {
246  void clear() { myAuthored = false; }
247  bool import(T &val) const
248  {
249  if (myAuthored)
250  {
251  val = myValue;
252  return true;
253  }
254  return false;
255  }
257  bool myAuthored = false;
258  };
259  bool cameraPath(SdfPath &val) const
260  {
261  if (myCameraPath.IsEmpty())
262  return false;
263  val = myCameraPath;
264  return true;
265  }
266  bool shutter(GfVec2d &val) const { return myShutter.import(val); }
267  bool res(GfVec2i &val) const { return myRes.import(val); }
268  bool pixelAspect(float &val) const { return myPixelAspect.import(val); }
269  bool dataWindow(GfVec4f &val) const { return myDataWindowF.import(val); }
270  bool disableMotionBlur(bool &val) const;
271  bool disableDepthOfField(bool &val) const;
272  /// @}
273 
274  /// @{
275  /// Test whether the product list has a specific value for the given
276  /// attribute. If so, overwrite the value with the value of the product
277  /// list. Note, all products must author the attribute and have the same
278  /// value.
280  static bool specificRes(GfVec2i &val, const ProductList &products);
281  static bool specificPixelAspect(float &val, const ProductList &products);
282  static bool specificDataWindow(GfVec4f &val, const ProductList &products);
283  static bool specificDisableMotionBlur(bool &val, const ProductList &products);
284  static bool specificDisableDepthOfField(bool &val, const ProductList &products);
285  /// @}
286 
287  const SdfPath &cameraPath() const { return myCameraPath; }
288 
289  const_iterator begin() const { return myVars.begin(); }
290  const_iterator end() const { return myVars.end(); }
291 
292  /// Expand product name variables. Returns false if there are multiple
293  /// frames, but no frame expansion. The @c product_index is -1 for
294  /// non-raster products or the offset into the list of raster products.
295  bool expandProduct(const XUSD_RenderSettingsContext &opts,
296  int product_index, int frame);
297  bool collectAovs(TfTokenVector &aovs,
298  HdAovDescriptorList &descs) const;
299 
300  /// User settings for this product
301  const HdAovSettingsMap &settings() const { return mySettings; }
302 
303  /// Print out the settings
304  void dump(UT_JSONWriter &w) const;
305 
306  bool isDefault() const { return myIsDefault; }
307  void setIsDefault() { myIsDefault = true; }
308 
309 protected:
310  /// If you have a sub-class of XUSD_RenderVar, you can create it here
312  {
313  return UTmakeUnique<XUSD_RenderVar>();
314  }
315 
316  // Member data
322 
323  // Override values
332 
333 };
334 
335 /// XUSD_RenderSettings contains the HdRenderSettings for the render
337  : public UT_NonCopyable
338 {
339 public:
344 
346  virtual ~XUSD_RenderSettings();
347 
348  static void findCameras(UT_Array<SdfPath> &list, UsdPrim prim);
349 
350  /// Since the settings primitive may specify values used by the render
351  /// settings context (like frame count, etc.) we pass in a
352  /// non-const @c context so the initialization process so we can call
353  /// initFromUSD() once we've found the render settings.
354  bool init(const UsdStageRefPtr &usd,
355  const SdfPath &settings_path,
357  /// Alternative initialization with a string path
358  bool init(const UsdStageRefPtr &usd,
359  const UT_StringHolder &settings_path,
361 
362  /// Update the frame
363  bool updateFrame(const UsdStageRefPtr &usd,
365  HUSD_CustomProductAction custom_product_action);
366 
367  /// Resolve products/vars
368  bool resolveProducts(const UsdStageRefPtr &usd,
369  const XUSD_RenderSettingsContext &ctx,
370  HUSD_CustomProductAction custom_product_action);
371 
372  /// Get the render settings
373  UsdPrim prim() const { return myUsdSettings.GetPrim(); }
374 
375  /// Rendering head
376  const TfToken &renderer() const { return myRenderer; }
377 
378  /// Properties from the render settings which cannot be overridden per
379  /// product.
380  const VtArray<TfToken> &purpose() const { return myPurpose; }
381 
382  /// Properties which a render product might override
383  SdfPath cameraPath(const XUSD_RenderProduct *p) const;
384  double shutterOpen(const XUSD_RenderProduct *p) const;
385  double shutterClose(const XUSD_RenderProduct *p) const;
386  int xres(const XUSD_RenderProduct *p) const;
387  int yres(const XUSD_RenderProduct *p) const;
388  GfVec2i res(const XUSD_RenderProduct *p) const;
389  float pixelAspect(const XUSD_RenderProduct *p) const;
390  GfVec4f dataWindowF(const XUSD_RenderProduct *p) const;
391  UT_DimRect dataWindow(const XUSD_RenderProduct *p) const;
392  bool disableMotionBlur(const XUSD_RenderProduct *p) const;
393  bool disableDepthOfField(const XUSD_RenderProduct *p) const;
394  UT_StringHolder outputName(int product_group) const;
395 
396  const HdRenderSettingsMap &renderSettings() const { return mySettings; }
397 
398  /// @{
399  /// Render Products
400  const ProductGroupList &productGroups() const { return myProductGroups; }
401  const ProductList &products() const { return myProducts; }
402  const_iterator begin() const { return myProducts.begin(); }
403  const_iterator end() const { return myProducts.end(); }
404  /// @}
405 
406  /// Expand product name variables
407  bool expandProducts(const XUSD_RenderSettingsContext &ctx,
408  int frame,
409  int product_group);
410 
411  /// Print out the settings to UT_ErrorLog
412  void printSettings() const;
413  void dump() const; // Dump for a debug build
414  void dump(UT_JSONWriter &w) const;
415 
416  bool collectAovs(TfTokenVector &aovs,
417  HUSD_CustomProductAction custom_product_action,
418  HdAovDescriptorList &descs) const;
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  { return renderProducts(product_group, false); }
453 
454  // Return a VtValue for the raster render products.
455  VtValue rasterRenderProducts(int product_group) const
456  { return renderProducts(product_group, true); }
457 
458  virtual bool supportedDelegate(const TfToken &name) const;
459 
460 protected:
462  { return UTmakeUnique<XUSD_RenderProduct>(); }
463 
464  void partitionProducts();
465  void computeImageWindows(const UsdStageRefPtr &usd,
466  const XUSD_RenderSettingsContext &ctx);
467  void setDefaults(const UsdStageRefPtr &usd,
468  const XUSD_RenderSettingsContext &ctx);
469  bool loadFromPrim(const UsdStageRefPtr &usd,
470  const XUSD_RenderSettingsContext &ctx);
471  bool loadFromOptions(const UsdStageRefPtr &usd,
472  const XUSD_RenderSettingsContext &ctx);
473  void buildRenderSettings(const UsdStageRefPtr &usd,
474  const XUSD_RenderSettingsContext &ctx);
475  bool isDefaultProduct() const
476  { return myProducts.size() >= 1 && myProducts[0]->isDefault(); }
477  /// Check to see whether there have been any unexpected products added (as
478  /// in the mplay monitor or the dummy raster product). Returns true if the
479  /// path list size matches.
480  bool accountForExtraProducts(const SdfPathVector &paths) const;
481 
482  VtValue renderProducts(int product_group, bool raster) const;
483 
501 };
502 
504 
505 #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
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.
SettingOverride< bool > myDisableDepthOfField
const_iterator end() const
const HdAovSettingsMap & settings() const
User settings for this product.
UT_StringHolder myFilename
const HdRenderSettingsMap & renderSettings() const
VtValue rasterRenderProducts(int product_group) const
PXL_Packing
Definition: PXL_Common.h:32
HUSD_API const char * raster()
Definition: prim.h:133
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:457
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:290
HdAovDescriptor myHdDesc
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
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
VtValue delegateRenderProducts(int product_group) 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:2804
const std::string & aovName() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
virtual void initFromUSD(UsdRenderSettings &settings)
fpreal64 fpreal
Definition: SYS_Types.h:277
virtual const std::vector< fpreal > * frameList() const
Start frame for a render sequence.
virtual const char * overridePurpose() const
Return if there's an overridden purpose for the render.
HUSD_AspectConformPolicy
Definition: HUSD_Utils.h:106
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:164
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
HUSD_CustomProductAction
Definition: HUSD_Utils.h:123