I'm implementing shadow mapping in my deferred rendering engine. I've got spot lights working, and now I'm working on point lights. Currently, I do it like this:

// Loop through the point lights
for each point light do

    Loop through "directions"
    for I = 1, 6 do
        Render the shadow map for direction 'I'
        Render the point light

This works fine, but is this sub-optimal? Should I instead render all the shadow maps at once? If so, how would I handle all the shadow maps at once in the second phase when rendering the light volume?


If I understand your question correctly, you are building and applying the shadow maps at the same time. You really do not want to do that.

If you are smart about this, you can vary the frequency of shadow map updates and save massive amounts of memory bandwidth necessary to actually fill the shadow maps (e.g. if nothing in the world moves inside the light volume and the light doesn't move, then there is no need to recompute the shadow map). I have gone as far as to determine which of the individual faces in a shadow cubemap need to be recalculated - a lot of work to implement, but worth it.

Another thing to consider is that you do not actually have to update shadow maps every frame. Surprisingly, for distant light sources or a reasonably small number of nearby light sources you can get away with updating at 1/2 or lower render frequency without the end-user noticing. I have used this to great success in my own work, on lower-end GPUs I update half of the shadow maps every frame (so a full update takes 2 frames) and very few people ever notice ;)

In short, consider implementing some logic that allows you to update the shadow maps periodically instead of every frame. Performance should improve drastically.

  • 1
    \$\begingroup\$ By the way, the metric I use for shadow updates is not actually the number of frames. It's measure in terms of milliseconds. That helps iron things out when the end-user is running at ridiculously low or high framerates. For instance, shadows might only need an update every 20 ms. At 60 FPS, that's every 2 frames, at 30 FPS every frame, at 120 FPS every 3 frames. \$\endgroup\$ – Andon M. Coleman Dec 30 '14 at 1:28

You can use a cube map for point lights.

The cube shadow map might need to be rendered face-by-face as before but the last step can be done as one pass.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.