HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~RAY_ProcGT();
95 
96  /// @{
97  /// Methods from RAY_Procedural
98  virtual const char *className() const;
99  virtual int initialize(const UT_BoundingBox *box);
100  virtual void getBoundingBox(UT_BoundingBox &box);
101  virtual void render();
102  virtual bool canGenerateInstancedGeometry() const;
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 &pivot);
115  bool velocityBlur() const { return myVelocityBlur; }
116 
117  /// @{
118  /// @private
119  /// Create a new styler for each instance in a child ProcGT based on our
120  /// existing instance stylers and any new instance defined in the prim.
121  StylingContext &stylingContext() { return myStylingContext; }
122  void setInstanceTransform(const RAY_ProceduralChildPtr &kid,
123  const GT_TransformHandle &xform) const;
124  void processInstanceAttributes(const RAY_ProceduralChildPtr &kid,
125  const GT_AttributeListHandle &attrib,
126  exint idx) const;
127  void velocityBlurTransform(const RAY_ProceduralChildPtr &kid,
128  const GT_TransformArrayHandle &xforms,
129  const GT_DataArrayHandle &v,
130  const GT_DataArrayHandle &w,
131  const GT_DataArrayHandle &pivot,
132  const GT_TransformHandle &packed,
133  exint xform) const;
134  void renderPrim(const GT_PrimitiveHandle &prim,
135  StylingContext &styling) const;
136  /// @}
137 
138  // Top level primitives will handle pre-blur on velocity different, since
139  // they assume the velocity blur has been applied to the top level
140  // geometry.
141  void setTopLevel(bool v) { myTopLevel = v; }
142 
143 private:
144  void computeBounds(UT_BoundingBox &box,
145  const GT_PrimitiveHandle &prim) const;
146  static void computeInstanceBounds(UT_BoundingBox &box,
147  const GT_PrimitiveHandle &prim,
148  const GT_DataArrayHandle &v,
149  const GT_DataArrayHandle &w,
150  const GT_DataArrayHandle &pivot,
151  fpreal preblur,
152  fpreal postblur);
153  void renderSimpleInstances(const UT_StringHolder &basename,
154  const GT_PrimitiveHandle &prim,
155  const GT_TransformArrayHandle &xforms,
156  const GT_AttributeListHandle &uniform,
157  const GT_AttributeListHandle &detail,
158  const StylingContext &styling,
159  bool pack_instance) const;
160  void initShutter()
161  {
162  if (!myShutterInitialized)
163  {
164  myShutterInitialized = true;
165  importShutter();
166  }
167  }
168  void importShutter();
169  int getMotionSegments() const
170  {
171  return mySegments;
172  }
173 
174 
175  GT_PrimitiveHandle myPrim;
176  UT_BoundingBox myBox;
177  GT_DataArrayHandle myParentVelocity;
178  GT_DataArrayHandle myParentAngularVelocity;
179  GT_DataArrayHandle myParentPivot;
180  StylingContext myStylingContext;
181  fpreal myPreBlur, myPostBlur; // Velocity blur
182  fpreal myShutterClose; // Shutter close
183  int mySegments;
184  bool myVelocityBlur;
185  bool myShutterInitialized;
186  bool myTopLevel;
187 };
188 
189 #endif
bool velocityBlur() const
Definition: RAY_ProcGT.h:115
const GLdouble * v
Definition: glcorearb.h:836
void setTopLevel(bool v)
Definition: RAY_ProcGT.h:141
virtual void render()=0
virtual bool canGenerateInstancedGeometry() const
Procedural primitive for mantra (RAY)
virtual const char * className() const =0
virtual void getBoundingBox(UT_BoundingBox &box)=0
The bounding box is the "object space" bounds of the procedural.
int64 exint
Definition: SYS_Types.h:115
void appendStyle(const RAY_StylerInfo &styler)
Definition: RAY_ProcGT.h:59
const StylerInfoArray & infos() const
Definition: RAY_ProcGT.h:58
RAY_ProceduralChildPtr createChild() const
virtual int initialize(const UT_BoundingBox *box)=0
double fpreal
Definition: SYS_Types.h:269
#define RAY_API
Definition: RAY_API.h:12
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:856