HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RAY_ProcGT.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: RAY_ProcGT.h ( RAY Library, C++)
7  *
8  * COMMENTS: Procedural to render a GT primitive
9  */
10 
11 #ifndef __RAY_ProcGT__
12 #define __RAY_ProcGT__
13 
14 #include "RAY_Procedural.h"
15 #include "RAY_StylerInfo.h"
16 #include <GT/GT_Handles.h>
17 #include <STY/STY_Styler.h>
18 #include <GA/GA_Types.h>
19 #include <UT/UT_Array.h>
20 #include <UT/UT_ArrayMap.h>
21 #include <UT/UT_Lock.h>
22 
23 class GT_RefineParms;
24 class GU_Primitive;
25 
26 /// @brief Procedural to render a single GT primitive
27 ///
28 /// When rendering GT primitives, they will be refined until they hit geometry
29 /// that Mantra can handle.
30 ///
31 /// When GT_PRIM_INSTANCE primitives are encountered, the procedural will
32 /// create multiple instance objects in mantra, allowing the geometry to be
33 /// shared between instances automatically. In addition, the following
34 /// uniform/detail attributes are handled on the instance primitives:
35 /// - shop_materialpath @n
36 /// Assign a material for the instance. This calls
37 /// RAY_Procedural::setShopMaterialPath(). If the @c shop_materialpath is
38 /// found, then additional attributes (@c material_override and @c
39 /// property_override) are evaluated to handle shader argument and property
40 /// overrides.
41 /// - lightcategories @n
42 /// Set the @b lightcategories property on the instance
43 /// - lightmask @n
44 /// Set the @b lightmask property on the instance. Note that this may not
45 /// handle light instancing properly.
46 /// - categories @n
47 /// Set the categories for instance.
49 {
50 public:
52  {
53  public:
57 
58  const StylerInfoArray &infos() const { return myInstanceStylerInfos; }
59  void appendStyle(const RAY_StylerInfo &styler)
60  { myInstanceStylerInfos.append(styler); }
61 
62  void setInstanceStylers(StylingContext &child,
63  const GT_PrimitiveHandle &prim);
64  void clearInfos() { myInstanceStylerInfos.clear(); }
65  private:
66  StylerInfoArray myInstanceStylerInfos;
67  SharedPrimGroup myGroupSharingHolder;
68  GroupSharingMap myInstanceGroupSharingMap;
69  UT_Lock myInstanceGroupLock;
70  };
74  static const GT_RefineParms *mantraRefineParms(const RAY_Procedural &proc);
75 
76  /// A mantra procedural to render a GT primitive. If the GT primitive has
77  /// multiple segments, the primitive will be rendered with deformation
78  /// motion blur unless @c use_multi_segments is false.
79  ///
80  /// When multi-segment blur is active, the @c shutter_close can be
81  /// specified. If the @c shutter_close is less than 0, the value will be
82  /// imported from the camera:shutter setting. If @c shutter_close is 0,
83  /// multi-segment blur will be disabled.
84  ///
85  /// If the GT primitive has the proper sub-frame sampling time, then you
86  /// likely want to set the @c shutter_close to 1.0.
87  RAY_ProcGT(const GT_PrimitiveHandle &prim,
88  bool use_multi_segments=true,
89  fpreal shutter_close=-1);
90  /// Alternatively, motion segments can be specified using an array of
91  /// primitives.
92  RAY_ProcGT(const UT_Array<GT_PrimitiveHandle> &primitives,
93  fpreal shutter_close=-1);
94  ~RAY_ProcGT() override;
95 
96  /// @{
97  /// Methods from RAY_Procedural
98  const char *className() const override;
99  int initialize(const UT_BoundingBox *box) override;
100  void getBoundingBox(UT_BoundingBox &box) override;
101  void render() override;
102  bool canGenerateInstancedGeometry() const override;
103  /// @}
104 
105  /// @{
106  /// @private
107  /// Provide public accessor to create new procedural children.
108  RAY_ProceduralChildPtr newChild() const { return createChild(); }
109  /// @}
110 
111  void dump(bool dump_full_geo=false);
112  void instanceVelocityBlur(const GT_DataArrayHandle &v,
113  const GT_DataArrayHandle &w,
114  const GT_DataArrayHandle &a,
115  const GT_DataArrayHandle &pivot);
116  int velocityBlur() const { return myVelocityBlur; }
117 
118  /// @{
119  /// @private
120  /// Create a new styler for each instance in a child ProcGT based on our
121  /// existing instance stylers and any new instance defined in the prim.
122  StylingContext &stylingContext() { return myStylingContext; }
123  void setInstanceTransform(const RAY_ProceduralChildPtr &kid,
124  const GT_TransformHandle &xform) const;
125  void processInstanceAttributes(const RAY_ProceduralChildPtr &kid,
126  const GT_AttributeListHandle &attrib,
127  exint idx) const;
128  void velocityBlurTransform(const RAY_ProceduralChildPtr &kid,
129  const GT_TransformArrayHandle &xforms,
130  const GT_DataArrayHandle &v,
131  const GT_DataArrayHandle &w,
132  const GT_DataArrayHandle &accel,
133  const GT_DataArrayHandle &pivot,
134  const GT_TransformHandle &packed,
135  exint xform) const;
136  void renderPrim(const GT_PrimitiveHandle &prim,
137  StylingContext &styling) const;
138  /// @}
139 
140  // Top level primitives will handle pre-blur on velocity different, since
141  // they assume the velocity blur has been applied to the top level
142  // geometry.
143  void setTopLevel(bool v) { myTopLevel = v; }
144 
145 private:
146  void computeBounds(UT_BoundingBox &box,
147  const GT_PrimitiveHandle &prim) const;
148  static void computeInstanceBounds(UT_BoundingBox &box,
149  const GT_PrimitiveHandle &prim,
150  const GT_DataArrayHandle &v,
151  const GT_DataArrayHandle &w,
152  const GT_DataArrayHandle &a,
153  const GT_DataArrayHandle &pivot,
154  int velocityBlur,
155  fpreal preblur,
156  fpreal postblur);
157  void renderSimpleInstances(const UT_StringHolder &basename,
158  const GT_PrimitiveHandle &prim,
159  const GT_TransformArrayHandle &xforms,
160  const GT_AttributeListHandle &uniform,
161  const GT_AttributeListHandle &detail,
162  const StylingContext &styling,
163  bool pack_instance) const;
164  void initShutter()
165  {
166  if (!myShutterInitialized)
167  {
168  myShutterInitialized = true;
169  importShutter();
170  }
171  }
172  void importShutter();
173  int getMotionSegments() const
174  {
175  return mySegments;
176  }
177 
178 
179  GT_PrimitiveHandle myPrim;
180  UT_BoundingBox myBox;
181  GT_DataArrayHandle myParentVelocity;
182  GT_DataArrayHandle myParentAngularVelocity;
183  GT_DataArrayHandle myParentAcceleration;
184  GT_DataArrayHandle myParentPivot;
185  StylingContext myStylingContext;
186  fpreal myPreBlur, myPostBlur; // Velocity blur
187  fpreal myShutterClose; // Shutter close
188  int mySegments;
189  int myVelocityBlur;
190  bool myShutterInitialized;
191  bool myTopLevel;
192 };
193 
194 #endif
StylingContext::SharedPrimGroup SharedPrimGroup
Definition: RAY_ProcGT.h:72
GA_API const UT_StringHolder accel
const GLdouble * v
Definition: glcorearb.h:837
void setTopLevel(bool v)
Definition: RAY_ProcGT.h:143
virtual void render()=0
int64 exint
Definition: SYS_Types.h:125
virtual bool canGenerateInstancedGeometry() const
Procedural primitive for mantra (RAY)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
int velocityBlur() const
Definition: RAY_ProcGT.h:116
virtual const char * className() const =0
virtual void getBoundingBox(UT_BoundingBox &box)=0
The bounding box is the "object space" bounds of the procedural.
UT_SharedPtr< GSTY_SubjectPrimGroup > SharedPrimGroup
Definition: RAY_ProcGT.h:55
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
void appendStyle(const RAY_StylerInfo &styler)
Definition: RAY_ProcGT.h:59
const StylerInfoArray & infos() const
Definition: RAY_ProcGT.h:58
VULKAN_HPP_INLINE VULKAN_HPP_CONSTEXPR_14 uint8_t packed(VULKAN_HPP_NAMESPACE::Format format)
RAY_ProceduralChildPtr createChild() const
virtual int initialize(const UT_BoundingBox *box)=0
#define RAY_API
Definition: RAY_API.h:12
fpreal64 fpreal
Definition: SYS_Types.h:277
GA_API const UT_StringHolder pivot
Procedural to render a single GT primitive.
Definition: RAY_ProcGT.h:48
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857