Jump to content
  • Advertisement
Sign in to follow this  
Endemoniada

Shadow Mapping Directional/Sun Light

This topic is 1919 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'm creating shadows from a directional light (the sun) and I don't know what to use for the light position. In tutorials they always say "for a directional light use an orthogonal projection" but they don't tell you how to setup the view matrix which needs a light position (I think).

 

I also need a light position in the lighting shader to get the distance to the light (for VSM or ESM) for depth comparison.

 

By definition a directional light has no position.

 

Please help. Thanks.

 

Share this post


Link to post
Share on other sites
Advertisement

I just used my camera position suitably transformed back down the inverse of the light direction. I vary the absolute distance (i.e. the multiplication factor applied to the light normalized direction) based on size of the view frustum available to the player at any given time - for landscapes I don't shade beyond a given perceived visible range, but in a closed environment you might choose to bring the light source nearer in to get more detail in the shadowing.

 

I understand that the light projection matrix is orthogonal for sunlight, but perhaps not for spot light sources ?

 

Hope this helps.

Share this post


Link to post
Share on other sites

See LispSM (both paper and provided source code implementations).

 

Long story short, create what they call hull body that takes into account casters, then clips against the scene aabb and view frustum; then checks the farthest point (in light's direction) of the hull which supposedly by placing the camera there, it should enclose all relevant casters.

 

In other words the answer is "far enough". The method you use to find out how much is far enough varies. It can be more mathematically defined and analyzed, or just empirical or through heuristics.

Of course, if you go farther than necessary, you'll start suffering quality degradation.

Share this post


Link to post
Share on other sites

That helps Phillip, that's pretty much what I ended up doing: having the light move with the camera. For the most part it works.

 

Matias, I found a Microsoft tutorial that automatically adjusts the light frustum, I think that's similar to what you're recommending, although I didn't look in to it too much.

 

Shadow mapping kinda burnt me out for a bit, I'm going to take a break from it now that things look decent. Maybe next week I'll try to get VSM or ESM working properly.

 

Thanks guys.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!