次の方法で共有


Opaque and One-Bit Alpha Textures (Windows Embedded CE 6.0)

1/6/2010

Texture format DXT1 (see D3DMFORMAT) is for textures that are opaque or have a single transparent color.

For each opaque or one-bit alpha block, two 16-bit values (RGB 5:6:5 format) and a 4x4 bitmap with 2-bits-per-pixel are stored. This totals 64 bits for 16 texels, or four bits per texel. In the block bitmap, there are two bits per texel to select between the four colors, two of which are stored in the encoded data. The other two colors are derived from these stored colors by linear interpolation. This layout is shown in the following illustration.

Ee491074.7185ecc8-f6c2-40c1-bdb4-f06ff3109005(en-US,WinEmbedded.60).gif

The one-bit alpha format is distinguished from the opaque format by comparing the two 16-bit color values stored in the block. They are treated as unsigned integers. If the first color is greater than the second, it implies that only opaque texels are defined. This means four colors are used to represent the texels. In four-color encoding, there are two derived colors and all four colors are equally distributed in RGB color space. This format is analogous to RGB 5:6:5 format. Otherwise, for one-bit alpha transparency, three colors are used and the fourth is reserved to represent transparent texels.

In three-color encoding, there is one derived color and the fourth two-bit code is reserved to indicate a transparent texel (alpha information). This format is analogous to RGBA 5:5:5:1, where the final bit is used for encoding the alpha mask.

The following code example shows the algorithm for deciding whether three- or four-color encoding is selected.

if (color_0 > color_1) 
{
    // Four-color block: derive the other two colors. 
    // 00 = color_0, 01 = color_1, 10 = color_2, 11 = color_3
    // These 2-bit codes correspond to the 2-bit fields 
    // stored in the 64-bit block.
    color_2 = (2 * color_0 + color_1 + 1) / 3;
    color_3 = (color_0 + 2 * color_1 + 1) / 3;
}    
else
{ 
    // Three-color block: derive the other color.
    // 00 = color_0,  01 = color_1,  10 = color_2,  
    // 11 = transparent.
    // These 2-bit codes correspond to the 2-bit fields 
    // stored in the 64-bit block. 
     color_2 = (color_0 + color_1) / 2;    
     color_3 = transparent;    

}

It is recommended that you set the RGBA components of the transparency pixel to zero before blending.

The following tables show the memory layout for the 8-byte block. It is assumed that the first index corresponds to the y-coordinate and the second corresponds to the x-coordinate. For example, Texel[1][2] refers to the texture map pixel at (x,y) = (2,1).

The following table shows the memory layout for the 8-byte (64-bit) block.

Word address 16-bit word

0

Color_0

1

Color_1

2

Bitmap Word_0

3

Bitmap Word_1

Color_0 and Color_1 — the colors at the two extremes — are laid out as shown in the following table.

Bits Color

4:0 (LSB)

Blue color component

10:5

Green color component

15:11

Red color component

Bitmap Word_0 is laid out as shown in the following table.

Bits Texel

1:0 (LSB)

Texel[0][0]

3:2

Texel[0][1]

5:4

Texel[0][2]

7:6

Texel[0][3]

9:8

Texel[1][0]

11:10

Texel[1][1]

13:12

Texel[1][2]

15:14 (MSB)

Texel[1][3]

Bitmap Word_1 is laid out as shown in the following table.

Bits Texel

1:0 (LSB)

Texel[2][0]

3:2

Texel[2][1]

5:4

Texel[2][2]

7:6

Texel[2][3]

9:8

Texel[3][0]

11:10

Texel[3][1]

13:12

Texel[3][2]

15:14 (MSB)

Texel[3][3]

Example of Opaque Color Encoding

As an example of opaque encoding, assume that the colors red and black are at the extremes. Red is color_0, and black is color_1. There are four interpolated colors that form the uniformly distributed gradient between them. To determine the values for the 4x4 bitmap, the following calculations are used.

00 ? color_0
01 ? color_1
10 ? 2/3 color_0 + 1/3 color_1
11 ? 1/3 color_0 + 2/3 color_1

The bitmap then looks like the following illustration.

Ee491074.05538f93-6cae-4218-9cba-719c25208c35(en-US,WinEmbedded.60).gif

This looks like the following series of colors.

Ee491074.6103b4c8-aae6-4943-bbf1-d983249ffca3(en-US,WinEmbedded.60).gif

Example of One-Bit Alpha Encoding

This format is selected when the unsigned 16-bit integer, color_0, is less than the unsigned 16-bit integer, color_1. An example of where this format can be used is leaves on a tree, shown against a blue sky. Some texels can be marked as transparent while three shades of green are still available for the leaves. Two colors fix the extremes, and the third is an interpolated color.

Here is an example of such a picture.

Ee491074.3d8afbbf-0b19-4b46-8045-9b5dae52682b(en-US,WinEmbedded.60).gif

Note that where the image is shown as white, the texel would be encoded as transparent. Also note that the RGBA components of the transparent texels should be set to zero before blending.

The bitmap encoding for the colors and the transparency is determined using the following calculations.

00 ? color_0
01 ? color_1
10 ? 1/2 color_0 + 1/2 color_1
11   ?   Transparent

The bitmap then looks like the following graphic.

Ee491074.48259dbd-68ae-4b45-b0e3-170caf674aa5(en-US,WinEmbedded.60).gif

See Also

Concepts

Compressed Texture Resources