Perfect Texture Format (DDS vs TGA vs PNG)

Perfect Texture Format (DDS vs TGA vs PNG)

Share and discuss visual creations and creation practices like texturing, modelling and musing on the meaning of life.

Moderators: MR.D, Moderators

User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Perfect Texture Format (DDS vs TGA vs PNG)

Post by SpliFF »

I can see this debate has raged awhile and opinions differ but I'm having trouble working out the factual information from the opinions and out-of-date stuff. Basically I'm at the start of my mod work and I want to use the "best" texture format going forward.

I'd prefer the format not be lossy and to be capable of mip-mapping. It would be good for it to have good performance on game start and during the game. It should also be reasonable easy to load in image software. I know I can't have everything but my preference would be for performance over other concerns (I'll be running games with very high unit counts).

My preferred format is currently PNG, but I was wondering if anyone could shed some light on the matter as far as the current engine goes.

PNG (32bit) / TIFF
Lossless
Very good compression (use LZW or Deflate for Tiff)
Excellent image software support
No embedded mip-maps

TGA
Lossless
Low/No compression
Packs well in archives
No embedded mip-maps

DDS DXT3
Lossy
Supports embedded mip-maps
Excellent compression
Texture artifacts / blurring
Requires plug-in for most image software

DDS DXT5
Lossy
Supports embedded mip-maps
Excellent compression
Texture artifacts / blurring
Requires plug-in for most image software

DDS R8G8B8A8
Uncompressed
Supports embedded mip-maps
Inefficient VRAM usage
No artifacts
Requires plug-in for most image software

Questions:

Does Spring create and use mip-maps from loaded PNGs? If so is this a slow process?
Answer(s): Sometimes and maybe. Automatic compression and mipmapping of all image formats except DDS happens on load if "compress textures" is enabled in the players Spring Settings. This is off by default in current Spring builds. The second answer is maybe because I don't have a benchmark for how noticeable the loading delay is.

Also, given that mod archives are Zip/7zip are there actually any download savings from DDS/PNG compression? (you generally can't compress a compressed file much further)
Answer: TGA compresses the best. The others don't compress much further than they already are.

My Conclusions
(for those not interested in the whole rambling discussion)

Convenience / Development / Original file:
PNG32, TIF or TGA. All are lossless, well supported everywhere and have alpha. TGA is best if you don't want to distribute as DDS because it packs well in mod archives well and loads quickly.

Units with teamcolor:
DDS(DXT3) with auto mipmaps (unless teamcolor is graduated, then DXT5)

Features / Maps / Units with no teamcolor:
DDS(DXT1) with auto mipmaps

Specular / Glow Map / Transparency:
DDS(DXT1) with auto mipmaps

I'll be working in PNG at high resolutions then using a batch conversion tool like The Compressonator to downsample and generate the DDS files prior to packaging for releases.

I believe this covers everything I need except in some fringe cases like particles / sprites etc where DDS is incompatible or mipmaps overkill.
Last edited by SpliFF on 25 Mar 2009, 16:50, edited 3 times in total.
User avatar
Peet
Malcontent
Posts: 4382
Joined: 27 Feb 2006, 22:04

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by Peet »

DDS stays compressed in the video memory which is its primary advantage. PNG doesn't really compress further than tga when it's in an archive so it's not particuarly useful.
User avatar
smoth
Posts: 22306
Joined: 13 Jan 2005, 00:46

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by smoth »

use what ever makes your work flow effiecient.


ps. we don't use 24 bit, 24 bit has no alpha channel
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by SpliFF »

I was thinking the other formats would be converted to S3TC but I can't tell from the code I've seen if that's the case.

I did learn something interesting from the source though. If I'm not mistaken about 400 lines of texture loading code could be replaced with a single function ilutGLBindTexImage or (ilutD3D8Texture for DirectX). The current code even splits out DDS loading to a seperate class despite DevIL having supported DDS for years.

I'm quite tempted to jump in and rewrite the whole CBitmap class but I'm curious to know whether there's a valid reason for keeping the current process.
Warlord Zsinj
Imperial Winter Developer
Posts: 3742
Joined: 24 Aug 2004, 08:59

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by Warlord Zsinj »

For IW we use TGA for private currency because of its lossless nature, but whenever packaging for distribution to players (ie: beta releases), we will convert to dds.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by jK »

1. yes, spring generates the mipmaps for all loaded textures (and even compress them on runtime if CompressTextures is enabled). And yes this process is slow and can cause a lag up to 2sec for large images.
2. you forgot DXT3, which has a much better alpha channel quality (than DXT5) in my experience.
3. also it is not spring that flips the texcoord it is upspring that flips them (long story why it does so, but it has to do with dds).
4. if you would use DevIL to handle dds wouldn't it first decompress the texture just to upload it uncompressed to the gfx?
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by SpliFF »

Here's an informative primer on texture formats and DDS. I couldn't find any info on whether DevIL has good or bad performance with DDS (that primer is 4 years old). I guess I can ask the DevIL people directly but I would hope it wouldn't do much more than shunt the DDS data across to the appropriate ARB extension. Even if that isn't the case I would say the CBitmap class could really use a cleanup. Is that Quicktime stuff even used? I think I'd enjoy messing with it when I can find some time.

My plan now is to do all work and testing in PNG (which despite comments made on forum is EXACTLY the same quality as TGA - ie, lossless). Then when I do a release I'll just pipe all the PNGs through a DDS conversion batch script to generate the mipmaps (rather than rely on the engine to do them on load every game).

Hopefully I won't have to reload the textures through Upspring when I swap formats because that would be a pain.

EDIT: Found an answer to whether DeviL uncompresses DDS:
http://www.ogre3d.org/forums/viewtopic.php?p=100965
It shouldn't if you tell it to keep DDS compressed, which we do when we use it to load DDS in GL. All DevIL does is strip the metadata out into readable attributes - we then load the compressed data up to GL as-is. Also, DevIL only handles DDS under GL, in D3D9 DDS loading bypasses DevIL entirely and it gets directly loaded in compressed form by D3D, since DDS is a binary dump of the D3D surface(s) anyway.

Both options therefore pass the compressed data through to the driver without decompressing it.
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by SpliFF »

Here's an interesting one, from the Google/Nvidia texture tools page:
http://code.google.com/p/nvidia-texture-tools/
DXT compression is based on Simon Brown's squish library. The library also contains an alternative GPU-accelerated compressor that uses CUDA and is one order of magnitude faster.
Sounds like a great idea, since the GPU would be largely idle during Spring loading. You could just shove DevILs PNG/TGA/Whatever data straight into the GPU and let it worry about the texture compression.

Of course, being CUDA I guess it's an Nvidia only thing.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by lurker »

CompressTextures uses what compression method?

And DXT3 vs. DXT5 really depends on a lot of things. DXT3 alpha is flat 4-bit, while DXT5 has 2-bit interpolation between two values it chooses for each 4x4 block, much better on gradients.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by Argh »

Lossless format suggestions:

DDS 8:8:8:8: Best quality, period (because you're controlling each mip step, instead of letting Spring create the mips, which is important, as it doesn't do a very good job).

Largest filesize. Won't compress very well (i.e., 7zip / zip doesn't reduce as much as other formats). Eats as much texture RAM as any other image file compressed by Spring.

TIF: Highest-quality lossless format without mip support. Compresses fairly well. Must be flipped vertically- texture in UpSpring is the opposite of what you're actually going to see in game.

PNG: Very high quality lossless format. Compresses moderately, but takes longer than TIF for DeVil to process. Same issues with UpSpring as TIF.

I can't recommend using any of the lossless formats other than DDS 8:8:8:8, and it's huge filesize and lack of advantages other than being perfect fidelity make it questionable for larger projects.



Lossy format suggestions:

Important Notes:

1. You must make every mip level(automatically, just set that setting), or DDS files won't work properly in Spring.

2. Only DDS DXT1, DXT3, DXT5 and 8:8:8:8 are supported. You can't use the more exotic formats at all.

DDS DXT1: Low levels of loss in RGB channel, only supports 1-bit alpha. Great compression, and uses 1/4 of the texture RAM of lossless formats. Ideal for items that aren't using detailed alpha channels.

Hard to use, if you want professional results. All of the DDS formats require quite a bit of practice to get good results out of the filtering available in the DDS plugins / conversion tools available. If you don't have Photoshop, I recommend using the plugin for GIMP or ATi's Compressionator application, to get good control over the settings. However, I'm just going to be real and say that, having tried all of that out... the Photoshop plugin is markedly superior, in terms of detailed control.

DDS DXT3: Low levels of loss in the RGB channel, alpha is lossy 8-bit but tends to come out "crisp", due to compression algorithm used. Uses half the texture RAM of lossless formats. Needs sharpening applied to mips for good results, and tends to work best if you accept some high contrast where you might want subtlety ideally. Good for "glow" style teamcolor, where the alpha compression is acceptable, but works fairly poorly for "paint" style, where you need more subtle alphas.

Can sometimes cause major artifacts in RGB channel (blocks of area where the compression method doesn't handle the area well), which are very hard to get rid of.

DDS DXT5: RGB channel is usually a little more lossy than DXT3. Alpha channel is more "soft" than DXT3. Uses half the texture RAM of lossless formats. DXT5 is tricky, and you may have to adjust sharpness / contrast between mips per piece, due to the way that the compression works- it's not as consistent as DXT3, in terms of artifacts.

Alpha is better for "paint" style teamcolor. Works far worse for "glow". Artifacts may shift color values enough that it's a problem for texture2, where tiny changes in RG values make a big difference in terms of what you see in the engine.

Can sometimes cause major artifacts in RGB channel (blocks of area where the compression method doesn't handle the area well), which are very hard to get rid of.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by rattle »

DDS all the way

DXT5 for texture1
DXT1 for texture2

If you happen to use normal maps then DXT5 for them as well if you use that Doom3 trick and move the red channel into the alpha. There's also the possiblity to reconstruct the z-value and use DXT5 (XY) instead but I don't think this is useful in an RTS.


I've had bad experiences with PS and PNG in the past, because of the way PS stores the alpha, but smoth never had any. Either way, I'd stick with DDS since it can be lossless as well if you need a lossless format. Filesize will be larger than the other uncompressed formats because of the mipmaps.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by Argh »

I think that DXT1-3-5 is all arguable for texture1, depending on a variety of things. I tend to get better overall fidelity with DXT1, but usually need the alpha channel. For "glow" teamcolor, DXT3 seems to work better than DXT5.

I agree about DXT1 for texture2, there really isn't a better choice.
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by rattle »

From what I read in a number of articles DXT3 has no advantage over DXT5 in regards to colors. The difference is that in DXT5 the alpha gets interpolated.
User avatar
SpliFF
Posts: 1224
Joined: 28 Jul 2008, 06:51

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by SpliFF »

Argh wrote:DDS DXT3: Low levels of loss in the RGB channel, alpha is lossy 8-bit but tends to come out "crisp", due to compression algorithm used. Uses half the texture RAM of lossless formats.
DXT3 alpha is 4-bit, not 8-bit. Wikipedia: "DXT3 converts 16 input pixels into 128 bits of output, consisting of 64 bits of alpha channel data (four bits for each pixel) followed by 64 bits of color data"

Wikipedia also clearly states that all DXT (S3TC) compression ratios are 4:1 except DXT1 which is 8:1. Where is your "half the texture ram of lossless formats" statement coming from?
Argh wrote:RGB channel is usually a little more lossy than DXT3.
Wikipedia: DXT5 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 DXT2 and DXT3).

How can data "encoded the same way" be more lossy?
Argh wrote:TIF: Highest-quality lossless format
Not picking on you Argh, but seriously. Read that comment again! How can something that's 'lossless' have higher quality than something else that's lossless? 32-bit TIF, TGA, BMP and PNG all have exactly the same quality. Which is exactly the same quality as it was in your editor (minus layers and metadata). The relevant difference is that PNG has excellent lossless compressor whereas the others use RLE or nothing.

Come on Argh! I appreciate your effort but the point of this thread was to break through the assumptions and misinformation.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by lurker »

Oh, right. The alpha interpolation is 3 bits because alpha takes less space. So that should just about never look bad compared to a flat 4 bits; comments, jK?

But I'm confused as to how it's even possible to use DXT1 as a main texture, as has been implied, because where you don't have teamcolor/alpha it doesn't encode any color info at all.
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by trepan »

jK: mipmaps are generated for almost all loaded textures :)
User avatar
rattle
Damned Developer
Posts: 8278
Joined: 01 Jun 2006, 13:15

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by rattle »

lurker wrote:But I'm confused as to how it's even possible to use DXT1 as a main texture, as has been implied, because where you don't have teamcolor/alpha it doesn't encode any color info at all.
That was a problem in the past when using layer transparency in a certain adobe program, which forgot to store color information when the layer transparency value is 0... which is why I use DDS and store alpha channels.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by Argh »

@Spliff: um, I'm telling you, DXT3 and DXT5 don't come out the same way. I really don't care what the Wikipedia said on that, the results are obviously different, and I've done many comparisions between them (ATi's Compressionator is a good tool for this). I don't know why this is the case, but it is, with every compression tool I've used.

Maybe it uses a more aggressive method to keep the samples at the same size (since DXT3 and DXT5 tend to come out nearly exactly the same size, but DXT5 has more bits in the alpha channel), but DXT5 tends to come out blurrier, with more artifacts on the RGB channel, but comes out a lot better for alphas with subtle grays.

The "half the texture RAM" is completely different than the compression ratio, which is how much the image size is smaller, per mip, than a lossless format (i.e., storing every mip as a physically separate image file, like a lot of old games used to do). DDS is totally different than non-DDS textures- GPUs handle them differently, if the engine is handling them properly. Which, because Spring is OpenGL, I'm still not 100% certain it's doing. I read some articles which suggested that OpenGL isn't making use of DDS like it should be, but frankly that's not my area of expertise so IDK.

While the distinction between TIF and PNG is meaningless in Spring, they aren't the same thing.

TIF is truly lossless, and is very close to being raw image data. It can contain different color spaces, for example, which PNG (and for that matter DDS 8:8:8:8) does not support. There's a reason why TIF is TIF, and not PNG.

Again, that doesn't actually matter in Spring. Except for one thing. Because PNG uses a lossless compression, it takes a lot longer to decompress and make the mips, per model, which takes awhile, given Spring's lazy-loading system. If you're going to use a lossless format, use TIF, it seems to be fastest, and if in a 7zip / zip, it compresses almost as well as PNG.

Basically, though... if you're not using DDS, you're doing it wrong. Doesn't matter, if quality is more important to you than performance- you can have either one.

I'm not entirely happy with DDS DXT1-5, as the compression artifacts are obnoxious and occasionally cause real problems, it's a real pain setting up the filters in a way that works really well, etc., but even if you're a fanatic about quality, you should be using DDS 8:8:8:8 over other formats.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by lurker »

Argh wrote:@Spliff: um, I'm telling you, DXT3 and DXT5 don't come out the same way.
Sounds like a quirk of the compressor.
Argh wrote:The "half the texture RAM" is completely different than the compression ratio, which is how much the image size is smaller, per mip, than a lossless format (i.e., storing every mip as a physically separate image file, like a lot of old games used to do). DDS is totally different than non-DDS textures- GPUs handle them differently, if the engine is handling them properly. Which, because Spring is OpenGL, I'm still not 100% certain it's doing.
What in the world are you talking about? Anything that's not DXT-compressed will be stored as a plain 8:8:8:8 bitmap, anything that is will take either 1/4 or 1/8 the ram, assuming the same mipping. Are you confusing unmipped textures and mipped DXT-compressed versions? Even that is 1/3, rather than 1/2.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Perfect Texture Format (DDS vs TGA vs PNG)

Post by Argh »

What in the world are you talking about? Anything that's not DXT-compressed will be stored as a plain 8:8:8:8 bitmap, anything that is will take either 1/4 or 1/8 the ram, assuming the same mipping.
No, that's just compression ratios for stuff that's not being used atm. Uncompressed it's not the same. But apparently there's a significant gain because of access times.

Meh... I need to go look at Spring again. Are we actually using the equivalent of dwFourCC in DirectX? I know Spring's ripping DDS, but I'm not sure about how it's shoveling that into the GPU.
Post Reply

Return to “Art & Modelling”