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

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

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 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 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 on other sites
thank you everyone I have just realized

1. 1
Rutin
24
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 9
• 46
• 41
• 23
• 13
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002031
×