# [dx9 HLSL] Shadow Map with point light

## Recommended Posts

cebugdev    635
Hi all,

i am reading the tutorial for implementing shadow map in HLSL directx9 at

and got me wondering how shadow map is done when using point light?
see, the tutorial is using a directional light where the LightViewProjection Matrix is calculated using D3DXMatrixLookAtLH( &matView, &vLightPos, &vLightAim, &g_vUp );
Point light does not have direction, but the direction is computed in HLSL instead.

so how do i do the shadowmap descrbed on the above link using point lights?
How do i compute the lightViewProjection matrix for point lights? can it be done in HLSL?

Thanks,

##### Share on other sites
Hodgman    51223
You can represent the point light as 6 spot-lights ([url="http://www.google.com.au/search?q=cubic+shadow+maps"]cubic shadow maps[/url]), or 2 spot-lights ([url="http://www.google.com.au/search?q=dual+paraboloid+shadow+maps"]dual paraboloid shadow maps[/url]), or if the light source itself is outside the view-frustum, you can take a short-cut and treat it as a single spot-light.

##### Share on other sites
zipwax    114
That wasn't the most informative reply. Why represent it as six spot lights? Why can't I find a HLSL example for a point-light shadow routine where the point light simply uses a perspective transformation instead of a orthographic transformation? Are there any examples online of a point-source shadow mapping (SIMPLE) example?

Zero01    109

##### Share on other sites
zipwax    114
To the first guy who asked the question, I figured it out. For a point-light, you simply duplicate the exact same projection matrix as you use for the camera. In other words, move the "eye" to the point source's location (the view matrix), and calculate the projection matrix to be the same as you used for the camera. Then calculate the shadow map. Be careful that the light is not too close to your model, or the shadow map won't contain all of the model, and you'll get STRANGE shadows.