Next | Prev | Up | Top | Contents | Index

Using the Sharpen Texture Extension

This section first explains how to use the sharpen texture extension to sharpen the component of your choice. It then gives some background information about how the extension works and explains how you can customize the LOD extrapolation function.


How to Use the Sharpen Texture Extension

You can use the extension to sharpen the alpha component, the color components, or both, depending on the magnification filter. To specify sharpening, use one of the magnification filters in Table 6-3.

Magnification Filters for Sharpen Texture
GL_TEXTURE_MAG_FILTERAlphaRed, Green, Blue
GL_LINEAR_SHARPEN_SGISsharpensharpen
GL_LINEAR_SHARPEN_COLOR_SGISbilinearsharpen
GL_LINEAR_SHARPEN_ALPHA_SGISsharpenbilinear

For example, suppose that a texture contains a picture of a tree in the color components, and the opacity in the alpha component. To sharpen the outline of the tree, use

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                               GL_LINEAR_SHARPEN_ALPHA_SGIS);

How Sharpen Texture Works

When OpenGL applies a texture to a pixel, it computes a level of detail (LOD) factor that represents the amount by which the base texture (that is, level 0) must be scaled. LOD n represents a scaling of 2-n. For example, if OpenGL needs to magnify the base texture by a factor of 4 in both S and T, the LOD is -2. Note that magnification corresponds to negative values of LOD.

To produce a sharpened texel at level-of-detail n, OpenGL adds the weighted difference between the texel at LOD 0 and LOD 1 to LOD 0; that is:

LODn = LOD0 + weight(n) * (LOD0 - LOD1)
The variables are defined as follows:

n

level-of-detail

weight(n)

LOD extrapolation function

LOD0

base texture

LOD1

texture at mipmap level 1
By default, OpenGL uses a linear extrapolation function, where weight(n) =-n/4. You can customize the LOD extrapolation function by specifying its control points, as discussed in the next section.


Customizing the LOD Extrapolation Function

With the default linear LOD extrapolation function, the weight may be too large at high levels of magnification, that is, as n becomes more negative. This can result in so much extrapolation that noticeable bands appear around edge features, an artifact known as "ringing." In this case, it's useful to create a nonlinear LOD extrapolation function.

Figure 6-3 shows LOD extrapolation curves as a function of magnification factors. The curve on the left is the default linear extrapolation, where weight(n) = -n/4. The curve on the right is a nonlinear extrapolation, where the LOD extrapolation function is modified to control the amount of sharpening so that less sharpening is applied as the magnification factor increases. The function is defined for n less than or equal to 0.

Figure 6-3 : LOD Extrapolation Curves Use glSharpenTexFuncSGIS() to specify control points for shaping the LOD extrapolation function. Each control point contains a pair of values; the first value specifies the LOD, and the second value specifies a weight multiplier for that magnification level. (Remember that the LOD values are negative.)

For example, to gradually ease the sharpening effect, use a nonlinear LOD extrapolation curve--as shown on the right in Figure 6-3--with these control points:

GLfloat points[] = {
      0., 0., 
 -    1., 1., 
 -    2., 1.7, 
 -    4., 2.
};
glSharpenTexFuncSGIS(GL_TEXTURE_2D, 4, points);
Note that how these control points determine the function is system dependent. For example, your system may choose to create a piecewise linear function, a piecewise quadratic function, or a cubic function. However, regardless of which kind of function is chosen, the function will pass through the control points.


Using Sharpen Texture and Texture Object

If you are using the texture object extension, each texture object contains its own LOD extrapolation function and magnification filter. Setting the function or the filter therefore affects only the texture object that is currently bound to the texture target.


Next | Prev | Up | Top | Contents | Index