Original Post
I'm trying to get a simple GLSL shader to work but the light that I have rotating around the cube doesn't seem to show up o nthe cube. It's just looks like there is a static light position. I think it's how I set my uniform variable g_lightPositions[0] = glGetUniformLocationARB( g_program, "lightPosition0" ); glUseProgramObjectARB( g_program ); glUniform3fARB( g_lightPositions[0], g_lights[2].x, g_lights[2].y, g_lights[2].z ); Here is my vertex shader(Simple phong illumination). And my fragment shader Thanks for the help.
varying vec3 normal;
varying vec3 mvVertex;
varying vec3 L;
varying float pattern;
uniform vec3 lightPosition0;
void main(void)
{
mvVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
normal = normalize(gl_NormalMatrix * gl_Normal);
L = normalize(lightPosition0 - mvVertex);
pattern = fract( 4.0 * ( gl_Vertex.y + gl_Vertex.x + gl_Vertex.z ) );
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
uniform sampler2D textureHandle;
//uniform vec3 diffuse;
//uniform vec3 specular;
//uniform float shininess;
varying vec3 normal;
varying vec3 mvVertex;
varying vec3 L;
varying float pattern;
uniform vec3 eyePos;
void main (void)
{
vec3 diffuse = vec3( 0.8, 0.0, 0.0 );
vec3 specular = vec3( 0.2, 0.0, 0.0 );
float shininess = 50.0;
vec3 E = normalize( eyePos - mvVertex ); // we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 R = normalize( 2.0 * dot(normal, L) * normal - L );
//calculate Diffuse Term:
vec4 Idiff = vec4( diffuse * max( dot( normal, L ), 0.0 ), 1.0 );
// calculate Specular Term:
vec4 Ispec = vec4( specular * pow( max( dot( R, E ), 0.0 ), 0.3 * shininess ), 1.0 ) * pattern;
// write Total Color:
gl_FragColor = ( Idiff + Ispec ) * texture2D( textureHandle, gl_TexCoord[0].xy );
}