In game development, common texture compression methods

Texture Compression Purpose

The purpose is to allow the texture to be transferred from the CPU to the GPU in a compressed state, and to exist in the video memory in a compressed state, which can reduce bandwidth and reduce video memory; too much bandwidth will increase power consumption and affect performance; for a good Mobile games must meet the two basic requirements of no heat generation and smooth images .

Why is texture compression not suitable for algorithms such as PNG and jpg?

  • Simply put : the GPU sometimes only needs a small portion of the entire image, at which point decompressing the entire image is computationally expensive, so the texture sampler must support real-time random access.
  • To be specific : traditional compression schemes, such as JPEG or PNG, are designed to compress or decompress entire images. They can achieve very good compression ratios and image quality, but they are not good without decompressing the entire image. Supports real-time random access. When mapping a 2D texture onto a model, individual texels may be fetched from the full texture image in an unpredictable order, not all texels are required. For example, depending on the orientation of the model and any other objects that might obscure parts of it. Textures that are rendered next to each other in the final image, may originate from different parts of the texture. Decompressing the entire image is computationally expensive when the GPU requires only a small portion of the entire image. In the common game texture compression algorithm, the real-time compression scheme is designed to provide efficient decoding for random sampling of elements in a larger image, that is, to support real-time random access of compressed textures.

Commonly used compression methods

There are DXTC (Windows), BC1-BC7, ETC (1 and 2), PVRTC (IOS), ASTC, etc.

DXTC(DirectX Texture Compress)

This compression method is mainly used on the PC side

BC1-BC7, mainly used in Direct3D

  1. BC1 (DXGI_FORMAT_BC1_UNORM): This format supports 3 color channels and only uses 1 bit (on/off) to represent the alpha component.
  2. BC2 (DXGI_FORMAT_BC2_UNORM): This format supports 3 color channels and only uses 4 bits to represent the alpha component.
  3. BC3 (DXGI_FORMAT_BC3_UNORM): This format supports 3 color channels and represents the alpha component in 8 bits.
  4. BC4 (DXGI_FORMAT_BC4_UNORM): This format supports 1 color channel (for example, grayscale images).
  5. BC5 (DXGI_FORMAT_BC5_UNORM): This format supports two color channels.
  6. BC6 (DXGI_FORMAT_BC6_UF16): This format is used for compressed HDR (high dynamic range, high dynamic range) image data.
  7. BC7 (DXGI_FORMAT_BC7_UNORM): This format is used for high-quality RGBA compression. In particular, this format can significantly reduce errors caused by compressed normal maps.

ETC

Divided into ETC1 and ETC2

  • ETC1: Supports OpenGL ES2.0 and above, but ETC1 has a serious disadvantage - it does not support alpha channel , so RGB and alpha are generally compressed separately, and finally combined and calculated during rendering ; all iPhones are supported.
  • ETC2: Solve the problem that ETC1 does not support the alpha channel, OpenGL ES3.0 version machines and above support, support iPhone 5S and above.
    The reason why IOS does not use ETC is that PVRTC performs better under the premise of similar compression size.

PVRTC

Due to patent reasons, it is generally used on ios devices and some Android machines that support PVRTC. The size requirement is the Nth power of 2, and it must be square. As for why there is a size requirement, it is determined by the specific compression algorithm.

ASTC

In the Android system, OpenGL ES 3.0 level hardware is widely supported; in the ios system, iPhone6 ​​and above models are supported; most mobile devices can now support ASTC.

Compression scheme 1 commonly used in the industry:

  • Android : The industry generally chooses ETC1 because it is part of the OpenGL ES graphics standard and is supported by all Android devices using opengl2.0. However, since ETC1 does not have an alpha channel, the map with an alpha channel needs to split the original map into two channels, compress it in two, and finally merge and calculate it when rendering.
  • IOS : The industry generally uses the pvrtc RGBA 4bits format.

Commonly used compression scheme 2 in the industry:

  • Android : ETC2, the size requirement (divisible by 4) abandons part of the low-end device market.
  • IOS : PVRTC, ASTC (discard some old ios devices).
  • There are three compression formats of ASTC4\5\6 . At present, the difference visible to the naked eye is not obvious. You can start with ASCT5. For the more common UI, the compression format of ASTC5 is used, and the less important UI is ASTC6.

Guess you like

Origin blog.csdn.net/qq_41841073/article/details/127692650