Commit 3c9a2943 authored by Ken Martin's avatar Ken Martin

some rough changes to the VBO polydata mapper

parent 45e89396
......@@ -23,8 +23,9 @@ set(Module_SRCS
)
set(shader_files
glsl/mesh_vs.glsl
glsl/mesh_fs.glsl
glsl/vtkglPolyDataVSLightKit.glsl
glsl/vtkglPolyDataVSHeadlight.glsl
glsl/vtkglPolyDataFS.glsl
)
unset(shader_h_files)
......
......@@ -42,7 +42,7 @@ int TestVBOPLYMapper(int argc, char *argv[])
renderer->AddActor(actor.Get());
const char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
"Data/dragon.ply");
"Data/bunny.ply");
vtkNew<vtkPLYReader> reader;
reader->SetFileName(fileName);
......@@ -53,8 +53,10 @@ int TestVBOPLYMapper(int argc, char *argv[])
mapper->SetInputConnection(computeNormals->GetOutputPort());
actor->SetMapper(mapper.Get());
actor->GetProperty()->SetColor(1.0, 1.0, 0.0);
actor->GetProperty()->SetOpacity(0.6);
actor->GetProperty()->SetDiffuseColor(1.0, 1.0, 0.0);
actor->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
actor->GetProperty()->SetSpecular(1.0);
actor->GetProperty()->SetOpacity(1.0);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renderWindow.Get());
......
varying vec3 fnormal;
void main()
{
vec3 N = normalize(fnormal);
vec3 L = normalize(vec3(0, 1, 1));
vec3 E = vec3(0, 0, 1);
vec3 H = normalize(L + E);
float df = max(0.0, dot(N, L));
float sf = max(0.0, dot(N, H));
vec4 ambient = 0.4 * gl_Color;
vec4 diffuse = 0.55 * gl_Color;
vec4 specular = 0.5 * (vec4(1, 1, 1, 1) - gl_Color);
gl_FragColor = ambient + df * diffuse + pow(sf, 20.0) * specular;
gl_FragColor.a = gl_Color.a;
}
attribute vec4 vertex;
attribute vec3 normal;
uniform float opacity;
uniform vec3 color;
uniform mat4 modelView;
uniform mat4 projection;
uniform mat3 normalMatrix;
varying vec3 fnormal;
void main()
{
gl_FrontColor = vec4(color, opacity);
gl_Position = projection * modelView * vertex;
fnormal = normalize(normalMatrix * normal);
}
/*=========================================================================
Program: Visualization Toolkit
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.
=========================================================================*/
varying vec4 fcolor;
void main()
{
gl_FragColor = fcolor;
}
/*=========================================================================
Program: Visualization Toolkit
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 very simple
// it requires only one white light, positioned at the camera
// Gouraud shading
attribute vec4 vertex;
attribute vec3 normal;
// material property values
uniform float opacity;
uniform vec3 diffuseColor;
uniform vec3 specularColor;
uniform vec3 specularPower;
// camera and actor matrix values
uniform mat4 modelView;
uniform mat4 projection;
uniform mat3 normalMatrix;
varying vec4 fcolor;
void main()
{
gl_Position = projection * modelView * vertex;
vec3 N = normalize(normalMatrix * normal);
// diffuse and specular lighting
float df = max(0.0, dot(N, vec3(0,0,-1)));
float sf = pow(df, 20.0);
//vec3 ambient = 0.4 * color;
vec3 diffuse = df * diffuseColor;
vec3 specular = sf * specularColor;
fcolor = vec4(diffuse + specular, opacity);
}
/*=========================================================================
Program: Visualization Toolkit
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 more complex
// and supports the VTK light kit, multiple lights
// some off axis from the camera, Gouraud shading
attribute vec4 vertex;
attribute vec3 normal;
// material property values
uniform float opacity;
uniform vec3 diffuseColor;
uniform vec3 specularColor;
uniform vec3 specularPower;
// camera and actor matrix values
uniform mat4 modelView;
uniform mat4 projection;
uniform mat3 normalMatrix;
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
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
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]));
diffuse += (df * lightColor[lightNum]);
float sf = pow( max(0.0, dot(reflect(lightDirection[lightNum], N), E)), 20.0);
specular += (sf * lightColor[lightNum]);
}
diffuse = diffuse * diffuseColor;
specular = specular * specularColor;
fcolor = vec4(diffuse + specular, opacity);
}
This diff is collapsed.
......@@ -66,10 +66,26 @@ protected:
// simply obtains the bounds from the data-object and returns it.
virtual void ComputeBounds();
// Description:
// Determine what shader to use and compile/link it
virtual void UpdateShader(vtkRenderer *ren, vtkActor *act);
// Description:
// Update the scene when necessary.
void UpdateVBO();
// Description:
// Set the shader parameteres related to lighting
void SetLightingShaderParameters(vtkRenderer *ren, vtkActor *act);
// Description:
// Set the shader parameteres related to lighting
void SetCameraShaderParameters(vtkRenderer *ren, vtkActor *act);
// Description:
// Set the shader parameteres related to lighting
void SetPropertyShaderParameters(vtkRenderer *ren, vtkActor *act);
// Description:
// The scene used by the mapper, all rendering is deferred to the scene.
class Private;
......
......@@ -380,6 +380,18 @@ bool ShaderProgram::setUniformValue(const std::string &name,
return true;
}
bool ShaderProgram::setUniformValue(const std::string &name, const int count,
const float (*v)[3])
{
GLint location = static_cast<GLint>(findUniform(name));
if (location == -1) {
m_error = "Could not set uniform " + name + ". No such uniform.";
return false;
}
glUniform3fv(location, count, (const GLfloat *)v);
return true;
}
bool ShaderProgram::setUniformValue(const std::string &name, const Vector3f &v)
{
GLint location = static_cast<GLint>(findUniform(name));
......
......@@ -153,6 +153,9 @@ public:
/** Set the @p name uniform value to float @p f. */
bool setUniformValue(const std::string &name, float f);
/** Set the @p name uniform value to @p matrix. */
bool setUniformValue(const std::string &name, const int count, const float (*f)[3]);
/** Set the @p name uniform value to @p matrix. */
bool setUniformValue(const std::string &name, const Matrix3f &matrix);
bool setUniformValue(const std::string &name, const Matrix4f &matrix);
......
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