Sign in to follow this  
ehsan_the_tiamat

which texture format should I use (.TIF .JPG .BMP etc) ???

Recommended Posts

please help me with D3DXCreateTextureFromFile(...) or D3DXCreateTextureFromFileEX(...) which texture format should i use for these functions and which is faster. i have seen in many games that they use TIFF format but its too big in size why they use this format. thanks in advance.

Share this post


Link to post
Share on other sites
I love pngs because they can have an alpha channel, they're compressed but they don't use lossy compression.

- bmp: are very large and have no alpha channel but are easy to read
- tga: have alpha and can be compressed but most arn't resulting in them basically being bmp's with alpha
- gif: are palleted which reduces the number of usable colurs (you can have true colour gifs but really i'd stay away)
- jpeg: use lossy compression so loose image quality but they're very small

take your pic - I think I covered most of the major points. Pngs can be harder to read the other formats but google for libpng for a free and relativly easy to use lib for reading png's.

Share this post


Link to post
Share on other sites
DDS files load fastest and also have the advantage that they support all the funky D3D formats (including DXT compression) directly so you can do all your processing offline and store the textures on disk in the optimum format for runtime use. The only disadvantage is that they are quite large compared to some of the other compressed formats and so may not be ideal if you want to stream data over the Internet or offer your game as a very small download.

Share this post


Link to post
Share on other sites
Speaking of which, does anyone have a link to a clip of C++ code to transfer GIF images into memory? I personally use GIF for any webbaised image, I think it's the best, however from it's docs it seems to go way over my head.

Share this post


Link to post
Share on other sites
Quote:
Original post by ehsan_the_tiamat
please help me with D3DXCreateTextureFromFile(...) or D3DXCreateTextureFromFileEX(...)
which texture format should i use for these functions and which is faster. i have seen in many games that they use TIFF format but its too big in size why they use this format.
thanks in advance.


The DDS file format is a good one because there is no processing on load. This is especially helpful when you are using DXT compressed textures (which you should), since compressing them is somewhat slow. I DO not recommend using JPEG due to the compression artifacts.

Additionally, it is one of the few formats that supports MIP levels, which is handy if your mip levels cannot be computed via load, or it is expensive.

Since few appliciations save in DDS format, an easy way to manage it is to create a file cache. You check to see if the .dds file exists, if it does, you load it, if not, you load a .tiff or .png, process it, then save out the .dds version (using D3DX). This way you only get slow load times when you change your textures (but you must blow away the cache when they change).

Share this post


Link to post
Share on other sites
Make sure your DDS contains MIPs because if it doesn't loading takes even longer than usual as D3DX decompresses the DXT, computes mips and recompresses all the mip levels. We shaved several seconds off our load times by using DDS files with precomputed MIPs (using nVidia's Photoshop DDS saver plugin).

Also, if you make a DDS in a format that your card doesn't like, for example R8G8B8 24 bit format, beware. I can't remember if it was the PCs or the XBoxes, but one of them just crashed if you tried to render using these. D3DX *should* have converted it to a valid format, but I guess it doesn't always.

Also, since it hasn't been mentioned, while PNG may be smaller on disk than a DDS, a DDS using DXT will always take less video memory than a similar bit-depth PNG. This saves video memory, which saves GPU memory bandwidth (a critcal resource), and improves the usage of the texture cache. If the quality loss of a DDS DXT format is acceptable, use it. Some textures however, look better without compression. Also, note Doom3's sneaky use of DXT5 (or is it 3) with explict alpha for normal maps. They put R and B in the color channels, which get compressed better as you don't have 3 changing components, then put the G in the alpha channel. The result was higher quality compressed normal maps.

Share this post


Link to post
Share on other sites
Quote:
Original post by PumpkinPieman
Speaking of which, does anyone have a link to a clip of C++ code to transfer GIF images into memory? I personally use GIF for any webbaised image, I think it's the best, however from it's docs it seems to go way over my head.

PNG is a better format than GIF in just about every respect. The only disadvantage is slightly less widespread support but most modern browsers support PNGs pretty well. The major issue is supporting PNGs with alpha channels but since GIFs don't support alpha anyway it doesn't really affect the comparison. The other advantage of PNG is that there's a freely available library for handling PNG files (libpng).

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilDecl81
Since few appliciations save in DDS format, an easy way to manage it is to create a file cache. You check to see if the .dds file exists, if it does, you load it, if not, you load a .tiff or .png, process it, then save out the .dds version (using D3DX). This way you only get slow load times when you change your textures (but you must blow away the cache when they change).

Oh please don't do that. The quality of the DDS files that D3DX creates are really not that good. If you care about the quality of your images use a real tool. Both NVIDIA and ATI have free tools available that will compress them with much higher quality.

Share this post


Link to post
Share on other sites
Jpegs may be bad for in-game textures, but the fact is I'm not downloading your game if its 200 megs of texture data. Cube uses jpegs and they look just fine, and it lets the game have an assload of texture data in a 20 meg download - and most of that DL is the Ogg music.

edit: is there any support for jpeg2000 yet? I've been itching to play with the lossy + alpha stuff in it.

Share this post


Link to post
Share on other sites
Quote:
Original post by DrunkenHyena
Quote:
Original post by EvilDecl81
Since few appliciations save in DDS format, an easy way to manage it is to create a file cache. You check to see if the .dds file exists, if it does, you load it, if not, you load a .tiff or .png, process it, then save out the .dds version (using D3DX). This way you only get slow load times when you change your textures (but you must blow away the cache when they change).

Oh please don't do that. The quality of the DDS files that D3DX creates are really not that good. If you care about the quality of your images use a real tool. Both NVIDIA and ATI have free tools available that will compress them with much higher quality.


? DDS file is a loss-less file format - they are exactly the bits of the texture. Its impossible to have higher quality.

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilDecl81
? DDS file is a loss-less file format - they are exactly the bits of the texture. Its impossible to have higher quality.


Only DDS files containing uncompressed images are loss-less. Compressed images are not.

Share this post


Link to post
Share on other sites
A lot of bad things have been said about JPEG but you should strongly consider using it for any application where you don't need an alpha channel, especially where disk space/download size matters.

High quality JPEGs (quality 10, 11, 12 in Photoshop 6) look pretty good and it can be difficult to see any artifacts at all, and the file size is -ridiculously- smaller than any lossless format. I have a downloadable game and for one large 32-bit texture, I save the RGB into one JPEG and the alpha into another JPEG and splice them at run-time just because the file size is so much smaller than, for instance, a single 1024x1024x32 TGA/PNG. I can't believe some of the things said in that article about JPEGs, I think the author must have used super low quality compression or something. I think JPEG is very well suited to textures especially because the artifacts become even more difficult to spot on a 3D mesh that's moving/rotating/etc.

If you need the higher quality and/or alpha channel, go for .PNG files, there is rarely a better choice. DDS files may be optimal for performance/memory but the visual quality just isn't there. A lot of files that I've converted to DDS look absolutely terrible compared to PNG alternative.

Share this post


Link to post
Share on other sites
Quote:
Original post by EvilDecl81
? DDS file is a loss-less file format - they are exactly the bits of the texture. Its impossible to have higher quality.

Usually when using DDS people use DXT. DDS files do have the nice advantage that you can pre-generate mipmaps, but if you store these in an uncompressed form, they are massive. So in most cases it's not practical to use DDS for anything other than DXT. Of course there are always exceptions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this