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 <RE/RE_Texture.h>
15 #include <UT/UT_Array.h>
16 #include <UT/UT_SharedPtr.h>
17 #include <UT/UT_VectorTypes.h>
18 #ifdef USE_VULKAN
19 #include <UT/UT_UniquePtr.h>
20 #endif
21 
22 #include "GR_API.h"
23 #include "GR_Defines.h"
24 #include "GR_TextureRef.h"
25 
26 class RE_Geometry;
27 class RE_Render;
28 class RE_ShaderHandle;
30 class GR_VolumeSlice;
31 #ifdef USE_VULKAN
32 class GR_Uniforms;
33 class RV_Geometry;
34 class RV_Render;
35 class RV_ShaderBlock;
36 class RV_ShaderProgram;
38 #endif
40 {
41 public:
42  static GR_VolumeRender *get(int idx = 0);
43 
44  static int getMaxVolumeSlices();
45 
46  // Normal volumes
47  void addSlices(const UT_Array<GR_VolumeSlice*> &new_slices);
48 
49  // volumetric fog
50  void addFogSlice(fpreal depth, fpreal slice);
51  void setFogTexture(GR_TextureRef fog, fpreal opacity)
52  {
53  myFogVolume = fog;
54  myFogOpacity = opacity;
55  }
56  bool hasSlices() const { return mySlices.entries() > 0; }
57 
58  void clearSlices();
59 
60  // Draw all elements and reset
61  void draw(RE_Render *r,
62  const GR_CommonDispOption *opt,
63  bool hq_lighting,
64  bool has_fog,
65  bool show_selection);
66 
67 #ifdef USE_VULKAN
68  // Draw all elements and reset
69  void drawVK(RV_Render *r,
70  GR_Uniforms* u,
71  const GR_CommonDispOption *opt,
72  bool hq_lighting,
73  bool has_fog,
74  bool show_selection);
75 
76  void destroyResources();
77 #endif
78 private:
80  ~GR_VolumeRender();
81  void setupVolumeShader(RE_Render *r,
82  RE_ShaderHandle &sh,
83  float astep,
84  bool use_transparent) const;
85 
87  UT_Array<GR_VolumeSlice *> myFogSlices;
88  UT_Array<GR_VolumeSlice *> myFreeFogSlices;
89  RE_Geometry *myGeo;
90  RE_Geometry *myFullscreenGeo;
91 
92  // Temporary per draw but cached to avoid reallocs
93  UT_Array<GR_VolumeSlice *> myReducedSlices;
94  UT_Vector3FArray myPosData;
95  UT_Vector3FArray myTexData;
96  UT_IntArray myDrawMode;
97  UT_Array<GR_TextureRef> myTextures;
98  UT_IntArray myDrawCount;
99  UT_FloatArray myZInc;
100  UT_FloatArray myDepth;
101  UT_ValArray<UT_SharedPtr<UT_Matrix3D>> myObjectMatrices;
102  GR_TextureRef myFogVolume;
103  fpreal myFogOpacity;
104 
105 #ifdef USE_VULKAN
106  // Vulkan resource ptrs
108  UT_UniquePtr<RV_Geometry> myFullscreenGeoVK;
110 
112  UT_UniquePtr<RV_ShaderBlock> myObjUniforms;
113 
116 #endif
117 };
118 
120 {
121 public:
122  // True volume
124  const UT_Vector3Array &texcoords,
125  GR_TextureRef volume,
126  bool selected,
127  bool motion,
128  bool normal,
129  fpreal32 zinc)
130  : myPoints(points), myTexcoords(texcoords), mySelectValue(selected?1:0),
131  myVolume(volume), myZInc(zinc), myIsFog(false),
132  myDepth(0.0), myMotionFlag(motion), myNormalFlag(normal)
133  { }
134  // Fog
136  : myVolume(nullptr), myZInc(slice), myIsFog(true), myDepth(depth)
137  { }
138 
139  void setDepth(const UT_Matrix4D &proj);
140  void setMesh(const UT_Vector3Array &points,
141  const UT_Vector3Array &texcoords);
142  void setVolume(GR_TextureRef vol_tex) { myVolume = vol_tex; }
143  void setInc(fpreal32 i) { myZInc = i; }
144  void setFlags(int select, bool motion, bool normal)
145  {
146  mySelectValue = select;
147  myMotionFlag = motion;
148  myNormalFlag = normal;
149  }
150 
152  {
153  myObjectMatrix = object;
154  }
155 
156  void setFog(fpreal depth, fpreal slice)
157  {
158  myDepth = depth;
159  myZInc = slice;
160  }
161  fpreal32 depth() const { return myDepth; }
162  int triCount() const { return myPoints.entries()/3; }
163 
164  void createSlice(UT_Vector3FArray &pos,
165  UT_Vector3FArray &texcoord,
166  UT_IntArray &draw_mode,
168  UT_IntArray &draw_count,
169  UT_FloatArray &zincs,
171  bool show_selection,
172  UT_ValArray<UT_SharedPtr<UT_Matrix3D>> *obj_mats = nullptr)
173  const;
174 
175 private:
176 
177  GR_TextureRef myVolume;
178  UT_Vector3FArray myPoints;
179  UT_Vector3FArray myTexcoords;
180  int mySelectValue;
181  fpreal32 myZInc;
182  fpreal32 myDepth;
183  unsigned myIsFog:1,
184  myNormalFlag:1,
185  myMotionFlag:1;
186 
187  UT_SharedPtr<UT_Matrix3D> myObjectMatrix;
188 };
189 
190 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
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)
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:52
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 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:655
void setObjectXform(const UT_SharedPtr< UT_Matrix3D > &object)
bool hasSlices() const
fpreal64 fpreal
Definition: SYS_Types.h:278
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 setFlags(int select, bool motion, bool normal)
Simple interface to building a shader from a .prog file.