VTK  9.0.1
vtkDualDepthPeelingPass.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDualDepthPeelingPass.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
51 #ifndef vtkDualDepthPeelingPass_h
52 #define vtkDualDepthPeelingPass_h
53 
54 #include "vtkDepthPeelingPass.h"
55 #include "vtkRenderingOpenGL2Module.h" // For export macro
56 
57 #include <array> // For std::array!
58 
62 class vtkRenderTimerLog;
63 class vtkShaderProgram;
64 class vtkTextureObject;
65 
66 class VTKRENDERINGOPENGL2_EXPORT vtkDualDepthPeelingPass : public vtkDepthPeelingPass
67 {
68 public:
69  static vtkDualDepthPeelingPass* New();
71  void PrintSelf(ostream& os, vtkIndent indent) override;
72 
73  void Render(const vtkRenderState* s) override;
74  void ReleaseGraphicsResources(vtkWindow* w) override;
75 
77 
82  vtkGetObjectMacro(VolumetricPass, vtkRenderPass) virtual void SetVolumetricPass(
83  vtkRenderPass* volumetricPass);
85 
86  // vtkOpenGLRenderPass virtuals:
87  bool PreReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
88  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
89  bool PostReplaceShaderValues(std::string& vertexShader, std::string& geometryShader,
90  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop) override;
91  bool SetShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper, vtkProp* prop,
92  vtkOpenGLVertexArrayObject* VAO = nullptr) override;
94 
95 protected:
96  bool PostReplaceTranslucentShaderValues(std::string& vertexShader, std::string& geometryShader,
97  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
98  bool PreReplaceVolumetricShaderValues(std::string& vertexShader, std::string& geometryShader,
99  std::string& fragmentShader, vtkAbstractMapper* mapper, vtkProp* prop);
100  bool SetTranslucentShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
101  vtkProp* prop, vtkOpenGLVertexArrayObject* VAO);
102  bool SetVolumetricShaderParameters(vtkShaderProgram* program, vtkAbstractMapper* mapper,
103  vtkProp* prop, vtkOpenGLVertexArrayObject* VAO);
104 
105  // Name the textures used by this render pass. These are indexes into
106  // this->Textures
108  {
109  BackTemp = 0, // RGBA8 back-to-front peeling buffer
110  Back, // RGBA8 back-to-front accumulation buffer
111  FrontA, // RGBA8 front-to-back accumulation buffer
112  FrontB, // RGBA8 front-to-back accumulation buffer
113  DepthA, // RG32F min-max depth buffer
114  DepthB, // RG32F min-max depth buffer
115  OpaqueDepth, // Stores the depth map from the opaque passes
116 
117  NumberOfTextures
118  };
119 
120  // The stages of this multipass render pass:
122  {
126 
128  Inactive = -1,
129  };
130 
131  enum PeelType
132  {
134  VolumetricPeel
135  };
136 
138  ~vtkDualDepthPeelingPass() override;
139 
140  void SetCurrentStage(ShaderStage stage);
141  vtkSetMacro(CurrentPeelType, PeelType);
142 
146  void FreeGLObjects();
147 
151  void RenderTranslucentPass();
152 
156  void RenderVolumetricPass();
157 
158  bool IsRenderingVolumes();
159 
163  void Initialize(const vtkRenderState* state);
164 
166 
169  void InitColorTexture(vtkTextureObject* tex, const vtkRenderState* s);
170  void InitDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
171  void InitOpaqueDepthTexture(vtkTextureObject* tex, const vtkRenderState* s);
172  void InitFramebuffer(const vtkRenderState* s);
174 
179  void ActivateDrawBuffer(TextureName id) { this->ActivateDrawBuffers(&id, 1); }
180  template <size_t NumTextures>
181  void ActivateDrawBuffers(const std::array<TextureName, NumTextures>& a)
182  {
183  this->ActivateDrawBuffers(a.data(), a.size());
184  }
185  void ActivateDrawBuffers(const TextureName* ids, size_t numTextures);
191  void Prepare();
192 
193  void InitializeOcclusionQuery();
194  void CopyOpaqueDepthBuffer();
195  void InitializeDepth();
196 
197  void PeelVolumesOutsideTranslucentRange();
198 
199  bool PeelingDone();
200 
204  void Peel();
205 
206  // Depending on whether we're handling volumes or not, we'll initialize the
207  // front destination buffer by either clearing it or copying the last peel's
208  // output into it.
209  void PrepareFrontDestination();
210  void ClearFrontDestination();
211  void CopyFrontSourceToFrontDestination();
212 
213  void InitializeTargetsForTranslucentPass();
214  void InitializeTargetsForVolumetricPass();
215 
216  void PeelTranslucentGeometry();
217  void PeelVolumetricGeometry();
218 
219  void BlendBackBuffer();
220 
221  void StartTranslucentOcclusionQuery();
222  void EndTranslucentOcclusionQuery();
223 
224  void StartVolumetricOcclusionQuery();
225  void EndVolumetricOcclusionQuery();
226 
230  void SwapFrontBufferSourceDest();
231  void SwapDepthBufferSourceDest();
232 
233  void Finalize();
234 
235  void AlphaBlendRender();
236 
237  void BlendFinalImage();
238  void DeleteOcclusionQueryIds();
239 
243 
248 
249  vtkTextureObject* Textures[NumberOfTextures];
250 
251  TextureName FrontSource; // The current front source buffer
252  TextureName FrontDestination; // The current front destination buffer
253  TextureName DepthSource; // The current depth source buffer
254  TextureName DepthDestination; // The current depth destination buffer
255 
259 
266  unsigned int OcclusionThreshold;
267 
268  int TranslucentRenderCount; // Debug info, counts number of geometry passes.
269  int VolumetricRenderCount; // Debug info, counts number of volumetric passes.
270 
271  // Cached state:
276 
277 private:
279  void operator=(const vtkDualDepthPeelingPass&) = delete;
280 };
281 
282 #endif // vtkDualDepthPeelingPass_h
vtkDualDepthPeelingPass::PeelType
PeelType
Definition: vtkDualDepthPeelingPass.h:131
vtkDualDepthPeelingPass::FrontDestination
TextureName FrontDestination
Definition: vtkDualDepthPeelingPass.h:252
vtkOpenGLRenderPass::GetShaderStageMTime
virtual vtkMTimeType GetShaderStageMTime()
For multi-stage render passes that need to change shader code during a single pass,...
vtkDualDepthPeelingPass::SaveScissorTestState
bool SaveScissorTestState
Definition: vtkDualDepthPeelingPass.h:272
vtkDualDepthPeelingPass::TranslucentOcclusionQueryId
unsigned int TranslucentOcclusionQueryId
Definition: vtkDualDepthPeelingPass.h:262
vtkDualDepthPeelingPass
Implements the dual depth peeling algorithm.
Definition: vtkDualDepthPeelingPass.h:66
vtkDualDepthPeelingPass::ActivateDrawBuffers
void ActivateDrawBuffers(const std::array< TextureName, NumTextures > &a)
Bind and activate draw buffers.
Definition: vtkDualDepthPeelingPass.h:181
vtkDepthPeelingPass::New
static vtkDepthPeelingPass * New()
vtkDepthPeelingPass
Implement Depth Peeling for use within a framebuffer pass.
Definition: vtkDepthPeelingPass.h:63
vtkDualDepthPeelingPass::TranslucentPeel
@ TranslucentPeel
Definition: vtkDualDepthPeelingPass.h:133
vtkDualDepthPeelingPass::DepthB
@ DepthB
Definition: vtkDualDepthPeelingPass.h:114
vtkDualDepthPeelingPass::RenderState
const vtkRenderState * RenderState
Definition: vtkDualDepthPeelingPass.h:242
vtkDualDepthPeelingPass::BackBlendHelper
vtkOpenGLQuadHelper * BackBlendHelper
Definition: vtkDualDepthPeelingPass.h:246
vtkDualDepthPeelingPass::CopyDepthHelper
vtkOpenGLQuadHelper * CopyDepthHelper
Definition: vtkDualDepthPeelingPass.h:245
vtkDepthPeelingPass::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *w) override
Release graphics resources and ask components to release their own resources.
vtkDepthPeelingPass::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkDualDepthPeelingPass::InitializingDepth
@ InitializingDepth
Definition: vtkDualDepthPeelingPass.h:123
vtkDualDepthPeelingPass::VolumetricWrittenPixels
unsigned int VolumetricWrittenPixels
Definition: vtkDualDepthPeelingPass.h:265
vtkDualDepthPeelingPass::TextureName
TextureName
Definition: vtkDualDepthPeelingPass.h:107
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkDualDepthPeelingPass::CurrentStageTimeStamp
vtkTimeStamp CurrentStageTimeStamp
Definition: vtkDualDepthPeelingPass.h:258
vtkOpenGLRenderPass::PreReplaceShaderValues
virtual bool PreReplaceShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop)
Use vtkShaderProgram::Substitute to replace //VTK::XXX:YYY declarations in the shader sources.
vtkOpenGLFramebufferObject
Internal class which encapsulates OpenGL FramebufferObject.
Definition: vtkOpenGLFramebufferObject.h:181
vtkDualDepthPeelingPass::CurrentPeelType
PeelType CurrentPeelType
Definition: vtkDualDepthPeelingPass.h:257
vtkOpenGLQuadHelper
Class to make rendering a full screen quad easier.
Definition: vtkOpenGLQuadHelper.h:57
vtkDualDepthPeelingPass::NumberOfPasses
@ NumberOfPasses
Definition: vtkDualDepthPeelingPass.h:127
vtkDualDepthPeelingPass::FrontA
@ FrontA
Definition: vtkDualDepthPeelingPass.h:111
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
vtkDualDepthPeelingPass::DepthDestination
TextureName DepthDestination
Definition: vtkDualDepthPeelingPass.h:254
vtkDualDepthPeelingPass::Back
@ Back
Definition: vtkDualDepthPeelingPass.h:110
vtkDepthPeelingPass.h
vtkDualDepthPeelingPass::OcclusionThreshold
unsigned int OcclusionThreshold
Definition: vtkDualDepthPeelingPass.h:266
vtkDualDepthPeelingPass::CurrentStage
ShaderStage CurrentStage
Definition: vtkDualDepthPeelingPass.h:256
vtkShaderProgram
The ShaderProgram uses one or more Shader objects.
Definition: vtkShaderProgram.h:44
vtkDualDepthPeelingPass::LastPeelHadVolumes
bool LastPeelHadVolumes
Definition: vtkDualDepthPeelingPass.h:260
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkDepthPeelingPass::PostReplaceShaderValues
bool PostReplaceShaderValues(std::string &vertexShader, std::string &geometryShader, std::string &fragmentShader, vtkAbstractMapper *mapper, vtkProp *prop) override
Use vtkShaderProgram::Substitute to replace //VTK::XXX:YYY declarations in the shader sources.
vtkDualDepthPeelingPass::CullFaceEnabled
bool CullFaceEnabled
Definition: vtkDualDepthPeelingPass.h:274
vtkDualDepthPeelingPass::DepthA
@ DepthA
Definition: vtkDualDepthPeelingPass.h:113
vtkDualDepthPeelingPass::VolumetricRenderCount
int VolumetricRenderCount
Definition: vtkDualDepthPeelingPass.h:269
vtkRenderTimerLog
Asynchronously measures GPU execution times for a series of events.
Definition: vtkRenderTimerLog.h:80
vtkDualDepthPeelingPass::CopyColorHelper
vtkOpenGLQuadHelper * CopyColorHelper
Definition: vtkDualDepthPeelingPass.h:244
vtkDepthPeelingPass::Render
void Render(const vtkRenderState *s) override
Perform rendering according to a render state s.
vtkDualDepthPeelingPass::TranslucentRenderCount
int TranslucentRenderCount
Definition: vtkDualDepthPeelingPass.h:268
vtkProp
abstract superclass for all actors, volumes and annotations
Definition: vtkProp.h:53
vtkX3D::string
@ string
Definition: vtkX3D.h:496
vtkDualDepthPeelingPass::Timer
vtkRenderTimerLog * Timer
Definition: vtkDualDepthPeelingPass.h:240
vtkDualDepthPeelingPass::VolumetricPass
vtkRenderPass * VolumetricPass
Definition: vtkDualDepthPeelingPass.h:241
vtkDualDepthPeelingPass::BlendHelper
vtkOpenGLQuadHelper * BlendHelper
Definition: vtkDualDepthPeelingPass.h:247
vtkDualDepthPeelingPass::AlphaBlending
@ AlphaBlending
Definition: vtkDualDepthPeelingPass.h:125
vtkDualDepthPeelingPass::FrontSource
TextureName FrontSource
Definition: vtkDualDepthPeelingPass.h:251
vtkDualDepthPeelingPass::Peeling
@ Peeling
Definition: vtkDualDepthPeelingPass.h:124
vtkDualDepthPeelingPass::OpaqueDepth
@ OpaqueDepth
Definition: vtkDualDepthPeelingPass.h:115
vtkDualDepthPeelingPass::ActivateDrawBuffer
void ActivateDrawBuffer(TextureName id)
Bind and activate draw buffers.
Definition: vtkDualDepthPeelingPass.h:179
vtkDualDepthPeelingPass::CurrentPeel
int CurrentPeel
Definition: vtkDualDepthPeelingPass.h:261
vtkDepthPeelingPass::SetShaderParameters
bool SetShaderParameters(vtkShaderProgram *program, vtkAbstractMapper *mapper, vtkProp *prop, vtkOpenGLVertexArrayObject *VAO=nullptr) override
Update the uniforms of the shader program.
vtkDualDepthPeelingPass::FrontB
@ FrontB
Definition: vtkDualDepthPeelingPass.h:112
vtkDualDepthPeelingPass::DepthSource
TextureName DepthSource
Definition: vtkDualDepthPeelingPass.h:253
vtkDualDepthPeelingPass::CullFaceMode
int CullFaceMode
Definition: vtkDualDepthPeelingPass.h:273
vtkRenderState
Context in which a vtkRenderPass will render.
Definition: vtkRenderState.h:40
vtkOpenGLVertexArrayObject
The VertexArrayObject class uses, or emulates, vertex array objects.
Definition: vtkOpenGLVertexArrayObject.h:36
vtkDualDepthPeelingPass::TranslucentWrittenPixels
unsigned int TranslucentWrittenPixels
Definition: vtkDualDepthPeelingPass.h:263
vtkDualDepthPeelingPass::VolumetricOcclusionQueryId
unsigned int VolumetricOcclusionQueryId
Definition: vtkDualDepthPeelingPass.h:264
vtkAbstractMapper
abstract class specifies interface to map data
Definition: vtkAbstractMapper.h:52
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
vtkDualDepthPeelingPass::ShaderStage
ShaderStage
Definition: vtkDualDepthPeelingPass.h:121
vtkRenderPass
Perform part of the rendering of a vtkRenderer.
Definition: vtkRenderPass.h:56
vtkDualDepthPeelingPass::DepthTestEnabled
bool DepthTestEnabled
Definition: vtkDualDepthPeelingPass.h:275