Directional Lights, Orthographic projections, and shadow maps

Started by
6 comments, last by ChenA 18 years, 7 months ago
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.
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



ldeej,
can you tell me where can find a implementation of directional light of shadow map?
thanks.
hehe.
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.

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?
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.
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.
ldeej
Thanks,i find it.
hehe.

This topic is closed to new replies.

Advertisement