DDS Texture compression resources

Update: If I understand correctly, DDS texture display and compression should work correctly in all current versions of Blender. If you are still using 2.49, the note below applies.

Original Post:
(Special thanks to VenomSeven for originally informing me about Blender’s DDS support, and to cyborg_ar for first telling VenomSeven. And thanks to whoever put the feature there to begin with. :D)

It’s a lesser known fact in the Blender community, but Blender’s Game Engine supports the industry standard DDS texture format. Dim and I have been doing a bit of reading and testing on the subject, and I thought I would share some of our findings thus far.

What is DDS?
DDS stands for “DirectDraw Surface”. It was originally developed for use with DirectX, but it is also compatible with OpenGL. Though DDS is technically more than a simple image format, it is often used as a lossy image compression format for games.

Why use DDS?
Unlike other image compression formats, DDS files remain compressed in memory. This is especially helpful when you are trying to cram as many textures as possible into a limited amount of video card RAM.

For example, some modern game consoles have only 256 MiB of available video memory. A 16-bit 1024x1024 Targa image would take 2.4 MiB when uncompressed in memory. However, the same image stored in DDS format using DXT1 compression would take only 630 KiB in memory. (Most of that information was taken from the Gamasutra article below.)

Downfalls of DDS
Certain DDS formats are lossy compression methods, which means you will lose detail and color information from your original image. If you do not use the compression carefully, you may lose a good deal of quality. Read the articles below to gain a better understanding of what each compression method does and when it is useful.

How well does it work with Blender?
I use the GIMP DDS plugin to output DDS files, and I’ve found that textures made using no compression don’t seem to work in Blender. However, DXT1, DXT3, and DXT5 textures all appear to work correctly, and these three are the most useful in terms of compression.

Further reading:
http://www.poopinmymouth.com/tutorial/dds_types.html
Ben Mathis explains several compression formats on his website. Some of this is specific to the Photoshop DDS plugin, but several of the methods are also available in the GIMP plugin. A nice introduction with images showing comparison between the different formats.


Riccard Linde explores some of the pitfalls of DXT1 compression and suggests multiple solutions in this well written Gamasutra article. (Sadly, the website uses lossy jpeg compression for the article’s images, so it is difficult to make out the difference between some of the comparisons.)

Tools:
Cross-Platform
GIMP DDS plugin (Ubuntu users: “sudo apt-get install gimp-dds” or install gimp-dds through Synaptic)

Windows
nVidia DDS plugin for Photoshop
Paint.NET DDS plugin
The Compressonator (DDS conversion tool from AMD/ATI)

Note: (pre-2.5) ideasman42 confirmed that Blender (pre-2.5) uncompresses DDS textures in the video memory. For 2.49 and previous, it seems that there is no runtime benefit to the DDS format. Proper handling of the DDS format has been implemented in 2.5 and later, but in 2.49 it is still useful for making your filesize smaller (as is the case for internet games). If filesize is not a concern, then go with PNG or Targa for higher quality. (Reference: http://blenderartists.org/forum/showthread.php?t=156435)

I’ll just add a little more info to Blendenzo’s article as to what this means for an artist. This is a mixture of info from the above two sources, as well as my own experience.

The three primary compression methods to be concerned with as an artist are DXT1 and DXT5. There are many other types but they have various pros and cons, and some of them are only available on NVIDIA hardware, or exclusively ATI. The two I’ve mentioned here are by far the most universal and most flexible.

A few words about how DXT compression effects your images. The way the compression works is that it takes a 4x4 square of pixels and saves only two of the three RGB channels for that square. For each 4x4 square, it alternates which channel it drops. What this means is that sharp lines, areas of fine, high contrast, and fine detail, will all end up with some artifacts. In general, this isn’t terrible. Because of the alternation within the algorithm, the eye is successfully tricked, but if images are too small, it becomes hard for the compression to go unnoticed. I don’t recommend going below 256^2 images, and certainly not below 128^2. DXT works wonderfully for 512^2 and higher.

DXT1: This format is an 8:1 compression ratio (it is very small, so a 1MiB image file can be reduced to 128KiB) and it has reasonably lossy RGB channels, but each channel for the most part remains intact, and the artifacts are not obvious. However, it saves the alpha channel as a 1-bit channel (essentially what “clip alpha” does in the GE), so it is not appropriate for smoothed alpha surfaces. For foliage, or other situations where “clip alpha” is desired, this filetype may very well be appropriate, but I can’t seem to be able to get 1-bit alpha to work in Blender. If anyone else can, please speak up! DXT1 is also NOT good for normal maps and creates a wide variety of terrible artifacts. Basically, DXT1 should be used for diffuse and specular maps because of the high compression ratio, but not for much of anything else. There is slight banding in the Diffuse or spec maps, but they can be taken care of (see the gamasutra article above).

DXT3: I cannot recommend this algorithm. It seems pretty much the same as DXT5, but the alpha channel has severe banding.

DXT5: This algorithm has a 4:1 ratio of compression, so it is not as small as DXT1. There is little RGB difference, however, it does have an 8-bit interpolated alpha channel, so it is useful for all alpha applications. The interpolation means it doesn’t have the severe banding associated with DXT3. Because of the lesser compression, there are less artifacts on the normalmap than in DXT1, but they are still there. This would be most useful with organic, or highly noisy maps, but not clean, sharp edged ones, where an uncompressed Targa or even .png maybe the best choice. Like DXT1, DXT5 will eliminate much or your fine detail within a normalmap.

Summary:
DXT Compression is useful for:
Scenes with many large texture files that need to remain in memory
Internet delivery with small filesize

DXT Compression is NOT useful for:
Images that must look very clean or remain lossless

DXT1 has an 8:1 compression ratio and is useful for:
Diffuse maps
Specular maps
“Clip Alpha” foliage (provided it works in the BGE)

DXT1 is NOT useful for:
Normalmaps
Smooth Alpha maps

DXT5 has an 4:1 compression ratio and is useful for:
Normal maps
Alpha
Any other map (though it is a larger file than DXT1)

DXT5 is NOT useful for:
Images requiring high visual fidelity

veyr useful article, thanks

and a question: if the dds texture is stored compressed in video memory then I assume some time is required to decompress them before placing on the mesh, no? if yes, how does it affect performace?

It shouldn’t affect performance negatively at all because it doesn’t decompress unlike other formats. It should actually save you performance for that reason.

I’ve been wondering about this since I saw a previous thread about it. Thanks for looking into it guys, I’m sure many people will find this as valuable information.

I’ll probubly need DDS Testures soon as well, so I’ve ‘bookmarked’ this for later reference.

Cheers

Glad to be of assistance. It’s my hope that this format is looked into a little more by people. It can really optimize projects and allow them to use more, larger textures within a scene. Image how much detail you can have with DDS if 1 DDS file can equal 8 targas.

I would like to bump this thread from 2009.

Is DDS still as relevant for performance using BGE? Is it the preferred format, Blender always save images as PNG as default.

Is it recommended to convert these files to DDS for performance?

p.s. DXT3 is for alpha clip if You need more precise (antialiased) alpha. DXT5 is for alpha blend.