I'm writing a deferred renderer and a few things come to mind. The render will be done in at least two passes: first I render positions, normals and diffuse+specular color into three different textures. Then I combine these in the final pass and do the lighting for each light and add postprocessing effects to produce the final image. This part I got working though.
Here comes the problem: how to do with shadows? The naive approach would be to render a depth map for each active light in a single pass each. So that means as many extra passes as there are lights. This seems to defeat the whole purpose of deferred shading to do all lighting in a single pass.
A better way would have been if I could render the depth maps together in a single pass. But is this even somehow possible? ..because to render the scene from a different perspective would require to do the same kind of culling as is done for the main camera. So rendering from the perspective of each light require just as much scenegraph traversal and vertex buffer bindings as rendering the main camera view. So it's quite expensive then.
But what is the proper way to do this? What is the standard way to render shadow maps in terms of multiple passes? Is it really necessary to do a separate render for every light that will contribute a shadow to the scene or is there a better and faster way to compute the sum of all shadows. Is there a way to do multiple perspective rendering to multiple framebuffers in a single shader pass?
Also I suppose it would be a good idea to bind two buffers for each lighting pass: one that contains sum of results from previous passes and one that contains pixel distances. Then the product of all lighting passes will be a shadow intensity map that can be passed to the final render pass.
The final render pass then only renders a single quad on the whole screen on which it does the postprocessing and shading. So it's at least 2+1 passes. And with 8 lights it would mean rendering the scene 10 times for every frame?