Skip to content

Instantly share code, notes, and snippets.

@dvessel
Last active May 7, 2022 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvessel/6ca975d8641a017bb18e67fc386a4b72 to your computer and use it in GitHub Desktop.
Save dvessel/6ca975d8641a017bb18e67fc386a4b72 to your computer and use it in GitHub Desktop.

Supported compression types in Dolphin

Taken from S3_Texture_Compression (Wikipedia) and condensed to what's relevant to Dolphin's texture support.

Codecs

There are five three variations of the S3TC algorithm (named DXT1 through DXT5, referring to the FourCC code assigned by Microsoft to each format), each designed for specific types of image data. All convert a 4×4 block of pixels to a 64-bit or 128-bit quantity, resulting in compression ratios of 6:1 with 24-bit RGB input data or 4:1 with 32-bit RGBA input data. S3TC is a lossy compression algorithm, resulting in image quality degradation, an effect which is minimized by the ability to increase texture resolutions while maintaining the same memory requirements. Hand-drawn cartoon-like images do not compress well which usually generate artifacts.

Like many modern image compression algorithms, S3TC only specifies the method used to decompress images, allowing implementers to design the compression algorithm to suit their specific needs, although the patent still covers compression algorithms. The nVidia GeForce 256 through to GeForce 4 cards also used 16-bit interpolation to render DXT1 textures, which resulted in banding when unpacking textures with color gradients. Again, this created an unfavorable impression of texture compression, not related to the fundamentals of the codec itself.

DXT1,BC1: 1-bit Alpha/Opaque

Suited to large textures due to the memory savings.

  • Alpha Premultiplied: Yes
  • Compression Ratio: 6:1 (for 24-bit source image)
  • Texture Type: Simple 1-bit Alpha/Opaque

DXT1 or Block Compression 1, is the smallest variation of S3TC, storing 16 input pixels in 64 bits of output, consisting of two 16-bit RGB 5:6:5 color values and a 4x4 two-bit lookup table. Simple 1-bit alpha is supported.

Note that a black border surrounding the transparent area can appear when linear texture filtering and alpha test is used, due to colors being interpolated between the color of opaque texel and neighbouring black transparent texel.

DXT3,BC2: Explicit alpha

Color compression works the same way as BC1 (opaque version) but more bits are allocated to the alpha channel. No real benefits to this codec. Takes up the same amount of memory as BC5/7 with no benefits. Avoid it.

  • Alpha Premultiplied: No
  • Compression Ratio: 4:1
  • Texture Type: Sharp Alpha

DXT3 or Block Compression 2, converts 16 input pixels (corresponding to a 4x4 pixel block) into 128 bits of output, consisting of 64 bits of alpha channel data (4 bits for each pixel) followed by 64 bits of color data, encoded the same way as DXT1.

DXT5,BC3: Interpolated alpha

If your hardware supports BC7 compression, use that. The only benefit to this codec is for smooth alpha gradients in mobile hardware without BC7 support.

  • Alpha Premultiplied: No
  • Compression Ratio: 4:1
  • Texture Type: Gradient Alpha

DXT5 or Block Compression 3, converts 16 input pixels into 128 bits of output, consisting of 64 bits of alpha channel data (two 8-bit alpha values and a 4x4 3-bit lookup table) followed by 64 bits of color data (encoded the same way as DXT1). Because DXT5 use an interpolated alpha scheme, they generally produce superior results for alpha gradients than DXT3.

BPTC,BC7: High quality compression

Most textures should use this codec if your hardware supports it. It takes up the same amount of RAM and storage as BC2 and 3 but the results are superior. Use BC1 to cut down on resource usage when it makes sense and BC7 when you need the quality. Best for small and medium sized textures.

  • Alpha premultiplied: No
  • Compression ratio: 4:1
  • Texture Type: Gradient Alpha

BC7 encodes 16 input RGB8/RGBA8 pixels into 128 bits of output. BC7 have a much more complex algorithm with a selection of encoding modes. The quality is much better as a result.

Encoding with this codec can take a lot more computing power but there are mature tools to speed up the process.

Command line examples with Cuttlefish.

Precompiled binaries for Cuttlefish available. Windows/Mac/Linux supported. Apple M1 (ARM) binaries must be compiled manually.

Alpha is enabled by default [standard]. Disable it [none] or set it to premultiply [pre-multipied] based on the codec. The -j option or --jobs [n] is to enable multi-threading. Set it for a nice boost in performance.

DXT1,BC1 with 1-bit alpha:

cuttlefish -j --format bc1_rgba --alpha pre-multiped -i input.png -o output.dds

DXT1,BC1 opaque:

cuttlefish -j --format bc1_rgb --alpha none -i input.png -o output.dds

BPTC,BC7:

cuttlefish -j --format bc7 -i input.png -o output.dds