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  /// Override the path to the camera
63  virtual SdfPath overrideCamera() const
64  {
65  return SdfPath();
66  }
67 
68  /// Return the default resolution for rendering products
69  virtual GfVec2i defaultResolution() const = 0;
70 
71  /// Optionally override the resolution of the product
72  virtual GfVec2i overrideResolution(const GfVec2i &res) const
73  {
74  return res;
75  }
76 
77  /// Optionally, override the pixel aspect ratio.
78  virtual fpreal overridePixelAspect(fpreal pa) const { return pa; }
79 
80  /// Optionally, override the data window
81  virtual GfVec4f overrideDataWindow(const GfVec4f &w) const { return w; }
82 
83  /// Optionally, override the disableMotionBlur
84  virtual bool overrideDisableMotionBlur(bool v) const { return v; }
85 
86  /// Return if there's an overridden purpose for the render
87  virtual const char *overridePurpose() const { return nullptr; }
88 
89  /// Return the default purpose (this is a comma separated list)
90  virtual const char *defaultPurpose() const
91  {
92  const char *p = overridePurpose();
93  if (!p)
94  p = "geometry,render";
95  return p;
96  }
97 
98  /// Start frame for a render sequence
99  virtual fpreal startFrame() const = 0;
100 
101  /// Frame increment, when computing sequences
102  virtual fpreal frameInc() const { return 1; }
103 
104  /// Return the number of frames being rendered
105  virtual int frameCount() const { return 1; }
106 
107  /// Start frame for a render sequence
108  virtual const std::vector<fpreal> *frameList() const { return nullptr; }
109 
110  /// Return the fps
111  virtual fpreal fps() const { return 24; }
112 
113  /// Current frame in the render sequence
114  virtual UsdTimeCode evalTime() const = 0;
115 
116  /// Get a default rendering descriptor for a given AOV
117  virtual HdAovDescriptor defaultAovDescriptor(const TfToken &aov) const
118  {
119  return HdAovDescriptor();
120  }
121 
122  /// Default product name
123  virtual const char *defaultProductName() const { return nullptr; }
124 
125  /// Return a product name override
126  virtual const char *overrideProductName(const XUSD_RenderProduct &p,
127  int pidx) const
128  {
129  return nullptr;
130  }
131 
132  /// Optionally, override the path to the snapshots
133  virtual const char *overrideSnapshotPath(const XUSD_RenderProduct &p,
134  int pidx) const
135  {
136  return nullptr;
137  }
138  /// Optionally, override the suffix on snapshots
139  virtual const char *overrideSnapshotSuffix(const XUSD_RenderProduct &p,
140  int pidx) const
141  {
142  return "_part";
143  }
144 
145  /// When rendering with tiles, adjust an product filename for a unique name
146  /// for the given tile.
147  virtual UT_StringHolder addTileSuffix(const UT_StringHolder &fname) const
148  {
149  return fname;
150  }
151 
152  /// Build initial render settings map
153  virtual void setDefaultSettings(const XUSD_RenderSettings &rset,
154  HdRenderSettingsMap &settings) const
155  { }
156 
157  /// After the products have been loaded, apply any overrides
158  virtual void overrideSettings(const XUSD_RenderSettings &rset,
159  HdRenderSettingsMap &settings) const
160  { }
161 
162  /// Allow render options to be applied without a camera present.
163  virtual bool allowCameraless() const { return false; }
164 };
165 
167  : public UT_NonCopyable
168 {
169 public:
170  XUSD_RenderVar();
171  virtual ~XUSD_RenderVar();
172 
173  bool loadFrom(const UsdRenderVar &prim,
174  const XUSD_RenderSettingsContext &ctx);
175  bool resolveFrom(const UsdRenderVar &prim,
176  const XUSD_RenderSettingsContext &ctx);
177  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
178 
179  virtual UT_UniquePtr<XUSD_RenderVar> clone() const;
180 
181  const std::string &aovName() const { return myAovName; }
182  const TfToken &aovToken() const { return myAovToken; }
183  const TfToken &dataType() const;
184  const std::string &sourceName() const;
185  const TfToken &sourceType() const;
186 
187  const HdAovDescriptor &desc() const { return myHdDesc; }
188  PXL_DataFormat pxlFormat() const { return myDataFormat; }
189  PXL_Packing pxlPacking() const { return myPacking; }
190 
191  /// Print out the settings
192  void dump(UT_JSONWriter &w) const;
193 
194 protected:
196  std::string myAovName;
200 };
201 
203  : public UT_NonCopyable
204 {
205 public:
208 
210  virtual ~XUSD_RenderProduct();
211 
212  bool loadFrom(const UsdStageRefPtr &usd,
213  const UsdRenderProduct &prim,
214  const XUSD_RenderSettingsContext &ctx);
215  bool resolveFrom(const UsdStageRefPtr &usd,
216  const UsdRenderProduct &prim,
217  const XUSD_RenderSettingsContext &ctx);
218  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
219  bool buildDummyRaster(const XUSD_RenderSettingsContext &ctx,
220  const XUSD_RenderProduct &src);
221 
222  void updateSettings(const UsdStageRefPtr &use,
223  const UsdRenderProduct &prim,
224  const XUSD_RenderSettingsContext &ctx);
225 
226  const TfToken &productType() const;
227  TfToken productName(int frame = 0) const;
228 
229  bool isRaster() const;
230 
231  // Current output filename (with all variables expanded)
232  const UT_StringHolder &outputName() const { return myFilename; }
233 
234  // Full filename (without tile suffix)
235  const UT_StringHolder &fullOutputName() const { return myFullFilename; }
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  UT_Set<UT_StringHolder> &other_products);
298  bool collectAovs(TfTokenVector &aovs,
299  HdAovDescriptorList &descs) const;
300 
301  /// User settings for this product
302  const HdAovSettingsMap &settings() const { return mySettings; }
303 
304  /// Print out the settings
305  void dump(UT_JSONWriter &w) const;
306 
307  bool isDefault() const { return myIsDefault; }
308  void setIsDefault() { myIsDefault = true; }
309 
310 protected:
311  /// If you have a sub-class of XUSD_RenderVar, you can create it here
313  {
314  return UTmakeUnique<XUSD_RenderVar>();
315  }
316 
317  // Member data
324 
325  // Override values
334 
335 };
336 
337 /// XUSD_RenderSettings contains the HdRenderSettings for the render
339  : public UT_NonCopyable
340 {
341 public:
346 
348  virtual ~XUSD_RenderSettings();
349 
350  static void findCameras(UT_Array<SdfPath> &list, UsdPrim prim);
351 
352  /// Since the settings primitive may specify values used by the render
353  /// settings context (like frame count, etc.) we pass in a
354  /// non-const @c context so the initialization process so we can call
355  /// initFromUSD() once we've found the render settings.
356  bool init(const UsdStageRefPtr &usd,
357  const SdfPath &settings_path,
359  /// Alternative initialization with a string path
360  bool init(const UsdStageRefPtr &usd,
361  const UT_StringHolder &settings_path,
363 
364  /// Update the frame
365  bool updateFrame(const UsdStageRefPtr &usd,
367  HUSD_CustomProductAction custom_product_action);
368 
369  /// Resolve products/vars
370  bool resolveProducts(const UsdStageRefPtr &usd,
371  const XUSD_RenderSettingsContext &ctx,
372  HUSD_CustomProductAction custom_product_action);
373 
374  /// Get the render settings
375  UsdPrim prim() const { return myUsdSettings.GetPrim(); }
376 
377  /// Properties from the render settings which cannot be overridden per
378  /// product.
379  const VtArray<TfToken> &purpose() const { return myPurpose; }
380 
381  /// Properties which a render product might override
382  SdfPath cameraPath(const XUSD_RenderProduct *p) const;
383  double shutterOpen(const XUSD_RenderProduct *p) const;
384  double shutterClose(const XUSD_RenderProduct *p) const;
385  int xres(const XUSD_RenderProduct *p) const;
386  int yres(const XUSD_RenderProduct *p) const;
387  GfVec2i res(const XUSD_RenderProduct *p) const;
388  float pixelAspect(const XUSD_RenderProduct *p) const;
389  GfVec4f dataWindowF(const XUSD_RenderProduct *p) const;
390  UT_DimRect dataWindow(const XUSD_RenderProduct *p) const;
391  bool disableMotionBlur(const XUSD_RenderProduct *p) const;
392  bool disableDepthOfField(const XUSD_RenderProduct *p) const;
393  UT_StringHolder outputName(int product_group) const;
394 
395  const HdRenderSettingsMap &renderSettings() const { return mySettings; }
396 
397  /// @{
398  /// Render Products
399  const ProductGroupList &productGroups() const { return myProductGroups; }
400  const ProductList &products() const { return myProducts; }
401  const_iterator begin() const { return myProducts.begin(); }
402  const_iterator end() const { return myProducts.end(); }
403  /// @}
404 
405  /// Expand product name variables
406  bool expandProducts(const XUSD_RenderSettingsContext &ctx,
407  int frame,
408  int product_group,
409  bool delegate_products);
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  /// Check if the karma random seed was authored
461  bool getKarmaRandomSeed(int64 &seed,
462  const XUSD_RenderSettingsContext &ctx) const;
463 
464 protected:
466  { return UTmakeUnique<XUSD_RenderProduct>(); }
467 
468  void partitionProducts();
469  void computeImageWindows(const UsdStageRefPtr &usd,
470  const XUSD_RenderSettingsContext &ctx);
471  void setDefaults(const UsdStageRefPtr &usd,
472  const XUSD_RenderSettingsContext &ctx);
473  bool loadFromPrim(const UsdStageRefPtr &usd,
474  const XUSD_RenderSettingsContext &ctx);
475  bool loadFromOptions(const UsdStageRefPtr &usd,
476  const XUSD_RenderSettingsContext &ctx);
477  void buildRenderSettings(const UsdStageRefPtr &usd,
478  const XUSD_RenderSettingsContext &ctx);
479  bool isDefaultProduct() const
480  { return myProducts.size() >= 1 && myProducts[0]->isDefault(); }
481  /// Check to see whether there have been any unexpected products added (as
482  /// in the mplay monitor or the dummy raster product). Returns true if the
483  /// path list size matches.
484  bool accountForExtraProducts(const SdfPathVector &paths) const;
485 
486  VtValue renderProducts(int product_group, bool raster) const;
487 
504 };
505 
507 
508 #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:43
const RenderVarList & vars() const
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.
UT_StringHolder myFullFilename
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:31
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:45
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 UT_StringHolder addTileSuffix(const UT_StringHolder &fname) const
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:70
PXL_DataFormat myDataFormat
const_iterator begin() const
std::vector< class SdfPath > SdfPathVector
PXR_NAMESPACE_OPEN_SCOPE typedef TfHashMap< TfToken, VtValue, TfToken::HashFunctor > HdAovSettingsMap
Definition: aov.h:21
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()
long long int64
Definition: SYS_Types.h:116
Definition: prim.h:116
std::vector< HdAovDescriptor > HdAovDescriptorList
Definition: aov.h:62
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:440
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:273
HdAovDescriptor myHdDesc
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:45
const ProductGroupList & productGroups() const
UT_StringHolder myPartname
SettingOverride< GfVec2i > myRes
bool dataWindow(GfVec4f &val) const
UsdPrim GetPrim() const
Definition: prim.h:2787
const std::string & aovName() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual void initFromUSD(UsdRenderSettings &settings)
fpreal64 fpreal
Definition: SYS_Types.h:278
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:112
virtual UT_UniquePtr< XUSD_RenderProduct > newRenderProduct() const
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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()
const UT_StringHolder & fullOutputName() const
SettingOverride< bool > myInstantaneousShutter
UsdPrim prim() const
Get the render settings.
SettingOverride< float > myPixelAspect
virtual fpreal fps() const
Return the fps.
HUSD_API const char * dataType()
Definition: value.h:146
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:129