Chapter 10
Advanced Texturing
The demand for high-quality rendering has led to the increase in comput-
ing power and programmability of GPU. Many attempts have been made to
utilize the GPU power and extend the lighting functions beyond the local illu-
mination model. As a result, a global illumination look has been increasingly
added to the images generated at real time. In the algorithms developed along
the trend, textures play key roles. This chapter presents a few representative
algorithms that use textures for more realistic shading.
10.1 Environment Mapping
Environment mapping simulates a shiny object reflecting its surrounding
environment. Fig. 10.1 shows an example. The first task for environment
mapping is to capture the environment images in a texture called an envi-
ronment map. Among several implementations, the most popular is a cubic
environment map, simply referred to as a cube map. It consists of six square
faces. Each face contains an image of the environment.
Fig. 10.1: The teapot surface reflects its surrounding environment.
226 3D Graphics for Game Programming
Fig. 10.2: Cube map authoring. (a) The environment is captured or ren-
dered along six view directions. (b) Six images are organized into a cube map.
(Image courtesy of Emil Persson.)
10.1.1 Cube Mapping
Consider an imaginary cube at the center of which a camera is located, as
shown in Fig. 10.2-(a). The environment can be captured onto the six faces
of the cube such that each face covers a 90
field of view both vertically and
horizontally. In order to build a cube map upon such a set of six images, we
can use a 2D graphics package’s tool, e.g., Photoshop plug-in named NVIDIA
DDS Exporter
. Fig. 10.2-(b) shows an unfolded form of a cube map.
Fig. 10.3-(a) illustrates a cube map in cross section. Conceptually, it
surrounds the object to be environment-mapped. Suppose that a surface
point p reflects the environment. To determine the reflected color at p, a ray
denoted by I is fired from the viewpoint toward p. It is reflected with respect
to the surface normal n at p. The reflection vector R is computed as follows:
R = I 2n(n · I) (10.1)
(This is identical to Equation (5.12) presented in the section of ray tracing for
global illumination.) R intersects a face of the cube map. Then, the image
associated with the face is filtered to fetch the texels hit by R. They determine
the reflected color at p. Environment mapping is often called a simplified ray
tracing in the sense that only the one-bounce reflection vector (R) is traced.
Cube mapping is widely used and is supported by hardware. For example,
HLSL provides a library function texCUBE(). It takes a cube map and R as
DDS stands for DirectDraw Surface. The DDS file format was introduced with Direct3D
7 and is widely used to store textures.
Advanced Texturing 227
Fig. 10.3: Cube mapping. (a) The cube map (illustrated as a box) sur-
rounds an object. A ray fired from the viewpoint is traced to determine the
color reflected at p. (b) The cube map should be referenced using (u
, v
but the cube mapping algorithm uses (u, v). Only when the environment is
infinitely far away, (u, v) and (u
, v
) will lead to the same filtering result.
input and returns an RGB color. Section 10.1.2 presents the internal mecha-
nism of texCUBE(), i.e., how to identify the face hit by R and how to convert
R into the texture coordinates (u, v) used for filtering the face’s image.
Notice that R is a vector and is independent of the start point. It causes
an error. See Fig. 10.3-(b). The cube map should be referenced using (u
, v
returned by “the ray starting from p.” However, texCUBE() actually uses “the
ray starting from the origin.” It returns (u, v), which are obviously different
from (u
, v
). Only when the environment is infinitely far away, the scene
points hit by the two rays are captured at an identical texel of the cube map.
Fortunately, people are fairly forgiving about the incorrectness that results
when the environment is not sufficiently far away.
It is simple to implement environment mapping, and the result is fairly
pleasing. Environment mapping is often taken as an effort toward global
illumination, and in fact it adds a global illumination look to the images
generated by a local illumination model. However, it is just a small step out
of local illumination and does not sufficiently overcome its limitations. For
example, the concave reflector does not reflect itself.
10.1.2 Cube Map Access
The cube map faces are named {+x,x,+y,y,+z,z}. See Fig. 10.4. The
name of each face is taken from the axis pointing the face, and the remaining
two axes constitute the 2D basis of the face. The coordinate system in Fig.
10.4 is left-handed.

Get 3D Graphics for Game Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.