# Request for Explaination of Light Half Vector ...

• 09-08-2014, 06:31 AM
tmason
Request for Explaination of Light Half Vector ...
Hello,

I have been trying to get my head around light half-vectors for a minute now but I still don't understand it. Here is what I found on a StackExchange article:

Quote:

http://www.lighthouse3d.com/opengl/g...ex.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

Code :

`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.]
My two questions are:

1. In the above code, is the "out_Vertex" the vPosition that is coming in for the geometry?
2. I don't have a light position in my GLSL shader but it seems based on the above example I need one. Am I correct? Or do I need to send a light position to the GLSL fragment shader as well?

Thank you for any input you can provide on this.
• 09-08-2014, 07:29 PM
The half-vector is used in specular lighting and represents the normal at micro-imperfections in the surface which would cause incoming light to reflect toward the viewer. When the half-vector is closer to the surface normal, more imperfections align with the actual surface normal. Smoother surfaces will have fewer imperfections pointing away from the surface normal and result in a sharper highlight with a more significant drop off of light as the half-vector moves away from the actual normal than a rougher surface. The amount of drop off is controlled by the specular term, which is the power to which the cosine between the half-vector and normal vector is taken, so smoother surfaces have a higher power.

We call it the half-vector (H) because it is half-way between the vector point to the light (light vector, L) and the vector pointing to the viewer (which is the eye position. view vector, V). Before you calculate H, make sure the vector to the light and the eye are in the same coordinate space (legacy OpenGL used eye-space).
Code :

`H = normalize( L + V )`

Code :

`vec3 Light = normalize(light_position - vec3(out_Vertex));`
out_Vertex is the eye position of the vertex, which is the vertex after modelView transform. The term light_position here is wrong, since the tutorial cited is the Directional light tutorial, which by definition, directional lights don't have position. The light vector for directional lights is independent of the vertex, so here, he has combined three equations. Keep in mind, the light vector is toward the light, so opposite of the flow of photons from the light.
Code :

```//i'm keeping his term here... I'm assuming // he wanted to simulate at light coming from that position, so the light direction // would be -light_position, making L = -(-light_position) = light_position. vec3 L = light_position; vec3 V = -out_Vertex; // really it is (eye - vertexPosition), so (0,0,0) - out_Vertex vec3 H = normalize(L + V);```

For a point light, you need the direction from the vertex to the point so instead,
Code :

```vec3 L = light_position - out_Vertex; vec3 V = -out_Vertex; vec3 H = normalize(L+V);```

Quote:

In the above code, is the "out_Vertex" the vPosition that is coming in for the geometry?
Eye position for the vertex, so (modelview * vertex)

Quote:

I don't have a light position in my GLSL shader but it seems based on the above example I need one. Am I correct? Or do I need to send a light position to the GLSL fragment shader as well?
You need a light position for point lights, or a light direction for directional lights submitted to your shader
• 09-10-2014, 08:48 AM
tmason
Thank you for this!

I have been busy but I wanted to say thank you for your time.