421
various color formats, including RGB888, RGBA8888, RGB565, RGBA5551,
and so on.
Most modern graphics cards and graphics APIs support compressed tex-
tures. DirectX supports a family of compressed formats known as DXT or S3
Texture Compression (S3TC). We won’t cover the details here, but the basic
idea is to break the texture into 2 × 2 blocks of pixels and use a small color pal-
ett e to store the colors for each block. You can read more about S3 compressed
texture formats at htt p://en.wikipedia.org/wiki/S3_Texture_Compression.
Compressed textures have the obvious benefi t of using less memory than
their uncompressed counterparts. An additional unexpected plus is that they
are faster to render with as well. S3 compressed textures achieve this speed-up
because of more cache-friendly memory access patt erns—4 × 4 blocks of ad-
jacent pixels are stored in a single 64- or 128-bit machine word—and because
more of the texture can fi t into the cache at once. Compressed textures do
suff er from compression artifacts. While the anomalies are usually not notice-
able, there are situations in which uncompressed textures must be used.
Texel Density and Mipmapping
Imagine rendering a full-screen quad (a rectangle composed of two triangles)
that has been mapped with a texture whose resolution exactly matches that of
the screen. In this case, each texel maps exactly to a single pixel on-screen, and
we say that the texel density (ratio of texels to pixels) is one. When this same
quad is viewed at a distance, its on-screen area becomes smaller. The resolu-
tion of the texture hasn’t changed, so the quad’s texel density is now greater
than one (meaning that more than one texel is contributing to each pixel).
Clearly texel density is not a fi xed quantity—it changes as a texture-
mapped object moves relative to the camera. Texel density aff ects the memory
consumption and the visual quality of a three-dimensional scene. When the
texel density is much less than one, the texels become signifi cantly larger than
a pixel on-screen, and you can start to see the edges of the texels. This destroys
the illusion. When texel density is much greater than one, many texels contrib-
ute to a single pixel on-screen. This can cause a moiré banding patt ern , as shown
in Figure 10.17. Worse, a pixel’s color can appear to swim and fl icker as diff er-
ent texels within the boundaries of the pixel dominate its color depending on
subtle changes in camera angle or position. Rendering a distant object with a
very high texel density can also be a waste of memory if the player can never
get close to it. Aft er all, why keep such a high-res texture in memory if no one
will ever see all that detail?
Ideally we’d like to maintain a texel density that is close to one at all times,
for both nearby and distant objects. This is impossible to achieve exactly, but
it can be approximated via a technique called mipmapping. For each texture,
10.1. Foundations of Depth-Buffered Triangle Rasterization