Shadow map with direct light ?

Started by
4 comments, last by MJP 14 years, 2 months ago
Hi guys, So I finally want to have shadow in my demo and decide to implement it using shadow map. However, I have trouble figuring out how to implement shadow map with direct light. The general process to my understanding is: 1) Render the scene from the light perspective -> shadow map in a buffer 2) Perform rendering, and compare the depth of current pixel with value read out from shadow map to perform shadow shading. For spot light there are demos so I can understand step 1 because a spot light has a definitive world position, hence we can construct its world-view-projection matrix. But the direct light ( like the sun ), we won't have a position for it. We usually only have direction where the light comes from. So how do you render shadow map for direct light? Thanks in advance for all the help.
Advertisement
Construct a bounding box around the camera's frustum, then place the light's position on the edge of this bounding-volume (away from the center in the opposite direction to the light). The light's projection matrix will be ortho instead of perspective.

Because this shadow map will cover a huge area though, you usually get low-quality results. To combat this, often PSSM is used.
Usually you calculate the shadow view volume in a way, that it will enclose the camera view volume, so you only shadow what you see. But you have to stretch it in the direction to the light, so you have to make sure all possible occluders are inside the volume.

I hope that's clear.

EDIT: PWNED!
Hi guys,

Thanks for helping.

@ Hodgman:

It's interesting when you bring up PSSM because I've been looking at the PSSM articles in GPU Gems 3 and also at several CSM in ShaderX series. I also look through the CSM demo from NVIDIA OpenGL SDK. However, all the splitting view frustum is kinda out of my understanding right now :(. I just want to have a shadow map first, then I will dive into the splitting frustum scheme.

So with that said, all the articles doesn't show me how to construct a bounding volume. I would greatly appreciate if you can point me to some resources :) ?

@ szecs:

You didn't see it coming did you :D ? It's interesting because I just watch your youtube demo a few days ago, but I didn't know it's you at the time. Great job on that.

Thanks!

other thread

It fits the camera view frustum perfectly, although I've heard an other way: Get the bounding sphere of the camera view frustum, and fit the light view volume on that. That way you can reduce the shadow edge flickering caused by the texels.
If you want, the XNA shadow map sample does the basic AABB setup of a orthographic projection for a directional light. Pretty easy to look at and see what they're doing, even if you don't know C#/XNA.

This topic is closed to new replies.

Advertisement