-
Notifications
You must be signed in to change notification settings - Fork 6
HowItWorks
A simple explanation of S2TC is given here for the simplest case - the DXT1 format, with no alpha channel.
We are working with this image, which was especially designed to compress badly with block compression schemes:
(768KiB in RGB, 1024KiB in RGBA)
Experience showed that doing the RGB565 conversion as a step prior to the actual compression can yield better results than doing it during block compression, and it also yields faster running code if you want dithering. As we sure do want dithering, we do it here.
The reason why doing it here yields better result, is that doing dithering here tends to avoid "high amplitude" dither patterns, which may happen if dithering took place during the block compression. But if one does it this way, it basically leads to "high amplitude" blocks to not use dithering, and "low amplitude" blocks to retain the dither from this step, which tends to look better and clearer in the end.
The image is split into 4x4 blocks.
Each 4x4 block is reduced to a 2-colors palette. It is crucial to select these two colors well; this is the selection GIMP would use for color reducing:
-->
The reference compressor uses a different color selection method which works better at retaining detail, yielding these colors:
-->
For each block, 64 bits are stored as follows: 16 bits for the first palette color, 16 bits for the second palette color, and then 2 bits for each pixel (which always are 00 or 01, when no alpha channel is involved). For further details on this, see FileFormats.
(128KiB in DXT1)
Of course this does lose some visual quality, but reduces graphics memory utilization by factor 6 (or factor 8, if we upload in RGBA format which generally performs better due to aligned memory access). This reduction allows us to use more detail on textures or geometry, which will be more than enough to compensate for the quality loss.
How important a good compression algorithm, especially the selection of the palette colors, is, can be seen by comparing to S3TC compression tools. These have more degrees of freedom to encode an image, thus they should always get better quality.
NVidia Texture Tools's nvcompress
tool for example would yield this on the
same input image:
(128KiB in DXT1)
This looks clearly worse than what S2TC produces, mainly because nvcompress
does a poor selection of the reference colors!