Commit 5b62e02d authored by Ken Martin's avatar Ken Martin

Make it so that fragment shaders can modify vertexVC

Somefragment shaders want to modify vertexVC which previously
was a hard coded varying that is used by the lighting calcs.
Made it no longer hard coded. Fixes imposters for Intel chips.

Change-Id: I3feae834a0b6c9a7eb775404b083bdaba55dfb49
parent 6207dbb1
......@@ -81,7 +81,7 @@ int TestPDBBallAndStick(int argc, char *argv[])
double firstRender = timer->GetElapsedTime();
cerr << "first render time: " << firstRender << endl;
/*
/*
int numRenders = 500;
timer->StartTimer();
for (int i = 0; i < numRenders; ++i)
......@@ -93,7 +93,7 @@ int TestPDBBallAndStick(int argc, char *argv[])
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);
......
......@@ -47,7 +47,7 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
varying vec4 vertexVC;
varying vec4 vertexVCClose;
varying float radiusVC;
varying vec3 centerVC;
......@@ -65,23 +65,23 @@ void main()
//VTK::Clip::Impl
// compute the projected vertex position
vertexVC = MCVCMatrix * vertexMC;
centerVC = vertexVC.xyz;
vertexVCClose = MCVCMatrix * vertexMC;
centerVC = vertexVCClose.xyz;
radiusVC = radiusMC;
// make the triangle face the camera
if (cameraParallel == 0)
{
vec3 dir = normalize(vec3(0,0,cameraDistance) - vertexVC.xyz);
vec3 base2 = normalize(cross(dir,vec3(1,0,0)));
vec3 dir = normalize(vec3(0.0,0.0,cameraDistance) - vertexVCClose.xyz);
vec3 base2 = normalize(cross(dir,vec3(1.0,0.0,0.0)));
vec3 base1 = cross(base2,dir);
vertexVC.xyz = vertexVC.xyz + offsetMC.x*base1 + offsetMC.y*base2;
vertexVCClose.xyz = vertexVCClose.xyz + offsetMC.x*base1 + offsetMC.y*base2;
}
else
{
// add in the offset
vertexVC.xy = vertexVC.xy + offsetMC;
vertexVCClose.xy = vertexVCClose.xy + offsetMC;
}
gl_Position = VCDCMatrix * vertexVC;
gl_Position = VCDCMatrix * vertexVCClose;
}
......@@ -50,7 +50,7 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
varying vec4 vertexVC;
varying vec4 vertexVCClose;
varying float radiusVC;
varying float lengthVC;
varying vec3 centerVC;
......@@ -71,14 +71,14 @@ void main()
//VTK::Clip::Impl
vertexVC = MCVCMatrix * vertexMC;
centerVC = vertexVC.xyz;
vertexVCClose = MCVCMatrix * vertexMC;
centerVC = vertexVCClose.xyz;
radiusVC = radiusMC;
lengthVC = length(orientMC);
orientVC = normalMatrix * normalize(orientMC);
// make sure it is pointing out of the screen
if (orientVC.z < 0)
if (orientVC.z < 0.0)
{
orientVC = -orientVC;
}
......@@ -89,11 +89,11 @@ void main()
vec3 dir = vec3(0.0,0.0,1.0);
if (cameraParallel == 0)
{
dir = normalize(vec3(0,0,cameraDistance) - vertexVC.xyz);
dir = normalize(vec3(0.0,0.0,cameraDistance) - vertexVCClose.xyz);
}
if (abs(dot(dir,orientVC)) == 1.0)
{
xbase = normalize(cross(vec3(0,1,0),orientVC));
xbase = normalize(cross(vec3(0.0,1.0,0.0),orientVC));
ybase = cross(xbase,orientVC);
}
else
......@@ -102,11 +102,11 @@ void main()
ybase = cross(orientVC,xbase);
}
vec3 offsets = offsetMC*2.0-1.0;
vertexVC.xyz = vertexVC.xyz +
vec3 offsets = offsetMC.xyz*2.0-1.0;
vertexVCClose.xyz = vertexVCClose.xyz +
radiusVC*offsets.x*xbase +
radiusVC*offsets.y*ybase +
0.5*lengthVC*offsets.z*orientVC;
gl_Position = VCDCMatrix * vertexVC;
gl_Position = VCDCMatrix * vertexVCClose;
}
......@@ -57,6 +57,10 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(std::string &VSSource,
vtkRenderer* ren,
vtkActor *actor)
{
FSSource = replace(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCClose;");
// for lights kit and positional the VCDC matrix is already defined
// so don't redefine it
std::string replacement =
......@@ -74,7 +78,8 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(std::string &VSSource,
FSSource = replace(FSSource,"//VTK::Normal::Impl",
// compute the eye position and unit direction
"vec3 EyePos = vec3(0.0,0.0,cameraDistance);\n"
"vec4 vertexVC = vertexVCClose;\n"
" vec3 EyePos = vec3(0.0,0.0,cameraDistance);\n"
" if (cameraParallel != 0) { EyePos = EyePos + vertexVC.xyz;}\n"
" vec3 EyeDir = vertexVC.xyz - EyePos;\n"
// we adjust the EyePos to be closer if it is too far away
......
......@@ -57,6 +57,10 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
vtkRenderer* ren,
vtkActor *actor)
{
FSSource = replace(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCClose;");
// for lights kit and positional the VCDC matrix is already defined
// so don't redefine it
std::string replacement =
......@@ -77,7 +81,8 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(std::string &VSSource,
// see https://www.cl.cam.ac.uk/teaching/1999/AGraphHCI/SMAG/node2.html
FSSource = replace(FSSource,"//VTK::Normal::Impl",
// compute the eye position and unit direction
"vec3 EyePos = vec3(0.0,0.0,cameraDistance);\n"
" vec4 vertexVC = vertexVCClose;\n"
" vec3 EyePos = vec3(0.0,0.0,cameraDistance);\n"
" if (cameraParallel != 0) { EyePos = EyePos + vertexVC.xyz;}\n"
// we adjust the EyePos to be closer if it is too far away
// to prevent floating point precision noise
......
......@@ -28,6 +28,9 @@
attribute vec4 vertexMC;
// frag position in VC
//VTK::PositionVC::Dec
// optional normal declaration
//VTK::Normal::Dec
......@@ -48,8 +51,6 @@ uniform mat4 VCDCMatrix; // the camera's projection matrix
// clipping plane vars
//VTK::Clip::Dec
varying vec4 vertexVC;
void main()
{
//VTK::Glyph::Impl
......@@ -62,7 +63,6 @@ void main()
//VTK::TCoord::Impl
// compute the projected vertex position
vertexVC = MCVCMatrix * vertex;
gl_Position = VCDCMatrix * vertexVC;
// frag position in VC
//VTK::PositionVC::Impl
}
......@@ -25,8 +25,8 @@
// VC - View Coordinates
// DC - Display Coordinates
// passed from the vertex shader
varying vec4 vertexVC;
// VC positon of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
......
......@@ -35,8 +35,8 @@ uniform int numberOfLights; // only allow for up to 6 active lights
uniform vec3 lightColor[6]; // intensity weighted color
uniform vec3 lightDirectionVC[6]; // normalized
// passed from the vertex shader
varying vec4 vertexVC;
// VC positon of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
......
......@@ -41,8 +41,8 @@ uniform float lightConeAngle[6];
uniform float lightExponent[6];
uniform int lightPositional[6];
// passed from the vertex shader
varying vec4 vertexVC;
// VC positon of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
......
......@@ -28,6 +28,9 @@
attribute vec4 vertexMC;
// frag position in VC
//VTK::PositionVC::Dec
// optional normal declaration
//VTK::Normal::Dec
......@@ -46,8 +49,6 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
uniform mat4 MCVCMatrix; // combined Model to View transform
uniform mat4 VCDCMatrix; // the camera's projection matrix
varying vec4 vertexVC;
void main()
{
//VTK::Color::Impl
......@@ -58,9 +59,7 @@ void main()
//VTK::Clip::Impl
// compute the projected vertex position
vertexVC = MCVCMatrix * vertexMC;
gl_Position = VCDCMatrix * vertexVC;
//VTK::PositionVC::Impl
}
......
......@@ -74,6 +74,12 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderValues(std::string &VSSource,
vtkRenderer* ren,
vtkActor *actor)
{
// we use vertex instead of vertexMC
VSSource = replace(VSSource,
"//VTK::PositionVC::Impl",
"vertexVC = MCVCMatrix * vertex;\n"
" gl_Position = VCDCMatrix * vertexVC;\n");
// deal with color
if (this->UsingInstancing)
{
......
......@@ -323,6 +323,17 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(std::string &VSSource,
// handle colors / materials
this->ReplaceShaderColorMaterialValues(VSSource, FSSource, GSSource, lightComplexity, ren, actor);
VSSource = replace(VSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVC;");
VSSource = replace(VSSource,
"//VTK::PositionVC::Impl",
"vertexVC = MCVCMatrix * vertexMC;\n"
" gl_Position = VCDCMatrix * vertexVC;\n");
FSSource = replace(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVC;");
// normals?
if (this->Layout.NormalOffset)
{
......@@ -345,7 +356,7 @@ void vtkOpenGLPolyDataMapper::ReplaceShaderValues(std::string &VSSource,
" else { normalVC = normalVCVarying; }"
//"normalVC = normalVCVarying;"
);
}
}
else
{
FSSource = replace(FSSource,
......
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