From 6ca27d9f0fe57b0ba61218a0dca2021777afd54d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 7 Dec 2010 21:40:38 -0800 Subject: Make "eye" a uniform rather than an attribute. Previously I declared it as an attribute and then tried to initialize it with a bogus glUniform4fv call. Amazingly, it didn't completely break. --- src/main.cpp | 2 +- src/phong.vert | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2b70e56..ea90480 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -145,7 +145,7 @@ Redisplay(const patch_set_info *info) glUniformMatrix4fv(mv_location, 1, false, (float *) &mv); glUniformMatrix4fv(m_location, 1, false, (float *) &m); glUniform1i(sampler_location, 0); - glUniform4fv(eye_location, 4, (float *) &eye); + glUniform4fv(eye_location, 1, eye.values); glMultiDrawElements(info->mode, info->count, info->type, (const GLvoid**) info->indices, diff --git a/src/phong.vert b/src/phong.vert index 7219354..a28d346 100755 --- a/src/phong.vert +++ b/src/phong.vert @@ -1,12 +1,12 @@ #version 120 -uniform mat4 mvp; // eye -> screen -uniform mat4 mv; // world -> eye +uniform mat4 mvp; // object -> world -> eye -> screen +uniform mat4 mv; // object -> world -> eye uniform mat4 m; // object -> world // These three are in object space attribute vec4 normal; attribute vec4 tangent; -attribute vec4 eye; // Eye position in object space +uniform vec4 eye; // Eye position in object space attribute vec2 uv; @@ -41,13 +41,9 @@ void main(void) light_ss = normalize(light_direction_es * tbn); eye_ss = -normalize(vertex_pos_es * tbn); - /* World space vectors for environment mapping - * FIXME: eye should already be in world space, so I'm not sure why - * I have to do m * eye here. But it looks wrong otherwise. - */ vec3 vertex_pos_ws = vec3(m * gl_Vertex); - vec3 eye_pos_ws = vec3(m * eye); + vec3 eye_pos_ws = vec3(eye); normal_ws = vec3(m * normal); - eye_direction_ws = eye_pos_ws - vertex_pos_ws; + eye_direction_ws = vertex_pos_ws - eye_pos_ws; } -- cgit v1.2.3