Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Why reverse the light direction?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 arkerone   Members   -  Reputation: 113

Like
0Likes
Like

Posted 02 August 2012 - 06:24 PM

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, 02 August 2012 - 06:25 PM.


Ad:

#2 zacaj   Members   -  Reputation: 570

Like
0Likes
Like

Posted 02 August 2012 - 06:31 PM

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

#3 L. Spiro   Crossbones+   -  Reputation: 5144

Like
3Likes
Like

Posted 02 August 2012 - 07:00 PM

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.

Posted Image

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#4 Postie   Members   -  Reputation: 568

Like
0Likes
Like

Posted 02 August 2012 - 07:26 PM

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.
Currently working on an open world survival RPG - For info check out my Development blog: ByteWrangler

#5 SIC Games   Members   -  Reputation: 328

Like
0Likes
Like

Posted 02 August 2012 - 07:38 PM

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

#6 arkerone   Members   -  Reputation: 113

Like
0Likes
Like

Posted 02 August 2012 - 08:06 PM

thank you everyone I have just realizedPosted Image




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS