views:

133

answers:

1

http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2 reports that half vector in OpenGL context is 'Eye position - Light position' but then it goes on to say 'luckily OpenGL calculates it for us' [which is now deprecated].

How can, practically be calculated (a simple example would be greatly appreciated) [mainly, it puzzles me what "Eye" is and how it can be derived].

At the moment I managed to make specular calculations work (with good visual result) with half vector being equal to Light where Light is

vec3 Light = normalize(light_position - vec3(out_Vertex));

Now, I've no idea why that worked.

[If at least I knew what "Eye" is and how it can be derived practically.]

+2  A: 

In the fragment shader the vertex coordinates can be seen as a vector that goes from the camera (or the "eye" of the viewer) to the current fragment so by reversing the direction of this vector we then have the "Eye"-vector you are looking for. When calculating the Half-vector you also need to be aware of the direction of the Light-position vector, on the webpage you link they have that on pointing towards the surface, on http://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model its pointing away from the surface.

Daniel
You're saying Eye is only 1/out_Vertex.x, 1/out_Vertex.y, 1/out_Vertx.z?
Lela Dax
No, bad choice of wording on my part there, what I mean is that Eye = (-out_Vertex.x, -out_Vertex.y -out_Vertex.z)
Daniel