Miptex

From Valve Developer Community
Jump to: navigation, search

Miptex is an 8-bit texture format used by Quake Quake and GoldSrc GoldSrc. They can be stored individually with a .mip file, but most tools and engines expect them to be embedded in a BSP or WAD.

Miptex are always a multiple of 16, and contains the full-size texture plus 3 smaller mipmaps, although these mipmaps are only used by the software renderer (the OpenGL renderer uses the GPU to generate 32-bit mipmaps). Some programs also will use these mipmaps, such as TrenchBroom TrenchBroom.

Half-Life extends the miptex format to add a dedicated palette, instead of relying upon an external shared palette. This is an uncompressed 768 byte array of 256 24-bit RGB values, like Quake1-16px.png Quake's palette.lmp.

Technical

The header of a miptex lump can be represented by the following C struct (from 🖿client/bspfile.h in the Quake I source code release):

#define	MIPLEVELS	4
typedef struct miptex_s
{
	char		name[16];
	unsigned	width, height;
	unsigned	offsets[MIPLEVELS];		// four mip maps stored
} miptex_t;
Note.pngNote:unsigned is 32-bits.

It is then followed by raw 8-bit image data for each mipmap, at the offsets relative to the start of the lump.

For WAD3 miptex, the final mipmap is immediately followed by a 16-bit signed short enumerating the number of palette indices (should always be 256). That is then followed by raw RGB888 image data, representing the palette.

Icon-Important.pngImportant:Even though the palette is always supposed to be 256 values (256 * 3 = 768 bytes), some wad editors will pad out the data with garbage at the end of the lump. Therefore, palette size should not be assumed based upon data size.[1]

Derivatives

Quake II Quake II encapsulates a modified version of miptex in a file format called WAL, which is always stored individually per texture and contains additional surface metadata for compilers. Variations of WAL, such as Daikatana WALs, M8, and M32, are used in other Quake II Engine Quake II Engine games, and add some additional features.

References

  1. Fail to read palette for some texture lumps in some Valve WADs · Issue #4254 · TrenchBroom/TrenchBroom