•      Sign In
• Create Account

### #Actualfrench_hustler

Posted 09 August 2012 - 11:37 AM

People above pretty much nailed it.

Say L.pos = {10, 10, 10} & V.pos = {5, 5, 5}
L.pos - V.pos = {5, 5, 5}

The light vector is a direction, it just points in a certain direction, hence it should have no length, so you normalize it... and it becomes a unit directional vector {1, 1, 1}. Now you can do the dot product for your lighting without it being over scaled.
Further more, the dot product requires both vectors to be unit vectors to acquire the cosine angle between them.

Remember that when you calculate a "directional vector", you will most of the time want it normalized.

For the point light, you can see that it isn't normalized right away since the equation needs the length from the light position to the vector position to validate its range first. If it does pass, it just divides by the distance to normalize. This is done for efficiency reasons since the normalize function would need to recalculate the length of the vector anyways.

Just to be clear: normalized V = V / length(V).

Also, due to interpolation done by the GPU from the vertex shader to pixel shader, you will need to re-normalize your vectors in the pixel shader.

It is rough to get used to the linear algebra required for 3d graphics. But once you understand the general idea of what each function does visually, you won't really need to remember the exact formulas to do what you envision.

Cheers.

### #1french_hustler

Posted 09 August 2012 - 11:31 AM

People above pretty much nailed it.

Say L.pos = {10, 10, 10} & V.pos = {5, 5, 5}
L.pos - V.pos = {5, 5, 5}

The light vector is a direction, it just points in a certain direction, hence it should have no length, so you normalize it... and it becomes a unit directional vector {1, 1, 1}. Now you can do the dot product for your lighting without it being over scaled.

Remember that when you calculate a "directional vector", you will most of the time want it normalized.

For the point light, you can see that it isn't normalized right away since the equation needs the length from the light position to the vector position to validate its range first. If it does pass, it just divides by the distance to normalize. This is done for efficiency reasons since the normalize function would need to recalculate the length of the vector anyways.

Just to be clear: normalized V = V / length(V).

It is rough to get used to the linear algebra required for 3d graphics. But once you understand the general idea of what each function does visually, you won't really need to remember the exact formulas to do what you envision.

Cheers.

PARTNERS