i
i
i
i
i
i
i
i
5.8. Gamma Correction 145
not implement it properly for blending and MSAA antialiasing (both of
which were—incorrectly—performed on nonlinear values), but more recent
hardware has resolved these issues.
Although the GPU is capable of correctly converting linear radiance
values to nonlinear pixel encodings, artifacts will result if the feature is
unused or misused. It is important to apply the conversion at the final
stage of rendering (when the values are written to the display buffer for
the last time), and not before. If post-processing is applied after gamma
correction, post-processing effects will be computed in nonlinear space,
which is incorrect and will often cause visible artifacts. So operations
such as tone mapping (see Section 10.11) can be applied to images to
adjust luminance balance, but gamma correction should always be done
last.
This does not mean that intermediate buffers cannot contain nonlin-
ear encodings (in fact, this is preferable if the buffers use low-precision
formats, to minimize banding), but then the buffer contents must be care-
fully converted back to linear space before computing the post-processing
effect.
Applying the encoding transfer function at the output of the rendering
pipeline is not sufficient—it is also necessary to convert any nonlinear input
values to a linear space as well. Many textures (such as reflectance maps)
contain values between 0 and 1 and are typically stored in a low-bit-depth
format, requiring nonlinear encoding to avoid banding. Fortunately, GPUs
now available can be set to convert nonlinear textures automatically by
configuring them as sRGB textures. As for the output correction discussed
above, the first GPUs to implement sRGB textures did so incorrectly (per-
forming texture filtering in nonlinear space), but newer hardware imple-
ments the feature properly. As noted in Section 6.2.2, mipmap generation
must also take any nonlinear encoding into account.
Applications used for authoring textures typically store the results in a
nonlinear space, not necessarily the same one used by the GPU for conver-
sion. Care must be taken to use the correct color space when authoring, in-
cluding calibration of the display used. Any photographic textures require
calibration of the camera as well. The Munsell ColorChecker chart [189]
(formerly known as the Macbeth or GretagMacbeth ColorChecker chart)
is a standard color chart that can be quite useful for these calibrations.
Various shader inputs other than textures may be encoded nonlinearly
and require similar conversion before use in shading. Color constants (such
as tint values) are often authored in a nonlinear space; the same may apply
to vertex colors. Care must be taken not to “convert” values already in
linear space!