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  // Draw all elements and reset
59  void draw(RE_Render *r,
60  const GR_CommonDispOption *opt,
61  bool hq_lighting,
62  bool has_fog,
63  bool show_selection);
64 
65 #ifdef USE_VULKAN
66  // Draw all elements and reset
67  void drawVK(RV_Render *r,
68  GR_Uniforms* u,
69  const GR_CommonDispOption *opt,
70  bool hq_lighting,
71  bool has_fog,
72  bool show_selection);
73 
74  void destroyResources();
75 #endif
76 private:
78  ~GR_VolumeRender();
79  void setupVolumeShader(RE_Render *r,
80  RE_ShaderHandle &sh,
81  float astep,
82  bool use_transparent) const;
83 
85  UT_Array<GR_VolumeSlice *> myFogSlices;
86  UT_Array<GR_VolumeSlice *> myFreeFogSlices;
87  RE_Geometry *myGeo;
88  RE_Geometry *myFullscreenGeo;
89 
90  // Temporary per draw but cached to avoid reallocs
91  UT_Array<GR_VolumeSlice *> myReducedSlices;
92  UT_Vector3FArray myPosData;
93  UT_Vector3FArray myTexData;
94  UT_IntArray myDrawMode;
95  UT_Array<GR_TextureRef> myTextures;
96  UT_IntArray myDrawCount;
97  UT_FloatArray myZInc;
98  UT_FloatArray myDepth;
99  UT_ValArray<UT_SharedPtr<UT_Matrix3D>> myObjectMatrices;
100  GR_TextureRef myFogVolume;
101  fpreal myFogOpacity;
102 
103 #ifdef USE_VULKAN
104  // Vulkan resource ptrs
106  UT_UniquePtr<RV_Geometry> myFullscreenGeoVK;
108 
110  UT_UniquePtr<RV_ShaderBlock> myObjUniforms;
111 
114 #endif
115 };
116 
118 {
119 public:
120  // True volume
122  const UT_Vector3Array &texcoords,
123  GR_TextureRef volume,
124  bool selected,
125  bool motion,
126  bool normal,
127  fpreal32 zinc)
128  : myPoints(points), myTexcoords(texcoords), mySelectValue(selected?1:0),
129  myVolume(volume), myZInc(zinc), myIsFog(false),
130  myDepth(0.0), myMotionFlag(motion), myNormalFlag(normal)
131  {}
132  // Fog
134  : myVolume(nullptr), myZInc(slice), myIsFog(true), myDepth(depth)
135  {}
136 
137  void setDepth(const UT_Matrix4D &proj);
138  void setMesh(const UT_Vector3Array &points,
139  const UT_Vector3Array &texcoords);
140  void setVolume(GR_TextureRef vol_tex) { myVolume = vol_tex; }
141  void setInc(fpreal32 i) { myZInc = i; }
142  void setFlags(int select, bool motion, bool normal)
143  {
144  mySelectValue = select;
145  myMotionFlag = motion;
146  myNormalFlag = normal;
147  }
148 
150  {
151  myObjectMatrix = object;
152  }
153 
154  void setFog(fpreal depth, fpreal slice)
155  {
156  myDepth = depth;
157  myZInc = slice;
158  }
159  fpreal32 depth() const { return myDepth; }
160  int triCount() const { return myPoints.entries()/3; }
161 
162  void createSlice(UT_Vector3FArray &pos,
163  UT_Vector3FArray &texcoord,
164  UT_IntArray &draw_mode,
166  UT_IntArray &draw_count,
167  UT_FloatArray &zincs,
169  bool show_selection,
170  UT_ValArray<UT_SharedPtr<UT_Matrix3D>> *obj_mats = nullptr)
171  const;
172 
173 private:
174 
175  GR_TextureRef myVolume;
176  UT_Vector3FArray myPoints;
177  UT_Vector3FArray myTexcoords;
178  int mySelectValue;
179  fpreal32 myZInc;
180  fpreal32 myDepth;
181  unsigned myIsFog:1,
182  myNormalFlag:1,
183  myMotionFlag:1;
184 
185  UT_SharedPtr<UT_Matrix3D> myObjectMatrix;
186 };
187 
188 #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:53
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:4816
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:648
void setObjectXform(const UT_SharedPtr< UT_Matrix3D > &object)
bool hasSlices() const
fpreal64 fpreal
Definition: SYS_Types.h:277
void setInc(fpreal32 i)
void setFogTexture(GR_TextureRef fog, fpreal opacity)
GLboolean r
Definition: glcorearb.h:1222
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.