Valve Developer Union

Converting GoldSrc WADs to Source Textures

(September 13, 2017)


"I swear r_speeds are still relevant—"

This was one of the Valve Developer Union's very first guides used to test the site, and as such, it's not very good. A far better and cleaner way to convert these textures can be found in the rewritten "Converting WADs to Materials With xwad" guide.

The GoldSrc engine, much like the earlier Doom and Quake engines, use one large WAD file to store many textures. In the Source engine, these textures are instead separate files with a VMT to denote their properties. While the Valve Developer Community site lists xwad as the official tool to use, it's no longer included in the SDK. The name of the game is to take a WAD full of textures and turn them into fully working materials for use in Hammer. (Model materials are handled in a different way, as GoldSrc model textures are baked into the model itself, unlike in Source.)

Many tools exist to manipulate WADs; the one we'll be looking at today is TexMex, which supports HL1 WADs, despite being a Quake mapping tool. TexMex can export textures to TGA; these will then be used by Vtex to produce materials. (VTFedit can be substituted, but its autogenerated VMTs don't work properly without being edited. For a large amount of textures, we recommend using Vtex.)

1. Extracting Textures

Start by loading your Half-Life WAD into TexMex. If there are a lot of textures, it might take awhile. TexMex isn't choking on the WAD, honest. To select all of the textures in one, use Ctrl+A or the Select All option in the Edit menu. You can then extract the textures in either the File menu or by right-clicking any of the textures and selecting it from the context menu. As Vtex takes TGA files, export them to that format.

Make a materialsrc folder in the game directory (e.g. Half-Life 2\hl2\materialsrc). Vtex wants the TGA files there. Keep in mind that this folder will mirror what the materials folder will look like when this is done. For Half-Life: Source, where the textures from halflife.wad ended up in Half-Life 2\hl1\materials\halflife, Valve would've put the TGAs in Half-Life 2\hl1\materialsrc\halflife.

2. Converting Textures

Load up a command prompt, because Vtex is CLI only. Vtex also requires Steam to run, so make sure that's on. If you're anxious about things without colorful buttons, no worries, we'll give you the commands to run it. Navigate off to the directory where Vtex is for your particular game:

cd C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\bin

From there, Vtex supports wildcards. To convert the entire folder, point it at the folder where you put your TGAs and let it run with the -shader parameter. The shader in this case, as these are world textures, would most likely be LightmappedGeneric.

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

The path will vary depending on what game you're converting for. There's one rather cryptic error you might encounter as you let Vtex do its thing:

ERROR: Can't convert image from RGBA8888 to DXT1 in CalcLowResImage

This means you have a texture whose dimensions are not a power of 2. Powers of 2 (4, 8, 16, 32, 64, 128, etc.) are required by Vtex. VTFedit can automatically resize textures that have irregular dimensions, but as noted, its VMTs don't work without a find and replace to fix the $basetexture directories. This becomes the catch-22 of both tools. If you're comfortable with a folder find and replace afterwards, VTFcmd's (the command line version of VTFedit) syntax is very similar, but gives you much more control.

vtfcmd -folder [full path to input folder\*.tga] -output "[likely your game directory's materials folder]" -resize -rmethod "nearest" -rfilter "gaussian" -format "dxt1" -alphaformat "dxt5" -shader "LightmappedGeneric"

You should now have a folder of textures immediately usable in Hammer. They won't have proper $surfaceprop values, though, and no reflectivity information. You'll have to edit that in by hand.

3. Animated Textures

The Source engine stores all frames of a texture in the same VTF, unlike Quake and GoldSrc. In those days, you'd have to store them all separately in the WAD and use a numbering system, i.e. +0button, +1button, +2button, along with an +abutton frame if it was ever meant to be activated. With VTFedit, it isn't too much trouble to create an animated VTF from these loose frames.

Start by exporting out only the frames of your animated texture like normal. Keep them in the same spot, where you can see them. Open VTFedit and go to "File > Import". You can select multiple images to import at once; they'll be sorted alphabetically in the final file, which is perfect for the way the frames were originally numbered.

VTFedit will pop up with a box of options for the final texture. Matching them to the settings below is a safe bet, but even if you have them set differently (say, using a lossless texture format rather than DXT1), be sure that the Texture Type is set to "Animated Texture".

Once you create the VTF, you'll be able to test the various frames by playing with the frame counter in the sidebar. If you don't see it, be sure the sidebar is set to the Image tab. Even though it's now an animated texture, it won't animate in-game until you add a material proxy to your VMT. At the bottom of your VMT, before the ending bracket (}), add this block of code:

		animatedTextureVar $basetexture
		animatedTextureFrameNumVar $frame
		animatedTextureFramerate 10

This will animate the texture at 10fps, which is the animation speed of textures in GoldSrc. Aside from compression differences, when you use it in-game, it'll look pretty identical.

I don't know if there's a good way to batch convert animated textures, so you might have to do the ones you need by hand.