i
i
i
i
i
i
i
i
144 5. Visual Appearance
Figure 5.40. On the left, four pixels covered by the edge of a white polygon on a black
(shown as gray) background, with true area coverage shown. If gamma correction is
not performed, the darkening of midtones will cause the perception of the edge to be
distorted, as seen on the right.
Figure 5.41. On the left, the set of antialiased lines are gamma-corrected; in the middle,
the set is partially corrected; on the right, there is no gamma correction. (Images
courtesy of Scott R. Nelson.)
Ignoring gamma correction also affects the quality of antialiased edges.
For example, say a polygon edge covers four screen grid cells (Figure 5.40).
The polygon’s normalized radiance is 1 (white); the background’s is 0
(black). Left to right, the cells are covered
1
8
,
3
8
,
5
8
,and
7
8
.Soifweareus-
ing a box filter, we want to represent the normalized scene radiance of the
pixels as 0.125, 0.375, 0.625, and 0.875. The correct approach is to perform
antialiasing in linear space, applying the encoding transfer function to the
four resulting values. If this is not done, the represented scene radiance for
the pixels will be too dark, resulting in a perceived deformation of the edge
as seen in the right side of the figure. This artifact is called roping, because
the edge looks somewhat like a twisted rope [107, 923]. Figure 5.41 shows
this effect.
Fortunately, modern GPUs can be set to automatically apply the en-
coding transfer function (typically the sRGB transfer function) when values
are written to the color buffer.
15
The first GPUs including this feature did
15
In DirectX the texture sampler call is D3DSAMP SRGBTEXTURE and the render state is
D3DRS
SRGBWRITEENABLE. DirectX 9’s implementation incorrectly converts before blend-
ing, but is fine for opaque surfaces. DirectX 10’s works for all cases, converting after
blending.
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!
i
i
i
i
i
i
i
i
146 5. Visual Appearance
Further Reading and Resources
A good introduction to lights, color, signal processing, and other topics dis-
cussed in this chapter can be found in Fundamentals of Computer Graphics,
Second Edition [1172] by Shirley et al.
Blinn’s article “What Is a Pixel?” [111] provides an excellent tour of a
number of areas of computer graphics while discussing different definitions.
Wolberg’s book [1367] is an exhaustive guide to sampling and filtering for
computer graphics. Foley et al. cover the topic in some depth in a section
of their classic book [349]. Blinn’s Dirty Pixels book [106] includes some
good introductory articles on filtering and antialiasing, as well as articles
on alpha, compositing, and gamma correction.
Shirley has a useful summary of sampling patterns used in computer
graphics [1169]. A summary of practical antialiasing methods for consoles
and PCs is provided by Mitchell [884]. This article also touches on solutions
to problems caused by interlaced television displays. A good quick read that
helps correct the misconception that a pixel is a little square is Smith’s
article on the topic [1196], and Smith’s tutorials on sampling and filtering
are also of interest [1194, 1195]. Gritz and d’Eon [459] have an excellent
summary of gamma correction issues. Poynton’s Digital Video and HDTV:
Algorithms and Interfaces [1028] gives solid coverage of gamma correction
in various media, as well as other color-related topics.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset