Jump to content
  • Advertisement
Sign in to follow this  
ldeej

Directional Lights, Orthographic projections, and shadow maps

This topic is 4813 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

I have read some articles on shadow maps, and looked at some demos. Most Demos focus on spotlights, and I have found a couple that have implementations for directional lights (NVidia and ATI) The problem is that for the implementations there are tons of magic numbers being used, and it is unclear to me how the ortho projection for the directional light is being built. I was hoping somebody could either explain the "vanilla" ortho projection derivation for directional lights to me or point me to some good resources. I am not interested on advanced techniques (PSM, TSM, etc, etc), just the basics. Some examples of the code I have found: // ATI shadow map sample // Projection for directional light D3DXMatrixOrthoLH(&matProj, 5.0f, 5.0f, 0.0f, DEPTH_RANGE); D3DXMATRIX matShadowModelMVP, matShadowFloorMVP; D3DXMatrixMultiply(&mat, &matView, &matProj); D3DXMatrixMultiply(&matShadowModelMVP, &matWorldModel, &mat); // Texture adjustment matrix D3DXMATRIX matTexAdj(/*magic numbers here*/); D3DXMatrixMultiplyTranspose(&m_matShadowModelTex, &matShadowModelMVP, &matTexAdj); For example, I do not understand why the value 5.0 is used for width and height for the projection, or why they have a adjustment matrix.

Share this post


Link to post
Share on other sites
Advertisement
The 5.0 means that the orthograpic projection should be 5 world space units wide, and the other 5.0 means 5.0 world space units tall.

It really just depends how big of an object you are trying to fit in the limited space of the shadow map. In this case you could fit a sphere of radius 2.5 units.

The other magic # matrix is most likely set up to

1) reverse the Y axis texcoords
2) convert -1..1 range into 0..1
3) apply a depth bias



Share this post


Link to post
Share on other sites
ldeej,
can you tell me where can find a implementation of directional light of shadow map?
thanks.

Share this post


Link to post
Share on other sites
Nothing comes to mind. Which part are you stuck on?

I actually took out the orthogonal projection for directional lights out of my engine to simplify the code. Since I am doing a separate shadow map for each shadow caster, I can treat a directional light as a distant point light.

Share this post


Link to post
Share on other sites
Quote:
Original post by SimmerD
Nothing comes to mind. Which part are you stuck on?

I actually took out the orthogonal projection for directional lights out of my engine to simplify the code. Since I am doing a separate shadow map for each shadow caster, I can treat a directional light as a distant point light.


Humm...why not still make the seperate shadow maps orthogonal though? Just to kind of unify the shadowing system?

Share this post


Link to post
Share on other sites
Yes, just a way to simplify and unify things. With a far enough point ( I use 500 meters or so ), you get the same result with a small frustum.

Share this post


Link to post
Share on other sites
I got the directional shadow map samples from both the NVidia and the ATI sites:

http://www.ati.com/developer/samples/dx9/ShadowMap.html
http://download.developer.nvidia.com/developer/SDK/Individual_Samples/samples.html

The Nvidia sample if for prespective shadow mapping, but it also has modes for directional lights with plain shadow maps.

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!