HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_VolumeRender.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: GR_VolumeRender.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Global Volume slice renderer. Slices are acculated then sorted and drawn.
10  */
11 #ifndef GR_VolumeRender_h
12 #define GR_VolumeRender_h
13 
14 #include <UT/UT_Array.h>
15 #include <UT/UT_SharedPtr.h>
16 #include <UT/UT_VectorTypes.h>
17 #include <UT/UT_UniquePtr.h>
18 
19 #include "GR_API.h"
20 #include "GR_Defines.h"
21 #include "GR_TextureRef.h"
22 
24 class GR_VolumeSlice;
25 class GR_Uniforms;
26 class RV_Geometry;
27 class RV_Render;
28 class RV_ShaderBlock;
29 class RV_ShaderProgram;
31 
33 {
34 public:
35  static GR_VolumeRender *get(int idx = 0);
36 
37  static int getMaxVolumeSlices();
38 
39  // Normal volumes
40  void addSlices(const UT_Array<GR_VolumeSlice*> &new_slices);
41 
42  // volumetric fog
43  void addFogSlice(fpreal depth, fpreal slice);
44  void setFogTexture(GR_TextureRef fog, fpreal opacity)
45  {
46  myFogVolume = fog;
47  myFogOpacity = opacity;
48  }
50  {
51  myFogShader = sh;
52  }
53  void setFogRange(const UT_Vector2D &range) { myFogRange = range; }
54 
55  bool hasSlices() const { return mySlices.entries() > 0; }
56 
57  void clearSlices();
58 
59  // Draw all elements and reset
60  void draw(RV_Render *r,
61  GR_Uniforms* u,
62  const GR_CommonDispOption *opt,
63  bool hq_lighting,
64  bool has_fog,
65  bool show_selection);
66 
67  void destroyResources();
68 private:
70  ~GR_VolumeRender();
71 
73  UT_Array<GR_VolumeSlice *> myFogSlices;
74  UT_Array<GR_VolumeSlice *> myFreeFogSlices;
75 
76  // Temporary per draw but cached to avoid reallocs
77  UT_Array<GR_VolumeSlice *> myReducedSlices;
78  UT_Vector3FArray myPosData;
79  UT_Vector3FArray myTexData;
80  UT_IntArray myDrawMode;
81  UT_Array<GR_TextureRef> myTextures;
82  UT_IntArray myDrawCount;
83  UT_FloatArray myZInc;
84  UT_FloatArray myDepth;
85  UT_ValArray<UT_SharedPtr<UT_Matrix3D>> myObjectMatrices;
86  GR_TextureRef myFogVolume;
87  fpreal myFogOpacity;
88  UT_Vector2D myFogRange;
89 
90  // Vulkan resource ptrs
92  UT_UniquePtr<RV_Geometry> myFullscreenGeoVK;
94 
96  UT_UniquePtr<RV_ShaderBlock> myObjUniforms;
97 
100  RV_ShaderProgram* myFogShader = nullptr;
101 };
102 
104 {
105 public:
106  // True volume
108  const UT_Vector3Array &texcoords,
109  GR_TextureRef volume,
110  bool selected,
111  bool motion,
112  bool normal,
113  fpreal32 zinc)
114  : myPoints(points), myTexcoords(texcoords), mySelectValue(selected?1:0),
115  myVolume(volume), myZInc(zinc), myIsFog(false),
116  myDepth(0.0), myMotionFlag(motion), myNormalFlag(normal)
117  { }
118  // Fog
120  : myVolume(nullptr), myZInc(slice), myIsFog(true), myDepth(depth)
121  { }
122 
123  void setDepth(const UT_Matrix4D &proj);
124  void setMesh(const UT_Vector3Array &points,
125  const UT_Vector3Array &texcoords);
126  void setVolume(GR_TextureRef vol_tex) { myVolume = vol_tex; }
127  void setInc(fpreal32 i) { myZInc = i; }
128  void setFlags(int select, bool motion, bool normal)
129  {
130  mySelectValue = select;
131  myMotionFlag = motion;
132  myNormalFlag = normal;
133  }
134 
136  {
137  myObjectMatrix = object;
138  }
139 
140  void setFog(fpreal depth, fpreal slice)
141  {
142  myDepth = depth;
143  myZInc = slice;
144  }
145  fpreal32 depth() const { return myDepth; }
146  int triCount() const { return myPoints.entries()/3; }
147 
148  void createSlice(UT_Vector3FArray &pos,
149  UT_Vector3FArray &texcoord,
150  UT_IntArray &draw_mode,
152  UT_IntArray &draw_count,
153  UT_FloatArray &zincs,
155  bool show_selection,
156  UT_ValArray<UT_SharedPtr<UT_Matrix3D>> *obj_mats = nullptr)
157  const;
158 
159 private:
160 
161  GR_TextureRef myVolume;
162  UT_Vector3FArray myPoints;
163  UT_Vector3FArray myTexcoords;
164  int mySelectValue;
165  fpreal32 myZInc;
166  fpreal32 myDepth;
167  unsigned myIsFog:1,
168  myNormalFlag:1,
169  myMotionFlag:1;
170 
171  UT_SharedPtr<UT_Matrix3D> myObjectMatrix;
172 };
173 
174 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
GLenum GLint * range
Definition: glcorearb.h:1925
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
void setVolume(GR_TextureRef vol_tex)
void setDepth(const UT_Matrix4D &proj)
int triCount() const
GR_VolumeSlice(fpreal depth, fpreal slice)
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
void createSlice(UT_Vector3FArray &pos, UT_Vector3FArray &texcoord, UT_IntArray &draw_mode, UT_Array< GR_TextureRef > &tex, UT_IntArray &draw_count, UT_FloatArray &zincs, UT_FloatArray &depth, bool show_selection, UT_ValArray< UT_SharedPtr< UT_Matrix3D >> *obj_mats=nullptr) const
float fpreal32
Definition: SYS_Types.h:200
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void setFogRange(const UT_Vector2D &range)
void setMesh(const UT_Vector3Array &points, const UT_Vector3Array &texcoords)
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4983
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
fpreal32 depth() const
#define GR_API
Definition: GR_API.h:10
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:669
void setObjectXform(const UT_SharedPtr< UT_Matrix3D > &object)
bool hasSlices() const
fpreal64 fpreal
Definition: SYS_Types.h:283
void setInc(fpreal32 i)
void setFogTexture(GR_TextureRef fog, fpreal opacity)
GLboolean r
Definition: glcorearb.h:1222
set of parameters sent to GR_Primitive::update()
Definition: GR_Uniforms.h:56
GR_VolumeSlice(const UT_Vector3Array &points, const UT_Vector3Array &texcoords, GR_TextureRef volume, bool selected, bool motion, bool normal, fpreal32 zinc)
void setFog(fpreal depth, fpreal slice)
void setFogShader(RV_ShaderProgram *sh)
void setFlags(int select, bool motion, bool normal)