Skip to content
Snippets Groups Projects
Commit 640f9a0e authored by Ken Martin's avatar Ken Martin
Browse files

Some cleanups to make the shader a bit simpler

Some minor cleanups and added timing code
parent 494e9f16
No related branches found
No related tags found
1 merge request!783Add a super smapling AA pass
......@@ -140,7 +140,6 @@ set(shader_files
glsl/vtkPolyDataVS.glsl
glsl/vtkPolyDataWideLineGS.glsl
glsl/vtkSSAAPassFS.glsl
glsl/vtkSSAAPassVS.glsl
glsl/vtkSobelGradientMagnitudePass1FS.glsl
glsl/vtkSobelGradientMagnitudePass2FS.glsl
glsl/vtkTextureObjectFS.glsl
......
......@@ -37,6 +37,8 @@
#include "vtkSSAAPass.h"
#include "vtkRenderStepsPass.h"
#include "vtkCellArray.h"
#include "vtkTimerLog.h"
int TestSSAAPass(int argc, char* argv[])
{
......@@ -87,6 +89,32 @@ int TestSSAAPass(int argc, char* argv[])
actor->GetProperty()->SetSpecularPower(20.0);
actor->GetProperty()->SetOpacity(1.0);
vtkNew<vtkTimerLog> timer;
timer->StartTimer();
renWin->Render();
timer->StopTimer();
double firstRender = timer->GetElapsedTime();
cerr << "first render time: " << firstRender << endl;
timer->StartTimer();
int numRenders = 4;
for (int i = 0; i < numRenders; ++i)
{
renderer->GetActiveCamera()->Azimuth(80.0/numRenders);
renderer->GetActiveCamera()->Elevation(88.0/numRenders);
renWin->Render();
}
timer->StopTimer();
double elapsed = timer->GetElapsedTime();
cerr << "interactive render time: " << elapsed / numRenders << endl;
unsigned int numTris = reader->GetOutput()->GetPolys()->GetNumberOfCells();
cerr << "number of triangles: " << numTris << endl;
cerr << "triangles per second: " << numTris*(numRenders/elapsed) << endl;
renderer->GetActiveCamera()->SetPosition(0,0,1);
renderer->GetActiveCamera()->SetFocalPoint(0,0,0);
renderer->GetActiveCamera()->SetViewUp(0,1,0);
renderer->ResetCamera();
renWin->Render();
int retVal = vtkRegressionTestImage( renWin.Get() );
......
......@@ -15,21 +15,17 @@
//
// ============================================================================
// thanks to Brad Larson for posting sample code that helped get this started
uniform sampler2D source;
// the output of this shader
//VTK::Output::Dec
uniform float texelWidthOffset;
uniform float texelHeightOffset;
varying vec2 centerTextureCoordinate;
varying vec2 oneStepLeftTextureCoordinate;
varying vec2 twoStepsLeftTextureCoordinate;
varying vec2 threeStepsLeftTextureCoordinate;
varying vec2 fourStepsLeftTextureCoordinate;
varying vec2 oneStepRightTextureCoordinate;
varying vec2 twoStepsRightTextureCoordinate;
varying vec2 threeStepsRightTextureCoordinate;
varying vec2 fourStepsRightTextureCoordinate;
varying vec2 tcoordVC;
// Note that the texel offsets should be 3/8 of a pixel in the
// resulting image not the source image. Also note that this
......@@ -42,19 +38,21 @@ varying vec2 fourStepsRightTextureCoordinate;
void main()
{
lowp vec4 fragmentColor = texture2D(source, centerTextureCoordinate) * 0.38026;
vec2 firstOffset = vec2(texelWidthOffset, texelHeightOffset);
vec4 fragmentColor = texture2D(source, tcoordVC) * 0.38026;
fragmentColor += texture2D(source, oneStepLeftTextureCoordinate) * 0.27667;
fragmentColor += texture2D(source, oneStepRightTextureCoordinate) * 0.27667;
fragmentColor += texture2D(source, tcoordVC - firstOffset) * 0.27667;
fragmentColor += texture2D(source, tcoordVC + firstOffset) * 0.27667;
fragmentColor += texture2D(source, twoStepsLeftTextureCoordinate) * 0.08074;
fragmentColor += texture2D(source, twoStepsRightTextureCoordinate) * 0.08074;
fragmentColor += texture2D(source, tcoordVC - 2.0*firstOffset) * 0.08074;
fragmentColor += texture2D(source, tcoordVC + 2.0*firstOffset) * 0.08074;
fragmentColor += texture2D(source, threeStepsLeftTextureCoordinate) * -0.02612;
fragmentColor += texture2D(source, threeStepsRightTextureCoordinate) * -0.02612;
fragmentColor += texture2D(source, tcoordVC - 3.0*firstOffset) * -0.02612;
fragmentColor += texture2D(source, tcoordVC + 3.0*firstOffset) * -0.02612;
fragmentColor += texture2D(source, fourStepsLeftTextureCoordinate) * -0.02143;
fragmentColor += texture2D(source, fourStepsRightTextureCoordinate) * -0.02143;
fragmentColor += texture2D(source, tcoordVC - 4.0*firstOffset) * -0.02143;
fragmentColor += texture2D(source, tcoordVC + 4.0*firstOffset) * -0.02143;
gl_FragData[0] = fragmentColor;
}
\ No newline at end of file
}
//VTK::System::Dec
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSSAAPassVS.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.
=========================================================================*/
attribute vec4 vertexMC;
attribute vec2 tcoordMC;
// Note that the texel offsets should be 3/8 of a pixel in the
// resulting image not the source image. Also note that this
// filter is meant to be run one dimension at a time.
uniform float texelWidthOffset;
uniform float texelHeightOffset;
varying vec2 centerTextureCoordinate;
varying vec2 oneStepLeftTextureCoordinate;
varying vec2 twoStepsLeftTextureCoordinate;
varying vec2 threeStepsLeftTextureCoordinate;
varying vec2 fourStepsLeftTextureCoordinate;
varying vec2 oneStepRightTextureCoordinate;
varying vec2 twoStepsRightTextureCoordinate;
varying vec2 threeStepsRightTextureCoordinate;
varying vec2 fourStepsRightTextureCoordinate;
void main()
{
vec2 firstOffset = vec2(texelWidthOffset, texelHeightOffset);
vec2 secondOffset = vec2(2.0 * texelWidthOffset, 2.0 * texelHeightOffset);
vec2 thirdOffset = vec2(3.0 * texelWidthOffset, 3.0 * texelHeightOffset);
vec2 fourthOffset = vec2(4.0 * texelWidthOffset, 4.0 * texelHeightOffset);
centerTextureCoordinate = tcoordMC;
oneStepLeftTextureCoordinate = tcoordMC - firstOffset;
twoStepsLeftTextureCoordinate = tcoordMC - secondOffset;
threeStepsLeftTextureCoordinate = tcoordMC - thirdOffset;
fourStepsLeftTextureCoordinate = tcoordMC - fourthOffset;
oneStepRightTextureCoordinate = tcoordMC + firstOffset;
twoStepsRightTextureCoordinate = tcoordMC + secondOffset;
threeStepsRightTextureCoordinate = tcoordMC + thirdOffset;
fourStepsRightTextureCoordinate = tcoordMC + fourthOffset;
gl_Position = vertexMC;
}
......@@ -30,7 +30,7 @@
#include "vtkOpenGLHelper.h"
#include "vtkSSAAPassFS.h"
#include "vtkSSAAPassVS.h"
#include "vtkTextureObjectVS.h" // a pass through shader
vtkStandardNewMacro(vtkSSAAPass);
......@@ -245,7 +245,8 @@ void vtkSSAAPass::Render(const vtkRenderState *s)
{
this->SSAAProgram = new vtkOpenGLHelper;
// build the shader source code
std::string VSSource = vtkSSAAPassVS;
// std::string VSSource = vtkSSAAPassVS;
std::string VSSource = vtkTextureObjectVS;
std::string FSSource = vtkSSAAPassFS;
std::string GSSource;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment