Sign in to follow this  
arkerone

Why reverse the light direction?

Recommended Posts

Hello,

I have a question why do reverse the direction of a directional light?

[source lang="cpp"] // Invert the light direction for calculations.
lightDir = -lightDirection;

// Calculate the amount of light on this pixel.
lightIntensity = saturate(dot(input.normal, lightDir));[/source]

Thx! Edited by arkerone

Share this post


Link to post
Share on other sites
They probably subtract in the wrong order somewhere earlier (possibly for another calculation that needs it the other way)
for instance lightPos-vertPos instead of vertPos-lightPos

Share this post


Link to post
Share on other sites
When calculating the half vector, the vectors are both from the object to the eye or light.
That is, the half vector is created by adding the vector from the object to the light and the vector from the object to the eye.

[img]http://memoryhacking.com/Misc/display1863.png[/img]

Here, pay attention to only the V and the L vectors. V = View = Eye. The H vector is the half vector, half-way between the V and L vectors.
But notice that they all point [i]away[/i] from the surface. [i]Towards[/i] the eye and the sun/light.


Some people think better when visualizing the sun vector (or light vector of any kind) as going out of the sun in some direction.
Those people need to reverse the sun’s direction for lighting equations, because that line of thinking makes the L vector point towards the surface.


L. Spiro

Share this post


Link to post
Share on other sites
In comes down to the difference between the direction of a light vs its position relative to a surface being rendered. It's typical to define a directional light as a vector that points in the direction the light is shining. However, for lighting calculations we need to know the position of the light relative to the surface. For global lights this turns out to simply be the reverse of the light's direction vector.

Share this post


Link to post
Share on other sites
I can guess the calculation could come bouncing off a surface. If a surface contains more reflective material then the shader tells the light to bounce off and go into another direction. Just a guess.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this