I have the following GLSL code for lighting:
uniform vec3 lightDir; // Parallel light
uniform float ambient;
uniform vec3 lightColour;
void main()
{
gl_Position = ftransform();
vec3 eyeNormal = normalize(gl_NormalMatrix * gl_Normal);
float intensity = max(ambient, dot(eyeNormal, normalize(-lightDir));
gl_FrontColor = gl_Color * vec4(lightColour, 1.0) * intensity;
}
The light vector is specified in world space. I set the camera orientation and position using gluLookAt
. Since OpenGL assumes the light vector is in camera space, the light moves with the camera instead of staying in a fixed orientation.
I tried activating the shader and setting the light vector both before and after I call gluLookAt
, but I get the same effect. What exactly do I have to do to properly transform the light vector?