Use the correct position for light calcs.

I should have remembered that gl_FragCoord wasn't right.
This commit is contained in:
Bill Currie 2012-05-11 21:56:34 +09:00
parent 2080c337d7
commit 5b4fdd2a93
2 changed files with 6 additions and 3 deletions

View file

@ -7,6 +7,7 @@ uniform sampler2D normalmap;
uniform light lights[8];
uniform vec4 fog;
varying vec3 position;
varying vec3 bitangent;
varying vec3 tangent;
varying vec3 normal;
@ -35,7 +36,7 @@ calc_light (vec3 n, int ind)
vec3 d;
light l = lights[ind];
d = l.position.xyz - gl_FragCoord.xyz;
d = l.position.xyz - position;
return l.color.rgb * (l.position.w * dot (d, n) / dot (d, d));
}
@ -48,7 +49,7 @@ main (void)
norm = texture2D (normalmap, st).xyz;
norm = tbn * norm;
l += calc_light (norm, 0);
l = calc_light (norm, 0);
l += calc_light (norm, 1);
l += calc_light (norm, 2);
l += calc_light (norm, 3);

View file

@ -9,6 +9,7 @@ attribute vec4 vtangent;
attribute vec3 vnormal;
attribute vec3 vposition;
varying vec3 position;
varying vec3 bitangent;
varying vec3 tangent;
varying vec3 normal;
@ -49,10 +50,11 @@ main (void)
// but probably good enough
t = vtangent.xyz;
t += 2.0 * cross (q0.xyz, cross (q0.xyz, t) + q0.w * t);
gl_Position = mvp_mat * vec4 (v, 1.0);
position = v * 8.0;
normal = norm_mat * n;
tangent = norm_mat * t;
bitangent = cross (normal, tangent) * vtangent.w;
color = vcolor;
st = texcoord;
gl_Position = mvp_mat * vec4 (position, 1.0);
}