Commit d6a29684 authored by Ken Martin's avatar Ken Martin

Support wide lines in the polydata mappers on 3.2

Support wide lines in 3.2 using a geometry shader. This patch
includes a number of cleanups to make using geometry shaders
easier etc.
parent ecb72a46
......@@ -18,13 +18,6 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
attribute vec2 offsetMC;
......@@ -45,9 +38,9 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
// camera and actor matrix values
//VTK::Camera::Dec
varying vec4 vertexVCClose;
varying float radiusVC;
varying vec3 centerVC;
varying vec4 vertexVCVSOutput;
varying float radiusVCVSOutput;
varying vec3 centerVCVSOutput;
uniform int cameraParallel;
......@@ -62,23 +55,23 @@ void main()
//VTK::Clip::Impl
// compute the projected vertex position
vertexVCClose = MCVCMatrix * vertexMC;
centerVC = vertexVCClose.xyz;
radiusVC = length(offsetMC)*0.5;
vertexVCVSOutput = MCVCMatrix * vertexMC;
centerVCVSOutput = vertexVCVSOutput.xyz;
radiusVCVSOutput = length(offsetMC)*0.5;
// make the triangle face the camera
if (cameraParallel == 0)
{
vec3 dir = normalize(-vertexVCClose.xyz);
vec3 dir = normalize(-vertexVCVSOutput.xyz);
vec3 base2 = normalize(cross(dir,vec3(1.0,0.0,0.0)));
vec3 base1 = cross(base2,dir);
vertexVCClose.xyz = vertexVCClose.xyz + offsetMC.x*base1 + offsetMC.y*base2;
vertexVCVSOutput.xyz = vertexVCVSOutput.xyz + offsetMC.x*base1 + offsetMC.y*base2;
}
else
{
// add in the offset
vertexVCClose.xy = vertexVCClose.xy + offsetMC;
vertexVCVSOutput.xy = vertexVCVSOutput.xy + offsetMC;
}
gl_Position = VCDCMatrix * vertexVCClose;
gl_Position = VCDCMatrix * vertexVCVSOutput;
}
......@@ -18,13 +18,6 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
attribute vec3 orientMC;
attribute vec4 offsetMC;
......@@ -49,11 +42,11 @@ uniform mat3 normalMatrix; // transform model coordinate directions to view coor
// camera and actor matrix values
//VTK::Camera::Dec
varying vec4 vertexVCClose;
varying float radiusVC;
varying float lengthVC;
varying vec3 centerVC;
varying vec3 orientVC;
varying vec4 vertexVCVSOutput;
varying float radiusVCVSOutput;
varying float lengthVCVSOutput;
varying vec3 centerVCVSOutput;
varying vec3 orientVCVSOutput;
uniform int cameraParallel;
......@@ -69,16 +62,16 @@ void main()
//VTK::Clip::Impl
vertexVCClose = MCVCMatrix * vertexMC;
centerVC = vertexVCClose.xyz;
radiusVC = radiusMC;
lengthVC = length(orientMC);
orientVC = normalMatrix * normalize(orientMC);
vertexVCVSOutput = MCVCMatrix * vertexMC;
centerVCVSOutput = vertexVCVSOutput.xyz;
radiusVCVSOutput = radiusMC;
lengthVCVSOutput = length(orientMC);
orientVCVSOutput = normalMatrix * normalize(orientMC);
// make sure it is pointing out of the screen
if (orientVC.z < 0.0)
if (orientVCVSOutput.z < 0.0)
{
orientVC = -orientVC;
orientVCVSOutput = -orientVCVSOutput;
}
// make the basis
......@@ -87,24 +80,24 @@ void main()
vec3 dir = vec3(0.0,0.0,1.0);
if (cameraParallel == 0)
{
dir = normalize(-vertexVCClose.xyz);
dir = normalize(-vertexVCVSOutput.xyz);
}
if (abs(dot(dir,orientVC)) == 1.0)
if (abs(dot(dir,orientVCVSOutput)) == 1.0)
{
xbase = normalize(cross(vec3(0.0,1.0,0.0),orientVC));
ybase = cross(xbase,orientVC);
xbase = normalize(cross(vec3(0.0,1.0,0.0),orientVCVSOutput));
ybase = cross(xbase,orientVCVSOutput);
}
else
{
xbase = normalize(cross(orientVC,dir));
ybase = cross(orientVC,xbase);
xbase = normalize(cross(orientVCVSOutput,dir));
ybase = cross(orientVCVSOutput,xbase);
}
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;
vertexVCVSOutput.xyz = vertexVCVSOutput.xyz +
radiusVCVSOutput*offsets.x*xbase +
radiusVCVSOutput*offsets.y*ybase +
0.5*lengthVCVSOutput*offsets.z*orientVCVSOutput;
gl_Position = VCDCMatrix * vertexVCClose;
gl_Position = VCDCMatrix * vertexVCVSOutput;
}
......@@ -68,25 +68,25 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(
vtkShaderProgram::Substitute(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCClose;");
"varying vec4 vertexVCVSOutput;");
// for lights kit and positional the VCDC matrix is already defined
// so don't redefine it
std::string replacement =
"uniform float invertedDepth;\n"
"uniform int cameraParallel;\n"
"varying float radiusVC;\n"
"varying vec3 centerVC;\n"
"varying float radiusVCVSOutput;\n"
"varying vec3 centerVCVSOutput;\n"
"uniform mat4 VCDCMatrix;\n";
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Dec",replacement);
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Impl",
// compute the eye position and unit direction
"vec4 vertexVC = vertexVCClose;\n"
"vec4 vertexVC = vertexVCVSOutput;\n"
" vec3 EyePos;\n"
" vec3 EyeDir;\n"
" if (cameraParallel != 0) {\n"
" EyePos = vec3(vertexVC.x, vertexVC.y, vertexVC.z + 3.0*radiusVC);\n"
" EyePos = vec3(vertexVC.x, vertexVC.y, vertexVC.z + 3.0*radiusVCVSOutput);\n"
" EyeDir = vec3(0.0,0.0,-1.0); }\n"
" else {\n"
" EyeDir = vertexVC.xyz;\n"
......@@ -95,31 +95,31 @@ void vtkOpenGLSphereMapper::ReplaceShaderValues(
" EyeDir = normalize(EyeDir);\n"
// we adjust the EyePos to be closer if it is too far away
// to prevent floating point precision noise
" if (lengthED > radiusVC*3.0) {\n"
" EyePos = vertexVC.xyz - EyeDir*3.0*radiusVC; }\n"
" if (lengthED > radiusVCVSOutput*3.0) {\n"
" EyePos = vertexVC.xyz - EyeDir*3.0*radiusVCVSOutput; }\n"
" }\n"
// translate to Sphere center
" EyePos = EyePos - centerVC;\n"
" EyePos = EyePos - centerVCVSOutput;\n"
// scale to radius 1.0
" EyePos = EyePos/radiusVC;\n"
" EyePos = EyePos/radiusVCVSOutput;\n"
// find the intersection
" float b = 2.0*dot(EyePos,EyeDir);\n"
" float c = dot(EyePos,EyePos) - 1.0;\n"
" float d = b*b - 4.0*c;\n"
" vec3 normalVC = vec3(0.0,0.0,1.0);\n"
" vec3 normalVCVSOutput = vec3(0.0,0.0,1.0);\n"
" if (d < 0.0) { discard; }\n"
" else {\n"
" float t = (-b - invertedDepth*sqrt(d))*0.5;\n"
// compute the normal, for unit sphere this is just
// the intersection point
" normalVC = invertedDepth*normalize(EyePos + t*EyeDir);\n"
" normalVCVSOutput = invertedDepth*normalize(EyePos + t*EyeDir);\n"
// compute the intersection point in VC
" vertexVC.xyz = normalVC*radiusVC + centerVC;\n"
" vertexVC.xyz = normalVCVSOutput*radiusVCVSOutput + centerVCVSOutput;\n"
" }\n"
// compute the pixel's depth
// " normalVC = vec3(0,0,1);\n"
// " normalVCVSOutput = vec3(0,0,1);\n"
" vec4 pos = VCDCMatrix * vertexVC;\n"
" gl_FragDepth = (pos.z / pos.w + 1.0) / 2.0;\n"
);
......
......@@ -70,16 +70,16 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(
vtkShaderProgram::Substitute(FSSource,
"//VTK::PositionVC::Dec",
"varying vec4 vertexVCClose;");
"varying vec4 vertexVCVSOutput;");
// for lights kit and positional the VCDC matrix is already defined
// so don't redefine it
std::string replacement =
"uniform int cameraParallel;\n"
"varying float radiusVC;\n"
"varying vec3 orientVC;\n"
"varying float lengthVC;\n"
"varying vec3 centerVC;\n"
"varying float radiusVCVSOutput;\n"
"varying vec3 orientVCVSOutput;\n"
"varying float lengthVCVSOutput;\n"
"varying vec3 centerVCVSOutput;\n"
"uniform mat4 VCDCMatrix;\n";
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Dec",replacement);
......@@ -87,11 +87,11 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(
// see https://www.cl.cam.ac.uk/teaching/1999/AGraphHCI/SMAG/node2.html
vtkShaderProgram::Substitute(FSSource,"//VTK::Normal::Impl",
// compute the eye position and unit direction
" vec4 vertexVC = vertexVCClose;\n"
" vec4 vertexVC = vertexVCVSOutput;\n"
" vec3 EyePos;\n"
" vec3 EyeDir;\n"
" if (cameraParallel != 0) {\n"
" EyePos = vec3(vertexVC.x, vertexVC.y, vertexVC.z + 3.0*radiusVC);\n"
" EyePos = vec3(vertexVC.x, vertexVC.y, vertexVC.z + 3.0*radiusVCVSOutput);\n"
" EyeDir = vec3(0.0,0.0,-1.0); }\n"
" else {\n"
" EyeDir = vertexVC.xyz;\n"
......@@ -100,55 +100,55 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(
" EyeDir = normalize(EyeDir);\n"
// we adjust the EyePos to be closer if it is too far away
// to prevent floating point precision noise
" if (lengthED > radiusVC*3.0) {\n"
" EyePos = vertexVC.xyz - EyeDir*3.0*radiusVC; }\n"
" if (lengthED > radiusVCVSOutput*3.0) {\n"
" EyePos = vertexVC.xyz - EyeDir*3.0*radiusVCVSOutput; }\n"
" }\n"
// translate to Cylinder center
" EyePos = EyePos - centerVC;\n"
" EyePos = EyePos - centerVCVSOutput;\n"
// rotate to new basis
// base1, base2, orientVC
" vec3 base1;\n"
" if (abs(orientVC.z) < 0.99) {\n"
" base1 = normalize(cross(orientVC,vec3(0.0,0.0,1.0))); }\n"
" if (abs(orientVCVSOutput.z) < 0.99) {\n"
" base1 = normalize(cross(orientVCVSOutput,vec3(0.0,0.0,1.0))); }\n"
" else {\n"
" base1 = normalize(cross(orientVC,vec3(0.0,1.0,0.0))); }\n"
" vec3 base2 = cross(orientVC,base1);\n"
" EyePos = vec3(dot(EyePos,base1),dot(EyePos,base2),dot(EyePos,orientVC));\n"
" EyeDir = vec3(dot(EyeDir,base1),dot(EyeDir,base2),dot(EyeDir,orientVC));\n"
" base1 = normalize(cross(orientVCVSOutput,vec3(0.0,1.0,0.0))); }\n"
" vec3 base2 = cross(orientVCVSOutput,base1);\n"
" EyePos = vec3(dot(EyePos,base1),dot(EyePos,base2),dot(EyePos,orientVCVSOutput));\n"
" EyeDir = vec3(dot(EyeDir,base1),dot(EyeDir,base2),dot(EyeDir,orientVCVSOutput));\n"
// scale by radius
" EyePos = EyePos/radiusVC;\n"
" EyePos = EyePos/radiusVCVSOutput;\n"
// find the intersection
" float a = EyeDir.x*EyeDir.x + EyeDir.y*EyeDir.y;\n"
" float b = 2.0*(EyePos.x*EyeDir.x + EyePos.y*EyeDir.y);\n"
" float c = EyePos.x*EyePos.x + EyePos.y*EyePos.y - 1.0;\n"
" float d = b*b - 4.0*a*c;\n"
" vec3 normalVC = vec3(0.0,0.0,1.0);\n"
" vec3 normalVCVSOutput = vec3(0.0,0.0,1.0);\n"
" if (d < 0.0) { discard; }\n"
" else {\n"
" float t = (-b - sqrt(d))/(2.0*a);\n"
" float tz = EyePos.z + t*EyeDir.z;\n"
" vec3 iPoint = EyePos + t*EyeDir;\n"
" if (abs(iPoint.z)*radiusVC > lengthVC*0.5) {\n"
" if (abs(iPoint.z)*radiusVCVSOutput > lengthVCVSOutput*0.5) {\n"
// test for end cap
" float t2 = (-b + sqrt(d))/(2.0*a);\n"
" float tz2 = EyePos.z + t2*EyeDir.z;\n"
" if (tz2*radiusVC > lengthVC*0.5 || tz*radiusVC < -0.5*lengthVC) { discard; }\n"
" if (tz2*radiusVCVSOutput > lengthVCVSOutput*0.5 || tz*radiusVCVSOutput < -0.5*lengthVCVSOutput) { discard; }\n"
" else {\n"
" normalVC = orientVC;\n"
" float t3 = (lengthVC*0.5/radiusVC - EyePos.z)/EyeDir.z;\n"
" normalVCVSOutput = orientVCVSOutput;\n"
" float t3 = (lengthVCVSOutput*0.5/radiusVCVSOutput - EyePos.z)/EyeDir.z;\n"
" iPoint = EyePos + t3*EyeDir;\n"
" vertexVC.xyz = radiusVC*(iPoint.x*base1 + iPoint.y*base2 + iPoint.z*orientVC) + centerVC;\n"
" vertexVC.xyz = radiusVCVSOutput*(iPoint.x*base1 + iPoint.y*base2 + iPoint.z*orientVCVSOutput) + centerVCVSOutput;\n"
" }\n"
" }\n"
" else {\n"
// The normal is the iPoint.xy rotated back into VC
" normalVC = iPoint.x*base1 + iPoint.y*base2;\n"
" normalVCVSOutput = iPoint.x*base1 + iPoint.y*base2;\n"
// rescale rerotate and translate
" vertexVC.xyz = radiusVC*(normalVC + iPoint.z*orientVC) + centerVC;\n"
" vertexVC.xyz = radiusVCVSOutput*(normalVCVSOutput + iPoint.z*orientVCVSOutput) + centerVCVSOutput;\n"
" }\n"
" }\n"
......@@ -165,19 +165,19 @@ void vtkOpenGLStickMapper::ReplaceShaderValues(
vtkShaderProgram::Substitute(VSSource,
"//VTK::Picking::Dec",
"attribute vec4 selectionId;\n"
"varying vec4 selectionIdFrag;");
"varying vec4 selectionIdVSOutput;");
vtkShaderProgram::Substitute(VSSource,
"//VTK::Picking::Impl",
"selectionIdFrag = selectionId;");
"selectionIdVSOutput = selectionId;");
vtkShaderProgram::Substitute(FSSource,
"//VTK::Picking::Dec",
"uniform vec3 mapperIndex;\n"
"varying vec4 selectionIdFrag;");
"varying vec4 selectionIdVSOutput;");
vtkShaderProgram::Substitute(FSSource,
"//VTK::Picking::Impl",
"if (mapperIndex == vec3(0.0,0.0,0.0))\n"
" {\n"
" gl_FragData[0] = vec4(selectionIdFrag.rgb, 1.0);\n"
" gl_FragData[0] = vec4(selectionIdVSOutput.rgb, 1.0);\n"
" }\n"
" else\n"
" {\n"
......
......@@ -2471,11 +2471,11 @@ void vtkSurfaceLICMapper::ReplaceShaderValues(
vtkShaderProgram::Substitute(VSSource,
"//VTK::TCoord::Dec",
"attribute vec3 tcoordMC;\n"
"varying vec3 tcoordVC;\n"
"varying vec3 tcoordVCVSOutput;\n"
);
vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl",
"tcoordVC = tcoordMC;"
"tcoordVCVSOutput = tcoordMC;"
);
vtkShaderProgram::Substitute(FSSource,
......@@ -2483,14 +2483,14 @@ void vtkSurfaceLICMapper::ReplaceShaderValues(
// 0/1, when 1 V is projected to surface for |V| computation.
"uniform int uMaskOnSurface;\n"
"uniform mat3 normalMatrix;\n"
"varying vec3 tcoordVC;"
"varying vec3 tcoordVCVSOutput;"
);
vtkShaderProgram::Substitute(FSSource,
"//VTK::TCoord::Impl",
// projected vectors
" vec3 tcoordLIC = normalMatrix * tcoordVC;\n"
" vec3 normN = normalize(normalVC);\n"
" vec3 tcoordLIC = normalMatrix * tcoordVCVSOutput;\n"
" vec3 normN = normalize(normalVCVSOutput);\n"
" float k = dot(tcoordLIC, normN);\n"
" tcoordLIC = (tcoordLIC - k*normN);\n"
" gl_FragData[1] = vec4(tcoordLIC.x, tcoordLIC.y, 0.0 , gl_FragCoord.z);\n"
......@@ -2498,7 +2498,7 @@ void vtkSurfaceLICMapper::ReplaceShaderValues(
// vectors for fragment masking
" if (uMaskOnSurface == 0)\n"
" {\n"
" gl_FragData[2] = vec4(tcoordVC, gl_FragCoord.z);\n"
" gl_FragData[2] = vec4(tcoordVCVSOutput, gl_FragCoord.z);\n"
" }\n"
" else\n"
" {\n"
......
......@@ -132,7 +132,7 @@ set(shader_files
glsl/vtkPolyData2DFS.glsl
glsl/vtkPolyData2DVS.glsl
glsl/vtkPolyDataFS.glsl
glsl/vtkPolyDataGS.glsl
glsl/vtkPolyDataWideLineGS.glsl
glsl/vtkPolyDataVS.glsl
)
unset(shader_h_files)
......
VTK uses shaders to perform its OpenGL rendering. VTK supports many different
options when it comes to rendering, resulting in potentially thousands of
possible combinations. While we could make one giant shader that uses defines or
uniforms to switch between all these possibilities it would be limiting. Instead
we build up the shader using string replacements on the fly, and then cache the
results for performance.
When writing your own shaders you can use any approach you want. In the end they
are just strings of code. For vtkOpenGLPolyDataMapper we make use of heavy
string replacments. In other classes we do very little processing as the shader
has far fewer options. Regardless there are a few conventions you should be
aware of.
For shader replacements we tend to use a form of
//VTK::SomeConcept::SomeAction
For example
//VTK::Normal::Dec - declaration any uniforms/varying needed for normals
//VTK::Normal::Impl - Implementation of shader code for handling normals
All shaders should start with the folowing line
//VTK::System::Dec
Which vtkOpenGLShaderCache will replace with a #version and some other values to
match the system and OpenGL Context it has. The other line you need (only in
your fragment shader) is
//VTK::Output::Dec
which VTK uses to map shader outputs to the framebufer.
All vertex shaders should name their outputs with a postfix of VSOutput All
geometry shaders should name their outputs with a postfix of GSOutput All
fragment shaders shoudl name their inputs with a postfix of VSOutput. Put
another way fragment shaders should assuming their input is coming from the
vertex shader. If a geometry shader is present VTK will rename the fragment
shader inputs from VSOutput to GSOuput automatically.
All variables that represent positions or directions usually have a suffix
indicating the coordinate system they are in. The possible values are
MC - Model Coordinates
WC - WC world coordinates
VC - View Coordinates
DC - Display Coordinates
NVC - NormalizeViewCoordinates
......@@ -18,16 +18,8 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
attribute vec2 offsetMC;
//attribute float radiusMC;
// optional normal declaration
//VTK::Normal::Dec
......@@ -44,7 +36,7 @@ attribute vec2 offsetMC;
// camera and actor matrix values
//VTK::Camera::Dec
varying vec2 offsetVC;
varying vec2 offsetVCVSOutput;
uniform int cameraParallel;
void main()
......@@ -80,6 +72,6 @@ void main()
vertexVC.xy = vertexVC.xy + offsetMC;
}
offsetVC = offsetMC/radius;
offsetVCVSOutput = offsetMC/radius;
gl_Position = VCDCMatrix * vertexVC;
}
......@@ -20,13 +20,6 @@
uniform int PrimitiveIDOffset;
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
// VC position of this fragment
//VTK::PositionVC::Dec
......
......@@ -19,13 +19,6 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
attribute vec4 vertexMC;
// frag position in VC
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPolyDataGS.glsl
Module: vtkPolyDataWideLineGS.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -18,13 +18,6 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
// all variables that represent positions or directions have a suffix
// indicating the coordinate system they are in. The possible values are
// MC - Model Coordinates
// WC - WC world coordinates
// VC - View Coordinates
// DC - Display Coordinates
// VC position of this fragment
//VTK::PositionVC::Dec
......@@ -52,17 +45,48 @@
// the output of this shader
//VTK::Output::Dec
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
uniform vec2 lineWidthNVC;
layout(lines) in;
layout(triangle_strip, max_vertices = 4) out;
void main()
{
for(int i = 0; i < 3; i++)
// compute the lines direction
vec2 normal = normalize(
gl_in[1].gl_Position.xy/gl_in[1].gl_Position.w -
gl_in[0].gl_Position.xy/gl_in[0].gl_Position.w);
// rotate 90 degrees
normal = vec2(-1.0*normal.y,normal.x);
for (int j = 0; j < 4; j++)
{
int i = j/2;
//VTK::PrimID::Impl
//VTK::Clip::Impl
//VTK::Color::Impl
//VTK::Normal::Impl
gl_Position = gl_in[i].gl_Position;
gl_PrimitiveID = gl_PrimitiveIDIn;
//VTK::Light::Impl
//VTK::TCoord::Impl
//VTK::DepthPeeling::Impl
//VTK::Picking::Impl
// VC position of this fragment
//VTK::PositionVC::Impl
gl_Position = vec4(
gl_in[i].gl_Position.xy + (lineWidthNVC*normal)*((j+1)%2 - 0.5)*gl_in[i].gl_Position.w,
gl_in[i].gl_Position.z,
gl_in[i].gl_Position.w);
EmitVertex();
}
EndPrimitive();
......
......@@ -37,11 +37,8 @@
#include "vtkShaderProgram.h"
#include "vtkTransform.h"
#include "vtkGlyph3DVS.h"
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkOpenGLGlyph3DHelper)
......@@ -102,7 +99,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderPositionVC(
// we use vertex instead of vertexMC
vtkShaderProgram::Substitute(VSSource,
"//VTK::PositionVC::Impl",
"vertexVC = MCVCMatrix * vertex;\n"
"vertexVCVSOutput = MCVCMatrix * vertex;\n"
" gl_Position = MCDCMatrix * vertex;\n");
}
else
......@@ -127,20 +124,20 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
// deal with color
if (this->UsingInstancing)
{
vtkShaderProgram::Substitute(VSSource,"//VTK::Color::Dec",
"attribute vec4 glyphColor;\n"
"varying vec4 vertexColor;");
vtkShaderProgram::Substitute(VSSource,
"//VTK::Color::Dec",
"attribute vec4 glyphColor;\n"
"varying vec4 vertexColorVSOutput;");
}
else
{
vtkShaderProgram::Substitute(VSSource,
"//VTK::Color::Dec",
"uniform vec4 glyphColor;\n"
"varying vec4 vertexColor;");
"//VTK::Color::Dec",
"uniform vec4 glyphColor;\n"
"varying vec4 vertexColorVSOutput;");
}
vtkShaderProgram::Substitute(VSSource,"//VTK::Color::Impl",
"vertexColor = glyphColor;");
"vertexColorVSOutput = glyphColor;");
// crate the material/color property declarations, and VS implementation
// these are always defined
......@@ -169,7 +166,7 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
"uniform float specularPowerUniformBF;\n";
}
}
colorDec += "varying vec4 vertexColor;\n";
colorDec += "varying vec4 vertexColorVSOutput;\n";
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Dec", colorDec);
// now handle the more complex fragment shader implementation
......@@ -235,41 +232,44 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderColor(
(this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
actor->GetProperty()->GetAmbient() > actor->GetProperty()->GetDiffuse()))
{
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", colorImpl +
" ambientColor = vertexColor.rgb;\n"
" opacity = vertexColor.a;");
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl",
colorImpl +
" ambientColor = vertexColorVSOutput.rgb;\n"
" opacity = vertexColorVSOutput.a;");
}
else if (this->ScalarMaterialMode == VTK_MATERIALMODE_DIFFUSE ||
(this->ScalarMaterialMode == VTK_MATERIALMODE_DEFAULT &&
actor->GetProperty()->GetAmbient() <= actor->GetProperty()->GetDiffuse()))
{
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", colorImpl +
" diffuseColor = vertexColor.rgb;\n"
" opacity = vertexColor.a;");
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl",
colorImpl +
" diffuseColor = vertexColorVSOutput.rgb;\n"
" opacity = vertexColorVSOutput.a;");
}
else
{
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl", colorImpl +
" diffuseColor = vertexColor.rgb;\n"
" ambientColor = vertexColor.rgb;\n"
" opacity = vertexColor.a;");
vtkShaderProgram::Substitute(FSSource,"//VTK::Color::Impl",
colorImpl +
" diffuseColor = vertexColorVSOutput.rgb;\n"
" ambientColor = vertexColorVSOutput.rgb;\n"
" opacity = vertexColorVSOutput.a;");
}
if (this->UsingInstancing)
{
vtkShaderProgram::Substitute(VSSource,
"//VTK::Glyph::Dec",
"attribute mat4 GCMCMatrix;");
"//VTK::Glyph::Dec",
"attribute mat4 GCMCMatrix;");
}
else
{
vtkShaderProgram::Substitute(VSSource,
"//VTK::Glyph::Dec",
"uniform mat4 GCMCMatrix;");
"//VTK::Glyph::Dec",
"uniform mat4 GCMCMatrix;");
}
vtkShaderProgram::Substitute(VSSource,
"//VTK::Glyph::Impl",
"vec4 vertex = GCMCMatrix * vertexMC;\n");
"//VTK::Glyph::Impl",
"vec4 vertex = GCMCMatrix * vertexMC;\n");
shaders[vtkShader::Vertex]->SetSource(VSSource);
shaders[vtkShader::Fragment]->SetSource(FSSource);
......@@ -290,23 +290,23 @@ void vtkOpenGLGlyph3DHelper::ReplaceShaderNormal(