Graphics Reference
In-Depth Information
effects. Textures developed using cube maps operate
differently from standard textures on the surface of an
object. A cube map consists of six 2D textures, each one
corresponding to the face of a cube (+ X ,− X ,+ Y ,− Y ,+ Z ,− Z )
surrounding the scene. A cube map is indexed with
three texture coordinates: s , t , and p . You can think of
( s , t , p ) as being a vector that points toward one wall of
the cube map, as shown in Figure 9.8.
When you index into a cube map with ( s , t , p ), the
texture-mapping hardware does the following:
1. Determines which of s , t , and p has the largest
absolute value:
Figure 9.8. A cube map and the ( s , t , p )
vector that indexes into it.
(
)
Val
=
max,
s tp
,
.
This determines which face image (+ X ,− X ,+ Y ,− Y ,+ Z ,− Z ) of the cube map
to index into. In Figure 9.8, this would be s , corresponding to the − X face.
2. Divides the remaining two coordinates (called a and b here) by that larg-
est absolute value:
a
Val
s
′ =
,
b
Val
t
′ =
.
In Figure 9.8, a and b would be the texture coordinates p and t .
3. Uses ( s ′, t ′) as the 2D texture coordinates to use for the lookup on that face
image.
To use cube maps, you must create six square texture maps of the same
size that correspond to the sides of a cube. These individual texture maps are
often visualized as a latened or folded-up cube, as shown in Figure 9.9. The
cube map images are created by rendering or photographing each of the six
principle directions from the center of the cube, each with a 90° field of view.
Cube maps can be used to create reflection effects using the built-in GLSL
reflect( ) function to compute an ( s , t , p ) reflection vector to look up in the
cube map. Cube maps can also be used for refraction; for example, with a
lens or a glass object in a scene. To do this, you use the built-in GLSL function
refract( ) to compute the ( s , t , p ) refraction vector, and use it to look up in the
cube map.
Search WWH ::




Custom Search