Graphics Reference
In-Depth Information
The other texture operations are similar. If the mode is modulate , you
would replace the third step by
3. Compute the color component product C f * C t as the color of the pixel.
And finally, if the mode is either decal or replace , the third step is replaced by
3. Use the color C t as the color of the pixel.
There are other definitions of these texture modes for RGBA color, alpha,
or luminance, but the examples above are enough to show you that the com-
putations for these modes are simple. In the fixed-function world, you need to
know what all of these options are. In the shader world, you set this yourself
by what you write in the shader.
Texture Sampling Parameters
Texture sampling parameters are an intrinsic part of using textures, whether
you are in the fixed-function world or the shader world. For example, what
do you do if your texture coordinates lie outside the normal [0., 1.] range? The
options are to wrap or clamp these coordinates. Computing a wrapping or
clamping operation is straightforward; if you want to use clamp operations,
any value larger than 1 is simply replaced by 1, while any value smaller than
0 is simply replaced by 0. If you want to use wrap operations, replace any
texture coordinate c out of the standard range by c - loor ( c ) to get only the
fractional part of the coordinate.
Also, what do you do if an individual pixel's texture coordinates don't
correspond to exact integer indices of a texel in your texture? This can happen
if you have many texels within one pixel (minification) or if you have many
pixels that correspond to one texel (magnification). You need to define the fil-
ter operations that OpenGL is to perform when this happens. The two filter
options are to use nearest ( GL_NEAREST ) or linear interpolation ( GL_LINEAR )
with neighboring texels to get the particular pixel color. The actual operations
are straightforward for either minification or magnification. The nearest filter
is defined by simply picking the texel that is nearest the texture coordinates
(in x + measure), while the linear filter is defined by taking the weighted
average of the four texels that are nearest (in the same measure) to the texture
coordinates.
Samplers
Samplers are special kinds of functions that are used to access a particular tex-
ture map using the sampling parameters that you have set. Typically, they
Search WWH ::




Custom Search