Graphics Reference
In-Depth Information
11.4 Optimizations
The deferred rendering implementations that we have seen so far would present subopti-
mal performance characteristics in many situations, since their aim was to demonstrate the
core concepts of deferred rendering. To make the approach practical for use in real-time
applications, it is often necessary to leverage the flexibility and programmability of the
Direct3D 11 pipeline to improve the performance. The following sections will focus on
various methods for reducing the required memory and bandwidth usage associated with
rendering and sampling the g-buffer, as well as minimizing the number of pixel shader
executions that are needed in the lighting pass.
11.4.1 G-Buffer Attribute Packing
One of the primary disadvantages of using a deferred approach to rendering is that surface
and material properties must be rendered out to one or more render targets. A significant
amount of bandwidth must be dedicated to writing the values during the g-buffer genera-
tion pass, as well as when sampling the textures during the lighting pass. As a result, reduc-
ing the memory footprint of the g-buffer is a simple and effective method for optimizing
the performance of a deferred renderer. This is generally true even when some extra math is
performed in the shader programs to pack or unpack the values from a compressed format,
since almost all modern GPUs have a large number of ALUs relative to their bandwidth
and texturing units. With this in mind, we will look at the various types of data typically
stored in a g-buffer and determine a compressed format for storage, based on the typical
range of values, the precision required to avoid unacceptable artifacts, and the expense of
packing and unpacking the data.
Normal Vectors
For compressing normal vectors, we can take advantage of the fact that a normal vector
is a unit-length direction vector. This greatly restricts the domain of the normal values,
which can allow us to use a signed 8-bit integer format (DXGI_FORMAT_R8G8B8A8_SNORM)
for storage, instead of a floating point format. It can also allow us to store the direction in a
representation that requires only 2 values instead of 3, thus dropping a component entirely.
Perhaps the most obvious approach is to convert the normal vector to Spherical
Coordinates and omit p, since it is implicit that p = 1 for a normalized direction vector.
The equations for converting a vector from a Cartesian coordinate system to a spherical
coordinate system are well-known and are trivial to implement in HLSL. The conver-
sion can also be algebraically simplified for the case where p = 1, reducing the number
Search WWH ::




Custom Search