Graphics Reference
In-Depth Information
shader code then uses the built-in function
texture
to fetch from the
texture map. The
texture
built-in function takes the form shown here:
vec4
texture
(sampler2D
sampler
, vec2
coord
[
,
float
bias
])
sampler
a sampler bound to a texture unit specifying the texture from
which to fetch.
coord
a 2D texture coordinate used to fetch from the texture map.
bias
an optional parameter that provides a mipmap bias used for
the texture fetch. This allows the shader to explicitly bias the
computed LOD value used for mipmap selection.
The
texture
function returns a
vec4
representing the color fetched from
the texture map. The way the texture data is mapped into the channels
of this color depends on the base format of the texture. Table 9-11 shows
the way in which texture formats are mapped to
vec4
colors. The texture
swizzle (described in the
Texture Swizzles
section earlier in this chapter)
determines how the values from each of these components map to
components in the shader.
Table 9-11
Mapping of Texture Formats to Colors
Base Format
Texel Data Description
GL_RED
(R, 0.0, 0.0, 1.0)
GL_RG
(R, G, 0.0, 1.0)
GL_RGB
(R, G, B, 1.0)
GL_RGBA
(R, G, B, A)
GL_LUMINANCE
(L, L, L, 1.0)
GL_LUMINANCE_ALPHA
(L, L, L, A)
GL_ALPHA
(0.0, 0.0, 0.0, A)
In the case of the
Simple_Texture2D
example, the texture was loaded
as
GL_RGB
and the texture swizzles were left at the default values, so the
result of the texture fetch will be a
vec4
with values (R, G, B, 1.0).