Cogito, ergo sum
DXT, or DXTC, is a type of texture compression.
According to the UDN docs:
DXTC is the native, compressed texture format used in Wikipedia:DirectX 8. In many cases, DXTC reduces texture memory usage by 50% or more over palettized, 8-bit textures, allowing for twice the textures at the same resolution, or the same number of textures at twice the resolution. Three DXTC formats are available.
There are several types of DXT compression offered by DirectX 8/9:
- 0 or 1 bit alpha
- Explicit 4-bit alpha, color data is premultiplied by alpha – UnrealEd does not use this format
- Explicit 4-bit alpha, not premultiplied
- Interpolated alpha, color data is premultiplied by alpha – UnrealEd does not use this format
- Interpolated alpha, not premultiplied
In DXT compression, images are divided into 4x4 pixel blocks, or "texels". For each texel, two color values are chosen to represent the range of pixel colors within that block, and then each pixel is mapped to one of four possible colors (two bits) within that range. The compressed texel is represented by the two 16-bit color values, and 16 2-bit pixel values, totalling 64 bits of data per texel, amounting to an overall image size of 4 bits per pixel.
Alpha (transparency) information in DXT is handled in one of several ways, depending on the DXT format. In DXT1, each texel can either be defined as having four possible color values within the range (as described above), or alternately three color values and one value indicating "this pixel is transparent". Thus, in DXT1, one can have at most 1-bit (on or off) transparency in the image, but even this is done at the expense of some color information. Note: DXT1 transparency is supported by the Engine and UnrealEd but you can't use UnrealEd GUI to create DXT1 textures with one-bit alpha. Textures converted to DXT1 have all transparency information removed.
In DXT2/3/4/5, Alpha information is specified using a second 64-bit block for each texel (thus doubling the image size). In DXT2/3, for each pixel, four bits are used to indicate its alpha, providing 16 different transparency levels. DXT4/5 uses a method similar to the way color data is stored to provide "interpolated" alpha information: Two (8-bit) alpha values are chosen representing the range of transparency in that texel, and then for each pixel, three bits are used to represent its transparency within that defined range (This allows much better for subtle gradations, but can have less precision for large ranges within a texel).
In DXT2 and DXT4, the pixel color values are multiplied by the alpha values before compressing (so partially transparent pixels have a color value stored darker than it shows onscreen, and completely transparent pixels always have a color value of black in the compressed texture). This can speed up some types of compositing operations, but it has the side-effect of losing color information, and can result in uglier DXT compression for some types of textures. In any case, alpha premultiplication is not supported by current Unreal Engine versions, so DXT2 and DXT4 are not options for texture formats in UnrealEd (so you can forget they exist).
Which DXT Compression to Use?
Obviously, there are some trade-offs between the different formats which make them better or worse for different types of images. Some general rules of thumb for good use of DXT textures are as follows:
- If your image has no alpha, use DXT1 compression. Using DXT3/5 will double your image size over DXT1 and not gain anything.
- If your image has 1-bit (on or off) alpha information, use DXT1 with one-bit alpha. If the DXT1 image quality is too low and you don't mind doubling image size, use DXT3 or DXT5 (which one doesn't matter, they'll give the same results).
- If your image has smooth gradations of alpha (fading in/out slowly), DXT5 is almost certainly your best bet, as it will give you the most accurate transparency representation.
- If your image has sharp transitions between multiple alpha levels (one pixel is 100%, the next one is 50%, and another neighbor is 12%), DXT3 is probably your best bet. You may want to compare the alpha results in DXT1, DXT3 and DXT5 compression, however, to make sure.
In UnrealEd 3, RGBA8 and P8 textures can be compressed to DXT1, DXT3, or DXT5 by right-clicking on the texture in the Texture Browser and selecting from the "Compress" option of the pop-up menu. Once compressed to DXT, the compression type cannot be changed in UnrealEd.
UnrealEd exports DXT textures as .DDS (Microsoft DirectDraw Surface) files. Most software does not handle this file format, so you will need conversion tools such as the Nvidia Texture Tools to convert these files into a form usable by other graphics applications.
- Nvidia Texture Tools has links to texture conversion tools, PhotoShop plug-ins, etc. for dealing with DXT/DDS data.
- Epic's version of the Nvidia Texture Tools package: http://udn.epicgames.com/pub/Content/TextureSpecifications/DXT_TOOLS.zip
- The GIMP also has a plugin which can handle DXT-compressed DDS images.