Jump to content
  • Advertisement
Sign in to follow this  
arkerone

Why reverse the light direction?

This topic is 2176 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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.

display1863.png

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 away from the surface. Towards 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!