Commit 925f5066 authored by Ken Martin's avatar Ken Martin

Add in depth peeling pass and a couple other passes

Convert depth peeling render pass to the OpenGL2 backend.
Also add a new class that encapsulates the basic rendering
steps that VTK uses.

Modify the renderer to use the depth peeling pass instead of
having two copies of the code lying around. Removed the depth
peeling code from Mapper2D as it is no longer needed now that we
have CopyToFrameBuffer working. That is a lighter weight way to
get a quad up on the screen. Plus that keeps the depth peeling
code more localized as it should be. Clean up a lot of depth
peeling code that was in the renderer and now there are cleaner
ways of doing it (passing information keys).

Change-Id: I8d0a53bb25920bd30eade49ed12126b9b44be358
parent 2b642e2e
......@@ -172,7 +172,9 @@ vtkIdType vtkOpenGLContextBufferId::GetPickedItem(int x, int y)
this->Texture->Bind();
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glEnable(GL_TEXTURE_2D);
this->Texture->CopyToFrameBuffer(x,y,x,y,x,y,this->Context,NULL,NULL);
this->Texture->CopyToFrameBuffer(x,y,x,y,x,y,
this->Context->GetSize()[0],
this->Context->GetSize()[1],NULL,NULL);
glDisable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // restore
......
......@@ -142,7 +142,6 @@ int TestOpacity(int argc, char* argv[])
planeActor->SetMapper(planeMapper);
planeMapper->Delete();
renderer->AddActor(planeActor);
planeActor->Delete();
vtkProperty *planeProperty=vtkProperty::New();
planeProperty->SetOpacity(1.0);
......@@ -151,6 +150,7 @@ int TestOpacity(int argc, char* argv[])
planeProperty->Delete();
planeProperty->SetBackfaceCulling(0);
planeProperty->SetFrontfaceCulling(0);
planeActor->Delete();
renderer->SetUseDepthPeeling(1);
// reasonable depth peeling settings
......
......@@ -20,8 +20,11 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/vtkTDxConfigure.h.in
set(Module_SRCS
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx
vtkCameraPass.cxx
vtkClearRGBPass.cxx
vtkClearZPass.cxx
vtkCompositePolyDataMapper2.cxx
vtkDefaultPass.cxx
vtkDepthPeelingPass.cxx
vtkGaussianBlurPass.cxx
vtkImageProcessingPass.cxx
vtkLightsPass.cxx
......@@ -43,6 +46,7 @@ set(Module_SRCS
vtkOpenGLTexture.cxx
vtkOverlayPass.cxx
vtkRenderPass.cxx
vtkRenderStepsPass.cxx
vtkRenderPassCollection.cxx
vtkRenderState.cxx
vtkSequencePass.cxx
......@@ -99,29 +103,24 @@ set_source_files_properties(
)
set(shader_files
glsl/vtkglPolyData2DVS.glsl
glsl/vtkDepthPeelingPassFinalFS.glsl
glsl/vtkDepthPeelingPassIntermediateFS.glsl
glsl/vtkGaussianBlurPassFS.glsl
glsl/vtkGaussianBlurPassVS.glsl
glsl/vtkSobelGradientMagnitudePass1FS.glsl
glsl/vtkSobelGradientMagnitudePass2FS.glsl
glsl/vtkTextureObjectFS.glsl
glsl/vtkTextureObjectVS.glsl
glsl/vtkglGlyph3DVSFragmentLit.glsl
glsl/vtkglPolyData2DFS.glsl
glsl/vtkglPolyDataVSNoLighting.glsl
glsl/vtkglPolyDataFSNoLighting.glsl
glsl/vtkglPolyDataVSFragmentLit.glsl
glsl/vtkglPolyData2DVS.glsl
glsl/vtkglPolyDataFSHeadlight.glsl
glsl/vtkglPolyDataFSLightKit.glsl
glsl/vtkglPolyDataFSNoLighting.glsl
glsl/vtkglPolyDataFSPositionalLights.glsl
glsl/vtkglGlyph3DVSFragmentLit.glsl
glsl/vtkTextureObjectVS.glsl
glsl/vtkTextureObjectFS.glsl
glsl/vtkGaussianBlurPassVS.glsl
glsl/vtkGaussianBlurPassFS.glsl
glsl/vtkSobelGradientMagnitudePass1FS.glsl
glsl/vtkSobelGradientMagnitudePass2FS.glsl
glsl/vtkglPolyDataVSFragmentLit.glsl
glsl/vtkglPolyDataVSNoLighting.glsl
)
unset(shader_h_files)
foreach(file ${shader_files})
get_filename_component(file_we ${file} NAME_WE)
......
......@@ -30,6 +30,7 @@
#include "vtkOpenGLRenderer.h"
#include "vtkActor.h"
#include "vtkConeSource.h"
#include "vtkImageSinusoidSource.h"
#include "vtkImageData.h"
#include "vtkImageDataGeometryFilter.h"
......@@ -38,17 +39,10 @@
#include "vtkLookupTable.h"
#include "vtkCamera.h"
#include "vtkCameraPass.h"
#include "vtkLightsPass.h"
#include "vtkSequencePass.h"
#include "vtkOpaquePass.h"
//#include "vtkDepthPeelingPass.h"
#include "vtkTranslucentPass.h"
#include "vtkVolumetricPass.h"
#include "vtkOverlayPass.h"
#include "vtkRenderPassCollection.h"
#include "vtkDepthPeelingPass.h"
#include "vtkGaussianBlurPass.h"
#include "vtkConeSource.h"
#include "vtkRenderStepsPass.h"
int TestGaussianBlurPass(int argc, char* argv[])
{
......@@ -68,54 +62,29 @@ int TestGaussianBlurPass(int argc, char* argv[])
vtkOpenGLRenderer *glrenderer =
vtkOpenGLRenderer::SafeDownCast(renderer.GetPointer());
vtkSmartPointer<vtkCameraPass> cameraP=
vtkSmartPointer<vtkCameraPass>::New();
// create the basic VTK render steps
vtkSmartPointer<vtkRenderStepsPass> basicPasses =
vtkSmartPointer<vtkRenderStepsPass>::New();
vtkSmartPointer<vtkSequencePass> seq=
vtkSmartPointer<vtkSequencePass>::New();
vtkSmartPointer<vtkOpaquePass> opaque=
vtkSmartPointer<vtkOpaquePass>::New();
/*
// replace the default translucent pass with
// a more advanced depth peeling pass
vtkSmartPointer<vtkDepthPeelingPass> peeling=
vtkSmartPointer<vtkDepthPeelingPass>::New();
peeling->SetMaximumNumberOfPeels(200); // these settings make no sense 200, 0.1?
peeling->SetOcclusionRatio(0.1); // far more reasonable values would be 50, 0.01
*/
vtkSmartPointer<vtkTranslucentPass> translucent=
vtkSmartPointer<vtkTranslucentPass>::New();
//peeling->SetTranslucentPass(translucent);
vtkSmartPointer<vtkVolumetricPass> volume=
vtkSmartPointer<vtkVolumetricPass>::New();
vtkSmartPointer<vtkOverlayPass> overlay=
vtkSmartPointer<vtkOverlayPass>::New();
vtkSmartPointer<vtkLightsPass> lights=
vtkSmartPointer<vtkLightsPass>::New();
vtkSmartPointer<vtkRenderPassCollection> passes=
vtkSmartPointer<vtkRenderPassCollection>::New();
passes->AddItem(lights);
passes->AddItem(opaque);
// passes->AddItem(peeling);
passes->AddItem(translucent);
passes->AddItem(volume);
passes->AddItem(overlay);
seq->SetPasses(passes);
cameraP->SetDelegatePass(seq);
peeling->SetMaximumNumberOfPeels(20);
peeling->SetOcclusionRatio(0.001);
peeling->SetTranslucentPass(basicPasses->GetTranslucentPass());
basicPasses->SetTranslucentPass(peeling);
// finally blur the resulting image
// The blur delegates rendering the unblured image
// to the basicPasses
vtkSmartPointer<vtkGaussianBlurPass> blurP=
vtkSmartPointer<vtkGaussianBlurPass>::New();
blurP->SetDelegatePass(cameraP);
blurP->SetDelegatePass(basicPasses);
// tell the renderer to use our render pass pipeline
glrenderer->SetPass(blurP);
// renderer->SetPass(cameraP);
// glrenderer->SetPass(basicPasses);
vtkSmartPointer<vtkImageSinusoidSource> imageSource=
vtkSmartPointer<vtkImageSinusoidSource>::New();
......@@ -170,28 +139,22 @@ int TestGaussianBlurPass(int argc, char* argv[])
renderer->SetBackground(0.1,0.3,0.0);
renWin->SetSize(400,400);
// empty scene during OpenGL detection.
actor->SetVisibility(0);
coneActor->SetVisibility(0);
renWin->Render();
int retVal;
actor->SetVisibility(1);
coneActor->SetVisibility(1);
renderer->ResetCamera();
vtkCamera *camera=renderer->GetActiveCamera();
camera->Azimuth(-40.0);
camera->Elevation(20.0);
renderer->ResetCamera();
renWin->Render();
// if(peeling->GetLastRenderingUsedDepthPeeling())
// {
// cout<<"depth peeling was used"<<endl;
// }
// else
// {
// cout<<"depth peeling was not used (alpha blending instead)"<<endl;
// }
if(peeling->GetLastRenderingUsedDepthPeeling())
{
cout<<"depth peeling was used"<<endl;
}
else
{
cout<<"depth peeling was not used (alpha blending instead)"<<endl;
}
retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDepthPeelingPassFinalFS.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
varying vec2 tcoordVC;
uniform sampler2D translucentRGBATexture;
uniform sampler2D opaqueRGBATexture;
void main()
{
vec4 t1Color = texture2D(translucentRGBATexture, tcoordVC);
vec4 t2Color = texture2D(opaqueRGBATexture, tcoordVC);
gl_FragColor.a = 1.0;
gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*(1.0-t1Color.a));
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDepthPeelingPassIntermediateFS.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
varying vec2 tcoordVC;
uniform sampler2D translucentRGBATexture;
uniform sampler2D currentRGBATexture;
void main()
{
vec4 t1Color = texture2D(translucentRGBATexture, tcoordVC);
vec4 t2Color = texture2D(currentRGBATexture, tcoordVC);
gl_FragColor.a = t1Color.a + t2Color.a * (1.0-t1Color.a);
if (gl_FragColor.a > 0.0)
{
gl_FragColor.rgb = (t1Color.rgb*t1Color.a + t2Color.rgb*t2Color.a*(1.0-t1Color.a))/gl_FragColor.a;
}
else
{
gl_FragColor.rgb = vec3(0.0,0.0,0.0);
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkClearRGBPass.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkClearRGBPass.h"
#include "vtkObjectFactory.h"
#include "vtkRenderState.h"
#include "vtkRenderer.h"
#include "vtk_glew.h"
vtkStandardNewMacro(vtkClearRGBPass);
// ----------------------------------------------------------------------------
vtkClearRGBPass::vtkClearRGBPass()
{
this->Background[0] = 0;
this->Background[1] = 0;
this->Background[2] = 0;
}
// ----------------------------------------------------------------------------
vtkClearRGBPass::~vtkClearRGBPass()
{
}
// ----------------------------------------------------------------------------
void vtkClearRGBPass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Background:"
<< this->Background[0] << "," << this->Background[1] << ","
<< this->Background[2] << endl;
}
// ----------------------------------------------------------------------------
void vtkClearRGBPass::Render(const vtkRenderState *s)
{
(void)s;
this->NumberOfRenderedProps=0;
glClearColor( static_cast<GLclampf>(this->Background[0]),
static_cast<GLclampf>(this->Background[1]),
static_cast<GLclampf>(this->Background[2]),
static_cast<GLclampf>(0.0));
glClear(GL_COLOR_BUFFER_BIT);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkClearRGBPass.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkClearRGBPass - Paint in the color buffer.
// .SECTION Description
// Clear the color buffer to the specified color.
//
// .SECTION See Also
// vtkValuePasses
#ifndef __vtkClearRGBPass_h
#define __vtkClearRGBPass_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkRenderPass.h"
class vtkOpenGLRenderWindow;
class VTKRENDERINGOPENGL2_EXPORT vtkClearRGBPass : public vtkRenderPass
{
public:
static vtkClearRGBPass *New();
vtkTypeMacro(vtkClearRGBPass,vtkRenderPass);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Perform rendering according to a render state s.
virtual void Render(const vtkRenderState *s);
// Description:
// Set/Get the background color of the rendering screen using an rgb color
// specification.
vtkSetVector3Macro(Background,double);
vtkGetVector3Macro(Background,double);
protected:
// Description:
// Default constructor.
vtkClearRGBPass();
// Description:
// Destructor.
virtual ~vtkClearRGBPass();
double Background[3];
private:
vtkClearRGBPass(const vtkClearRGBPass&); // Not implemented.
void operator=(const vtkClearRGBPass&); // Not implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkClearZPass.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkClearZPass.h"
#include "vtkObjectFactory.h"
#include <cassert>
#include "vtkRenderState.h"
#include "vtkRenderer.h"
#include "vtk_glew.h"
vtkStandardNewMacro(vtkClearZPass);
// ----------------------------------------------------------------------------
vtkClearZPass::vtkClearZPass()
{
this->Depth=1.0;
}
// ----------------------------------------------------------------------------
vtkClearZPass::~vtkClearZPass()
{
}
// ----------------------------------------------------------------------------
void vtkClearZPass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Depth:" << this->Depth << endl;
}
// ----------------------------------------------------------------------------
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
void vtkClearZPass::Render(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
(void)s;
this->NumberOfRenderedProps=0;
glDepthMask(GL_TRUE);
glClearDepth(this->Depth);
glClear(GL_DEPTH_BUFFER_BIT);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkClearZPass.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkClearZPass - Clear the depth buffer with a given value.
// .SECTION Description
// Clear the depth buffer with a given value.
//
// .SECTION See Also
// vtkRenderPass
#ifndef __vtkClearZPass_h
#define __vtkClearZPass_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkRenderPass.h"
class vtkOpenGLRenderWindow;
class VTKRENDERINGOPENGL2_EXPORT vtkClearZPass : public vtkRenderPass
{
public:
static vtkClearZPass *New();
vtkTypeMacro(vtkClearZPass,vtkRenderPass);
void PrintSelf(ostream& os, vtkIndent indent);
//BTX
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
virtual void Render(const vtkRenderState *s);
//ETX
// Description:
// Set/Get the depth value. Initial value is 1.0 (farest).
vtkSetClampMacro(Depth,double,0.0,1.0);
vtkGetMacro(Depth,double);
protected:
// Description:
// Default constructor.
vtkClearZPass();
// Description:
// Destructor.
virtual ~vtkClearZPass();
double Depth;
private:
vtkClearZPass(const vtkClearZPass&); // Not implemented.
void operator=(const vtkClearZPass&); // Not implemented.
};
#endif
......@@ -61,6 +61,9 @@ void vtkDefaultPass::RenderOpaqueGeometry(const vtkRenderState *s)
{
assert("pre s_exits" && s!=0);
// initialize to false
this->SetLastRenderingUsedDepthPeeling(s->GetRenderer(), false);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
......@@ -79,6 +82,9 @@ void vtkDefaultPass::RenderFilteredOpaqueGeometry(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
// initialize to false
this->SetLastRenderingUsedDepthPeeling(s->GetRenderer(), false);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDepthPeelingPass.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkDepthPeelingPass - Implement an Order Independent Transparency
// render pass.
// .SECTION Description
// Render the translucent polygonal geometry of a scene without sorting
// polygons in the view direction.
//
// This pass expects an initialized depth buffer and color buffer.
// Initialized buffers means they have been cleared with farest z-value and
// background color/gradient/transparent color.
// An opaque pass may have been performed right after the initialization.
//
// The depth peeling algorithm works by rendering the translucent polygonal
// geometry multiple times (once for each peel). The actually rendering of
// the translucent polygonal geometry is performed by its delegate
// TranslucentPass. This delegate is therefore used multiple times.
//
// Its delegate is usually set to a vtkTranslucentPass.
//
// .SECTION See Also
// vtkRenderPass, vtkTranslucentPass
#ifndef __vtkDepthPeelingPass_h
#define __vtkDepthPeelingPass_h
#include "vtkRenderingOpenGL2Module.h" // For export macro
#include "vtkRenderPass.h"
#include <vector> // STL Header
class vtkTextureObject;
class vtkOpenGLRenderWindow;
class vtkInformationIntegerKey;
class vtkInformationIntegerVectorKey;
namespace vtkgl
{
class CellBO;
}
class VTKRENDERINGOPENGL2_EXPORT vtkDepthPeelingPass : public vtkRenderPass
{
public:
static vtkDepthPeelingPass *New();
vtkTypeMacro(vtkDepthPeelingPass,vtkRenderPass);
void PrintSelf(ostream& os, vtkIndent indent);
//BTX
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
virtual void Render(const vtkRenderState *s);
//ETX
// Description:
// Release graphics resources and ask components to release their own
// resources.
// \pre w_exists: w!=0