Commit dd786767 authored by Francois Bertel's avatar Francois Bertel
Browse files

ENH:More progress on multipass rendering.

parent 4fe9da1f
......@@ -188,6 +188,11 @@ ENDIF(VTK_USE_CG_SHADERS)
SET( KitOpenGL_SRCS
vtkCameraPass.cxx
vtkDefaultPass.cxx
vtkDepthPeelingPass.cxx
vtkLightsPass.cxx
vtkOpaquePass.cxx
vtkOpenGLActor.cxx
vtkOpenGLCamera.cxx
vtkOpenGLClipPlanesPainter.cxx
......@@ -208,10 +213,15 @@ SET( KitOpenGL_SRCS
vtkOpenGLRepresentationPainter.cxx
vtkOpenGLScalarsToColorsPainter.cxx
vtkOpenGLTexture.cxx
vtkOverlayPass.cxx
vtkRenderPassCollection.cxx
vtkSequencePass.cxx
vtkShader2.cxx
vtkShader2Collection.cxx
vtkShaderProgram2.cxx
vtkTranslucentPass.cxx
vtkUniformVariables.cxx
vtkVolumetricPass.cxx
)
IF(VTK_USE_GLSL_SHADERS)
......@@ -248,11 +258,21 @@ SET_SOURCE_FILES_PROPERTIES(
)
SET_SOURCE_FILES_PROPERTIES(
vtkCameraPass
vtkDefaultPass
vtkDepthPeelingPass
vtkLightsPass
vtkOpaquePass
vtkRenderPass
vtkRenderState
vtkOverlayPass
vtkRenderPassCollection
vtkSequencePass
vtkShader2
vtkShader2Collection
vtkShaderProgram2
vtkTranslucentPass
vtkVolumetricPass
WRAP_EXCLUDE
)
......@@ -284,6 +304,7 @@ ENDIF(VTK_USE_X)
# The set of source files to be encoded.
SET(glsl_files
vtkDepthPeeling_fs
vtkOpenGLRenderer_PeelingFS
vtkOpenGLPropertyDefaultPropFunc_fs
vtkOpenGLPropertyDefaultMain_fs
......
......@@ -36,8 +36,9 @@ IF(VTK_USE_DISPLAY)
TestTextActor3DDepthPeeling.cxx
TestTranslucentLUTAlphaBlending.cxx
TestTranslucentLUTDepthPeeling.cxx
TestTranslucentLUTDepthPeelingPass.cxx
TestTranslucentLUTTextureAlphaBlending.cxx
TestTranslucentLUTTextureDepthPeeling.cxx
TestTranslucentLUTTextureDepthPeeling.cxx
)
IF(VTK_DATA_ROOT)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestTranslucentLUTDepthPeelingPass.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.
=========================================================================*/
// This test covers rendering of an actor with a translucent LUT and depth
// peeling using the multi renderpass classes. The mapper uses color
// interpolation (poor quality).
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkActor.h"
#include "vtkImageSinusoidSource.h"
#include "vtkImageData.h"
#include "vtkImageDataGeometryFilter.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkPolyDataMapper.h"
#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"
int TestTranslucentLUTDepthPeelingPass(int argc, char* argv[])
{
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->SetMultiSamples(0);
renWin->SetAlphaBitPlanes(1);
iren->SetRenderWindow(renWin);
renWin->Delete();
vtkRenderer *renderer = vtkRenderer::New();
renWin->AddRenderer(renderer);
renderer->Delete();
vtkCameraPass *cameraP=vtkCameraPass::New();
vtkSequencePass *seq=vtkSequencePass::New();
vtkOpaquePass *opaque=vtkOpaquePass::New();
vtkDepthPeelingPass *peeling=vtkDepthPeelingPass::New();
peeling->SetMaximumNumberOfPeels(200);
peeling->SetOcclusionRatio(0.1);
vtkTranslucentPass *translucent=vtkTranslucentPass::New();
peeling->SetTranslucentPass(translucent);
vtkVolumetricPass *volume=vtkVolumetricPass::New();
vtkOverlayPass *overlay=vtkOverlayPass::New();
vtkLightsPass *lights=vtkLightsPass::New();
vtkRenderPassCollection *passes=vtkRenderPassCollection::New();
passes->AddItem(lights);
passes->AddItem(opaque);
passes->AddItem(peeling);
passes->AddItem(volume);
passes->AddItem(overlay);
seq->SetPasses(passes);
cameraP->SetDelegatePass(seq);
renderer->SetPass(cameraP);
opaque->Delete();
peeling->Delete();
translucent->Delete();
volume->Delete();
overlay->Delete();
seq->Delete();
passes->Delete();
cameraP->Delete();
lights->Delete();
vtkImageSinusoidSource *imageSource=vtkImageSinusoidSource::New();
imageSource->SetWholeExtent(0,9,0,9,0,9);
imageSource->SetPeriod(5);
imageSource->Update();
vtkImageData *image=imageSource->GetOutput();
double range[2];
image->GetScalarRange(range);
vtkDataSetSurfaceFilter *surface=vtkDataSetSurfaceFilter::New();
surface->SetInputConnection(imageSource->GetOutputPort());
imageSource->Delete();
vtkPolyDataMapper *mapper=vtkPolyDataMapper::New();
mapper->SetInputConnection(surface->GetOutputPort());
surface->Delete();
vtkLookupTable *lut=vtkLookupTable::New();
lut->SetTableRange(range);
lut->SetAlphaRange(0.5,0.5);
lut->SetHueRange(0.2,0.7);
lut->SetNumberOfTableValues(256);
lut->Build();
mapper->SetScalarVisibility(1);
mapper->SetLookupTable(lut);
lut->Delete();
vtkActor *actor=vtkActor::New();
renderer->AddActor(actor);
actor->Delete();
actor->SetMapper(mapper);
mapper->Delete();
renderer->SetBackground(0.1,0.3,0.0);
renWin->SetSize(400,400);
renWin->Render();
if(peeling->GetLastRenderingUsedDepthPeeling())
{
cout<<"depth peeling was used"<<endl;
}
else
{
cout<<"depth peeling was not used (alpha blending instead)"<<endl;
}
vtkCamera *camera=renderer->GetActiveCamera();
camera->Azimuth(-40.0);
camera->Elevation(20.0);
renWin->Render();
int retVal = vtkRegressionTestImage( renWin );
if ( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
iren->Delete();
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCameraPass.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 "vtkCameraPass.h"
#include "vtkObjectFactory.h"
#include <assert.h>
#include "vtkRenderState.h"
#include "vtkRenderer.h"
#include "vtkgl.h"
vtkCxxRevisionMacro(vtkCameraPass, "1.1");
vtkStandardNewMacro(vtkCameraPass);
vtkCxxSetObjectMacro(vtkCameraPass,DelegatePass,vtkRenderPass);
// ----------------------------------------------------------------------------
vtkCameraPass::vtkCameraPass()
{
this->DelegatePass=0;
}
// ----------------------------------------------------------------------------
vtkCameraPass::~vtkCameraPass()
{
if(this->DelegatePass!=0)
{
this->DelegatePass->Delete();
}
}
// ----------------------------------------------------------------------------
void vtkCameraPass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "DelegatePass:";
if(this->DelegatePass!=0)
{
this->DelegatePass->PrintSelf(os,indent);
}
else
{
os << "(none)" <<endl;
}
}
// ----------------------------------------------------------------------------
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
void vtkCameraPass::Render(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
this->NumberOfRenderedProps=0;
this->UpdateCamera(s->GetRenderer());
if(this->DelegatePass!=0)
{
this->DelegatePass->Render(s);
this->NumberOfRenderedProps+=
this->DelegatePass->GetNumberOfRenderedProps();
}
else
{
vtkWarningMacro(<<" no delegate.");
}
// clean up the model view matrix set up by the camera
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
// ----------------------------------------------------------------------------
// Description:
// Release graphics resources and ask components to release their own
// resources.
// \pre w_exists: w!=0
void vtkCameraPass::ReleaseGraphicsResources(vtkWindow *w)
{
assert("pre: w_exists" && w!=0);
if(this->DelegatePass!=0)
{
this->DelegatePass->ReleaseGraphicsResources(w);
}
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCameraPass.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 vtkCameraPass - Implement the camera render pass.
// .SECTION Description
// Render the camera.
//
// It setups the projection and modelview matrices and can clear the background
// It calls its delegate once.
// After its delegate returns, it restore the modelview matrix stack.
//
// Its delegate is usually set to a vtkSequencePass with a vtkLigthsPass and
// a list of passes for the geometry.
//
// .SECTION See Also
// vtkRenderPass
#ifndef __vtkCameraPass_h
#define __vtkCameraPass_h
#include "vtkRenderPass.h"
class VTK_RENDERING_EXPORT vtkCameraPass : public vtkRenderPass
{
public:
static vtkCameraPass *New();
vtkTypeRevisionMacro(vtkCameraPass,vtkRenderPass);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
virtual void Render(const vtkRenderState *s);
// Description:
// Release graphics resources and ask components to release their own
// resources.
// \pre w_exists: w!=0
void ReleaseGraphicsResources(vtkWindow *w);
// Description:
// Delegate for rendering the geometry.
// If it is NULL, nothing will be rendered and a warning will be emitted.
// It is usually set to a vtkSequencePass with a vtkLigthsPass and
// a list of passes for the geometry.
// Initial value is a NULL pointer.
vtkGetObjectMacro(DelegatePass,vtkRenderPass);
virtual void SetDelegatePass(vtkRenderPass *delegatePass);
protected:
// Description:
// Default constructor. DelegatePass is set to NULL.
vtkCameraPass();
// Description:
// Destructor.
virtual ~vtkCameraPass();
vtkRenderPass *DelegatePass;
private:
vtkCameraPass(const vtkCameraPass&); // Not implemented.
void operator=(const vtkCameraPass&); // Not implemented.
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDefaultPass.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 "vtkDefaultPass.h"
#include "vtkObjectFactory.h"
#include <assert.h>
#include "vtkRenderState.h"
#include "vtkProp.h"
#include "vtkRenderer.h"
vtkCxxRevisionMacro(vtkDefaultPass, "1.1");
vtkStandardNewMacro(vtkDefaultPass);
// ----------------------------------------------------------------------------
vtkDefaultPass::vtkDefaultPass()
{
}
// ----------------------------------------------------------------------------
vtkDefaultPass::~vtkDefaultPass()
{
}
// ----------------------------------------------------------------------------
void vtkDefaultPass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
// ----------------------------------------------------------------------------
// Description:
// Perform rendering according to a render state \p s.
// \pre s_exists: s!=0
void vtkDefaultPass::Render(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
this->NumberOfRenderedProps=0;
this->RenderOpaqueGeometry(s);
this->RenderTranslucentPolygonalGeometry(s);
this->RenderVolumetricGeometry(s);
this->RenderOverlay(s);
}
// ----------------------------------------------------------------------------
// Description:
// Opaque pass without key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderOpaqueGeometry(const vtkRenderState *s)
{
assert("pre s_exits" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
int rendered=s->GetPropArray()[i]->RenderOpaqueGeometry(s->GetRenderer());
this->NumberOfRenderedProps+=rendered;
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Opaque pass with key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderFilteredOpaqueGeometry(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
vtkProp *p=s->GetPropArray()[i];
if(p->HasKeys(s->GetRequiredKeys()))
{
int rendered=
p->RenderFilteredOpaqueGeometry(s->GetRenderer(),s->GetRequiredKeys());
this->NumberOfRenderedProps+=rendered;
}
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Translucent pass without key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderTranslucentPolygonalGeometry(
const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
vtkProp *p=s->GetPropArray()[i];
int rendered=p->RenderTranslucentPolygonalGeometry(s->GetRenderer());
this->NumberOfRenderedProps+=rendered;
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Translucent pass with key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderFilteredTranslucentPolygonalGeometry(
const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
vtkProp *p=s->GetPropArray()[i];
if(p->HasKeys(s->GetRequiredKeys()))
{
int rendered=p->RenderFilteredTranslucentPolygonalGeometry(s->GetRenderer(),s->GetRequiredKeys());
this->NumberOfRenderedProps+=rendered;
}
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Volume pass without key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderVolumetricGeometry(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
int rendered=
s->GetPropArray()[i]->RenderVolumetricGeometry(s->GetRenderer());
this->NumberOfRenderedProps+=rendered;
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Translucent pass with key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderFilteredVolumetricGeometry(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
vtkProp *p=s->GetPropArray()[i];
if(p->HasKeys(s->GetRequiredKeys()))
{
int rendered=
p->RenderFilteredVolumetricGeometry(s->GetRenderer(),
s->GetRequiredKeys());
this->NumberOfRenderedProps+=rendered;
}
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Overlay pass without key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderOverlay(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;
while(i<c)
{
int rendered=s->GetPropArray()[i]->RenderOverlay(s->GetRenderer());
this->NumberOfRenderedProps+=rendered;
++i;
}
}
// ----------------------------------------------------------------------------
// Description:
// Overlay pass with key checking.
// \pre s_exists: s!=0
void vtkDefaultPass::RenderFilteredOverlay(const vtkRenderState *s)
{
assert("pre: s_exists" && s!=0);
int c=s->GetPropArrayCount();
int i=0;