Crystal Space 2.0.0: 4.9.13.1 About Deferred Shading

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

#### 4.9.13.1 About Deferred Shading

#### What is Deferred Shading?

Deferred shading is a rasterization based rendering method that separates the rendering of geometry from the process of lighting that geometry. In the traditional approach to rasterization (commonly referred to as forward shading) the rendering and lighting of geometry are done in tandem. As a result, using forward shading tends to limit the number of light sources that can affect a single object. However, with deferred shading the cost of adding a light to a scene is independent of the number of objects in a scene. This property allows for a scene to contain significantly more dynamic light sources before performance becomes an issue.

#### Implementing Deferred Shading

From a high-level deferred shading works in two main passes. In the first pass all geometry in a scene is drawn to a set of buffers referred to collectively as the GBuffer (short for Geometry Buffer). During this pass the GBuffer is filled with the information needed to evaluate the lighting equation. This information includes, but is not limited to, diffuse and specular color, surface normal, and surface position (often stored as depth and reconstructed when needed). In the second pass the filled GBuffer is used to evaluate the lighting equation for each light in the scene. The contribution from each light is added to, what is commonly referred to as, the accumulation buffer. At the start of the second pass the accumulation buffer is initialized to all black. During the pass the accumulation buffer will be filled with lighting information from each light. By the end of the pass the accumulation buffer will contain the final image of the lit scene.

To compute the lighting equation for a light source we must determine what pixels in the final image are affected by that light. To do this we take advantage of the rasterization capabilities of the GPU by rendering light proxy geometry. This proxy geometry is a mesh that approximates the size, shape, and position of the light source we are considering. As an example, we might use a cone mesh to approximate a spot light or a sphere mesh to approximate a point light. Ideally we want the proxy geometries approximation be as tight as possible so we do not needlessly consider pixels that are not affected by the light. The light proxy geometry is rendered using a shader (see section Shaders) that reads data from the GBuffer, computes the lighting equation, and outputs the result to the accumulation buffer at each pixel.

#### Considerations when Using Deferred Shading

Despite the benefits in lighting that deferred shading provides there are multiple issues that should be considered when choosing this rendering method:

- The first issue to consider is the hardware requirements necessary to implement deferred shading efficiently. At a minimum the hardware must support programmable shaders. Although, hardware support for shaders that can output to multiple buffers and enough memory to hold 3 to 4 full resolution buffers is ideal. Overtime, as hardware improves, this will become less of an issue However, depending on your requirements, using deferred shading may limit you potential target base.
- The second issues to consider is that deferred shading does not support semitransparent (alpha blended) objects. This is inherent to the method itself because of the data stored in the GBuffer. Most notably surface normals and surface positions cannot be blended in any meaningful way. The most common solution to this problem (and the one Crystal Space takes) is to render the semitransparent objects using forward shading after all deferred shading is completed. As a result, semitransparent objects will have to use a more traditional lighting scheme.
- The third issues to consider is that deferred shading does not (at the time of this writing) have widespread support for hardware based antialiasing. More specifically, the Crystal Space implementation of deferred shading does not currently support hardware based antialiasing even if hardware support is present.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated using texi2html 1.76.