Commit c4ba26d8 authored by Ken Martin's avatar Ken Martin

redo how cell data is handled and picking

parent 2fb156dd
......@@ -127,10 +127,7 @@ set(shader_files
glsl/vtkglGlyph3DVSFragmentLit.glsl
glsl/vtkglPolyData2DFS.glsl
glsl/vtkglPolyData2DVS.glsl
glsl/vtkglPolyDataFSHeadlight.glsl
glsl/vtkglPolyDataFSLightKit.glsl
glsl/vtkglPolyDataFSNoLighting.glsl
glsl/vtkglPolyDataFSPositionalLights.glsl
glsl/vtkglPolyDataFS.glsl
glsl/vtkglPolyDataVSFragmentLit.glsl
glsl/vtkglPolyDataVSNoLighting.glsl
)
......
......@@ -17,17 +17,20 @@
// default precisions, or defining precisions to null
//VTK::System::Dec
uniform int PrimitiveIDOffset;
// Texture coordinates
//VTK::TCoord::Dec
varying vec4 fcolor;
// Scalar coloring
//VTK::Color::Dec
// Depth Peeling
//VTK::DepthPeeling::Dec
void main()
{
gl_FragData[0] = fcolor;
//VTK::Color::Impl
//VTK::TCoord::Impl
//VTK::DepthPeeling::Impl
}
......@@ -28,19 +28,16 @@ attribute vec4 vertexWC;
// material property values
//VTK::Color::Dec
uniform vec3 ambientColor; // intensity weighted color
// Texture coordinates
//VTK::TCoord::Dec
uniform mat4 WCVCMatrix; // World to view matrix
varying vec4 fcolor;
void main()
{
gl_Position = WCVCMatrix*vertexWC;
//VTK::TCoord::Impl
fcolor = vec4(ambientColor + diffuseColor.rgb, diffuseColor.a);
//VTK::Color::Impl
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataFSHeadight.glsl
Module: vtkglPolyDataFS.glsl
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -12,12 +12,14 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// the lighting model for this shader is a Headlight
// Template for the polydata mappers fragment shader
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
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
......@@ -25,15 +27,18 @@
// VC - View Coordinates
// DC - Display Coordinates
// VC positon of this fragment
// VC position of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
// optional normal declaration
// optional surface normal declaration
//VTK::Normal::Dec
// extra lighting parameters
//VTK::Light::Dec
// Texture coordinates
//VTK::TCoord::Dec
......@@ -55,14 +60,8 @@ void main()
// Generate the normal if we are not passed in one
//VTK::Normal::Impl
// diffuse and specular lighting
float df = max(0.0, normalVC.z);
float sf = pow(df, specularPower);
vec3 diffuse = df * diffuseColor;
vec3 specular = sf * specularColor;
//VTK::Light::Impl
gl_FragData[0] = vec4(ambientColor + diffuse + specular, opacity);
//VTK::TCoord::Impl
if (gl_FragData[0].a <= 0.0)
......@@ -75,6 +74,3 @@ void main()
//VTK::Picking::Impl
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataFSHeadight.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.
=========================================================================*/
// the lighting model for this shader is the LightKit
// The following line handle system declarations such a
// 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
// camera and actor matrix values
//VTK::Camera::Dec
uniform int numberOfLights; // only allow for up to 6 active lights
uniform vec3 lightColor[6]; // intensity weighted color
uniform vec3 lightDirectionVC[6]; // normalized
uniform vec3 lightHalfAngleVC[6]; // normalized
// VC positon of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
// optional normal declaration
//VTK::Normal::Dec
// Texture coordinates
//VTK::TCoord::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
// clipping plane vars
//VTK::Clip::Dec
void main()
{
//VTK::Clip::Impl
//VTK::Color::Impl
// Note that the above will always define vec3 ambientColor, vec3 diffuseColor and float opacity
// Generate the normal if we are not passed in one
//VTK::Normal::Impl
// now compute the vertex color
vec3 diffuse = vec3(0,0,0);
vec3 specular = vec3(0,0,0);
for (int lightNum = 0; lightNum < numberOfLights; lightNum++)
{
// diffuse and specular lighting
float df = max(0.0, dot(normalVC, -lightDirectionVC[lightNum]));
diffuse += (df * lightColor[lightNum]);
if (dot(normalVC, lightDirectionVC[lightNum]) < 0.0)
{
float sf = pow( max(0.0, dot(lightHalfAngleVC[lightNum],normalVC)), specularPower);
specular += (sf * lightColor[lightNum]);
}
}
diffuse = diffuse * diffuseColor;
specular = specular * specularColor;
gl_FragData[0] = vec4(ambientColor + diffuse + specular, opacity);
//VTK::TCoord::Impl
if (gl_FragData[0].a <= 0.0)
{
discard;
}
//VTK::DepthPeeling::Impl
//VTK::Picking::Impl
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataFSNoLighting.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.
=========================================================================*/
// The following line handle system declarations such a
// default precisions, or defining precisions to null
//VTK::System::Dec
// VC positon of this fragment
//VTK::PositionVC::Dec
varying vec4 fcolor;
// Texture coordinates
//VTK::TCoord::Dec
//VTK::Color::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
// clipping plane vars
//VTK::Clip::Dec
void main()
{
//VTK::Clip::Impl
//VTK::Color::Impl
// Note that the above will always define vec3 ambientColor, vec3 diffuseColor and float opacity
gl_FragData[0] = vec4(ambientColor + diffuseColor, opacity);
//VTK::TCoord::Impl
if (gl_FragData[0].a <= 0.0)
{
discard;
}
//VTK::DepthPeeling::Impl
//VTK::Picking::Impl
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkglPolyDataFSPositionalLights.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.
=========================================================================*/
// the lighting model for this shader is complex
// and supports the full VTK light API
// The following line handle system declarations such a
// 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
// camera and actor matrix values
//VTK::Camera::Dec
uniform int numberOfLights; // only allow for up to 6 active lights
uniform vec3 lightColor[6]; // intensity weighted color
uniform vec3 lightDirectionVC[6]; // normalized
uniform vec3 lightHalfAngleVC[6]; // normalized
uniform vec3 lightPositionVC[6];
uniform vec3 lightAttenuation[6];
uniform float lightConeAngle[6];
uniform float lightExponent[6];
uniform int lightPositional[6];
// VC positon of this fragment
//VTK::PositionVC::Dec
// optional color passed in from the vertex shader, vertexColor
//VTK::Color::Dec
// optional normal declaration
//VTK::Normal::Dec
// Texture coordinates
//VTK::TCoord::Dec
// picking support
//VTK::Picking::Dec
// Depth Peeling Support
//VTK::DepthPeeling::Dec
// clipping plane vars
//VTK::Clip::Dec
void main()
{
//VTK::Clip::Impl
//VTK::Color::Impl
// Note that the above will always define vec3 ambientColor, vec3 diffuseColor and float opacity
// Generate the normal if we are not passed in one
//VTK::Normal::Impl
vec3 diffuse = vec3(0,0,0);
vec3 specular = vec3(0,0,0);
vec3 vertLightDirectionVC;
for (int lightNum = 0; lightNum < numberOfLights; lightNum++)
{
float attenuation = 1.0;
// directional
if (lightPositional[lightNum] == 0)
{
vertLightDirectionVC = lightDirectionVC[lightNum];
}
else
{
vertLightDirectionVC = vertexVC.xyz - lightPositionVC[lightNum];
float distanceVC = length(vertLightDirectionVC);
vertLightDirectionVC = normalize(vertLightDirectionVC);
attenuation = 1.0 /
(lightAttenuation[lightNum].x
+ lightAttenuation[lightNum].y * distanceVC
+ lightAttenuation[lightNum].z * distanceVC * distanceVC);
// per OpenGL standard cone angle is 90 or less for a spot light
if (lightConeAngle[lightNum] <= 90.0)
{
float coneDot = dot(vertLightDirectionVC, lightDirectionVC[lightNum]);
// if inside the cone
if (coneDot >= cos(radians(lightConeAngle[lightNum])))
{
attenuation = attenuation * pow(coneDot, lightExponent[lightNum]);
}
else
{
attenuation = 0.0;
}
}
}
// diffuse and specular lighting
float df = max(0.0, attenuation*dot(normalVC, -vertLightDirectionVC));
diffuse += (df * lightColor[lightNum]);
if (dot(normalVC, vertLightDirectionVC) < 0.0)
{
float sf = attenuation*pow( max(0.0, dot(lightHalfAngleVC[lightNum],normalVC)), specularPower);
specular += (sf * lightColor[lightNum]);
}
}
diffuse = diffuse * diffuseColor;
specular = specular * specularColor;
gl_FragData[0] = vec4(ambientColor + diffuse + specular, opacity);
//VTK::TCoord::Impl
if (gl_FragData[0].a <= 0.0)
{
discard;
}
//VTK::DepthPeeling::Impl
//VTK::Picking::Impl
}
......@@ -25,6 +25,7 @@
#include "vtkMultiBlockDataSet.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLTexture.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
......@@ -33,6 +34,7 @@
#include "vtkRenderWindow.h"
#include "vtkLookupTable.h"
#include "vtkShaderProgram.h"
#include "vtkTextureObject.h"
vtkStandardNewMacro(vtkCompositePolyDataMapper2);
......@@ -370,7 +372,7 @@ void vtkCompositePolyDataMapper2::RenderPieceDraw(
for (it = this->RenderValues.begin(); it != this->RenderValues.end(); it++)
{
// reset the offset so each compsoite starts at 0
this->pickingAttributeIDOffset = 0;
this->PrimitiveIDOffset = 0;
if (it->Visibility)
{
if (selector &&
......@@ -402,7 +404,7 @@ void vtkCompositePolyDataMapper2::RenderPieceDraw(
}
this->Tris.ibo.Release();
this->pickingAttributeIDOffset += (int)this->Tris.indexCount;
this->PrimitiveIDOffset += (int)this->Tris.indexCount;
}
}
......@@ -566,13 +568,17 @@ void vtkCompositePolyDataMapper2::BuildBufferObjects(
this->EdgeIndexOffsets.resize(this->MaximumFlatIndex+1);
this->CanUseTextureMapForColoringSet = false;
// used for cell values
std::vector<unsigned char> newColors;
std::vector<float> newNorms;
unsigned int voffset = 0;
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
unsigned int fidx = iter->GetCurrentFlatIndex();
vtkDataObject *dso = iter->GetCurrentDataObject();
vtkPolyData *pd = vtkPolyData::SafeDownCast(dso);
this->AppendOneBufferObject(ren, act, pd, voffset);
this->AppendOneBufferObject(ren, act, pd, voffset, newColors, newNorms);
this->VertexOffsets[fidx] =
static_cast<unsigned int>(this->Layout.VertexCount);
voffset = static_cast<unsigned int>(this->Layout.VertexCount);
......@@ -582,6 +588,28 @@ void vtkCompositePolyDataMapper2::BuildBufferObjects(
static_cast<unsigned int>(this->EdgeIndexArray.size());
}
if (this->HaveCellScalars)
{
this->CellScalarBuffer->Upload(newColors,
vtkgl::BufferObject::ArrayBuffer);
this->CellScalarTexture->CreateTextureBuffer(
static_cast<unsigned int>(newColors.size()/
this->Colors->GetNumberOfComponents()),
this->Colors->GetNumberOfComponents(),
VTK_UNSIGNED_CHAR,
this->CellScalarBuffer);
}
if (this->HaveCellNormals)
{
this->CellNormalBuffer->Upload(newNorms,
vtkgl::BufferObject::ArrayBuffer);
this->CellNormalTexture->CreateTextureBuffer(
static_cast<unsigned int>(newNorms.size()/3),
3, VTK_FLOAT,
this->CellNormalBuffer);
}
this->VBO.Upload(this->Layout.PackedVBO, vtkgl::BufferObject::ArrayBuffer);
this->Layout.PackedVBO.resize(0);
this->Tris.ibo.Upload(this->IndexArray,
......@@ -602,7 +630,10 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
vtkRenderer *ren,
vtkActor *act,
vtkPolyData *poly,
unsigned int voffset)
unsigned int voffset,
std::vector<unsigned char> &newColors,
std::vector<float> &newNorms
)
{
// if there are no cells then skip this piece
if (poly->GetPolys()->GetNumberOfCells() == 0)
......@@ -642,7 +673,7 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
this->InternalColorTexture->SetInputData(this->ColorTextureMap);
}
bool cellScalars = false;
this->HaveCellScalars = false;
if (this->ScalarVisibility)
{
// We must figure out how the scalars should be mapped to the polydata.
......@@ -653,17 +684,17 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
&& this->ScalarMode != VTK_SCALAR_MODE_USE_POINT_FIELD_DATA
&& this->Colors)
{
cellScalars = true;
this->HaveCellScalars = true;
}
}
bool cellNormals = false;
this->HaveCellNormals = false;
// Do we have cell normals?
vtkDataArray *n =
(act->GetProperty()->GetInterpolation() != VTK_FLAT) ? poly->GetPointData()->GetNormals() : NULL;
if (n == NULL && poly->GetCellData()->GetNormals())
{
cellNormals = true;
this->HaveCellNormals = true;
n = poly->GetCellData()->GetNormals();
}
......@@ -674,11 +705,54 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
prims[1] = poly->GetLines();
prims[2] = poly->GetPolys();
prims[3] = poly->GetStrips();
std::vector<unsigned int> cellPointMap;
std::vector<unsigned int> pointCellMap;
if (cellScalars || cellNormals)
int representation = act->GetProperty()->GetRepresentation();
std::vector<unsigned int> cellCellMap;
if (this->HaveCellScalars || this->HaveCellNormals)
{
vtkgl::CreateCellSupportArrays(poly, prims, cellPointMap, pointCellMap);
vtkgl::CreateCellSupportArrays(prims, cellCellMap, representation);
if (this->HaveCellScalars)
{
if (!this->CellScalarTexture)
{
this->CellScalarTexture = vtkTextureObject::New();
this->CellScalarBuffer = new vtkgl::BufferObject;
}
this->CellScalarTexture->SetContext(
static_cast<vtkOpenGLRenderWindow*>(ren->GetVTKWindow()));
// create the cell scalar array adjusted for ogl Cells
unsigned char *colorPtr = this->Colors->GetPointer(0);
int numComp = this->Colors->GetNumberOfComponents();
for (int i = 0; i < cellCellMap.size(); i++)
{
for (int j = 0; j < numComp; j++)
{
newColors.push_back(colorPtr[cellCellMap[i]*numComp + j]);
}
}
}
if (this->HaveCellNormals)
{
if (!this->CellNormalTexture)
{
this->CellNormalTexture = vtkTextureObject::New();
this->CellNormalBuffer = new vtkgl::BufferObject;
}
this->CellNormalTexture->SetContext(
static_cast<vtkOpenGLRenderWindow*>(ren->GetVTKWindow()));
// create the cell scalar array adjusted for ogl Cells
for (int i = 0; i < cellCellMap.size(); i++)
{
double *norms = n->GetTuple(cellCellMap[i]);
newNorms.push_back(norms[0]);
newNorms.push_back(norms[1]);
newNorms.push_back(norms[2]);
}
}
}
// do we have texture maps?
......@@ -702,18 +776,13 @@ void vtkCompositePolyDataMapper2::AppendOneBufferObject(
// Build the VBO