   bump mapping lightning problem
  Hi, I've just implemented bump mapping. It looks pretty good, but There is somwhere an error in the shader because when the bump mapped model is between the light and me (the eye), it looks strange: if I'm very near it is black as it should be, but as the distance increases it seems to get some more light. Since in the computations I'm not using distance nor view position, I wonder where the error is:VERTEX:varying vec3 normal;varying vec3 lightDir[2];varying vec4 pos;attribute vec3 tangent;attribute vec3 bitangent;varying float dist[2];varying vec3 viewDir;void main(){vec4 pos = gl_ModelViewMatrix * gl_Vertex;pos = pos / pos.w;/*normal = normalize(gl_NormalMatrix * gl_Normal);*/normal = gl_Normal;/*Build the inverse TSM matrix*/mat3 rotmat = mat3(tangent.x,bitangent.x,gl_Normal.x,tangent.y,bitangent.y,gl_Normal.y,tangent.z,bitangent.z,gl_Normal.z);viewDir = (gl_ModelViewMatrixInverse * pos).xyz;viewDir = rotmat * viewDir;lightDir[0] = (gl_LightSource[0].position - pos).xyz;dist[0] = length(lightDir[0]);lightDir[0] = (gl_ModelViewMatrixInverse * vec4(lightDir[0], 1.0)).xyz;lightDir[0] = rotmat * lightDir[0];lightDir[1] = (gl_LightSource[1].position - pos).xyz;dist[1] = length(lightDir[1]);    lightDir[1] = (gl_ModelViewMatrixInverse * vec4(lightDir[1], 1.0)).xyz;lightDir[1] = normalize(rotmat * lightDir[1]);gl_TexCoord[0] = gl_MultiTexCoord0;gl_TexCoord[1] = gl_MultiTexCoord1;gl_Position = ftransform();}FRAGMENT:varying vec3 normal;/*varying vec4 pos;*/varying float dist[2];varying vec3 lightDir[2];varying vec3 viewDir;uniform sampler2D tex[2];vec4 lightCont(int light, vec3 n){vec4 c = vec4(0.0,0.0,0.0,1.0);float lambertTerm = max(dot(n,normalize(lightDir[light])), 0.0);/*if(lambertTerm > 0.0)*/{c += vec4(0.6,0.6,0.6,1.0)*lambertTerm/**(1.0/(dist[light]*dist[light]*0.01)*0.5)*/;}return c;}vec4 spec(int light, vec3 n){vec4 s = vec4(0.0,0.0,0.0,1.0);float lambertTerm = dot(n,normalize(lightDir[light]));/*if(lambertTerm > 0.0){float p = dot(reflect(normalize(-viewDir), n), lightDir[light]);pow(clamp(p,0.0,1.0), 150.0);s += vec4(0.6,0.6,0.6,1.0) * p * (1.0/(dist[light]*dist[light]*0.01)); }*/return s;}void main(){gl_FragColor = vec4(0.0,0.0,0.0,1.0);vec3 n = vec3(texture2D(tex[1], gl_TexCoord[1].st));n = (n -0.5) * 2.0;n = normalize(n);/*Compute diffuse component*/gl_FragColor += lightCont(0, n)/* + lightCont(1, n)*/;/*gl_FragColor *= texture2D(tex[0], gl_TexCoord[0].st);*//*gl_FragColor += (spec(1,n));*/}Currently I'm testing them with only one light, and only diffuse. If I use specular instead, the same things happens. Ant Idea?   
  Ok, I've found that in order to have the correct light direction I have to do:lightDir[0] = (gl_LightSource[0].position - gl_Vertex).xyz;instead than:vec4 pos = gl_ModelViewMatrix * gl_Vertex;pos = pos / pos.w;lightDir[0] = (gl_LightSource[0].position - pos).xyz;What I don't understand is how that works! I mean, gl_LightSource[0].position is in eye space (right?) while gl_Vertex is in object space. How can I obtain a meaning direction in such way?In addition, if I want to modulate the light intensity based on distance, I need to use:float distance = length(gl_LightSource[0].position - pos).xyz;Can someone explain me that, please?   