Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is half-vector of light in glsl?

Tags:

math

opengl

glsl

I'm playing with per pixel lighting shaders and i don't know one thing: What is half vector of light source ?

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

I would like i you can explain it in math rows, i understand math better than words :)

like image 538
kravemir Avatar asked Sep 05 '10 14:09

kravemir


2 Answers

From this post:

A "halfway vector" (if you mean that by "half vector") is the unit vector at the half angle between two other vectors. Normally the halfway vector [...] is computed between the vector to the viewer v and the light source l:

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

The half vector therefore is the unit angle bisector of view- and light vector.

Edit: For a complete explanation of the lighting model including the half vector, just see the Blinn-Phong wikipedia article

like image 50
Dario Avatar answered Sep 18 '22 08:09

Dario


The the answer by Dario is correct, but since the question was for GLSL, here is the appropriate code:

vec3 hf = normalize(v + l);

Generally the "THE" half vector is the vector between the light and the view vector. It is generally used as input to the specular bit of the Blinn-Phong equations.

like image 33
rioki Avatar answered Sep 17 '22 08:09

rioki