Platform SDK: DirectX |
Texture format DXT1 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 4-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.
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 will be 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 piece of pseudocode illustrates 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 two bit codes correspond to the 2-bit fields // stored in the 64-bit block. color_2 = (2 * color_0 + color_1) / 3; color_3 = (color 0 + 2 * color_1) / 3; } else { // Three-color block: derive the other color. // 00 = color_0, 01 = color_1, 10 = color_2, // 11 = transparent. // These two bit codes correspond to the 2-bit fields // stored in the 64-bit block. color_2 = (color_0 + color_1) / 2; color_3 = transparent; }
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).
Here is 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 (colors at the two extremes) are laid out as follows:
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 follows:
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 follows:
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, we will assume that the colors red and black are at the extremes. We will call red color_0 and black color_1. There will be 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
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 could be used is leaves on a tree to be shown against a blue sky. Some texels could be marked as transparent while three shades of green are still available for the leaves. Two of these colors fix the extremes, and the third color is an interpolated color.
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
[C++,Visual Basic]