openglshadow-mappingdeferred-rendering

Shadow mapping for many light sources - is it slow?


I've reached a point where I've implemented deferred rendering and shadow mapping for a single light source. I was looking forward to adding more light sources to see how deferred rendering improves the performance but I realized that shadow mapping pretty much ruins it this time.

Is this to be expected? Should I use another shadow algorithm when having many light sources?

What I do is create a cube map from every light's point of view. Then, when rendering a fragment in the deferred rendering shader I take into account how much each light contributes to that fragment, meaning which lights the fragment can see. So, it's just a normal check of whether a fragment is in the shadows of a light source.


Solution

  • Generally speaking, shadows do not scale well with the number of lights. One or two shadow casting lights can be tolerated, but more than that will heavily bog down your performance. This is true of pretty much every general-purpose lighting mechanism (except maybe ray-traced-based shadowing).

    Deferred rendering does not change the math on this. You still have to render the scene from the perspective of each shadowing light source, and your lighting passes still have to fetch from those textures to do the shadowing.

    The typical solution is to restrict the number of shadow-casting lights to the primary light source and maybe a secondary light. Everything else doesn't cast shadows.