HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BRAY_Interface.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: BRAY_Interface.h (BRAY Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __BRAY_Interface__
12 #define __BRAY_Interface__
13 
14 #include "BRAY_API.h"
15 #include <UT/UT_Array.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_StringArray.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_Options.h>
20 #include <UT/UT_SharedPtr.h>
21 #include <UT/UT_IntrusivePtr.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_Rect.h>
24 #include <UT/UT_Set.h>
25 #include <UT/UT_VectorTypes.h>
26 #include <GT/GT_Handles.h>
27 #include <GT/GT_DataArray.h>
28 #include <PXL/PXL_Common.h>
29 #include "BRAY_Types.h"
30 
31 // Classes referenced by the interface
32 class BRAY_Procedural;
34 class BRAY_AOVBuffer;
35 class BRAY_Camera;
36 class BRAY_Object;
37 class BRAY_Renderer;
38 class BRAY_Light;
39 class BRAY_Scene;
40 class BRAY_ShaderGraph;
41 class BRAY_ShaderInstance;
42 class BRAY_VexMaterial;
43 class VPRM_Space;
44 class VPRM_OptionSet;
45 class UT_JSONWriter;
46 
49 
50 namespace BRAY
51 {
52 
53 class CameraPtr;
54 class LightPtr;
55 class MaterialPtr;
56 class ObjectPtr;
57 class ScenePtr;
58 class ShaderGraphPtr;
59 
61 {
62 public:
63  SpacePtr();
64  SpacePtr(const VPRM_SpacePtr &s);
65  SpacePtr(const SpacePtr &s);
66  SpacePtr(const UT_Matrix4D &xforms);
67  SpacePtr(const UT_Matrix4D *xforms, size_t num_motion_segments);
68  ~SpacePtr();
69  SpacePtr &operator=(const SpacePtr &s);
70 
71  /// @{
72  /// Private access
73  bool isValid() const { return mySpace.get() != nullptr; }
74  VPRM_SpacePtr &space() { return mySpace; }
75  const VPRM_SpacePtr &space() const { return mySpace; }
76  /// @}
77  /// Bool operator to test validity of pointer
78  SYS_SAFE_BOOL operator bool() const { return isValid(); }
79 
80  /// Multiply by the given space (i.e. this * sp)
81  SpacePtr mulSpace(const SpacePtr &sp) const;
82 
83  /// Return the number of motion segments
84  int motionSegments() const;
85  const UT_Matrix4D &getTransform(int segment) const;
86  void getTransform(UT_Matrix4D &x, BRAYtime shutter) const;
87  void dump() const;
88  void dump(UT_JSONWriter &w) const;
89 private:
90  VPRM_SpacePtr mySpace;
91 };
92 
93 /// The OptionSet acts as a pointer to an underlying set of options for various
94 /// different object types.
96 {
97 public:
98  OptionSet();
99  /// The copy c-tor will copy the underlying pointer, but refer to the same
100  /// underlying object.
101  OptionSet(const OptionSet &src);
102  OptionSet(const VPRM_OptionSetPtr &o);
103  ~OptionSet();
104 
105  /// The assignment operator will change the pointer to the underlying
106  /// object. Both OptionSets will point to the same underlying object.
107  OptionSet &operator=(const OptionSet &o);
108 
109  /// This will create a new OptionSet, inheriting state information from the
110  /// this option set. Note that changing values in the this set @b may
111  /// result in unexpected changes in the new option set.
112  OptionSet duplicate() const;
113 
114  /// Returns true if property can be erased to revert back to default value.
115  /// If the options aren't inherited (i.e. offline render), it cannot be
116  /// erased.
117  bool canErase(int token) const;
118 
119  /// Erase properties
120  void erase(const UT_Set<int> &tokens);
121 
122  /// @{
123  /// Private access
124  bool isValid() const { return myOptions.get() != nullptr; }
125  VPRM_OptionSetPtr &options() { return myOptions; }
126  const VPRM_OptionSetPtr &options() const { return myOptions; }
127  /// @}
128  /// Bool operator to test validity of pointer
129  SYS_SAFE_BOOL operator bool() const { return isValid(); }
130 
131  /// Return the name associated with a given option (i.e. dicingquality)
132  const UT_StringHolder &name(int token) const;
133 
134  /// Return the fully qualified name (i.e. karma::object::dicingquality)
135  UT_StringHolder fullName(int token) const;
136 
137  /// Return the token associated with a given name (or -1 if invalid)
138  int find(const UT_StringRef &name) const;
139 
140  /// Import a property value. Method is specialized for T in:
141  /// - bool
142  /// - int32/int64
143  /// - fpreal32/fpreal64
144  /// - UT_StringHolder
145  template <typename T>
146  const T *import(int token, T *val, size_t n) const;
147 
148  /// Interface to set an property. This template class is specialized for:
149  /// - bool
150  /// - int32
151  /// - int64
152  /// - fpreal32
153  /// - fpreal64
154  /// - UT_StringHolder
155  template <typename T>
156  bool set(int token, const T *value, exint tuple_size);
157 
158  /// Simple interface to set a scalar property
159  template <typename T>
160  SYS_FORCE_INLINE bool set(int token, const T &value)
161  {
162  return set(token, &value, 1);
163  }
164 
165  /// Test whether a value is the same as the current property
166  template <typename T>
167  bool isEqual(int token, const T *value, exint tuple_size) const;
168 
169  /// Simple interface for equality of a scalar value.
170  template <typename T>
171  SYS_FORCE_INLINE bool isEqual(int token, const T &value) const
172  {
173  return isEqual(token, &value, 1);
174  }
175 
176  /// Test whether an option has variadic arguments
177  bool isVariadic(int token) const;
178 
179  /// Return the size of an option. This can be used for variadics
180  exint size(int token) const;
181 
182  /// Return the storage of an option. This will only be one of:
183  /// - GT_STORE_INVALID
184  /// - GT_STORE_UINT8 (for bool storage)
185  /// - GT_STORE_INT64
186  /// - GT_STORE_REAL64
187  /// - GT_STORE_STRING
188  GT_Storage storage(int token) const;
189 
190  /// @{
191  /// Direct access to internal option data. There are no checks on these
192  /// methods
193  const bool *bval(int token) const;
194  const int64 *ival(int token) const;
195  const fpreal64 *fval(int token) const;
196  const UT_StringHolder *sval(int token) const;
197  /// @}
198 
199  /// @private Debug the options (only available in debug builds)
200  void dump(UT_JSONWriter &w) const;
201 
202 private:
203  VPRM_OptionSetPtr myOptions;
204 };
205 
206 /// When defining materials for face sets, the material specification is
207 /// given by a pair of the @c MaterialPtr and an array of integers. The
208 /// integers specify the list of faces to material and must appear in
209 /// sorted order (smallest to largest).
210 /// Interface to the scene manager
212 {
213 public:
214  ScenePtr() = default;
215  ~ScenePtr();
216 
217  /// Allocate a new scene
218  static ScenePtr allocScene();
219 
220  /// convenience methods to determine which renderer is active (tests
221  /// the value of the BRAY_OPT_ENGINE option)
222  bool isKarmaCPU() const;
223  bool isKarmaXPU() const;
224 
225  /// Test validity
226  bool isValid() const { return myScene.get() != nullptr; }
227 
228  /// Test whether the scene is thread-safe
229  bool threadSafe() const;
230 
231  /// Test whether the renderer supports nested instancing
232  bool nestedInstancing() const;
233 
234  /// Update an object in the scene
235  void updateObject(const ObjectPtr &ptr, BRAY_EventType event);
236 
237  /// Update light object in the scene
238  void updateLight(const LightPtr &ptr, BRAY_EventType event);
239 
240  /// Update camera object in the scene
241  void updateCamera(const CameraPtr &ptr, BRAY_EventType event);
242 
243  /// Update material object in the scene
244  void updateMaterial(const MaterialPtr &ptr, BRAY_EventType event);
245 
246  /// @{
247  /// Set the unit scale for the scene - this is in meters/unit. For
248  /// example, centimeters would be 0.01.
249  void setSceneUnits(fpreal64 units);
250  fpreal64 sceneUnits() const;
251  /// @}
252 
253  /// Set camera ray visibility. The mask should be a combination of
254  /// - BRAY_RAY_CAMERA
255  /// - BRAY_PROXY_CAMERA
256  /// - BRAY_GUIDE_CAMERA
257  /// For example, (BRAY_RAY_CAMERA|BRAY_GUIDE_CAMERA) will cause guide and
258  /// renderable object to be visible to camera rays, but not proxy objects
259  void setCameraRayMask(BRAY_RayVisibility mask);
260 
261  /// Set shadow ray visibility. The mask should be a combination of
262  /// - BRAY_RAY_SHADOW
263  /// - BRAY_PROXY_SHADOW
264  /// - BRAY_GUIDE_SHADOW
265  /// For example, (BRAY_RAY_SHADOW|BRAY_PROXY_SHADOW) will cause proxy and
266  /// renderable object to cast shadows, but not GUIDE objects.
267  void setShadowRayMask(BRAY_RayVisibility mask);
268 
269  /// Force redicing of displacement and subd surfaces on the next render.
270  /// This will only take effect on the next call to beginRender().
271  void forceRedice();
272 
273  /// @{
274  /// Private access to the underling scene
275  SYS_SAFE_BOOL operator bool() const { return isValid(); }
276  const BRAY_Scene *scenePtr() const { return myScene.get(); }
277  BRAY_Scene *scenePtr() { return myScene.get(); }
278  /// @}
279 
280  /// After changing any options, must commit prior to rendering
281  void commitOptions();
282 
283  /// @{
284  /// Grab a copy of the current scene options
285  OptionSet sceneOptions();
286  const OptionSet constSceneOptions() const;
287  /// @}
288 
289  /// @{
290  /// Grab a copy of the current object properties.
291  OptionSet objectProperties();
292  const OptionSet constObjectProperties() const;
293  /// @}
294 
295  /// @{
296  /// Grab a copy of the current light properties
297  OptionSet lightProperties();
298  const OptionSet constLightProperties() const;
299 
300  /// @{
301  /// Grab a copy of the current camera properties
302  OptionSet cameraProperties();
303  const OptionSet constCameraProperties() const;
304  /// @}
305 
306  /// Grab a copy of the current image plane properties
307  OptionSet planeProperties();
308  const OptionSet constPlaneProperties() const;
309  /// @}
310 
311  /// Grab a the default properties for a given type. Changing their values
312  /// will cause all future objects created to inherit the new values.
313  OptionSet defaultProperties(BRAY_PropertyType type) const;
314 
315  /// @{
316  /// Convenience methods to look up scene and scene options.
317  /// Get an scene option value.
318  template <typename T>
320  T *val, size_t n) const
321  {
322  return constSceneOptions().import(token, val, n);
323  }
324 
325  /// Interface to set an option. This template class is specialized for:
326  template <typename T>
328  const T *value,
329  exint tuple_size)
330  {
331  return sceneOptions().set(token, value, tuple_size);
332  }
333 
334  /// Simple interface to set a scalar option
335  template <typename T>
336  SYS_FORCE_INLINE bool
338  {
339  return setOption(token, &value, 1);
340  }
341 
342  /// Return the size of an option. This can be used for variadics
343  /// (e.g. shading quality will be 1)
345  {
346  return constSceneOptions().size(token);
347  }
348 
349  /// Return the storage class of an option.
352  {
353  return constSceneOptions().storage(token);
354  }
355 
356  /// Return whether an option has variadic arguments
357  SYS_FORCE_INLINE bool
359  {
360  return constSceneOptions().isVariadic(token);
361  }
363  { return *constSceneOptions().bval(t); }
365  { return *constSceneOptions().ival(t); }
367  { return *constSceneOptions().fval(t); }
369  { return *constSceneOptions().sval(t); }
370  /// @}
371 
372  /// @{
373  /// Convenience methods to look up object properties.
374  /// Get an object property value.
375  template <typename T>
377  T *val, size_t n) const
378  {
379  return constObjectProperties().import(token, val, n);
380  }
381 
382  /// Interface to set an property. This template class is specialized for:
383  template <typename T>
385  const T *value,
386  exint tuple_size)
387  {
388  return objectProperties().set(token, value, tuple_size);
389  }
390 
391  /// Locking the object property prevents any overriding of the property
392  /// after the fact, essentially turning the property into a read-only
393  /// property. This method is intended to lock default properties. The
394  /// current value of the property is used as the value.
395  ///
396  /// The return value is the previous lock state of the property.
397  bool lockProperty(BRAY_ObjectProperty token, bool state);
398 
399  /// Lock properties based on a string pattern of parameter names. This
400  /// method returns the number of properties modified.
401  exint lockProperties(const char *pattern, bool state);
402 
403  /// Lock or unlock all object properties.
405  { return lockProperties("*", state); }
406 
407  /// Simple interface to set a scalar property
408  template <typename T>
409  SYS_FORCE_INLINE bool
411  {
412  return setProperty(token, &value, 1);
413  }
414 
415  /// Return the size of an option. This can be used for variadics
416  /// (e.g. shading quality will be 1)
418  {
419  return constObjectProperties().size(token);
420  }
421 
422  /// Return the storage class of an option.
425  {
426  return constObjectProperties().storage(token);
427  }
428 
429  /// Return whether an property has variadic arguments
430  SYS_FORCE_INLINE bool
432  {
433  return constObjectProperties().isVariadic(token);
434  }
436  { return *constObjectProperties().bval(t); }
438  { return *constObjectProperties().ival(t); }
440  { return *constObjectProperties().fval(t); }
442  { return *constObjectProperties().sval(t); }
443  /// @}
444 
445  /// Create a light
446  LightPtr createLight(const UT_StringHolder &name);
447 
448  /// Create a camera
449  CameraPtr createCamera(const UT_StringHolder &name);
450 
451  /// Create a material
452  MaterialPtr createMaterial(const UT_StringHolder &name);
453 
454  /// Find a material.
455  MaterialPtr findMaterial(const UT_StringRef &name) const;
456 
457  /// Add a named transform space (that can be referenced from VEX)
458  /// Returns true if the space was added (false if the space already exists)
459  bool addSpace(const UT_StringHolder &name,
460  const SpacePtr &space,
461  bool replace_existing = true);
462 
463  /// Add traceset name to global list (categories on objects that do not
464  /// belong to this list will be ignored)
465  /// Returns true if added, false if already exists.
466  bool addTraceset(const UT_StringHolder &name);
467 
468  /// Check to see if a traceset exists.
469  bool isTraceset(const UT_StringHolder &name);
470 
471  /// Create a shader nodegraph
472  ShaderGraphPtr createShaderGraph(const UT_StringHolder &name);
473 
474  /// Load an HDA to define shader code. Not all applications support this
475  /// feature.
476  bool loadHDA(const char *path);
477 
478 private:
479  UT_SharedPtr<BRAY_Scene> myScene;
480 };
481 
482 /// Input connector for materials. This defines the name of the geometry
483 /// attribute (@c myInputName) to bind to the VEX shader parameter (@c myParmName)
485 {
486  enum class Storage
487  {
488  FLOAT,
489  INTEGER,
490  STRING
491  };
493  const UT_StringHolder &shader_parm,
494  Storage store,
495  int tsize,
496  bool is_array)
497  : myGeometry(primvar)
498  , myParmName(shader_parm)
499  , myStorage(store)
500  , myTupleSize(tsize)
501  , myIsArray(is_array)
502  {
503  }
504 
505  UT_StringHolder myGeometry; // Input name (primvar name)
506  UT_StringHolder myParmName; // Parameter Name (VEX parameter name)
507  Storage myStorage; // Base storage type
508  int myTupleSize; // Element tuple size
509  bool myIsArray; // Whether parameter is an array
510 };
511 
513 
514 /// Interface to scene materials
516 {
517 public:
518  MaterialPtr(BRAY_VexMaterial *mat = nullptr)
519  : myMat(mat)
520  {
521  }
523 
524  bool isValid() const { return myMat != nullptr; }
525 
526  /// @{
527  /// Access to the underling material
528  SYS_SAFE_BOOL operator bool() const { return isValid(); }
529  const BRAY_VexMaterial *materialPtr() const { return myMat; }
530  /// @}
531 
532  /// Update the surface shader and arguments
533  void updateSurface(const ScenePtr &scene,
534  const UT_StringArray &arguments);
535  /// Update the displacement shader and arguments
536  /// Returns true if arguments changed.
537  bool updateDisplace(const ScenePtr &scene,
538  const UT_StringArray &arguments);
539 
540  /// Update surface shader VEX code. The @c preload flag is used when other
541  /// shaders in the network might depend on the code being updated.
542  void updateSurfaceCode(const ScenePtr &scene,
543  const UT_StringHolder &name,
544  const UT_StringRef &code,
545  bool preload=false);
546  /// Update displacement shader VEX code The @c preload flag is used when
547  /// other shaders in the network might depend on the code being updated.
548  /// Returns true if the name or the code changed.
549  bool updateDisplaceCode(const ScenePtr &scene,
550  const UT_StringHolder &name,
551  const UT_StringRef &code,
552  bool preload=false);
553 
554  /// Update the surface shader graph
555  void updateSurfaceGraph(const ScenePtr &scene,
556  const UT_StringHolder &name,
557  const ShaderGraphPtr &graphptr);
558  /// Update the displacement shader graph
559  /// Returns true if the name or the code changed.
560  bool updateDisplaceGraph(const ScenePtr &scene,
561  const UT_StringHolder &name,
562  const ShaderGraphPtr &graphptr);
563 
564  /// Set the material input list
565  void setInputs(const ScenePtr &scene,
566  const MaterialInputList &inputs,
567  bool for_surface);
568 
569 private:
570  BRAY_VexMaterial *myMat;
571 };
572 
574 {
576  const MaterialPtr &material = MaterialPtr())
577  : myFaceList(facelist)
578  , myMaterial(material)
579  {
580  }
583 };
584 
586 {
587 public:
588  ObjectPtr() = default;
589  ~ObjectPtr();
590 
591  /// Create an object given a GT_Primitive handle.
592  /// At the current time, the only classes supported are:
593  /// - GT_PrimPolygonMesh
594  /// - GT_PrimSubdivisionMesh
595  /// - GT_PrimCurveMesh
596  /// - GT_PrimPointMesh
597  /// The method will return a nullptr if it can't create a primitive
598  static ObjectPtr createGeometry(const GT_PrimitiveHandle &prim);
599 
600  /// For polygonal meshes, use this to create geometry to handle holes
601  static ObjectPtr createGeometry(const GT_PrimitiveHandle &prim,
602  const GT_DataArrayHandle &holes);
603 
604  /// Create a volume given its detail attribute and the names and
605  /// GT_PrimitiveHandles of the corresponding fields in the volume
607  static ObjectPtr createVolume(const UT_StringHolder &name);
608 
609  /// Create an instance of an object
610  static ObjectPtr createInstance(const ObjectPtr &obj,
611  const UT_StringHolder &name);
612 
613  /// Create a nested scene graph
614  static ObjectPtr createScene();
615 
616  /// Create a procedural object.
617  /// Ownership of the procedural is passed to the object.
618  static ObjectPtr createProcedural(UT_UniquePtr<BRAY_Procedural> proc);
619 
620  /// Test validity
621  bool isValid() const { return myObject != nullptr; }
622 
623  /// Query if object is a leaf node (ie not scenegraph or instance)
624  bool isLeaf() const;
625 
626  /// @{
627  /// Access to the underlying object
628  SYS_SAFE_BOOL operator bool() const { return isValid(); }
629  const BRAY_Object *objectPtr() const { return myObject.get(); }
630  BRAY_Object *objectPtr() { return myObject.get(); }
631  /// @}
632 
633  /// Bind a material to the object. The method will fail if the underlying
634  /// object cannot set the material.
635  bool setMaterial(ScenePtr &scene,
636  const MaterialPtr &mat,
637  const OptionSet &opts,
638  exint nfacesets=0,
639  const FacesetMaterial *faceset_mat=nullptr);
640 
641  /// Set the prototype for an instance object
642  void setInstancePrototype(const ObjectPtr &proto);
643 
644  /// Set the transform on the instance
645  void setInstanceTransforms(const UT_Array<SpacePtr> &xforms);
646 
647  /// Set attributes on instances
648  void setInstanceAttributes(const ScenePtr &scene,
649  const GT_AttributeListHandle &alist);
650 
651  /// Set property overrides for instances. The array must have an entry for
652  /// every instance. It's possible to have default options. Each
653  /// attribute's name should match an object property name. Warnings will
654  /// be output if an attribute doesn't match.
655  void setInstanceProperties(const ScenePtr &scene,
656  const GT_AttributeListHandle &alist);
657 
658  /// Set instance IDs. If not set (or given an empty array), it is assumed
659  /// that the ids are contiguous 0...N-1 where N is the number of xforms.
660  void setInstanceIds(UT_Array<exint> ids);
661 
662  /// Add an object to a scene
663  void addInstanceToScene(ObjectPtr &obj);
664 
665  /// Check to make sure that number of xforms, attribute list, ids all match
666  bool validateInstance() const;
667 
668  /// @{
669  /// This will return the object's base properties, or the scene defaults if
670  /// the object isn't defined yet.
671  OptionSet objectProperties(ScenePtr &scene);
672  const OptionSet objectProperties(const ScenePtr &scene) const;
673  /// @}
674 
675  /// Get the underlying GT_PrimitiveHandle (if possible). This method may
676  /// return a nullptr.
677  GT_PrimitiveHandle geometry() const;
678 
679  /// Pointer to the contained procedural. This may return a nullptr.
680  BRAY_Procedural *procedural();
681 
682  /// Update the geometry for the object. The method will fail if you're
683  /// trying to change the underlying primitive type.
684  bool setGeometry(const GT_PrimitiveHandle &prim);
685 
686  /// Set the list of "holes" for a polygon mesh (subdivision meshes have the
687  /// list of holes specified in the subdivision tags).
688  bool setGeometry(const GT_PrimitiveHandle &prim,
689  const GT_DataArrayHandle &holes);
690 
691  /// Update volume fields. This method will fail if the underlying
692  /// primitive isn't a volume (see createVolume())
693  bool setVolume(const ScenePtr &scene,
694  const GT_AttributeListHandle &clist,
695  const FieldList& fields);
696 
697  /// Return the detail attributes for a volume primitive
698  const GT_AttributeListHandle &volumeDetailAttributes() const;
699 
700  /// TODO: Deprecate this
701  void takeOwnership(BRAY_Object *obj);
702 
703 protected:
705 };
706 
708 {
709 public:
711  : myLight(lp)
712  {
713  }
714  ~LightPtr();
715 
716  /// Test validity
717  bool isValid() const { return myLight != nullptr; }
718 
719  /// @{
720  /// Access to the underlying object
721  SYS_SAFE_BOOL operator bool() const { return isValid(); }
722  const BRAY_Light *lightPtr() const { return myLight.get(); }
723  BRAY_Light *lightPtr() { return myLight.get(); }
724  /// @}
725 
726  /// Return the type of light
727  BRAY_LightType type() const;
728 
729  /// Set the transform on the instance
730  void setTransform(const SpacePtr &xforms);
731 
732  /// Set the shader for the light
733  void setShader(ScenePtr &scene, const UT_StringArray &args);
734 
735  /// Get the current object properties for modification.
736  OptionSet objectProperties();
737 
738  /// Get the current light properties for modification.
739  OptionSet lightProperties();
740 
741  /// After changing any options, must lock prior to rendering
742  void commitOptions(ScenePtr &scene);
743 
744  /// Update the light shader graph
745  void updateShaderGraph(const ScenePtr &scene,
746  const UT_StringHolder &name,
747  const ShaderGraphPtr &graphptr);
748 
749 protected:
751 
752 };
753 
755 {
756 public:
758  : myCamera(cp)
759  {
760  }
761  ~CameraPtr();
762 
763  /// Test validity
764  bool isValid() const { return myCamera != nullptr; }
765 
766  /// @{
767  /// Access to the underlying object
768  SYS_SAFE_BOOL operator bool() const { return isValid(); }
769  const BRAY_Camera *cameraPtr() const { return myCamera.get(); }
770  BRAY_Camera *cameraPtr() { return myCamera.get(); }
771  /// @}
772 
773  /// Set the transform on the instance
774  void setTransform(const SpacePtr &xforms);
775 
776  /// Set the lens shader for the camera
777  void setShader(const ScenePtr &scene, const UT_StringArray &args);
778 
779  /// Get the current object properties for modification.
780  OptionSet objectProperties();
781 
782  /// Set number of motion samples for animated camera properties (1 upon
783  /// construction). The last motion sample is assumed to have time offset of
784  /// 1.0. (eg. if there are 3 samples, the time offsets are: 0, 0.5, 1.0)
785  void resizeCameraProperties(int nseg);
786 
787  /// Get the current camera properties for modification.
788  UT_Array<OptionSet> cameraProperties();
789 
790  /// After changing any options, must lock prior to rendering
791  void commitOptions(ScenePtr &scene);
792 
793 protected:
795 
796 };
797 
799 {
800 public:
801  AOVBufferPtr() = default;
802 
804  : myAOVBuffer(aov)
805  {}
806 
808 
809  bool operator==(const AOVBufferPtr &aov) const
810  { return aov.myAOVBuffer == myAOVBuffer; }
811  bool operator!=(const AOVBufferPtr &aov) const
812  { return !(*this == aov); }
813 
814  const UT_StringHolder &getName() const;
815  const UT_StringHolder &getVariable() const;
816 
817  int getXres() const;
818  int getYres() const;
819  PXL_DataFormat getFormat() const;
820  PXL_Packing getPacking() const;
821  float getDefaultValue() const;
822 
823  void *map();
824  void unmap();
825  bool isMapped() const;
826 
827  // For extra channels
828  int getNumExtra() const;
829  const UT_StringHolder &nameExtra(int idx) const;
830  PXL_DataFormat getFormatExtra(int idx) const;
831  PXL_Packing getPackingExtra(int idx) const;
832  void *mapExtra(int idx);
833  void unmapExtra(int idx);
834 
835  // metadata to write to header of output file
836  const UT_Options &getMetadata() const;
837 
838  bool isConverged() const;
839  void setConverged();
840  void clearConverged();
841 
842  // Valid only after raster is allocated (ie render started)
843  bool isValid() const;
844 
845  SYS_SAFE_BOOL operator bool() const { return isValid(); }
846 
847 private:
848  UT_SharedPtr<BRAY_AOVBuffer> myAOVBuffer;
849 };
850 
851 /// A render product represents an output file
853 {
854 public:
855  // Test whether the type is understook by karma
856  // For example "karma:checkpoint"
857  static bool isKnownType(const UT_StringRef &type);
858 
859  // Clear all existing output files
860  static void clearFiles(BRAY::ScenePtr &scene);
861 
862  struct BRAY_API AOV
863  {
865  : myName(name)
866  {
867  }
868  /// Method is specialized for T in:
869  /// - bool
870  /// - int32/int64
871  /// - fpreal32/fpreal64
872  /// - UT_StringHolder
873  template <typename T>
874  bool setOption(const UT_StringHolder &name,
875  const T *value,
876  exint size);
877  template <typename T>
878  bool setOption(const UT_StringHolder &name, const T &value)
879  { return setOption(name, &value, 1); }
880 
881  /// Copy over options from those passed in
882  bool setOptions(const UT_Options &options);
883 
884  const UT_StringHolder &name() const { return myName; }
885  const UT_Options &options() const { return myOptions; }
886 
887  /// Dump method for debugging
888  void dump(UT_JSONWriter &w) const;
889  private:
890  UT_StringHolder myName;
891  UT_Options myOptions;
892  };
894  const UT_StringHolder &filename,
895  const UT_StringHolder &type)
896  : myScene(scene)
897  , myFilename(filename)
898  , myType(type)
899  {
900  }
901 
903  {
904  if (myFilename)
905  commit();
906  }
907 
908  /// @{
909  /// Method is specialized for T in:
910  /// - bool
911  /// - int32/int64
912  /// - fpreal32/fpreal64
913  /// - UT_StringHolder
914  template <typename T>
915  bool setOption(const UT_StringHolder &name,
916  const T *value,
917  exint size);
918  template <typename T>
919  bool setOption(const UT_StringHolder &name, const T &value)
920  { return setOption(name, &value, 1); }
921  /// @}
922 
923  /// Copy over options from those passed in
924  bool setOptions(const UT_Options &options);
925 
926  /// Add an AOV to this output file
928  {
929  myAOVs.emplace_back(name);
930  return myAOVs.last();
931  }
932 
933  /// Commit and add this output file to the render
934  bool commit()
935  {
936  bool result = doCommit();
937  cancel(); // Once committed, no more changes
938  return result;
939  }
940  /// Cancel this output file for some reason
941  void cancel() { myFilename.clear(); }
942 
943  /// Access member data
944  const UT_StringHolder &filename() const { return myFilename; }
945  const UT_StringHolder &type() const { return myType; }
946  const UT_Array<AOV> &aovs() const { return myAOVs; }
947  const UT_Options &options() const { return myOptions; }
948 
949  /// @{
950  /// Dump information (used by karma:debug)
951  void dump() const;
952  void dump(UT_JSONWriter &w) const;
953  /// @}
954 
955 private:
956  bool doCommit();
957  BRAY::ScenePtr &myScene;
958  UT_StringHolder myFilename;
959  UT_StringHolder myType;
960  UT_Array<AOV> myAOVs;
961  UT_Options myOptions;
962 };
963 
964 
965 /// Interface to the renderer
967 {
968 public:
969  /// Class used to define image planes
970  struct ImagePlane
971  {
974  int mySize;
977  };
978 
979  struct Stats
980  {
982  {
988  };
989 
991  {
992  clear();
993  myFrameCount = 0;
994  }
995  void clear()
996  {
997  myWorldToCamera = UT_Matrix4D(1);
998  myWorldToScreen = UT_Matrix4D(1);
999  myWorldToNDC = UT_Matrix4D(1);
1000  myWorldToRaster = UT_Matrix4D(1);
1001  myStage = STAGE_INACTIVE;
1002  myPercentDone = 0;
1003  myCameraRays = 0;
1004  myIndirectRays = 0;
1005  myOcclusionRays = 0;
1006  myLightGeoRays = 0;
1007  myProbeRays = 0;
1008  myPolyCount = UT_Vector2I(0, 0);
1009  myCurveCount = UT_Vector2I(0, 0);
1010  myPointCount = UT_Vector2I(0, 0);
1011  myPointMeshCount = UT_Vector2I(0, 0);
1012  myVolumeCount = UT_Vector2I(0, 0);
1013  myProceduralCount = UT_Vector2I(0, 0);
1014  myLightCount = 0;
1015  myLightTreeCount = 0;
1016  myCameraCount = 0;
1017  myOctreeBuildTime = 0;
1018  myLoadWallClock = 0;
1019  myLoadCPU = 0;
1020  myLoadSystem = 0;
1021  myLoadMemory = 0;
1022  myTotalWallClock = 0;
1023  myTotalCPU = 0;
1024  myTotalSystem = 0;
1025  myCurrentMemory = 0;
1026  myPeakMemory = 0;
1027  myObjectCountsSet = false;
1028  myFilterErrors.clear();
1029  myPrimvar.clear();
1030  myDetailedTimes.clear();
1031  myRenderProgressAnnotation.clear();
1032  myRenderStatsAnnotation.clear();
1033  }
1034 
1035  /// Transform matrices
1040 
1041  /// Current state of rendering
1043 
1044  /// Total number of frames rendered
1046 
1047  /// Percent complete of current frame
1049 
1050  /// Ray counts
1056 
1057  /// Object counts -- only defined if verbose >= 2
1058  UT_Vector2I myPolyCount; // Individual/Instances
1059  UT_Vector2I myCurveCount; // Individual/Instances
1060  UT_Vector2I myPointCount; // Individual/Instances
1061  UT_Vector2I myPointMeshCount; // Individual/Instances
1062  UT_Vector2I myVolumeCount; // Individual/Instances
1063  UT_Vector2I myProceduralCount; // Individual/Instances
1065  int64 myLightCount; // Total lights in the scene
1066  int64 myLightTreeCount; // Lights in the light tree
1067  int64 myCameraCount; // Cameras in the scene
1068 
1069  /// Times
1070  fpreal myOctreeBuildTime; // Time to build octree
1071 
1072  /// Initialization times
1073  fpreal myLoadWallClock; // Wall clock time for load
1074  fpreal myLoadCPU; // CPU time for load
1075  fpreal myLoadSystem; // System time for load
1076  int64 myLoadMemory; // Memory after load
1077 
1078  /// Render times
1079  fpreal myTotalWallClock; // Wall clock time for render
1080  fpreal myTotalCPU; // CPU time for load
1081  fpreal myTotalSystem; // System time for load
1082  int64 myCurrentMemory; // Current memory
1083 
1084  int64 myPeakMemory; // Memory after load
1085 
1086  // Whether myPolyCount, myCurveCount etc. are set
1088 
1089  // Errors from image/pixel/sample filters
1091 
1092  // Internal stats
1094 
1095  /// Detailed times if verbose >= 4
1097 
1098  // Accelerator stats
1101  };
1102 
1103  RendererPtr() = default;
1105 
1106  /// Allocate renderer
1107  static RendererPtr allocRenderer(BRAY::ScenePtr &sceneptr);
1108 
1109  SYS_SAFE_BOOL operator bool() const { return myRenderer.get(); }
1110 
1111  /// @{
1112  /// Define image planes for rendering
1113  void clearOutputPlanes();
1114  AOVBufferPtr addOutputPlane(const ImagePlane &plane);
1115  int getAOVCount() const;
1116  /// @}
1117 
1118  /// Return stats about rendering
1119  const Stats &renderStats() const;
1120 
1121  /// Call before rendering begins. This lets the renderer prepare data
1122  /// structures before render() is called. For example, this will ensure
1123  /// all AOV buffers are allocated and active. The method returns false if
1124  /// there were errors setting up the render.
1125  bool prepareRender();
1126 
1127  /// Start rendering a scene
1128  void render(bool (*stopreq)(void *) = nullptr, void *data = nullptr);
1129 
1130  /// Test to see whether the current renderer is active
1131  bool isRendering() const;
1132 
1133  /// Test to see if there was an error rendering
1134  bool isError() const;
1135 
1136  /// Test to see if the renderer is paused
1137  bool isPaused() const;
1138 
1139  /// Tells the renderer to prepare to be stopped
1140  void prepareForStop();
1141 
1142  /// Pause rendering -- Returns true if the renderer is paused
1143  bool pauseRender();
1144 
1145  /// Restart rendering -- Returns true if @c isRendering();
1146  bool resumeRender();
1147 
1148  /// Set a point in the image to give priority to rendering
1149  void setPriority(int x, int y);
1150 
1151  /// Set a region in the image which should have priority
1152  void setPriority(const UT_DimRect &region);
1153 
1154  /// Clear the priority focus
1155  void clearPriority();
1156 
1157 private:
1158  UT_SharedPtr<BRAY_Renderer> myRenderer;
1159 };
1160 
1162 {
1163 public:
1165  : myGraph(graph)
1166  {}
1168 
1169  /// @{
1170  /// Access to the underlying object
1171  const BRAY_ShaderGraph *graphPtr() const { return myGraph.get(); }
1172  /// @}
1173 
1174  /// Make new node based on type and add to list of nodes in the current
1175  /// graph. Returns NULL if unknown type.
1176  /// Note that the root node (ie with surface/displace output) must be the
1177  /// first node added to the graph.
1178  BRAY_ShaderInstance *createNode(const UT_StringHolder &type,
1179  const UT_StringHolder &name);
1180 
1181  /// Returns OptionSet that contains input parameters for given shader node.
1182  /// Can be used to read and write values.
1183  OptionSet nodeParams(BRAY_ShaderInstance *node);
1184 
1185  /// Make connection between two nodes
1186  bool wireNodes(const UT_StringHolder &srcnode,
1187  const UT_StringHolder &srcoutput,
1188  const UT_StringHolder &dstnode,
1189  const UT_StringHolder &dstinput);
1190 
1191  // Definition of a shader node
1192  class NodeDecl
1193  : UT_NonCopyable
1194  {
1195  public:
1198  : myName(n)
1199  {
1200  }
1201 
1202  struct Parameter
1203  {
1204  UT_StringHolder myName; // Name of parameter
1205 
1206  bool isBool() const { return myB.size() > 0; }
1207  bool isInt() const { return myI.size() > 0; }
1208  bool isReal() const { return myF.size() > 0; }
1209  bool isFloat() const { return myF.size() > 0; }
1210  bool isString() const { return myS.size() > 0; }
1211  bool isVariadic() const { return myVariadic; }
1212 
1213  exint size() const
1214  {
1215  return myB.size() + myI.size() + myF.size() + myS.size();
1216  }
1217 
1218  UT_Array<bool> myB; // Bool defaults
1219  UT_Array<int64> myI; // Integer defaults
1220  UT_Array<fpreal64> myF; // Real defaults
1221  UT_Array<UT_StringHolder> myS; // String defaults
1222  bool myVariadic; // Array valued (variadic)
1223 
1224  void dump(UT_JSONWriter &w) const;
1225  };
1226 
1227  const UT_StringHolder name() const { return myName; }
1228  const UT_Array<Parameter> &inputs() const { return myInputs; }
1229  const UT_Array<Parameter> &outputs() const { return myOutputs; }
1230 
1231  void setName(const UT_StringHolder &n) { myName = n; }
1232  void addInput(const Parameter &parm) { myInputs.append(parm); }
1233  void addOutput(const Parameter &parm) { myOutputs.append(parm); }
1234 
1235  void dump() const;
1236  void dump(UT_JSONWriter &w) const;
1237 
1238  private:
1239  UT_StringHolder myName;
1240  UT_Array<Parameter> myInputs;
1241  UT_Array<Parameter> myOutputs;
1242  };
1243 
1244  // Extract the definition of all supported nodes
1245  static const UT_Array<const NodeDecl *> &allNodes();
1246  // Find a node given the name
1247  static const NodeDecl *findNode(const UT_StringRef &name);
1248 
1249 private:
1251 };
1252 
1253 }; // End of namespace
1254 
1255 #endif
int64 myCameraRays
Ray counts.
void cancel()
Cancel this output file for some reason.
type
Definition: core.h:977
BRAY_EventType
Types of events that can be sent as updates to the renderer.
Definition: BRAY_Types.h:39
UT_Vector2T< int64 > UT_Vector2I
AOV & appendAOV(const UT_StringHolder &name)
Add an AOV to this output file.
GT_Storage
Definition: GT_Types.h:18
UT_Matrix4T< fpreal64 > UT_Matrix4D
UT_StringHolder optionS(BRAY_SceneOption t) const
int64 propertyI(BRAY_SceneOption t) const
GT_API const UT_StringHolder filename
fpreal myOctreeBuildTime
Times.
GLintptr GLsizeiptr GLboolean commit
Definition: glcorearb.h:3362
Interface to scene materials.
const VPRM_SpacePtr & space() const
bool operator==(const AOVBufferPtr &aov) const
SYS_FORCE_INLINE const T * propertyImport(BRAY_ObjectProperty token, T *val, size_t n) const
const BRAY_Scene * scenePtr() const
bool commit()
Commit and add this output file to the render.
const BRAY_Camera * cameraPtr() const
void setName(const UT_StringHolder &n)
void addOutput(const Parameter &parm)
GLuint segment
Definition: glew.h:12701
bool isValid() const
Test validity.
float BRAYtime
Consistent representation of time type within BRAY.
Definition: BRAY_Types.h:586
UT_Vector2I myPolyCount
Object counts – only defined if verbose >= 2.
const BRAY_ShaderGraph * graphPtr() const
VPRM_SpacePtr & space()
BRAY_Light * lightPtr()
BRAY_RayVisibility
Ray visibility flags.
Definition: BRAY_Types.h:631
bool operator!=(const AOVBufferPtr &aov) const
SYS_FORCE_INLINE bool setProperty(BRAY_ObjectProperty token, const T &value)
Simple interface to set a scalar property.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
AOV(const UT_StringHolder &name)
UT_SharedPtr< BRAY_Light > myLight
FacesetMaterial(const GT_DataArrayHandle &facelist=GT_DataArrayHandle(), const MaterialPtr &material=MaterialPtr())
int64 exint
Definition: SYS_Types.h:125
const UT_Options & options() const
const UT_Array< AOV > & aovs() const
const UT_StringHolder & name() const
SYS_FORCE_INLINE const T * optionImport(BRAY_SceneOption token, T *val, size_t n) const
const UT_StringHolder & filename() const
Access member data.
bool setOption(const UT_StringHolder &name, const T &value)
UT_StringHolder myGeometry
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
int64 optionI(BRAY_SceneOption t) const
GLuint const GLchar * name
Definition: glcorearb.h:785
SYS_FORCE_INLINE bool set(int token, const T &value)
Simple interface to set a scalar property.
const BRAY_Object * objectPtr() const
GLenum src
Definition: glcorearb.h:1792
SYS_FORCE_INLINE exint propertySize(BRAY_ObjectProperty token) const
const UT_Array< Parameter > & inputs() const
GLdouble GLdouble t
Definition: glew.h:1403
const BRAY_Light * lightPtr() const
OutputFile(BRAY::ScenePtr &scene, const UT_StringHolder &filename, const UT_StringHolder &type)
bool isValid() const
Test validity.
UT_Matrix4D myWorldToCamera
Transform matrices.
CameraPtr(const UT_SharedPtr< BRAY_Camera > &cp=UT_SharedPtr< BRAY_Camera >())
IFDmantra you can see code vm_image_mplay_direction endcode When SOHO starts a render
Definition: HDK_Image.dox:266
const BRAY_VexMaterial * materialPtr() const
SYS_FORCE_INLINE bool isEqual(int token, const T &value) const
Simple interface for equality of a scalar value.
UT_StringHolder propertyS(BRAY_SceneOption t) const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
GLint GLenum GLint x
Definition: glcorearb.h:408
bool isValid() const
Test validity.
struct _cl_event * event
Definition: glcorearb.h:2960
GLsizeiptr size
Definition: glcorearb.h:663
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
UT_StringHolder myParmName
double fpreal64
Definition: SYS_Types.h:201
bool propertyB(BRAY_SceneOption t) const
VPRM_OptionSetPtr & options()
const UT_StringHolder name() const
GLuint64EXT * result
Definition: glew.h:14311
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
BRAY_ObjectProperty
Definition: BRAY_Types.h:168
SYS_FORCE_INLINE GT_Storage propertyStorage(BRAY_ObjectProperty token) const
Return the storage class of an option.
UT_SharedPtr< BRAY_Camera > myCamera
UT_SharedPtr< BRAY_Object > myObject
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
BRAY_Camera * cameraPtr()
bool isValid() const
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:30
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
GLint GLuint mask
Definition: glcorearb.h:123
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
Definition: format.h:2929
SYS_FORCE_INLINE exint optionSize(BRAY_SceneOption token) const
int setVolume(int speaker, float vol) override
ShaderGraphPtr(UT_SharedPtr< BRAY_ShaderGraph > graph)
bool isValid() const
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLhandleARB obj
Definition: glew.h:6266
NodeDecl(const UT_StringHolder &n)
SYS_FORCE_INLINE bool optionIsVariadic(BRAY_SceneOption token) const
Return whether an option has variadic arguments.
PXL_Packing
Definition: PXL_Common.h:30
SYS_FORCE_INLINE bool setOption(BRAY_SceneOption token, const T *value, exint tuple_size)
Interface to set an option. This template class is specialized for:
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE exint lockAllObjectProperties(bool state)
Lock or unlock all object properties.
int myFrameCount
Total number of frames rendered.
const UT_Array< Parameter > & outputs() const
fpreal myLoadWallClock
Initialization times.
bool isValid() const
Test validity.
Class used to define image planes.
MaterialInput(const UT_StringHolder &primvar, const UT_StringHolder &shader_parm, Storage store, int tsize, bool is_array)
PXL_DataFormat
Definition: PXL_Common.h:20
GLuint * ids
Definition: glcorearb.h:651
const UT_Options & options() const
UT_StringHolder myRenderStatsAnnotation
MX_GENSHADER_API const TypeDesc * INTEGER
GT_DataArrayHandle myFaceList
GLdouble n
Definition: glcorearb.h:2007
GLubyte * pattern
Definition: glew.h:5741
GLboolean * data
Definition: glcorearb.h:130
BRAY_LightType
Definition: BRAY_Types.h:477
SYS_FORCE_INLINE bool setOption(BRAY_SceneOption token, const T &value)
Simple interface to set a scalar option.
fpreal myPercentDone
Percent complete of current frame.
GLuint GLfloat * val
Definition: glcorearb.h:1607
A map of string to various well defined value types.
Definition: UT_Options.h:84
A render product represents an output file.
BRAY_SceneOption
Definition: BRAY_Types.h:66
UT_StringHolder myDetailedTimes
Detailed times if verbose >= 4.
const void * ptr(const T *p)
Definition: format.h:3603
bool isValid() const
fpreal64 fpreal
Definition: SYS_Types.h:277
fpreal64 optionF(BRAY_SceneOption t) const
MaterialPtr(BRAY_VexMaterial *mat=nullptr)
SYS_FORCE_INLINE bool setProperty(BRAY_ObjectProperty token, const T *value, exint tuple_size)
Interface to set an property. This template class is specialized for:
AOVBufferPtr(const UT_SharedPtr< BRAY_AOVBuffer > &aov)
SYS_FORCE_INLINE bool propertyIsVariadic(BRAY_ObjectProperty token) const
Return whether an property has variadic arguments.
#define BRAY_API
Definition: BRAY_API.h:12
GLsizei const GLfloat * value
Definition: glcorearb.h:823
**If you just want to fire and args
Definition: thread.h:615
BRAY_PropertyType
Definition: BRAY_Types.h:333
void addInput(const Parameter &parm)
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
RenderStage myStage
Current state of rendering.
bool setOption(const UT_StringHolder &name, const T &value)
GLfloat units
Definition: glcorearb.h:407
bool optionB(BRAY_SceneOption t) const
Interface to the renderer.
UT_StringHolder myRenderProgressAnnotation
const UT_StringHolder & type() const
fpreal64 propertyF(BRAY_SceneOption t) const
GLdouble s
Definition: glew.h:1395
GLint y
Definition: glcorearb.h:102
const VPRM_OptionSetPtr & options() const
BRAY_Object * objectPtr()
BRAY_Scene * scenePtr()
UT_StringArray myFilterErrors
LightPtr(const UT_SharedPtr< BRAY_Light > &lp=UT_SharedPtr< BRAY_Light >())
SYS_FORCE_INLINE GT_Storage optionStorage(BRAY_SceneOption token) const
Return the storage class of an option.
fpreal myTotalWallClock
Render times.