HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_VolumeVK.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_VolumeVK.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Volume rendering in VK.
10  */
11 #ifndef GR_VolumeVK_h
12 #define GR_VolumeVK_h
13 
14 #include "GR_API.h"
15 #include "GR_GeoRenderVK.h"
16 #include "GR_VolumeRender.h"
17 
18 #include <RV/RV_Geometry.h>
19 #include <UT/UT_BoundingBox.h>
20 #include <UT/UT_Lock.h>
21 #include <UT/UT_Array.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_Vector3.h>
24 #include <GU/GU_Detail.h>
25 #include <GEO/GEO_PrimVolume.h>
26 
27 struct gr_VolumeAngleVector;
28 
29 class GR_VolumeSlice;
30 class GR_VolumeBase;
31 class GU_PrimVolume;
32 class RV_Geometry;
33 class RV_Render;
35 class RV_ShaderBlock;
36 class UT_Color;
37 
39 {
40 public:
42  ~GR_VolumeVK() override;
43 
44  const char *className() const override { return "GR_VolumeVK"; }
45 
46  void update(RE_RenderContext rc,
47  const GT_PrimitiveHandle &primh,
48  const GR_UpdateParms &parms,
49  const char *cache_name) override;
50 
52  const GR_DisplayOption &opts,
53  const char *cache_name,
54  RE_CacheVersion geo_version,
55  RE_CacheVersion select_version) override;
56 
57  void draw(RE_RenderContext rc,
60  GR_DrawParms dp) override;
61 
62  exint getNumGLPrimitives() const override;
63 
64  void setTexture(GR_TextureRef tex);
65 
66  void updateTexture(GR_TextureRef tex);
67  void clearTexture();
68  const GR_TextureRef &getTexture() const { return myVolumeTexture; }
69 
70  UT_Array<GR_VolumeSlice *> &slices() { return myGLVolumeSlices; }
71  const UT_Array<GR_VolumeSlice *> &slices() const { return myGLVolumeSlices; }
72 
73  static RV_VKImage* get3DNoise(RV_Render* r);
74  static RV_VKImage* get2DNoise(RV_Render* r);
75  static RV_VKImage* getBSplineWeights(RV_Render* r);
76 
77  void setDrawMotionVectors(bool v) { myDrawMotionVectors = v; }
78  bool getDrawMotionVectors() const
79  { return myDrawMotionVectors; }
80 
81  void setDrawNormals(bool v) { myDrawNormals = v; }
82  bool getDrawNormals() const { return myDrawNormals; }
83 
84  void setIsSelected(bool v) { myIsSelected = v; }
85  bool getIsSelected() const { return myIsSelected; }
86 
88  { return myInstanceTransforms; }
89 
90  static void cleanupSlices();
91  static bool initShaders(RV_Instance* inst);
92  static void initResources(RV_Render* r);
93  static void cleanupShaders();
94  static void cleanupResources();
95 
96  static float getCutoff(int x, int y, int z);
97  static void fillBSplineData(const UT_Span<fpreal32> &out_values);
98  static bool useBSplineInterpolation(const GR_CommonDispOption& opt);
99 
100 
101  // Expose Shaders so `GR_VolumeRender` can use them
102  static RV_ShaderProgram* getVolumeSliceShader(RV_Render *r, bool bspline);
103  static RV_ShaderProgram* getVolumeSliceShaderHQ(RV_Render *r, bool bspline);
104  static RV_ShaderProgram* getVolumeMaterialShader(RV_Render *r, bool bspline);
105  static RV_ShaderProgram* getVolumeNormalShader(RV_Render *r, bool bspline);
106  static RV_ShaderProgram* getVolumeMotionShader(RV_Render *r, bool bspline);
107 private:
108  bool updateVolume( const GT_PrimitiveHandle &primh,
109  const GR_UpdateParms &p);
110  void setInstanceTransforms(const UT_Matrix4DArray& inst);
111  bool updateViewAligned(UT_Matrix4D &proj,
112  UT_Matrix4D &view,
113  UT_Matrix4D &object,
114  const GR_DisplayOption &drawOpt);
115 
116 
117  /// draw setup down outside Render Pass
118  void drawSlices(RV_Render *r,
119  GR_Uniforms* uniforms,
121  bool draw_normals,
122  GR_RenderMode render_mode,
123  const GR_DisplayOption *opt);
124 
125  // draw commands executed inside a Render Pass
126  void renderSlices(RV_Render *r,
128  const UT_IntArray &selected,
130  const UT_IntArray &draw_count,
131  const UT_FloatArray &zincs,
132  const UT_FloatArray &depth,
133  float astep,
134  bool show_selection,
135  bool use_transparent,
136  bool draw_normals);
137 
138  static void sliceCube(void *data, int idx, int num, UT_Lock &lock);
139  static void barycenterTriangulateConvexPoly(const UT_Vector3Array &points,
140  float tolerance2,
141  UT_Vector3Array *out_points,
142  int total_depth=1, int d=0);
143  static void sortPolygonCCW(gr_VolumeAngleVector *points, int n);
144  static UT_Vector3 pointAverage(const UT_Vector3Array &points);
145  static void triangulate(const UT_Vector3Array &points,
146  float tolerance2,
147  UT_Vector3Array *out_points,
148  int total_depth=-1, int d=0);
149 
150  static constexpr int getMaxVolumeSilces();
151 
152  bool instanceSlices(UT_Matrix4D &proj,
153  UT_Matrix4D &view, UT_Matrix4D &object,
154  fpreal zinc);
155 
156  void clearSlices(bool free);
157 
158  GU_Detail myBox;
159  GEO_PrimVolumeXform myVolumeSpace;
160  UT_Vector3I myVolumeRes;
161  UT_BoundingBox myVolumeBounds;
162  GR_TextureRef myVolumeTexture;
163  UT_Matrix4DArray myInstanceTransforms;
164  bool myDrawMotionVectors = false;
165  bool myDrawNormals = false;
166  bool myIsSelected = false;
167 
168  static int theVolumePassID;
169 
170  UT_Array<GR_VolumeSlice *> myGLVolumeSlices;
171  UT_Array<GR_VolumeSlice *> myCachedSlices;
172  static RV_ShaderProgram* theVolumeSliceShader;
173  static RV_ShaderProgram* theVolumeSliceShaderMaterial;
174  static RV_ShaderProgram* theVolumeSliceNormalShader;
175  static RV_ShaderProgram* theVolumeSliceMVShader;
176 
177  UT_UniquePtr<RV_ShaderBlock> myVolumeUniforms;
179 
180  friend struct gr_SliceDrawTask;
181  friend class GR_VolumeRender;
182 };
183 
184 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
GLbitfield flags
Definition: glcorearb.h:1596
virtual void draw(RE_RenderContext r, GR_RenderMode mode, GR_RenderFlags flags, GR_DrawParms draw_parms)=0
Normal drawing method. Only issue rendering commands.
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
void setIsSelected(bool v)
Definition: GR_VolumeVK.h:84
static bool initShaders(RV_Instance *inst)
bool getIsSelected() const
Definition: GR_VolumeVK.h:85
const GLdouble * v
Definition: glcorearb.h:837
void setDrawMotionVectors(bool v)
Definition: GR_VolumeVK.h:77
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
int64 exint
Definition: SYS_Types.h:125
GT_API const UT_StringHolder cache_name
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GLint y
Definition: glcorearb.h:103
Temporary container for either a RV_Render and an RE_Render.
virtual exint getNumGLPrimitives() const =0
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
set of parameters sent to GR_Primitive::update()
GLdouble n
Definition: glcorearb.h:2008
GR_RenderMode
Definition: GR_Defines.h:48
#define GR_API
Definition: GR_API.h:10
const UT_Array< GR_VolumeSlice * > & slices() const
Definition: GR_VolumeVK.h:71
GR_RenderFlags
Definition: GR_Defines.h:88
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:48
GLint GLenum GLint x
Definition: glcorearb.h:409
const char * className() const override
Definition: GR_VolumeVK.h:44
GLenum mode
Definition: glcorearb.h:99
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:476
bool getDrawNormals() const
Definition: GR_VolumeVK.h:82
GA_API const UT_StringHolder parms
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_Array< GR_VolumeSlice * > & slices()
Definition: GR_VolumeVK.h:70
Simple class for a mutli-integer cache tag.
virtual void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const char *cache_name)=0
void setDrawNormals(bool v)
Definition: GR_VolumeVK.h:81
GLboolean r
Definition: glcorearb.h:1222
set of parameters sent to GR_Primitive::update()
Definition: GR_Uniforms.h:56
const GLuint * textures
Definition: glcorearb.h:416
const GR_TextureRef & getTexture() const
Definition: GR_VolumeVK.h:68
static void cleanupShaders()
bool getDrawMotionVectors() const
Definition: GR_VolumeVK.h:78
Definition: format.h:1821
virtual void viewUpdate(RE_RenderContext r, const GR_DisplayOption &opts, const char *cache_name, RE_CacheVersion geo_version, RE_CacheVersion select_version)
Definition: GR_GeoRender.h:64
const UT_Matrix4DArray & getInstanceTransforms() const
Definition: GR_VolumeVK.h:87