Commit ece2ba8f authored by Ken Martin's avatar Ken Martin

some more cleanup

parent 3c9a2943
......@@ -23,6 +23,7 @@
#include "vtkPLYReader.h"
#include "vtkNew.h"
#include "vtkProperty.h"
#include "vtkLightKit.h"
#include "vtkTimerLog.h"
......@@ -41,6 +42,10 @@ int TestVBOPLYMapper(int argc, char *argv[])
renderWindow->AddRenderer(renderer.Get());
renderer->AddActor(actor.Get());
vtkNew<vtkLightKit> lightKit;
lightKit->AddLightsToRenderer(renderer.Get());
const char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/bunny.ply");
......@@ -53,9 +58,9 @@ int TestVBOPLYMapper(int argc, char *argv[])
mapper->SetInputConnection(computeNormals->GetOutputPort());
actor->SetMapper(mapper.Get());
actor->GetProperty()->SetDiffuseColor(1.0, 1.0, 0.0);
actor->GetProperty()->SetDiffuseColor(1.0, 0.65, 0.7);
actor->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
actor->GetProperty()->SetSpecular(1.0);
actor->GetProperty()->SetSpecular(0.5);
actor->GetProperty()->SetOpacity(1.0);
vtkNew<vtkRenderWindowInteractor> interactor;
......
......@@ -15,14 +15,22 @@
// it requires only one white light, positioned at the camera
// Gouraud shading
attribute vec4 vertex;
attribute vec3 normal;
// 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 normalMC;
// material property values
uniform float opacity;
uniform vec3 diffuseColor;
uniform vec3 specularColor;
uniform vec3 specularPower;
uniform float specularPower;
// camera and actor matrix values
uniform mat4 modelView;
......@@ -33,12 +41,12 @@ varying vec4 fcolor;
void main()
{
gl_Position = projection * modelView * vertex;
vec3 N = normalize(normalMatrix * normal);
gl_Position = projection * modelView * vertexMC;
vec3 normalVC = normalize(normalMatrix * normalMC);
// diffuse and specular lighting
float df = max(0.0, dot(N, vec3(0,0,-1)));
float sf = pow(df, 20.0);
float df = max(0.0, dot(normalVC, vec3(0,0,-1)));
float sf = pow(df, specularPower);
//vec3 ambient = 0.4 * color;
vec3 diffuse = df * diffuseColor;
......
......@@ -15,43 +15,59 @@
// and supports the VTK light kit, multiple lights
// some off axis from the camera, Gouraud shading
attribute vec4 vertex;
attribute vec3 normal;
// 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 normalMC;
// material property values
uniform float opacity;
uniform vec3 diffuseColor;
uniform vec3 specularColor;
uniform vec3 specularPower;
uniform float specularPower;
// camera and actor matrix values
uniform mat4 modelView;
uniform mat4 projection;
uniform mat3 normalMatrix;
uniform mat4 modelView; // combined actor (model) and view matricies
uniform mat4 projection; // the camera's projection matrix
uniform mat3 normalMatrix; // transform model coordinate directions to view coordinates
uniform int numberOfLights; // only allow for up to 6 active lights
uniform vec3 lightColor[6]; // intensity weighted
uniform vec3 lightDirection[6]; // normalized and in camera coords
uniform vec3 lightColor[6]; // intensity weighted color
uniform vec3 lightDirectionVC[6]; // normalized
// the resulting vertex color to be passed down to the fragment shader
varying vec4 fcolor;
void main()
{
gl_Position = projection * modelView * vertex;
vec3 N = normalize(normalMatrix * normal);
vec3 E = vec3(0, 0, 1); // eye/view/camera direction
// compute the projected vertex position
vec4 vertexVC = modelView * vertexMC;
gl_Position = projection * vertexVC;
// now compute the vertex color
vec3 normalVC = normalize(normalMatrix * normalMC);
vec3 viewDirectionVC = normalize(vec3(0.0, 0.0, 1.0) - vertexVC);
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(N, lightDirection[lightNum]));
float df = max(0.0, dot(normalVC, lightDirectionVC[lightNum]));
diffuse += (df * lightColor[lightNum]);
float sf = pow( max(0.0, dot(reflect(lightDirection[lightNum], N), E)), 20.0);
specular += (sf * lightColor[lightNum]);
if (dot(normalVC, lightDirectionVC[lightNum]) > 0.0)
{
float sf = pow( max(0.0, dot(
reflect(lightDirectionVC[lightNum], normalVC), viewDirectionVC)), specularPower);
specular += (sf * lightColor[lightNum]);
}
}
diffuse = diffuse * diffuseColor;
......
......@@ -217,7 +217,7 @@ void vtkVBOPolyDataMapper::SetLightingShaderParameters(vtkRenderer* ren, vtkActo
}
}
this->Internal->program.setUniformValue("lightColor", numberOfLights, lightColor);
this->Internal->program.setUniformValue("lightDirection", numberOfLights, lightDirection);
this->Internal->program.setUniformValue("lightDirectionVC", numberOfLights, lightDirection);
this->Internal->program.setUniformValue("numberOfLights", numberOfLights);
}
......@@ -250,10 +250,12 @@ void vtkVBOPolyDataMapper::SetPropertyShaderParameters(vtkRenderer* ren, vtkActo
vtkgl::Vector3ub specularColor(static_cast<unsigned char>(sColor[0] * sIntensity * 255.0),
static_cast<unsigned char>(sColor[1] * sIntensity * 255.0),
static_cast<unsigned char>(sColor[2] * sIntensity * 255.0));
float specularPower = actor->GetProperty()->GetSpecularPower();
this->Internal->program.setUniformValue("opacity", opacity);
this->Internal->program.setUniformValue("diffuseColor", diffuseColor);
this->Internal->program.setUniformValue("specularColor", specularColor);
this->Internal->program.setUniformValue("specularPower", specularPower);
}
//-----------------------------------------------------------------------------
......@@ -327,13 +329,13 @@ void vtkVBOPolyDataMapper::RenderPiece(vtkRenderer* ren, vtkActor *actor)
this->Internal->vbo.bind();
this->Internal->ibo.bind();
this->Internal->program.enableAttributeArray("vertex");
this->Internal->program.useAttributeArray("vertex", 0,
this->Internal->program.enableAttributeArray("vertexMC");
this->Internal->program.useAttributeArray("vertexMC", 0,
sizeof(float) * 6,
VTK_FLOAT, 3,
vtkgl::ShaderProgram::NoNormalize);
this->Internal->program.enableAttributeArray("normal");
this->Internal->program.useAttributeArray("normal", sizeof(float) * 3,
this->Internal->program.enableAttributeArray("normalMC");
this->Internal->program.useAttributeArray("normalMC", sizeof(float) * 3,
sizeof(float) * 6,
VTK_FLOAT, 3,
vtkgl::ShaderProgram::NoNormalize);
......
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