Okay I have a fairly standard bump-mapping shader. Everything works as it should with one big exception. The light position is totally incorrect to what is specified with glLightfv().
No matter what I specify, the light position reflected by the final output of the shader seems “locked” to one position. I’ve even tried using a manually specified vec3(), instead of the built-in gl_LightSource[x], that didn’t work either.
Here is an example with the shader turned off:
and here it is with it turned on:
no matter what I do I cannot get any other light position than what you see in the above image. I’ve been racking my brain for so long. I know I must be missing something key.
Here is my vertex shader:
varying vec3 g_lightVec;
varying vec3 g_viewVec;
varying vec2 texCoord;
void main()
{
gl_Position = ftransform();
texCoord = gl_MultiTexCoord0.xy;
vec3 tangent;
vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0));
vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0));
if(length(c1)> length(c2))
{
tangent = c1;
}
else
{
tangent = c2;
}
tangent = normalize(tangent);
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * tangent);
vec3 b = cross(n,t);
vec3 vVert = (gl_ModelViewMatrix * gl_Vertex);
vec3 tVec = gl_LightSource[0].position.xyz - vVert;
g_lightVec.x = dot(tVec,t);
g_lightVec.y = dot(tVec,b);
g_lightVec.z = dot(tVec,n);
tVec = -vVert;
g_viewVec.x = dot(tVec,t);
g_viewVec.y = dot(tVec,b);
g_viewVec.z = dot(tVec,n);
}
and here is how I setup my light (it’s a directional light):
float ambientLight0[] = { 0.9f, 0.9f, 0.9f, 1.0f };
float diffuseLight0[] = { 0.9f, 0.7f, 0.45f, 1.0f };
float specularLight0[] = { 0.4f, 0.4f, 0.4f, 1.0f };
float emissiveLight0[] = {0.5f,0.5f,0.5f,1.0f};
float position0[] = { 0.0f, 8.0f, -1.0f, 0.0f };
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
glLightfv(GL_LIGHT0, GL_EMISSION, emissiveLight0);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
so what am I missing here?