Graphics Reference
In-Depth Information
or it may be saved as another texture or output as
a file.
In Figure 11.1, we see a texture image as
it might have been read from an image file. This
texture file may be treated as an image raster by
working with each texel individually. A built-in
GLSL function textureSize( ) will tell you the
resolution of the texture, called ResS and ResT in
Figure 11.1.
There are two ways to access a single texel in
a texture. Since any OpenGL texture has texture
coordinates ranging from 0.0 to 1.0, the coordinates
of the center of the image are vec2(0.5,0.5) and
you can increment texture coordinates by 1./ ResS
or 1./ ResT to move from one texel to another hori-
zontally or vertically, respectively. Alternately, if
you are working with GLSL 1.50 (OpenGL 3.2) or
higher, you can access any texel with the texelFetch( ) function. We will use
these GLSL texture-access capabilities in the fragment shader to identify and
calculate colors for pixels in the color buffer.
In order to be as general as possible, we will address and increment tex-
ture coordinates with real numbers rather than integers, in spite of the weak-
ness in this approach, since it can lead to some unintentional interpolations of
pixel values.
Figure 11.1. A texture raster that could be
created from an image file.
Single-Image Manipulation
In the next several sections, we work with an individual image and compute
the color of output pixels by using information contained in the image. This
is in contrast to some later sections in this chapter, when we use two different
images as textures loaded into different texture units in our computation.
Luminance
The luminance of a color is the overall brightness of the color, with no reference
to the color's hue. Luminance is a more complex property than it might seem,
because our eyes respond to different primary colors differently. Luminance
has been studied because of the need to give luminance cues to persons who
have deficient color vision, as described in [15, Chapter 5], and because it was
Search WWH ::




Custom Search