Tutorial: Source Custom Materials Last edited 3 months ago2024-09-20 21:55:32 UTC

User posted image
This guide will use two different methods to create a VMT and VTF pair for a simple Source texture. These techniques work with any Source game.

For the purposes of this guide, the texture name will be texturename and the created files will be texturename.vtf and texturename.vmt.

Creating the image

Create your texture image (in any file format like JPG, PNG, TGA, etc.). The only requirement is that the dimensions are powers of 2 - that means the width and height must be numbers like 256, 512, 1024, etc. Once you've done this. continue to the next step.

Using VTFEdit Reloaded

VTFEdit Reloaded is a very convenient tool that allows you to create Source textures without having to mess around with command line tools. This is the recommended way to create your textures. Install and open VTFEdit Reloaded.

First go to File > Import... and select your texture image file. You will be presented with a range of options, but the defaults are fine. Click OK to continue.

After the import, the texture will be shown in the main window. Again, you will have some options, but you can ignore them. Simply go to File > Save and save the VTF file to <mod directory>\materials\texturename.vtf.

Next go to Tools > Create VMT File. You will have some more options, but the defaults will work correctly. Click Create and save the VMT file to <mod directory>\materials\texturename.vmt.

You can now open Hammer and apply your texture to a wall, then compile and run your map!

Using VTEX

More information: Vtex - VDC

VTEX is Valve's official tool used to create Source textures. It's a command line tool located in the bin folder of the game install. For example, for HL2, it is located at <steam install>\SteamApps\common\Half-Life 2\bin\vtex.exe. VTEX is a command line tool which means it can support more advanced scripting techniques to convert textures in batches rather than one at a time. If you're not familiar with command line tools, you should use VTFEdit instead.

Running VTEX

If you run vtex.exe without any parameters, the usage instructions will be printed:
Usage: vtex [-outdir dir] [-quiet] [-nopause] [-mkdir] [-shader ShaderName] [-vmtparam Param Value] tex1.txt tex2.txt . . .
-quiet            : don't print anything out, don't pause for input
-warningsaserrors : treat warnings as errors
-nopause          : don't pause for input
-nomkdir          : don't create destination folder if it doesn't exist
-vmtparam         : adds parameter and value to the .vmt file
-outdir <dir>     : write output to the specified dir regardless of source filename and vproject
-deducepath       : deduce path of sources by target file names
-quickconvert     : use with "-nop4 -dontusegamedir -quickconvert" to upgrade old .vmt files
-crcvalidate      : validate .vmt against the sources
-crcforce         : generate a new .vmt even if sources crc matches
        eg: -vmtparam $ignorez 1 -vmtparam $translucent 1
Note that you can use wildcards and that you can also chain them
e.g. materialsrc/monster1/*.tga materialsrc/monster2/*.tga
Hit a key to continue
In the bin folder, there's also a vtex.bat folder that sets some environment variables to make things a bit easier to deal with. This is a simple batch file that just calls vtex.exe, there's nothing magic about it.

Typically when setting up custom materials you put your source files in the <mod folder>\materialsrc directory as TGA files. You can create subfolders in this directory to reflect the folder structure you want in the materials directory. You do not include the materialsrc folder when releasing your map/mod.

When using VTEX, your image file must be the TGA format. Any image editing software (except mspaint) will support this format. Save your texture as TGA and place it in the materialsrc folder before you continue.

Next, use VTEX to convert the TGA into the VTF format. Open a command line and run the following (assuming you are using HL2):

.\bin\vtex.bat .\hl2\materialsrc\texturename.tga

The output should be something like the following:
<steam>\SteamApps\common\Half-Life 2> .\bin\vtex.bat .\hl2\materialsrc\texturename.tga
Configuring Source SDK environment variables for Half-Life 2
VPROJECT=F:\Steam\SteamApps\common\Half-Life 2\bin\..\hl2
Executing: ".\bin\vtex.exe" -game ".\bin\..\hl2" .\hl2\materialsrc\texturename.tga
input file: ./hl2/materialsrc/texturename
output directory: ./hl2/materials
no config file for ./hl2/materialsrc/texturename.tga
SUCCESS: Vtf file created
Hit a key to continue

Creating a VMT

More information: VDC - Material

Now that you have created your actual texture, it is time to create its material attributes (what it sounds like when dropped, whether it has any special cubemap properties etc.). If you are going for a basic texture with no specific material properties, then follow the instructions below.

Create a new file in your materials directory and call it the same name as your texture, except with the extension .vmt. Open this file in Notepad or any other text editor. Add the following content to the file:
LightmappedGeneric
{
    "$basetexture" "texturename"
}
Save the file and close Notepad. You can now open Hammer and apply your texture to a wall, then compile and run your map!

5 Comments

Commented 16 years ago2008-03-03 06:41:35 UTC Comment #100697
Great Tutorial, Only Can you put details as in the measures of walls and things because, I don't know how big to make them and more details on setting custom attributes?
Commented 16 years ago2008-03-07 22:27:53 UTC Comment #100698
Nice, maybe have some more details about the vmf file and its attributes? And btw, can you make a tutorial about VTFEdit?
Commented 16 years ago2008-09-03 19:30:55 UTC Comment #100699
great, to answer some questions, the size for textures should be 512x512 pixels.
VTFedit its the same, you just need to get the texture files and the text file in your folder.
Commented 12 years ago2012-07-03 16:40:12 UTC Comment #100700
Outdated tutorial, use vtfedit ;)
Commented 3 months ago2024-09-10 17:58:34 UTC Comment #106384
VTFEdit is no longer maintained, so I changed the section to talk about VTFEdit Reloaded instead. I believe it should work the same. It's a fork of VTFEdit

You must log in to post a comment. You can login or register a new account.