# Directional Lighting Question

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

## Recommended Posts

Hi guys. I have looked through several Graphics programming books regarding how to implement shader based directional lighting. Most of the books teach the Lambert method which makes total sense to me. The basic idea is to take the dot prodoct between a surface normal the the light direction. If the light is pointing directly at the surface, then the surface should get fully lit. If the light direction vector is perpendicular to the surface normal, then it should not be lit at all. Most of the books I have read seem to do something like the following,

 lighting += saturate( dot(lightDir, normal) ) * LightColor; 

The thing I don't understand is that is a surface normal is point down the negative z (depth) axis like so [0,0,-1] and the light direction is pointing down the positive z (depth) axis like so, [0,0,1],
the above code would give us the opposite effect as to what we want. The dot product between those 2 vectors would give us -1 which would be saturated to 0 thus giving us an unlit surface. I would think that as the dot product approaches -1, the surface would be fully lit and as the dot product approaches 0, it would not. Does that make sense or am I visualizing the problem incorrectly? Thanks in advance!

##### Share on other sites
The "L" direction used in your standard N dot L calculation is not the same as the direction of a directional light. L is a vector pointing from the surface towards the light source, which is the opposite of a directional light's direction. So in your case you want dot(-lightDir, normal), which gives you the results that you expect.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013378
×