Commit 64312b2e authored by Francois Bertel's avatar Francois Bertel

ENH:First revision.

parent c1192890
/*=========================================================================
Program: Visualization Toolkit
Module: TestGenericVertexAttributesGLSLAlphaBlending.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.
=========================================================================*/
// .NAME Test of vtkGLSLShaderDeviceAdapter2 with XML shader style 2 and
// alpha blending.
// .SECTION Description
// this program tests the shader support in vtkRendering.
#include "vtkActor.h"
#include "vtkBrownianPoints.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
int TestGenericVertexAttributesGLSLAlphaBlending(int argc, char *argv[])
{
char shaders1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<Material name=\"GenericAttributes1\"> \
<Shader scope=\"Vertex\" name=\"VertexShader\" location=\"Inline\"\
language=\"GLSL\" entry=\"main\" style=\"2\"> attribute vec3 genAttrVector; \
varying vec4 color; \
void propFuncVS(void) \
{ \
gl_Position = gl_ModelViewProjectionMatrix *gl_Vertex; \
color = vec4(normalize(genAttrVector), 0.3); \
} \
</Shader> \
<Shader scope=\"Fragment\" name=\"FragmentShader\" location=\"Inline\" \
language=\"GLSL\" entry=\"main\" style=\"2\"> \
varying vec4 color; \
void propFuncFS() \
{ \
gl_FragColor = color; \
} \
</Shader> \
</Material>";
vtkSphereSource * sphere = vtkSphereSource::New();
sphere->SetRadius(5);
sphere->SetPhiResolution(20);
sphere->SetThetaResolution(20);
vtkBrownianPoints * randomVector = vtkBrownianPoints::New();
randomVector->SetMinimumSpeed(0);
randomVector->SetMaximumSpeed(1);
randomVector->SetInputConnection(sphere->GetOutputPort());
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(randomVector->GetOutputPort());
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
actor->GetProperty()->LoadMaterialFromString(shaders1);
actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
actor->GetProperty()->GetShading();
actor->GetProperty()->ShadingOn();
actor->GetProperty()->SetOpacity(0.99); // to force alpha blending.
mapper->MapDataArrayToVertexAttribute("genAttrVector", "BrownianVectors", 0, -1);
vtkRenderer *renderer = vtkRenderer::New();
renderer->AddActor(actor);
renderer->SetBackground(0.5, 0.5, 0.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
interactor->SetRenderWindow(renWin);
renWin->SetSize(400,400);
renWin->Render();
interactor->Initialize();
renWin->Render();
int retVal = vtkRegressionTestImageThreshold(renWin,18);
if( retVal == vtkRegressionTester::DO_INTERACTOR)
{
interactor->Start();
}
sphere->Delete();
randomVector->Delete();
mapper->Delete();
actor->Delete();
renderer->Delete();
renWin->Delete();
interactor->Delete();
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestGenericVertexAttributesGLSLDepthPeelingPass.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.
=========================================================================*/
// .NAME Test of vtkGLSLShaderDeviceAdapter2 with XML shader style 2 with
// depth peeling pass.
// .SECTION Description
// this program tests the shader support in vtkRendering.
#include "vtkActor.h"
#include "vtkBrownianPoints.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSphereSource.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 "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
int TestGenericVertexAttributesGLSLDepthPeelingPass(int argc, char *argv[])
{
char shaders1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \
<Material name=\"GenericAttributes1\"> \
<Shader scope=\"Vertex\" name=\"VertexShader\" location=\"Inline\"\
language=\"GLSL\" entry=\"main\" style=\"2\"> attribute vec3 genAttrVector; \
varying vec4 color; \
void propFuncVS(void) \
{ \
gl_Position = gl_ModelViewProjectionMatrix *gl_Vertex; \
color = vec4(normalize(genAttrVector), 0.3); \
} \
</Shader> \
<Shader scope=\"Fragment\" name=\"FragmentShader\" location=\"Inline\" \
language=\"GLSL\" entry=\"main\" style=\"2\"> \
varying vec4 color; \
void propFuncFS() \
{ \
gl_FragColor = color; \
} \
</Shader> \
</Material>";
vtkSphereSource * sphere = vtkSphereSource::New();
sphere->SetRadius(5);
sphere->SetPhiResolution(20);
sphere->SetThetaResolution(20);
vtkBrownianPoints * randomVector = vtkBrownianPoints::New();
randomVector->SetMinimumSpeed(0);
randomVector->SetMaximumSpeed(1);
randomVector->SetInputConnection(sphere->GetOutputPort());
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(randomVector->GetOutputPort());
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
actor->GetProperty()->LoadMaterialFromString(shaders1);
actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
actor->GetProperty()->GetShading();
actor->GetProperty()->ShadingOn();
actor->GetProperty()->SetOpacity(0.99); // to force depth peeling.
mapper->MapDataArrayToVertexAttribute("genAttrVector", "BrownianVectors", 0, -1);
vtkRenderer *renderer = vtkRenderer::New();
renderer->AddActor(actor);
renderer->SetBackground(0.5, 0.5, 0.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->SetMultiSamples(0);
renWin->SetAlphaBitPlanes(1);
renWin->AddRenderer(renderer);
// All the passes.
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();
vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New();
interactor->SetRenderWindow(renWin);
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;
}
interactor->Initialize();
renWin->Render();
int retVal = vtkRegressionTestImageThreshold(renWin,18);
if( retVal == vtkRegressionTester::DO_INTERACTOR)
{
interactor->Start();
}
sphere->Delete();
randomVector->Delete();
mapper->Delete();
actor->Delete();
renderer->Delete();
renWin->Delete();
interactor->Delete();
return !retVal;
}
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGLSLShaderDeviceAdapter2.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 vtkGLSLShaderDeviceAdapter2 - adapter to pass generic vertex
// attributes to the rendering pipeline to be used in a vtkShaderProgram2.
// .SECTION Description
// vtkShaderDeviceAdapter subclass for vtkShaderProgram2.
#ifndef __vtkGLSLShaderDeviceAdapter2_h
#define __vtkGLSLShaderDeviceAdapter2_h
#include "vtkObject.h"
class vtkShaderProgram2;
class VTK_RENDERING_EXPORT vtkGLSLShaderDeviceAdapter2 : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkGLSLShaderDeviceAdapter2, vtkObject);
static vtkGLSLShaderDeviceAdapter2 *New();
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Descrition:
// This method is called before rendering. This gives the shader device
// adapter an opportunity to collect information, such as attribute indices
// that it will need while rendering.
virtual void PrepareForRender();
// Description:
// Sends a single attribute to the graphics card.
// The attrname parameter identifies the name of attribute.
// The components parameter gives the number of
// components in the attribute. In general, components must be between
// 1-4, but a rendering system may impose even more constraints. The
// type parameter is a VTK type enumeration (VTK_FLOAT, VTK_INT, etc.).
// Again, a rendering system may not support all types for all
// attributes. The attribute parameter is the actual data for the
// attribute.
// If offset is specified, it is added to attribute pointer \c after
// it has been casted to the proper type.
// If attribute is NULL, the OpenGL ID for the attribute will simply be
// cached.
virtual void SendAttribute(const char* attrname,
int components,
int type,
const void *attribute,
unsigned long offset=0);
// Description:
// Set the shader program which is being updated by this device adapter.
// The shader program is not reference counted to avoid reference loops.
void SetShaderProgram(vtkShaderProgram2 *program);
vtkGetObjectMacro(ShaderProgram, vtkShaderProgram2);
//BTX
protected:
vtkGLSLShaderDeviceAdapter2();
~vtkGLSLShaderDeviceAdapter2();
// Description:
int GetAttributeLocation(const char* attrName);
vtkShaderProgram2 *ShaderProgram;
private:
vtkGLSLShaderDeviceAdapter2(const vtkGLSLShaderDeviceAdapter2&);
// Not implemented
void operator=(const vtkGLSLShaderDeviceAdapter2&); // Not implemented
class vtkInternal;
vtkInternal* Internal;
//ETX
};
#endif
// ============================================================================
//
// Program: Visualization Toolkit
// Module: vtkOpenGLPropertyDefaultPropFunc_vs.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.
//
// ============================================================================
// Default vertex shader used on property.
void propFuncVS()
{
// default is empty. So far.
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment