Jump to content
  • Advertisement
Sign in to follow this  
akaitora

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.

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

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


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!