i
i
i
i
i
i
i
i
244 11. Texture Mapping
textures. When graphics programmers talk about textures without specifying di-
mension, they usually mean 2D textures. However, we begin with 3D textures
because, in many ways, they are easier to understand and implement. At the end
of the chapter we discuss bump mapping and displacement mapping which use
textures to change surface normals and position, respectively. Although those
methods modify properties other than reflectance, the images/functions they use
are still called textured. This is consistent with common usage where any image
used to modify object appearance is called a texture.
11.1 3D Texture Mapping
In previous chapters we used c
r
as the diffuse reflectance at a point on an object.
For an object that does not have a solid color, we can replace this with a function
c
r
(p) which maps 3D points to RGB colors (Peachey, 1985; Perlin, 1985). This
function might just return the reflectance of the object that contains p.Butfor
objects with texture, we should expect c
r
(p) to vary as p moves across a surface.
One way to do this is to create a 3D texture that defines an RGB value at every
point in 3D space. We will only call it for points p on the surface, but it is usually
easier to define it for all 3D points than a potentially strange 2D subset of points
that are on an arbitrary surface. Such a strategy is clearly suitable for surfaces that
are “carved” from a solid medium, such as a marble sculpture.
Note that in a ray-tracing program, we have immediate access to the point p
seen through a pixel. However, for a z-buffer or BSP-tree program, we only know
the point after projection into device coordinates. We will show how to resolve
this problem in Section 11.3.1.
11.1.1 3D Stripe Textures
There are a surprising number of ways to make a striped texture. Let’s assume we
have two colors c
0
and c
1
that we want to use to make the stripe color. We need
some oscillating function to switch between the two colors. An easy one is a sine:
RGB stripe( point p )
if (sin(x
p
) > 0) then
return c
0
else
return c
1