Deferred Shading

Deferred shading implemented with GLSL.

Description: I had implement a forward rendering system but was frustrated by the limited number of lights you can have. Using light groups and assigning them throughout a scene was tedious and adds another layer of complexity to working with the art. Deferred shading seemed to offer a solution.

Tools: Visual C++ Pro, OpenGL.

Topics: Deferred shading, g-buffers, framebuffer objects, multiple render targets, stencil buffer.

Technique overview:

Scene geometry is rendered to a series of g-buffers or geometry buffers, which are MRT color attachments filled with the necessary data to perform lighting calculations. In a second rendering pass, primitives are rendered with the stencil buffer to mark pixels inside the light volume. A shader is then invoked to do the lighting calculations for the marked pixels. This process is repeated for each light and the results are combined using a additive blending op.

The advantage is you are doing the lighting calculation only once per light per affected pixel instead of doing the calculations on all the objects as they are rendered. There are also organizational advantages too, you need less shaders to support things like normal and specular maps.

Here you can see the g-buffers filled with data to perform the lighting calculation.

Deferred Image 1

Here you can see the light tool that works with this system so I can adjust light settings.

Deferred Image 2

Here is a little movie of the tool in action and the debug volumes.

Obligatory code screen shot.

Deferred Image 3

Please contact me if you are interested in acquiring a copy of the program, seeing the source code, or have any comments.

Back to the projects page.