Valve Developer Union

Converting WADs to Materials With xwad

(May 21, 2018)


At some point, Valve removed xwad, the command-line utility for converting a WAD of GoldSrc textures to materials, from the utilities packed in with most of the Source games. The reason for this is unknown, but as a result, it's become much more difficult to convert WADs to materials. One of the oldest guides on this site detailed two ways to do it, extracting textures with TexMex and batch-converting them either with vtex or with VTFEdit. Both of these methods were clunky and did not properly handle textures with dimensions that weren't powers of two.

xwad, however, does correctly convert these textures and resizes them in-editor, letting them keep their original dimensions when you load the original map file. All you need is a copy of the program.

Converting the WAD with xwad

The first step would be to obtain a copy of xwad. Here's ours. It runs independent of Steam and no vproject needs to be set. More specifically, xwad converts all textures in a WAD file to TGA, an uncompressed format commonly used within the Source SDK. These are stored in the materialsrc folder of the mod, for instance steamapps\common\Half-Life 2\hl2\materialsrc. To demonstrate, we'll be using a WAD from Half-Life: Opposing Force, specifically OPFOR.WAD.

xwad requires two parameters to work, a -BaseDir, which sets the mod directory, and -WadFile, which is the WAD to convert. (xwad doesn't check if the mod directory is valid, and will take any folder. If the mod directory is nonexistent, it'll make it. Don't confuse yourself.) We'll be setting our textures to export to the steamapps\common\Half-Life 2\hl2 mod folder.

xwad -BaseDir "C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\hl2" -WadFile "C:\Program Files (x86)\Steam\steamapps\common\Half-Life\gearbox\OPFOR.WAD"

After running this command, two directories will exist inside hl2, if they don't already. The materials directory will contain VMT files for the WAD, along with RESIZEINFO files (which will be used later), and the materialsrc directory will contain the resized TGA files for all of the textures in the WAD.

This still requires you to convert the TGA files yourself, however. xwad has the ability to invoke vtex on its own, but we've been unable to get it working in any permutation. vtex is easy enough to use on its own, however:

vtex -game "C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\hl2" "C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\hl2\materialsrc\OPFOR\*.tga"

This will output VTF files into hl2\materials\opfor for all the TGAs in that folder. (You no longer need the materialsrc folder after the textures have been converted.) You might need to convert multiple WADs, depending on which ones were used in the original map.

Using the textures in Hammer

After loading your RMF or VMF in Hammer, you'll notice all surfaces are textured blank white; this means the texture for that face is missing, as they're still pointing to their original places in the WAD. You don't need to fix all the textures individually, however. The "Convert WAD to VMT" option in the File menu will take care of everything automatically. This is where those RESIZEINFO files come in handy: while xwad resizes textures to fit into powers of two, Hammer uses the RESIZEINFO files to stretch them back into shape.

op1a1, before texture conversion op1a1, after texture conversion
Left: op1a1, before texture conversion
Right: op1a1, after texture conversion

This is by far the least painful way to convert the textures of a GoldSrc map to Source.