Graphics Reference
In-Depth Information
In addition to 2D textures, OpenGL ES 3.0 supports cubemap textures.
At its most basic, a cubemap is a texture made up of six individual 2D
texture faces. Each face of the cubemap represents one of the six sides
of a cube. Although cubemaps have a variety of advanced uses in 3D
rendering, the most common use is for an effect known as
environment
mapping
. For this effect, the reflection of the environment onto the object
is rendered by using a cubemap to represent the environment. Typically,
a cubemap is generated for environment mapping by placing a camera
in the center of the scene and capturing an image of the scene from each
of the six axis directions (+
X
, -
X
, +
Y
, -
Y
, +
Z
, -
Z
) and storing the result in
each cube face.
Texels are fetched out of a cubemap by using a 3D vector (
s
,
t
,
r
) as the
texture coordinate to look up into the cubemap. The texture coordinates
(
s
,
t
,
r
) represent the (
x
,
y
,
z
) components of the 3D vector. The 3D vector
is used to first select a face of the cubemap to fetch from, and then the
coordinate is projected into a 2D (
s
,
t
) coordinate to fetch from the
cubemap face. The actual math for computing the 2D (
s
,
t
) coordinate
is outside our scope here, but suffice it to say that a 3D vector is used to
look up into a cubemap. You can visualize the way this process works by
picturing a 3D vector coming from the origin inside of a cube. The point
at which that vector intersects the cube is the texel that would be fetched
from the cubemap. This concept is illustrated in Figure 9-2, where a 3D
vector intersects the cube face.
Figure 9-2
3D Texture Coordinate for Cubemap