Dxt texture Compression

Source: Internet
Author: User

Turn: http://blog.csdn.net/lhc717/article/details/6802951

We know that the most important performance of 3D objects in the game is through textures. The higher the Resolution, the more real-color textures, the more expressive the texture, but at the same time, the problem is that the memory occupied will multiply, and memory saving is very important in the current game. Therefore, texture compression technology is used on all platforms to ensure the best balance between memory usage and Display Effect of texture textures. In DirectX, a texture compression technology called dxt is used. Currently, this technology is supported by most graphics cards. By understanding dxt, we can gain a glimpse of the texture compression technology. Dxt is a DirectDraw surface that stores graphical data in a compressed form, which can save a lot of system bandwidth and memory. Even if you do not directly use dxt surface rendering, you can use the dxt format to create textures to save disk space. Direct3d provides d3dfmt_dxt1 ~ D3dfmt_dxt5 consists of five compression texture formats. D3dfmt_dxt1 supports 15-bit RGB and 1-bit Alpha graphics. d3dfmt_dxt2 and d3dfmt_dxt3 support 12-bit RGB and 4-bit Alpha. d3dfmt_dxt4 and d3dfmt_dxt5 generate alpha by linear interpolation.

 

 

Dxt1
The dxt1 format is mainly applicable to non-transparent textures or only one Alpha texture (non-completely transparent). For textures in the full rgb565 format, dxt1 has a compression ratio, that is, the color of each pixel occupies 4 places on average. Although the compression ratio is not very good, the features of dxt make it more suitable for real-time games.
Dxt1 treats every 4x4 pixel blocks as a compression unit, and the 4x4 pixel blocks after compression occupy 64 bits, there are two 16-bit RGB colors and 16 2-bit indexes. The format is illustrated as follows:

 

The two RGB colors in dxt1 indicate the two extreme values of the colors in the 4 × 4 pixel blocks in which the data is compressed. Then, we can calculate the two intermediate color values through linear interpolation, the 16 2-digit index indicates the color value of the pixel where the 4x4 pixel blocks are located. The 2-digit index can represent four states, which can exactly represent color_0, color_1 and the intermediate color values color_2 and color_3 calculated through interpolation. For textures with an Alpha, only one intermediate color value is calculated. color_3 is used to indicate completely transparent.
The two color values color_0 and color_1 are used to determine whether the dxt1 format is an opaque or alpha texture, if the value of color_0 is greater than color_1, the texture is completely opaque. Otherwise, the texture has a transparent information.
Dxt2 and dxt3 
Dxt2 and dxt3 can represent textures with more complex transparent information. These two formats use explicit Alpha representation. We know that in dxt1, we use 64-bit data to describe the color information of 4*4 pixel blocks. In dxt2 and dxt3, the color information remains unchanged, instead, it adds 64-bit data, that is, 4 bits per pixel, to indicate their Alpha transparency information, normally, we can use the direct encoding method to represent the four-digit alpha information.
In this way, each 4x4 pixel block occupies 128 characters, that is, 8 words, 0 ~ 3 words for transparent information; 4 ~ 7 indicates the color information described above.
The difference between dxt2 and dxt3 is that the color in dxt2 has completed the premultiplied by Alpha operation (after the color and alpha are mixed, the overall color value is changed when the transparency changes, the Alpha information of dxt3 is relatively independent. The reason for the separation is to adapt to different needs, because in some cases, independent Alpha information is required.

 

Dxt4, dxt5 
Dxt4 and dxt5 are also used to represent textures with complex transparent information. Different from 2 and 3, the Alpha information of 4 and 5 is calculated by linear interpolation, similar to the color information of dxt1. Similarly, the transparent information of each 4 × 4 pixel block occupies 64 bits. The difference is that, the 64-bit system uses two 8-bit Alpha values and 16 3-bit index values. Since each pixel index occupies three places, it can represent eight different transparent states.
There are two kinds of interpolation methods here. One is used to represent a completely transparent and completely opaque state, and the other is interpolation only in the given extreme values alpha_0 and alpha_1. The difference is also achieved by comparing the sizes of alpha_0 and alpha_1. If alpha_0 is greater than alpha_1, the remaining six alpha values are calculated through interpolation. Otherwise, only four alpha values are calculated through interpolation. alpha_6 is directly assigned 0 values, while alpha_7 is directly assigned 255 values.
The differences between dxt4 and dxt5 are the same as those between dxt2 and dxt3. The color value of dxt4 is understood as the premultiplied by Alpha operation has been completed.
In addition, it should be noted that all the compressed texture formats are the power of 2, because the Unit of texture compression is 4x4 pixels, therefore, if the size of the texture is 16x2 or 8x1, the system will also compress the texture in 4x4 units, resulting in a waste of space, the same size will be occupied, but will not be used.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.