|Version 2 (modified by Philip, 3 years ago) (diff)|
Texture file format
- Textures should be in PNG format.
- Textures must be power-of-two sizes (width and height must be 64, 128, 256, 512, etc; non-square sizes like 256x512 are fine too).
- Textures go in an art/textures/ directory (typically binaries/data/mods/public/art/textures/).
- Everything should work automatically. If you care about the details or want more control over visual quality, see the rest of this page.
PNG files are small on disk, but they expand to 32-bit raw RGBA format in video memory when they're loaded. Reducing video memory usage is important for performance, especially on lower-end hardware. DXTC (also known as S3TC) is a way to store compressed textures in video memory, in three different formats (DXT1, DXT3, DXT5). For example, a 512x512 texture is:
- RGBA: 1024 kB
- DXT1: 128 kB
- DXT3: 256 kB
- DXT5: 256 kB
Compression allows us to increase the number or size of textures by 4x or 8x without hurting performance. The tradeoff is that the compression is lossy, causing ugly artifacts in some textures.
DXT1, DXT3 and DXT5 all compress the RGB channels in precisely the same way. The only difference is the alpha channel. The Wolfire Games blog (no relation to Wildfire Games) has some examples.
- DXT1: 1-bit alpha: good for textures that are all solid, or for UI elements with non-antialiased transparency masks. Generally unsuitable for non-solid world textures - even if the texture only needs 1-bit alpha, its mipmaps are likely to need semi-transparent pixels.
- DXT3: 4-bit alpha: good for textures with a wide range of alpha values in a 4x4 block of pixels; bad for smooth alpha gradients.
- DXT5: 3-bit alpha gradient: good for smooth gradients; fine for most of the cases where DXT3 is good. You should generally use this instead of DXT3.
Graphics hardware can't resize textures downwards (e.g. when zooming out) with high quality, so we pre-compute scaled versions and store them as mipmaps. Textures that are never scaled down (e.g. GUI elements) should not have mipmaps, to save space.
There are many ways to do the resizing, with effects on the sharpness of the textures when zoomed out. The NVIDIA Texture Tools page gives examples of different filtering methods and of gamma-correction.
Automatic texture conversion
Artists should save and upload textures in PNG format, and the game engine will automatically perform the mipmapping and compression and will cache the result so that it can load quickly next time. This allows us to losslessly edit the textures and tweak the conversion settings, and avoids problems with textures being manually exported with the wrong settings.
The texture conversion settings are specified in textures.xml files. For example, art/textures/ui/global/button/textures.xml might say:
<?xml version="1.0" encoding="utf-8"?> <Textures> <File pattern="*" format="dxt5" mipmap="false" alpha="transparency"/> <File pattern="button_wood.*" format="rgba"/> </Textures>
Each <File> line matches some filenames, and applies certain settings to them. If a filename matches multiple lines, later settings will override earlier settings. The textures.xml file applies to all files in the same directory, and in all subdirectories - e.g. you can specify some common default settings in art/textures/ui/textures.xml for all UI textures, then override them with specific settings in subdirectories.
pattern="..." determines which filenames are matched by that line. The pattern can include wildcards: ? matches any character, * matches any sequence of zero or more characters.
The available settings are:
- kaiserwidth="3.0" kaiseralpha="4.0" kaiserstretch="1.0"