Commit e0d01b00 authored by Ken Martin's avatar Ken Martin

Bunch of cleanup and reorg

parent 1c573012
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestPDBBallAndStickShadows.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
RENDERING_FACTORY
)
# On some machines this test takes 260ish seconds to complete, this allows for
# some extra time
if(NOT VTK_TEST_TIMEOUT_TestPDBBallAndStickShadows)
set(VTK_TEST_TIMEOUT_TestPDBBallAndStickShadows 360)
endif()
set_tests_properties(${vtk-module}Cxx-TestPDBBallAndStickShadows
PROPERTIES TIMEOUT ${VTK_TEST_TIMEOUT_TestPDBBallAndStickShadows}
RUN_SERIAL ON)
/*=========================================================================
Program: Visualization Toolkit
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 "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkMolecule.h"
#include "vtkLight.h"
#include "vtkMoleculeMapper.h"
#include "vtkNew.h"
#include "vtkProperty.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkPDBReader.h"
#include "vtkPlaneSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkTimerLog.h"
#include "vtkCamera.h"
int TestPDBBallAndStickShadows(int argc, char *argv[])
{
char* fileName =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/2LYZ.pdb");
// read protein from pdb
vtkNew<vtkPDBReader> reader;
reader->SetFileName(fileName);
reader->Update();
delete [] fileName;
vtkNew<vtkMoleculeMapper> molmapper;
molmapper->SetInputConnection(reader->GetOutputPort(1));
cerr << "Class: " << molmapper->GetClassName() << endl;
cerr << "Atoms: " << molmapper->GetInput()->GetNumberOfAtoms() << endl;
cerr << "Bonds: " << molmapper->GetInput()->GetNumberOfBonds() << endl;
molmapper->UseBallAndStickSettings();
vtkNew<vtkActor> actor;
actor->SetMapper(molmapper.GetPointer());
actor->GetProperty()->SetAmbient(0.2);
actor->GetProperty()->SetDiffuse(0.7);
actor->GetProperty()->SetSpecular(0.3);
actor->GetProperty()->SetSpecularPower(40);
vtkNew<vtkRenderer> ren;
vtkNew<vtkRenderWindow> win;
win->AddRenderer(ren.GetPointer());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(win.GetPointer());
ren->AddActor(actor.GetPointer());
ren->ResetCamera();
ren->GetActiveCamera()->Zoom(1.7);
ren->SetBackground(0.4, 0.5, 0.6);
win->SetSize(450, 450);
// add a plane
vtkNew<vtkPlaneSource> plane;
double *bounds = molmapper->GetBounds();
plane->SetOrigin(bounds[0], bounds[2], bounds[4]);
plane->SetPoint1(bounds[1], bounds[2], bounds[4]);
plane->SetPoint2(bounds[0], bounds[2], bounds[5]);
vtkNew<vtkPolyDataMapper> planeMapper;
planeMapper->SetInputConnection(plane->GetOutputPort());
vtkNew<vtkActor> planeActor;
planeActor->SetMapper(planeMapper.Get());
ren->AddActor(planeActor.Get());
vtkNew<vtkLight> light1;
light1->SetFocalPoint(0,0,0);
light1->SetPosition(0,1,0.2);
light1->SetColor(0.95,0.97,1.0);
light1->SetIntensity(0.8);
ren->AddLight(light1.Get());
vtkNew<vtkLight> light2;
light2->SetFocalPoint(0,0,0);
light2->SetPosition(1.0,1.0,1.0);
light2->SetColor(1.0,0.8,0.7);
light2->SetIntensity(0.3);
ren->AddLight(light2.Get());
ren->UseShadowsOn();
vtkNew<vtkTimerLog> timer;
timer->StartTimer();
win->Render();
timer->StopTimer();
double firstRender = timer->GetElapsedTime();
cerr << "first render time: " << firstRender << endl;
/*
int numRenders = 500;
timer->StartTimer();
for (int i = 0; i < numRenders; ++i)
{
ren->GetActiveCamera()->Azimuth(85.0/numRenders);
ren->GetActiveCamera()->Elevation(85.0/numRenders);
win->Render();
}
timer->StopTimer();
double elapsed = timer->GetElapsedTime();
cerr << "interactive render time: " << elapsed / numRenders << endl;
*/
ren->GetActiveCamera()->SetPosition(0,0,1);
ren->GetActiveCamera()->SetFocalPoint(0,0,0);
ren->GetActiveCamera()->SetViewUp(0,1,0);
ren->ResetCamera();
ren->GetActiveCamera()->Zoom(1.7);
win->Render();
// Finally render the scene and compare the image to a reference image
win->SetMultiSamples(0);
win->GetInteractor()->Initialize();
win->GetInteractor()->Start();
return EXIT_SUCCESS;
}
......@@ -11,4 +11,10 @@ vtk_module(vtkDomainsChemistryOpenGL2
vtkglew
KIT
vtkOpenGL
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
vtkInteractionStyle
vtkRendering${VTK_RENDERING_BACKEND}
${extra_opengl_depend}
)
......@@ -70,6 +70,11 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCVSOutput;");
// we create vertexVC below, so turn off the default
// implementation
vtkShaderProgram::Substitute(FSSource,
"//VTK::PositionVC::Impl","");
// for lights kit and positional the VCDC matrix is already defined
// so don't redefine it
std::string replacement =
......
......@@ -72,6 +72,11 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCVSOutput;");
// we create vertexVC below, so turn off the default
// implementation
vtkShaderProgram::Substitute(FSSource,
"//VTK::PositionVC::Impl","");
// for lights kit and positional the VCDC matrix is already defined
// so don't redefine it
std::string replacement =
......
......@@ -111,6 +111,8 @@ vtkRenderer::vtkRenderer()
this->GL2PSSpecialPropCollection = NULL;
this->UseShadows = 0;
this->UseDepthPeeling=0;
this->OcclusionRatio=0.0;
this->MaximumNumberOfPeels=4;
......
......@@ -508,6 +508,13 @@ public:
// method to release graphics resources in any derived renderers.
virtual void ReleaseGraphicsResources(vtkWindow *) { }
// Description:
// Turn on/off rendering of shadows if supported
// Initial value is off.
vtkSetMacro(UseShadows,int);
vtkGetMacro(UseShadows,int);
vtkBooleanMacro(UseShadows,int);
//BTX
protected:
vtkRenderer();
......@@ -640,6 +647,11 @@ protected:
// This is only used internally.
vtkCamera *GetActiveCameraAndResetIfCreated();
// Description:
// If this flag is on and the rendering engine supports it render shadows
// Initial value is off.
int UseShadows;
// Description:
// If this flag is on and the GPU supports it, depth peeling is used
// for rendering translucent materials.
......
......@@ -33,15 +33,9 @@
#include "vtkOpenGLRenderer.h"
#include "vtkPlaneSource.h"
#include "vtkOpenGLTexture.h"
#include "vtkCameraPass.h"
#include "vtkLightsPass.h"
#include "vtkSequencePass.h"
#include "vtkOpaquePass.h"
#include "vtkRenderPassCollection.h"
#include "vtkShadowMapBakerPass.h"
#include "vtkShadowMapPassInternal.h"
#include "vtkRenderStepsPass.h"
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
......@@ -89,32 +83,12 @@ int TestShadowMapBakerPass(int argc, char *argv[])
renderWindow->SetMultiSamples(0);
// create the basic VTK render steps
vtkNew<vtkRenderStepsPass> basicPasses;
vtkNew<vtkOpaquePass> opaque;
vtkNew<vtkLightsPass> lights;
vtkNew<vtkSequencePass> opaqueSequence;
vtkNew<vtkRenderPassCollection> passes2;
passes2->AddItem(lights.Get());
passes2->AddItem(opaque.Get());
opaqueSequence->SetPasses(passes2.Get());
vtkNew<vtkCameraPass> opaqueCameraPass;
opaqueCameraPass->SetDelegatePass(opaqueSequence.Get());
vtkNew<vtkShadowMapBakerPass> bakerPass;
// bakerPass->SetOpaquePass(basicPasses->GetOpaquePass());
bakerPass->SetOpaquePass(opaqueCameraPass.Get());
bakerPass->SetResolution(1024);
// To cancel self-shadowing.
bakerPass->SetPolygonOffsetFactor(3.1f);
bakerPass->SetPolygonOffsetUnits(10.0f);
basicPasses->SetOpaquePass(bakerPass.Get());
// tell the renderer to use our render pass pipeline
vtkOpenGLRenderer *glrenderer =
vtkOpenGLRenderer::SafeDownCast(renderer.GetPointer());
glrenderer->SetPass(basicPasses.Get());
glrenderer->SetPass(bakerPass.Get());
vtkNew<vtkTimerLog> timer;
timer->StartTimer();
......
......@@ -22,9 +22,7 @@
#include "vtkCameraPass.h"
#include "vtkCellArray.h"
#include "vtkLight.h"
#include "vtkLightsPass.h"
#include "vtkNew.h"
#include "vtkOpaquePass.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOpenGLTexture.h"
#include "vtkPLYReader.h"
......@@ -105,42 +103,20 @@ int TestShadowMapPass(int argc, char *argv[])
renderWindow->SetMultiSamples(0);
vtkNew<vtkOpaquePass> opaque;
vtkNew<vtkLightsPass> lights;
vtkNew<vtkSequencePass> opaqueSequence;
vtkNew<vtkRenderPassCollection> passes2;
passes2->AddItem(lights.Get());
passes2->AddItem(opaque.Get());
opaqueSequence->SetPasses(passes2.Get());
vtkNew<vtkCameraPass> opaqueCameraPass;
opaqueCameraPass->SetDelegatePass(opaqueSequence.Get());
vtkNew<vtkShadowMapBakerPass> bakerPass;
// bakerPass->SetOpaquePass(basicPasses->GetOpaquePass());
bakerPass->SetOpaquePass(opaqueCameraPass.Get());
bakerPass->SetResolution(1024);
// To cancel self-shadowing.
bakerPass->SetPolygonOffsetFactor(3.1f);
bakerPass->SetPolygonOffsetUnits(10.0f);
// tell the renderer to use our render pass pipeline
vtkOpenGLRenderer *glrenderer =
vtkOpenGLRenderer::SafeDownCast(renderer.GetPointer());
vtkNew<vtkShadowMapPass> shadows;
shadows->SetShadowMapBakerPass(bakerPass.Get());
shadows->SetOpaquePass(opaqueSequence.Get());
vtkNew<vtkSequencePass> seq;
vtkNew<vtkRenderPassCollection> passes;
passes->AddItem(bakerPass.Get());
passes->AddItem(shadows->GetShadowMapBakerPass());
passes->AddItem(shadows.Get());
passes->AddItem(lights.Get());
seq->SetPasses(passes.Get());
vtkNew<vtkCameraPass> cameraP;
cameraP->SetDelegatePass(seq.Get());
// tell the renderer to use our render pass pipeline
vtkOpenGLRenderer *glrenderer =
vtkOpenGLRenderer::SafeDownCast(renderer.GetPointer());
glrenderer->SetPass(cameraP.Get());
vtkNew<vtkTimerLog> timer;
......@@ -179,6 +155,5 @@ int TestShadowMapPass(int argc, char *argv[])
iren->Start();
}
bakerPass->ReleaseGraphicsResources(renderWindow.Get());
return EXIT_SUCCESS;
}
......@@ -59,6 +59,9 @@ void main()
//VTK::Color::Impl
// VC position of this fragment
//VTK::PositionVC::Impl
// Generate the normal if we are not passed in one
//VTK::Normal::Impl
......
......@@ -479,12 +479,11 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderLight(
{
int *shadowMapTextures = 0;
int numLights = 0;
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
shadowMapTextures = info->Get(vtkShadowMapPass::ShadowMapTextures());
numLights = info->Length(vtkShadowMapPass::ShadowMapTextures());
// how many lights have shadow maps
// count how many lights have shadow maps
int numSMT = 0;
for (int i = 0; i < numLights; i++)
{
......@@ -499,59 +498,57 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderLight(
vtkShaderProgram::Substitute(FSSource,"//VTK::Light::Dec",
"//VTK::Light::Dec\n"
"#define VTK_NUM_SHADOW_MAPS " + toString.str() + "\n"
"uniform sampler2DShadow shadowMaps[VTK_NUM_SHADOW_MAPS];\n"
"varying vec4 shadowCoordsVSOutput[VTK_NUM_SHADOW_MAPS];\n"
, false);
vtkShaderProgram::Substitute(VSSource,"//VTK::Light::Dec",
"//VTK::Light::Dec\n"
"#define VTK_NUM_SHADOW_MAPS " + toString.str() + "\n"
// "uniform sampler2DShadow shadowMaps[VTK_NUM_SHADOW_MAPS];\n"
"uniform sampler2D shadowMaps[VTK_NUM_SHADOW_MAPS];\n"
"uniform mat4 shadowTransforms[VTK_NUM_SHADOW_MAPS];\n"
"varying vec4 shadowCoordsVSOutput[VTK_NUM_SHADOW_MAPS];\n"
"float computeShadowFactor(in vec4 vc, in mat4 strans, in sampler2D smap)\n"
" {\n"
" vec4 shadowCoord = strans*vc;\n"
" if(shadowCoord.w > 0.0)\n"
" {\n"
" vec2 projected = shadowCoord.xy/shadowCoord.w;\n"
" if(projected.x >= 0.0 && projected.x <= 1.0\n"
" && projected.y >= 0.0 && projected.y <= 1.0)\n"
" {\n"
" float result = 0.0;\n"
" float zval = shadowCoord.z - 0.005;\n"
" if (textureProjOffset(smap,shadowCoord,ivec2( 0, 0)).r - zval > 0) { result += 0.34; }\n"
" if (textureProjOffset(smap,shadowCoord,ivec2( 0, 1)).r - zval > 0) { result += 0.33; }\n"
" if (textureProjOffset(smap,shadowCoord,ivec2( 1, 0)).r - zval > 0) { result += 0.33; }\n"
" return result;\n"
" }\n"
" }\n"
" return 1.0;\n"
" }\n"
, false);
// build the code for the lighting factors
std::string lfc =
"float factors[6];\n";
for (int i = 0, numSMT = 0; i < 6; i++)
numSMT = 0;
for (int i = 0; i < 6; i++)
{
toString.str("");
toString.clear();
toString << i;
lfc += " factors[" + toString.str() + "] = 1.0;\n";
if (shadowMapTextures[i] >= 0 && i < numLights)
{
std::ostringstream toString2;
toString2 << numSMT;
lfc +=
" if(shadowCoordsVSOutput[" + toString2.str() + "].w > 0.0)\n"
" {\n"
" vec2 projected = shadowCoordsVSOutput[" + toString2.str() + "].xy/shadowCoordsVSOutput[" + toString2.str() + "].w;\n"
" if(projected.x >= 0.0 && projected.x <= 1.0\n"
" && projected.y >= 0.0 && projected.y <= 1.0)\n"
" {\n"
" factors[" + toString.str() + "] = textureProj(shadowMaps["
+ toString2.str() + "],shadowCoordsVSOutput[" + toString2.str() + "]);\n"
" }\n"
// " factors[" + toString.str() + "] = 0.0;\n"
" }\n";
lfc += " factors[" + toString.str() + "] = computeShadowFactor(vertexVC,shadowTransforms["
+ toString2.str() + "],shadowMaps["
+ toString2.str() + "]);\n";
numSMT++;
}
else
{
lfc += " factors[" + toString.str() + "] = 1.0;\n";
}
}
lfc += "//VTK::Light::Impl";
vtkShaderProgram::Substitute(FSSource,"//VTK::Light::Impl",
lfc.c_str(), false);
vtkShaderProgram::Substitute(VSSource,"//VTK::Light::Impl",
"//VTK::Light::Impl\n"
" for (int i = 0; i < VTK_NUM_SHADOW_MAPS; i++)\n"
" {\n"
" shadowCoordsVSOutput[i] = shadowTransforms[i]*vertexVCVSOutput;\n"
" }\n"
, false);
shaders[vtkShader::Vertex]->SetSource(VSSource);
shadowFactor = "*factors[lightNum]";
}
......@@ -628,7 +625,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderLight(
" }\n"
" else\n"
" {\n"
" vertLightDirectionVC = vertexVCVSOutput.xyz - lightPositionVC[lightNum];\n"
" vertLightDirectionVC = vertexVC.xyz - lightPositionVC[lightNum];\n"
" float distanceVC = length(vertLightDirectionVC);\n"
" vertLightDirectionVC = normalize(vertLightDirectionVC);\n"
" attenuation = 1.0 /\n"
......@@ -994,8 +991,8 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
// the line (which is a plane but maximally aligned with the camera view.
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Impl",
"vec3 normalVCVSOutput;\n"
" vec3 fdx = normalize(vec3(dFdx(vertexVCVSOutput.x),dFdx(vertexVCVSOutput.y),dFdx(vertexVCVSOutput.z)));\n"
" vec3 fdy = normalize(vec3(dFdy(vertexVCVSOutput.x),dFdy(vertexVCVSOutput.y),dFdy(vertexVCVSOutput.z)));\n"
" vec3 fdx = normalize(vec3(dFdx(vertexVC.x),dFdx(vertexVC.y),dFdx(vertexVC.z)));\n"
" vec3 fdy = normalize(vec3(dFdy(vertexVC.x),dFdy(vertexVC.y),dFdy(vertexVC.z)));\n"
" if (abs(fdx.x) > 0.0)\n"
" { normalVCVSOutput = normalize(cross(vec3(fdx.y, -fdx.x, 0.0), fdx)); }\n"
" else { normalVCVSOutput = normalize(cross(vec3(fdy.y, -fdy.x, 0.0), fdy));}"
......@@ -1009,13 +1006,13 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderNormal(
this->ShaderVariablesUsed.push_back("cameraParallel");
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Impl",
"vec3 fdx = normalize(vec3(dFdx(vertexVCVSOutput.x),dFdx(vertexVCVSOutput.y),dFdx(vertexVCVSOutput.z)));\n"
" vec3 fdy = normalize(vec3(dFdy(vertexVCVSOutput.x),dFdy(vertexVCVSOutput.y),dFdy(vertexVCVSOutput.z)));\n"
"vec3 fdx = normalize(vec3(dFdx(vertexVC.x),dFdx(vertexVC.y),dFdx(vertexVC.z)));\n"
" vec3 fdy = normalize(vec3(dFdy(vertexVC.x),dFdy(vertexVC.y),dFdy(vertexVC.z)));\n"
" vec3 normalVCVSOutput = normalize(cross(fdx,fdy));\n"
// the code below is faster, but does not work on some devices
//"vec3 normalVC = normalize(cross(dFdx(vertexVCVSOutput.xyz), dFdy(vertexVCVSOutput.xyz)));\n"
//"vec3 normalVC = normalize(cross(dFdx(vertexVC.xyz), dFdy(vertexVC.xyz)));\n"
" if (cameraParallel == 1 && normalVCVSOutput.z < 0.0) { normalVCVSOutput = -1.0*normalVCVSOutput; }\n"
" if (cameraParallel == 0 && dot(normalVCVSOutput,vertexVCVSOutput.xyz) > 0.0) { normalVCVSOutput = -1.0*normalVCVSOutput; }"
" if (cameraParallel == 0 && dot(normalVCVSOutput,vertexVC.xyz) > 0.0) { normalVCVSOutput = -1.0*normalVCVSOutput; }"
);
}
}
......@@ -1062,6 +1059,9 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderPositionVC(
vtkShaderProgram::Substitute(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCVSOutput;");
vtkShaderProgram::Substitute(FSSource,
"//VTK::PositionVC::Impl",
"vec4 vertexVC = vertexVCVSOutput;");
}
else
{
......@@ -1509,9 +1509,9 @@ void vtkOpenGLPolyDataMapper::SetLightingShaderParameters(
if (shadowMapTextures[i] >= 0)
{
tunits[numSMT] = shadowMapTextures[i];
for (int i = 0; i < 16; i++)
for (int j = 0; j < 16; j++)
{
transforms[numSMT*16+i] = shadowTransforms[numSMT*16+i];
transforms[numSMT*16+j] = shadowTransforms[numSMT*16+j];
}
numSMT++;
}
......
......@@ -19,6 +19,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkCellArray.h"
#include "vtkDepthPeelingPass.h"
#include "vtkFloatArray.h"
#include "vtkHardwareSelector.h"
#include "vtkLight.h"
#include "vtkLightCollection.h"
#include "vtkNew.h"
......@@ -32,6 +33,8 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkPolyDataMapper2D.h"
#include "vtkRenderPass.h"
#include "vtkRenderState.h"
#include "vtkShadowMapBakerPass.h"
#include "vtkShadowMapPass.h"
#include "vtkTexture.h"
#include "vtkTextureObject.h"
#include "vtkTexturedActor2D.h"
......@@ -65,6 +68,7 @@ vtkOpenGLRenderer::vtkOpenGLRenderer()
this->PickedZ = 0;
this->DepthPeelingPass = 0;
this->ShadowMapPass = 0;
this->DepthPeelingHigherLayer=0;
this->BackgroundTexture = 0;
......@@ -159,6 +163,94 @@ void vtkOpenGLRenderer::DeviceRender(void)
vtkTimerLog::MarkEndEvent("OpenGL Dev Render");
}
// Ask actors to render themselves. As a side effect will cause
// visualization network to update.
int vtkOpenGLRenderer::UpdateGeometry()
{
int i;
this->NumberOfPropsRendered = 0;
if ( this->PropArrayCount == 0 )
{
return 0;
}
if (this->Selector)
{
// When selector is present, we are performing a selection,
// so do the selection rendering pass instead of the normal passes.
// Delegate the rendering of the props to the selector itself.
this->NumberOfPropsRendered = this->Selector->Render(this,
this->PropArray, this->PropArrayCount);
this->RenderTime.Modified();
vtkDebugMacro("Rendered " << this->NumberOfPropsRendered << " actors" );
return this->NumberOfPropsRendered;
}
// if we are suing shadows then let the renderpasses handle it
// for opaque and translucent
if (this->UseShadows)
{
if (!this->ShadowMapPass)
{
this->ShadowMapPass = vtkShadowMapPass::New();
}
vtkRenderState s(this);
s.SetPropArrayAndCount(this->PropArray, this->PropArrayCount);
//s.SetFrameBuffer(0);
this->ShadowMapPass->GetShadowMapBakerPass()->Render(&s);
this->ShadowMapPass->Render(&s);
}
else
{
// loop through props and give them a chance to
// render themselves as opaque geometry
for ( i = 0; i < this->PropArrayCount; i++ )
{
this->NumberOfPropsRendered +=
this->PropArray[i]->RenderOpaqueGeometry(this);
}
// do the render library specific stuff about translucent polygonal geometry.
// As it can be expensive, do a quick check if we can skip this step
int hasTranslucentPolygonalGeometry=0;
for ( i = 0; !hasTranslucentPolygonalGeometry && i < this->PropArrayCount;
i++ )
{
hasTranslucentPolygonalGeometry=
this->PropArray[i]->HasTranslucentPolygonalGeometry();
}
if(hasTranslucentPolygonalGeometry)
{
this->DeviceRenderTranslucentPolygonalGeometry();
}
}
// loop through props and give them a chance to
// render themselves as volumetric geometry.
for ( i = 0; i < this->PropArrayCount; i++ )
{
this->NumberOfPropsRendered +=
this->PropArray[i]->RenderVolumetricGeometry(this);
}
// loop through props and give them a chance to
// render themselves as an overlay (or underlay)
for ( i = 0; i < this->PropArrayCount; i++ )
{
this->NumberOfPropsRendered +=
this->PropArray[i]->RenderOverlay(this);
}
this->RenderTime.Modified();
vtkDebugMacro( << "Rendered " <<
this->NumberOfPropsRendered << " actors" );
return this->NumberOfPropsRendered;
}
// ----------------------------------------------------------------------------
// Description:
// Render translucent polygonal geometry. Default implementation just call
......@@ -422,6 +514,10 @@ void vtkOpenGLRenderer::ReleaseGraphicsResources(vtkWindow *w)
{
this->DepthPeelingPass->ReleaseGraphicsResources(w);
}
if (w && this->ShadowMapPass)
{
this->ShadowMapPass->ReleaseGraphicsResources(w);
}
}
void vtkOpenGLRenderer::UpdatePickId()
......@@ -543,6 +639,12 @@ vtkOpenGLRenderer::~vtkOpenGLRenderer()
this->Pass = NULL;
}
if (this->ShadowMapPass)
{
this->ShadowMapPass->Delete();
this->ShadowMapPass = 0;
}
if (this->DepthPeelingPass)
{
this->DepthPeelingPass->Delete();
......
......@@ -28,6 +28,7 @@ class vtkRenderPass;
class vtkOpenGLTexture;
class vtkTextureObject;
class vtkDepthPeelingPass;
class vtkShadowMapPass;
class VTKRENDERINGOPENGL2_EXPORT vtkOpenGLRenderer : public vtkRenderer
{
......@@ -77,6 +78,12 @@ protected:
// Internal method to release graphics resources in any derived renderers.
virtual void ReleaseGraphicsResources(vtkWindow *w);
// Description:
// Ask all props to update and draw any opaque and translucent
// geometry. This includes both vtkActors and vtkVolumes
// Returns the number of props that rendered geometry.
virtual int UpdateGeometry();
// Picking functions to be implemented by sub-classes
virtual void DevicePickRender();
virtual void StartPick(unsigned int pickFromSize);
......@@ -98,9 +105,13 @@ protected:
friend class vtkOpenGLImageResliceMapper;
// Description:
// Deepth peeling is delegated to an instance of vtkDepthPeelingPass
// Depth peeling is delegated to an instance of vtkDepthPeelingPass
vtkDepthPeelingPass *DepthPeelingPass;
// Description:
// Shadows are delegated to an instance of vtkShadowMapPass
vtkShadowMapPass *ShadowMapPass;
// Is rendering at translucent geometry stage using depth peeling and
// rendering a layer other than the first one? (Boolean value)
// If so, the uniform variables UseTexture and Texture can be set.
......
......@@ -13,36 +13,30 @@
=========================================================================*/
#include "vtkShadowMapBakerPass.h"
#include "vtkObjectFactory.h"
#include <cassert>
#include "vtkRenderState.h"
#include "vtkOpenGLRenderer.h"
//#include "vtkAbstractTransform.h" // for helper classes stack and concatenation
#include "vtkCamera.h"
#include "vtkCameraPass.h"
#include "vtkFrameBufferObject.h"
#include "vtkTextureObject.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLError.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#include "vtkMath.h"