PDA

View Full Version : Shadow Mapping with Deferred Shading



Cloudy McStrife
12-15-2015, 09:36 AM
Hey guys.
Instead of forward shading I implmented a deferred shader.
Now I want to add Shadows to my scene and wanted a step-by-step solution.
My thought:
1. Rendering all Meshes without light into G-Buffer
2. Rendering all Meshes into depth buffer of all lights. (For Shadows)
3. Draw G-Buffer Scene with light and shadows. (Shadows not completed)
4. Draw all Point-Lights on texture I get from Step No. 3.
5. ...
6. Profit

Is this valid or is there a better way for shadows?

Thank you in advance for your answer :)

GClements
12-15-2015, 03:07 PM
Is this valid or is there a better way for shadows?

It works, but it doesn't really buy you all that much when using shadows, and may well be a net loss.

When using forward rendering, you only need to transform the vertices of each primitive to the coordinate systems for each light source, and the coordinates for individual fragment are calculated by interpolation. With deferred rendering, you either have to transform the coordinates of each fragment or the G buffer requires a separate light-space position buffer for each light source. Neither of those options are cheap.

The biggest gains from deferred rendering come when using many lights, each of which affects a relatively small area of the scene, as it makes it reasonably straightforward to cull the lighting computations so that each fragment only considers the lights which affect it. But for lights which cast shadows, the expense of computing a depth map for each light severely limits the total number of lights you can have.

Also, if a light cone only covers a portion of the visible scene, you would typically perform frustum culling when rendering the light's depth buffer so that you aren't rendering unnecessary geometry. In which case, you can re-use that information when rendering the scene to avoid performing shadow calculations for geometry outside of the cone.