What is half light vector in glsl?

I play with pixel lighting shaders and I don’t know anything: what is a half light source vector?

vec3 halfVector = normalize(gl_LightSource[1].halfVector.xyz); 

I would like you to be able to explain this in mathematical lines, I understand math better than words :)

+6
math opengl glsl
source share
3 answers

From this post :

A “halfway vector” (if you mean the “half vector”) is the unit vector at half the angle between two other vectors. Usually the average vector [...] is calculated between the vector and the observer v and the light source l:

 h := ( v + l ) / || v + l || 

Thus, half of the vector is a block of the bisector angle of the view and light vector.

Edit:. For a full explanation of the lighting model, including half the vector, just check out the Blinn-Phong wikipedia article. a>

+6
source share

Dario's answer is correct, but since the question was about GLSL, here is the relevant code:

 vec3 hf = normalize(v + l); 

Typically, the "THE" vector is the vector between the light and the view vector. It is commonly used as an input to the mirror bit of the Blinn-Fong equations.

+2
source share
 vec3 halfVector = normalize(lightDirection + viewDirection); 
-2
source share

All Articles