1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkDepthPeelingPass.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 // .NAME vtkDepthPeelingPass - Implement an Order Independent Transparency 16 // render pass. 17 // .SECTION Description 18 // Render the translucent polygonal geometry of a scene without sorting 19 // polygons in the view direction. 20 // 21 // This pass expects an initialized depth buffer and color buffer. 22 // Initialized buffers means they have been cleared with farest z-value and 23 // background color/gradient/transparent color. 24 // An opaque pass may have been performed right after the initialization. 25 // 26 // The depth peeling algorithm works by rendering the translucent polygonal 27 // geometry multiple times (once for each peel). The actually rendering of 28 // the translucent polygonal geometry is performed by its delegate 29 // TranslucentPass. This delegate is therefore used multiple times. 30 // 31 // Its delegate is usually set to a vtkTranslucentPass. 32 // 33 // .SECTION See Also 34 // vtkRenderPass, vtkTranslucentPass 35 36 #ifndef vtkDepthPeelingPass_h 37 #define vtkDepthPeelingPass_h 38 39 #include "vtkRenderingOpenGL2Module.h" // For export macro 40 #include "vtkRenderPass.h" 41 #include <vector> // STL Header 42 43 class vtkTextureObject; 44 class vtkOpenGLRenderWindow; 45 class vtkInformationIntegerKey; 46 class vtkInformationIntegerVectorKey; 47 namespace vtkgl 48 { 49 class CellBO; 50 } 51 52 class VTKRENDERINGOPENGL2_EXPORT vtkDepthPeelingPass : public vtkRenderPass 53 { 54 public: 55 static vtkDepthPeelingPass *New(); 56 vtkTypeMacro(vtkDepthPeelingPass,vtkRenderPass); 57 void PrintSelf(ostream& os, vtkIndent indent); 58 59 //BTX 60 // Description: 61 // Perform rendering according to a render state \p s. 62 // \pre s_exists: s!=0 63 virtual void Render(const vtkRenderState *s); 64 //ETX 65 66 // Description: 67 // Release graphics resources and ask components to release their own 68 // resources. 69 // \pre w_exists: w!=0 70 void ReleaseGraphicsResources(vtkWindow *w); 71 72 // Description: 73 // Delegate for rendering the translucent polygonal geometry. 74 // If it is NULL, nothing will be rendered and a warning will be emitted. 75 // It is usually set to a vtkTranslucentPass. 76 // Initial value is a NULL pointer. 77 vtkGetObjectMacro(TranslucentPass,vtkRenderPass); 78 virtual void SetTranslucentPass(vtkRenderPass *translucentPass); 79 80 // Description: 81 // In case of use of depth peeling technique for rendering translucent 82 // material, define the threshold under which the algorithm stops to 83 // iterate over peel layers. This is the ratio of the number of pixels 84 // that have been touched by the last layer over the total number of pixels 85 // of the viewport area. 86 // Initial value is 0.0, meaning rendering have to be exact. Greater values 87 // may speed-up the rendering with small impact on the quality. 88 vtkSetClampMacro(OcclusionRatio,double,0.0,0.5); 89 vtkGetMacro(OcclusionRatio,double); 90 91 // Description: 92 // In case of depth peeling, define the maximum number of peeling layers. 93 // Initial value is 4. A special value of 0 means no maximum limit. 94 // It has to be a positive value. 95 vtkSetMacro(MaximumNumberOfPeels,int); 96 vtkGetMacro(MaximumNumberOfPeels,int); 97 98 // Description: 99 // Tells if the last time this pass was executed, the depth peeling 100 // algorithm was actually used. Initial value is false. 101 vtkGetMacro(LastRenderingUsedDepthPeeling,bool); 102 103 // Description: 104 // Is rendering at translucent geometry stage using depth peeling and 105 // rendering a layer other than the first one? (Boolean value) 106 // If so, the uniform variables UseTexture and Texture can be set. 107 // (Used by vtkOpenGLProperty or vtkOpenGLTexture) 108 // int GetDepthPeelingHigherLayer(); 109 110 // Description: 111 // Required Key Indicating the texture unit for the opaque z texture unit 112 static vtkInformationIntegerKey *OpaqueZTextureUnit(); 113 114 // Description: 115 // Required Key Indicating the texture unit for the translucent z texture unit 116 static vtkInformationIntegerKey *TranslucentZTextureUnit(); 117 118 // Description: 119 // Required Key Indicating the size of the destination 120 static vtkInformationIntegerVectorKey *DestinationSize(); 121 122 protected: 123 // Description: 124 // Default constructor. TranslucentPass is set to NULL. 125 vtkDepthPeelingPass(); 126 127 // Description: 128 // Destructor. 129 virtual ~vtkDepthPeelingPass(); 130 131 vtkRenderPass *TranslucentPass; 132 vtkTimeStamp CheckTime; 133 bool IsSupported; 134 135 // Description: 136 // Cache viewport values for depth peeling. 137 int ViewportX; 138 int ViewportY; 139 int ViewportWidth; 140 int ViewportHeight; 141 142 // Description: 143 // Actual depth format: vtkgl::DEPTH_COMPONENT16_ARB 144 // or vtkgl::DEPTH_COMPONENT24_ARB 145 unsigned int DepthFormat; 146 147 // Description: 148 // In case of use of depth peeling technique for rendering translucent 149 // material, define the threshold under which the algorithm stops to 150 // iterate over peel layers. This is the ratio of the number of pixels 151 // that have been touched by the last layer over the total number of pixels 152 // of the viewport area. 153 // Initial value is 0.0, meaning rendering have to be exact. Greater values 154 // may speed-up the rendering with small impact on the quality. 155 double OcclusionRatio; 156 157 // Description: 158 // In case of depth peeling, define the maximum number of peeling layers. 159 // Initial value is 4. A special value of 0 means no maximum limit. 160 // It has to be a positive value. 161 int MaximumNumberOfPeels; 162 163 bool LastRenderingUsedDepthPeeling; 164 165 // Is rendering at translucent geometry stage using depth peeling and 166 // rendering a layer other than the first one? (Boolean value) 167 // If so, the uniform variables UseTexture and Texture can be set. 168 // (Used by vtkOpenGLProperty or vtkOpenGLTexture) 169 int DepthPeelingHigherLayer; 170 171 vtkgl::CellBO *FinalBlendProgram; 172 vtkgl::CellBO *IntermediateBlendProgram; 173 174 vtkTextureObject *OpaqueZTexture; 175 vtkTextureObject *OpaqueRGBATexture; 176 vtkTextureObject *TranslucentRGBATexture; 177 vtkTextureObject *TranslucentZTexture; 178 vtkTextureObject *CurrentRGBATexture; 179 std::vector<float> *DepthZData; 180 181 void BlendIntermediatePeels(vtkOpenGLRenderWindow *renWin); 182 void BlendFinalPeel(vtkOpenGLRenderWindow *renWin); 183 184 private: 185 vtkDepthPeelingPass(const vtkDepthPeelingPass&); // Not implemented. 186 void operator=(const vtkDepthPeelingPass&); // Not implemented. 187 }; 188 189 #endif 190