First, what is DDS? It stands for "direct draw surface", but as a file format, it's basically a file whose structure is the same as the memory layout for a texture in DirectX. It's a simple image format but it does two useful things for X-Plane (or any other 3-d application):
- It can contain compressed images using the same compression OpenGL and DirectX use (DXT compression).
- It can contain mipmaps - smaller versions of the same image.
There would be three fundamental benefits to using DDS files:
File size on disk (and download).
PNG is a losslessly compressed file format. This kind of compression (the internal algorithm used by PNG is the same as ZIP files) preserves the image, but the reduction in image size is a function of how "simple" the image is. Images with a lot of detail and high frequency information (rapid changes in color) do not become much smaller than the amount of VRAM they use when compressed in a PNG. A lot of the terrain textures we use (4 MB in VRAM) are still 3 to 3.5 MB on disk!
By comparison, the texture compression used by OpenGL is lossy - the image looks worse. But the image is reduced by a factor of 4 to 8, every time. So one of these images (4 MB in VRAM when uncompressed) would be 1 MB with S3TC compression (available in a DDS file). Even for very simple PNG files, you rarely see such a reduction in size, so .dds files would be smaller, meaning faster updates and downloads.
(Another thought: if a PNG file is smaller than its VRAM requirement, it means the PNG file has lots of areas with the same color. This means the PNG file is WASTING VRAM! We encourage our artists to make use of every little pixel in an image, and this means that PNG files that are well-created for X-Plane tend to get relatively little benefit from PNG's internal compression.)
Image load time is a significant factor in X-Plane. There are several reasons why DDS files could load a lot faster than PNG.
- The actual DDS file is smaller - less data to load and process means faster performance.
- Because the DDS file can contain smaller copies of the image, X-Plane doesn't have to load a huge image and reduce its size using the CPU - it can just load the small version in the file.
- When compressed textures are used (and they almost always should be, see my previous blog post) it takes CPU power to compress the image, slowing down load. A DDS file containing a compressed image can be sent directly to the card!
Now one is a little bit tricky. First, please review my previous blog post, which argues that texture compression is the best way to maximize VRAM. A DDS file will look better than a PNG file when texture compression is on. Here's why:
The S3TC compression formats specify an EXACT way to "uncompress" and draw a compressed image. But there are MANY possible ways to compress the image. Remember that S3TC is a lossy compression - the compressed image is only an approximation of the original.
Well, it turns out that algorithms that find the best approximation of an image using S3TC are slow. So we can't use the highest quality compression inside X-Plane when compressing PNGs for the graphics card - it would be too slow.
But the image in a DDS file is already compressed -- because someone else has compressed it when creating the scenery. When converting the scenery from PNG to DDS that author can use a very slow, very high quality compression algorithm to make the DDS files. It might take 12 hours to convert the entire package from PNG to DDS, but who cares? It's something you do once and then everyone enjoys better looking images.
In other words, because the compression is done ahead of time for a DDS file, a higher quality algorithm can produce better approximations of the original images. Since we want to use compression anyway (to optimize our use of VRAM) this is a good thing.
When is DDS not appropriate?
Any time an image must not be compressed, DDS is inappropriate, and PNG is best. There are three basic cases in X-Plane where we avoid compression (see my previous blog entry for the real examples):
- Any time we need to preserve tiny detail accurately, like lettering and text.
- Any time the alpha channel needs to be smooth.
- Any time a texture is magnified so large that small color changes between two pixels is noticeable. (For example, compressing the color washes used for the sky make obvious artifacts.)