Next | Prev | Up | Top | Contents | Index

Using the Detail Texture Extension

Because the high-frequency detail in a texture (for example, a road) is often virtually the same across the entire texture, the detail from an arbitrary portion of the texture image can be used as the detail across the entire image.

When you use the detail texture extension, the high-resolution texture image is represented by the combination of a low-resolution texture image and a small high-frequency detail texture image (the detail texture). OpenGL combines these two images during rasterization to create an approximation of the high-resolution image.

This section first explains how to create the detail texture and the low resolution texture that are used by the extension, then briefly looks at how detail texture works and how to customize the LOD interpolation function, which controls how OpenGL combines the two textures.


Creating a Detail Texture and a Low-Resolution Texture

This section explains how to convert a high-resolution texture image into a detail texture and a low-resolution texture image. For example, for a 2K x 2K road texture, you may want to use a 512 x 512 low-resolution base texture and a 256 x 256 detail texture. Follow these steps to create the textures:

  1. Make the low-resolution image using izoom or another resampling program to make the low-resolution image by shrinking the high-resolution image by 2n.

    In this example, n is 2, so the resolution of the low-resolution image is 512 x 512. This band-limited image has the two highest-frequency bands of the original image removed from it.

  2. Create the subimage for the detail texture using subimage or another tool to select a 256 x 256 region of the original high-resolution image, whose n highest-frequency bands are characteristic of the image as a whole. (For example, rather than choosing a subimage from the lane markings or a road, choose an area in the middle of a lane.)

  3. Optionally, make this image self-repeating along its edges to eliminate seams.

  4. Create a blurry version of the 256 256 subimage as follows:

    1. First shrink the 256 256 subimage by 2n, to 64 64.

    2. Then scale the resulting image back up to 256 256.

      The image is blurry because it is missing the two highest-frequency bands present in the two highest levels of detail.

  5. Subtract the blurry subimage from the original subimage. This difference image--the detail texture--has only the two highest frequency bands.

  6. Define the low-resolution texture (the base texture created in Step 1) with the GL_TEXTURE_2D target and the detail texture (created in Step 5) with the GL_DETAIL_TEXTURE_2D_SGIS target. In the road example, you would use

    GLvoid *detailtex, *basetex;

    glTexImage2D(GL_DETAIL_TEXTURE_2D_SGIS, 0, 4, 256, 256, 0, GL_RGBA,

    GL_UNSIGNED_BYTE, detailtex);

    glTexImage2D(GL_TEXTURE_2D, 0, 4, 512, 512, 0, GL_RGBA,

    GL_UNSIGNED_BYTE, basetex);

    The internal format of the detail texture and the base texture must match exactly.

  7. Set the GL_DETAIL_TEXTURE_LEVEL_SGIS parameter to specify the level at which the detail texture resides. In the road example, the detail texture is level -2 (since the original 2048 x 2048 texture is two levels below the 512 x 512 base texture):

    glTexParameteri(GL_TEXTURE_2D, GL_DETAIL_TEXTURE_LEVEL_SGIS, -2);

    Since the actual detail texture supplied to OpenGL is 256 x 256, OpenGL replicates the detail texture as necessary to fill a 2048 x 2048 texture. In this case, the detail texture repeats eight times in S and in T.

    Note that the detail texture level is set on the GL_TEXTURE_2D target, not on GL_DETAIL_TEXTURE_2D_SGIS.

  8. Set the magnification filter to specify whether the detail texture is applied to the alpha or color component, or both. Use one of the filters in Table 6-3. For example, to apply the detail texture to both alpha and color components, use

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,

                   GL_LINEAR_DETAIL_SGIS);

Note that the magnification filter is set on the GL_TEXTURE_2D target, not on GL_DETAIL_TEXTURE_2D_SGIS.

Magnification Filters for Detail Texture
GL_TEXTURE_MAG_FILTERAlphaRed, Green, Blue
GL_LINEAR_DETAIL_SGISdetaildetail
GL_LINEAR_DETAIL_COLOR_SGISbilineardetail
GL_LINEAR_DETAIL_ALPHA_SGISdetailbilinear


How Detail Texture Is Computed

For each pixel that OpenGL textures, it computes an LOD-based factor that represents the amount by which the base texture (that is, level 0) is scaled. LOD n represents a scaling of 2-n. Negative values of LOD correspond to magnification of the base texture.

To produce a detailed textured pixel at level-of-detail n, OpenGL uses one of the two formulas shown in Table 6-5, depending on the detail texture mode.

How Detail Texture Is Computed
GL_DETAIL_TEXTURE_MODE_SGISFormula
GL_ADDLODn = LOD0 + weight(n) * DET
GL_MODULATELODn = LOD0 + weight(n) * DET * LOD0

The variables in the formulas are defined as follows:

n

level of detail

weight(n)

detail function

LOD0

base texture

DET

detail texture
For example, to specify GL_ADD as the detail mode, use

glTexParameteri(GL_TEXTURE_2D, GL_DETAIL_TEXTURE_MODE_SGIS, GL_ADD);

Customizing the Detail Function

In the road example, the 512 x 512 base texture is LOD 0. The detail texture combined with the base texture represents LOD -2, which is called the maximum-detail texture.

By default, OpenGL performs linear interpolation between LOD 0 and LOD -2 when a pixel's LOD is between 0 and -2. Linear interpolation between more than one LOD can result in aliasing. To minimize aliasing between the known LODs, OpenGL lets you specify a nonlinear LOD interpolation function.

Figure 6-4 shows the default linear interpolation curve and a nonlinear interpolation curve that minimizes aliasing when interpolating between two LODs.

Figure 6-4 : LOD Interpolation Curves The basic strategy is to use very little of the detail texture until the LOD is within one LOD of the maximum-detail texture. More of the information from the detail texture can be used as the LOD approaches LOD -2. At LOD -2, the full amount of detail is used, and the resultant texture exactly matches the high-resolution texture.

Use glDetailTexFuncSGIS() to specify control points for shaping the LOD interpolation function. Each control point contains a pair of values; the first value specifies the LOD, and the second value specifies the weight for that magnification level.

The following control points can be used to create a nonlinear interpolation function (as shown above in Figure 6-4):

GLfloat points[] = {
     0.0, 0.0, 
    -1.0, 0.3,
    -2.0, 1.0,
    -3.0, 1.1
};
glDetailTexFuncSGIS(GL_TEXTURE_2D, 4, points);
Note that how these control points determine a 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 passes through the control points.


Using Detail Texture and Texture Object

If you are using the texture object extension, the base texture and the detail texture are separate texture objects. You can bind any base texture object to GL_TEXTURE_2D and any detail texture object to GL_DETAIL_TEXTURE_2D_SGIS. Each base texture object contains its own detail mode, magnification filter, and LOD interpolation function. Setting these parameters therefore affects only the texture object that is currently bound to GL_TEXTURE_2D. (If you set these parameters on the detail texture object, they are ignored.)


Next | Prev | Up | Top | Contents | Index