Sign in to follow this  
akaitora

Directional Lighting Question

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,

[code]
lighting += saturate( dot(lightDir, normal) ) * LightColor;
[/code]

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 this post


Link to post
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.

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