summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2010-10-13 21:47:05 -0700
committerKenneth Graunke <kenneth@whitecape.org>2010-10-21 00:31:16 -0700
commit11fe460ece6259cb1f0e5ab29543c83767354918 (patch)
treeb795db02805c5f9759f5f38606934176ccfde634
parentea3656422bf5b0f3e7961052b55343cf91e4935f (diff)
Fix per-fragment lighting.
The code in the slides uses vec3s, but the supplied shaders use vec4s. My implementation incorrectly included the 'w' component in the normalize call, which threw off the results. This patch is quite ugly; fixing the code to use vec3s would almost certainly be superior. Or at least factoring the .xyz into one place.
-rwxr-xr-xsrc/phong.frag10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/phong.frag b/src/phong.frag
index f946cc7..026427d 100755
--- a/src/phong.frag
+++ b/src/phong.frag
@@ -12,12 +12,12 @@ const vec4 light_es = vec4(0.0, 3.0, 0.0, 1.0);
void main(void)
{
- vec4 l = normalize(light_es - position_es);
- vec4 v = normalize(-position_es);
- vec4 h = normalize(l + v);
- float n_dot_l = dot(normal_es, l);
+ vec3 l = normalize((light_es - position_es).xyz);
+ vec3 v = normalize(-position_es.xyz);
+ vec3 h = normalize(l + v);
+ float n_dot_l = dot(normal_es.xyz, l);
vec4 diff = diffuse_color * n_dot_l;
- float spec = pow(dot(normal_es, h), s);
+ float spec = pow(dot(normal_es.xyz, h), s);
vec4 color = vec4(1.0, 0.0, 0.0, 1.0);