Introduction
WAD3 is the lump archive of Valve’s Half-Life engine
(GoldSrc). It holds wall textures, pictures and fonts. Map compilers read textures from the WADs a
map names, and either copy each one into the level or only its header, leaving the game to load it
from the WAD. Unlike Quake’s WAD2, every texture and picture carries its own palette. It is not the
Doom engine WAD, whose header starts IWAD or
PWAD.
Header
All numbers are little-endian. Valve’s writer puts the first lump at offset 12 and the directory after the last lump; the header gives its place.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | identification | The letters WAD3 (57 41 44 33) |
| 4 | 4 | numlumps | Signed 32-bit count of directory entries |
| 8 | 4 | infotableofs | Signed 32-bit offset of the directory from the start of the file |
Valve’s tools also read WAD2 files. Their lump builder writes WAD3 when it
stores palettes with the lumps, which it does by default, and WAD2 with the
-8bit option.
Directory
The directory is numlumps entries of 32 bytes each.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | filepos | Offset of the lump’s data from the start of the file |
| 4 | 4 | disksize | Bytes the lump takes in the file |
| 8 | 4 | size | Bytes after decompression; the same as disksize for an uncompressed lump |
| 12 | 1 | type | Lump type, see below |
| 13 | 1 | compression | 0 = none (CMP_NONE), 1 = LZSS (CMP_LZSS) |
| 14 | 1 | pad1 | Padding; the writer leaves it 0 |
| 15 | 1 | pad2 | Padding; the writer leaves it 0 |
| 16 | 16 | name | Name, ended by a NUL, so at most 15 characters; the rest is zero |
Valve’s tools match names without regard to case. The lump builder stores them in upper case.
LZSS compression is declared, but the released writer marks it “FIXME: do compression” and stores the bytes it is given, and the lump builder gives it 0. No released program of Valve’s that has source writes or reads a compressed lump.
Lump types
type 0 is TYP_NONE and 1 is TYP_LABEL. Codes from 64
(TYP_LUMPY) are 64 plus the number of the lump builder command that made the lump:
| Code | Letter | Command | Layout |
|---|---|---|---|
| 64 | @ | palette | Palette |
| 65 | A | colormap | Colour map |
| 66 | B | qpic | Picture |
| 67 | C | miptex | Texture |
| 68 | D | raw | Raw block |
| 69 | E | colormap2 | Colour map |
| 70 | F | font | Font |
The map compiler finds textures by name and ignores the type. The lump builder pads each lump with zero bytes to a multiple of 4 and counts the padding in both sizes.
Embedded palette
Pictures, textures and fonts written by Valve’s builder (without -8bit) end with their
palette:
| Size | Field |
|---|---|
| 2 | Number of colours, unsigned 16-bit; the lump builder writes 256. Valve’s font maker,
makefont, writes 768, the number of bytes that follow |
| 768 | 256 colours of red, green and blue, one byte each |
Xash3D accepts either 256 or 768 in the count of a font’s palette.
Texture (miptex)
A wall texture with four sizes: full, half, quarter and eighth, then its palette.
| Offset | Size | Field |
|---|---|---|
| 0 | 16 | Texture name, NUL ended |
| 16 | 4 | Width, unsigned; a multiple of 16 |
| 20 | 4 | Height, unsigned; a multiple of 16 |
| 24 | 16 | Four unsigned 32-bit offsets of the mip levels, counted from the start of this block |
| 40 | width × height | Level 0, one palette index per pixel, rows from the top (where the builder puts it) |
| offset 1 | width/2 × height/2 | Level 1 |
| offset 2 | width/4 × height/4 | Level 2 |
| offset 3 | width/8 × height/8 | Level 3 |
| after level 3 | 770 | The embedded palette, then padding to a multiple of 4 |
The four levels together take width × height × 85 / 64 bytes. When a map compiler leaves a texture in its WAD, it copies only the 40-byte header into the level and sets all four offsets to 0.
Transparent textures
A source picture whose name begins { has pure blue (0, 0, 255) as its transparent
colour. The builder moves it to palette index 255, so index 255 is transparent and its palette entry
is that blue. In the smaller levels a pixel is made 255 when 40% or less of the pixels it covers
(rounded down to a whole count) are solid.
Names with a meaning
As in Quake, + followed by a digit or a letter marks the frames of an animation, and the
map compiler gathers the other frames of any + or - texture it uses, by
replacing the second character with 0 to 9 and A to
J.
How an engine reads textures and decals
Valve has not published the Half-Life engine. The rules below are those of Xash3D FWGS, an open source engine that runs Half-Life data; they are not taken from Valve’s code.
| Case | Reading |
|---|---|
Texture with { in its name, not used as a decal | Palette index 255 is transparent |
Decal with { in its name, palette colour 255 pure blue (0, 0, 255) | A decal in its own palette colours, with index 255 transparent |
Decal with { in its name, colour 255 anything else | A gradient decal: the whole decal has colour 255 of the palette, and each pixel’s index (0 to 255) is its opacity |
Name starting ! or water (any case) | Water: palette colour 3 is the colour of the underwater fog, and the red byte of colour 4 is its density |
Picture with any pixel of index 255, other than the console
background (conback) | Index 255 is transparent |
Names starting + that differ only in the second character | An animation,
played 0 to 9 in turn at 10 frames a second (5 for a texture without a
palette of its own, drawn with Quake’s). A to J form a second set, shown
when the object that carries the surface is in its other state |
Names starting - that differ only in the second character | Random tiling: each place on a surface takes one frame of the set, chosen from random numbers made by the engine |
Name starting ! or *, and outside Quake-compatible mode also
water or laser (any case) | A liquid. The texture repeats every 64 units of the surface, and the coordinate s moves by 8 sin(t / 8 + time), with time in seconds, and t likewise by s |
A player’s spray logo is a file of its own, tempdecal.wad: a WAD3 with exactly one lump.
The lump is laid out as a texture of at most 256 × 256 pixels whose first level
starts at offset 40. Its directory type is 67 for a logo in palette colours, with index 255
transparent, or 64 for a gradient decal in colour 255 as above; here 64 does not mean a bare palette.
Xash3D, writing this file, names the lump tempdecal and the texture {LOGO, fills
the palette of a gradient decal with a ramp from black to the logo’s colour, and counts the padding after
the palette in neither size.
Xash3D also reads the directory byte at 13 as a set of attribute bits (1 read-only; 2, 4 and 8 reserved
for compressed, hidden and system), where Valve’s wadlib.h calls it
compression.
Picture (qpic)
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | Width in pixels, signed 32-bit |
| 4 | 4 | Height in pixels, signed 32-bit |
| 8 | width × height | One palette index per pixel, row by row from the top |
| after the pixels | 770 | The embedded palette, then padding |
Font
A proportional font: a header, a table of 256 characters and one bitmap 256 pixels wide.
| Offset | Size | Field |
|---|---|---|
| 0 | 4 | Width, signed 32-bit; the lump builder writes the row height here too, and makefont the width of a character cell, 16 |
| 4 | 4 | Height of the bitmap in pixels, rounded up by the lump builder to 16, 32, 64, 128 or 256; makefont always writes 128 |
| 8 | 4 | Row count: the number of text rows packed into the bitmap |
| 12 | 4 | Row height: the height of every character in pixels |
| 16 | 1024 | 256 character entries of 4 bytes: signed 16-bit start offset into the bitmap, then signed 16-bit width in pixels. Unused characters are zero. |
| 1040 | 256 × height | Bitmap, one palette index per pixel. Space the builder did not write to is 255, as far as it prepares it (160 rows). |
| after the bitmap | 770 | The embedded palette, then padding; in a makefont font the 64 reserved bytes come first |
| after the palette | 64 | Written by makefont only: reserved. It allows for them in the lump’s length, clears the whole lump and never writes there, so they are 0 |
Row r of a character (0 to row height − 1) is width bytes at bitmap offset start + r × 256.
Fonts made by makefont
makefont draws a Windows typeface into three lumps of type 70, font0,
font1 and font2 (by default Arial at 9, 11 and 15 points). Each is 34,642
bytes before padding: the 16-byte header, the character table, a 256 × 128 bitmap, the 2-byte count,
768 bytes of palette and the 64 reserved bytes. The row height is the point size plus 5, the row count
6, and only characters 32 to 127 are drawn, 16 to a row, in cells 16 pixels wide: a character’s start
offset is its row’s top × 256 plus its cell’s left edge. In the bitmap, index 255 is transparent, 192
the character and 32 its dark outline; the palette is a ramp of greys from black.
Palette
Three bytes (red, green, blue) for each colour, with no header or count. The command takes an optional first and last colour; without them the lump holds colours 0 to 255, 768 bytes.
Colour map
Light-level tables: levels tables of 256 bytes, each mapping a palette index to another,
followed by one byte that gives the number of full-bright colours at the top of the palette. In a
colormap lump the first table maps every index to itself and the later ones grow darker,
while the full-bright colours stay as they are. colormap2, which the source calls
experimental, has the same shape without the identity table: its tables run from a chosen brightness
down to black.
Raw block
Width × height palette indexes with no header: neither the size nor a palette is stored.
In the explorer
A dropped .wad file that starts WAD3 opens as a Half-Life WAD3.
- Structure and tables: the header, every lump and the directory in a tree, and a paged table of all lumps; open a row for the lump’s fields and pictures. Animations and random tiles are gathered into a table of their own.
- Moving textures, as Xash3D draws them:
+sets play at 10 frames a second and liquids warp, each in an animated view with Play and a time slider; a-set is shown as an example of random tiling. - Pictures: every level of a texture with its own palette, pictures, fonts with
their bitmap and a table of all 256 characters, palettes, colour maps, spray logos, and any raw
block as palette indexes at a choice of widths. Textures named
{have index 255 transparent and, when palette colour 255 is not pure blue, are also drawn as gradient decals. Water textures show their fog colour and density. Pictures more than 4,096 pixels wide or high are shown in tiles. - Palette: lumps without their own use a 768-byte palette lump of the file, else a
palette.lmpsupplied beside it, else shades of grey. - Checks: lumps outside the file or sharing bytes, names without a zero byte, sizes that differ in an uncompressed lump, type codes that the size does not allow, mip levels out of order, missing palettes and missing animation frames.
Not described
Known, not yet covered
- Viewer: compressed lumps are listed and not decompressed, because their layout is not known.
Unknown
- Reference: the byte layout of an LZSS-compressed lump (
compression1). The code is named in the headers, but Valve’s released tools never compress, Xash3D reads the byte as something else, and the engine’s source is not published. Directory
Also used for
- Doom engine WAD – Doom engine game data: maps, pictures, sounds and music as named lumps in one file.
- Quake WAD2 – Quake’s pictures and wall textures, drawn with the game’s palette.
Variants
- Quake WAD2 – Quake’s pictures and wall textures, drawn with the game’s palette
- Half-Life WAD3 – Half-Life’s textures, pictures and fonts, each with its own palette
Links
Software
- TrenchBroom – map editor for Quake and Half-Life maps that takes textures from WAD files (Windows, macOS, Linux)
- Wally – texture editor that handles Half-Life WADs (Windows)
Developers
- Half-Life SDK – Valve’s source for the lump builder (qlumpy), the font maker (makefont), the WAD library and the map compiler (C, C++)
Reference
- utils/common –
wadlib.handwadlib.c, the header, directory and writer - utils/qlumpy –
qlumpy.candquakegrb.c, which build every lump type - qcsg/textures.c – how the map compiler reads textures from WADs
- Xash3D FWGS img_wad.c – how a compatible engine reads textures, decals, pictures and fonts
- Xash3D FWGS wadfile.h – its header and directory structures
- Xash3D FWGS gl_rsurf.c and mod_bmodel.c – animation, random tiling and liquid textures