VMT: Difference between revisions
(Moved and linked to information about targa images. (More to follow.)) |
(Shortened the list significantly, moving surplus info to other articles.) |
||
Line 12: | Line 12: | ||
Here is a brief summary of the steps necessary to create a material for the Source engine: | Here is a brief summary of the steps necessary to create a material for the Source engine: | ||
# Create the source texture as [[TGA|a valid targa (.tga) image]] | # Create the source texture as [[TGA|a valid targa (.tga) image]] (using graphics software such as MSPaint). | ||
# (Optional) Write the [[Vtex compile parameters|compile parameters]] for [[Vtex]] to use. | |||
# (Optional) | # Use the [[Vtex]] tool to compile the targa image into a [[VTF|Valve Texture File (.vtf)]]. | ||
# | # Create a [[VMT|Valve Material (.vmt)]] file, where you refer to the Valve Texture File (.vtf) you've created. (See [[#Creating a Valve Material (.vmt) file|below]].) | ||
# Create a .vmt | # Launch the Hammer editor (or model viewer) and check that the new material works properly. | ||
# Launch the Hammer editor and check that the new material works properly. | |||
Revision as of 08:59, 29 August 2007

A material is what the Source engine uses to define which textures (.vtf) and shaders (function which defines how materials are rendered to the screen) are used on a surface (models, world surfaces, sprites, etc). This information is stored in a Valve Material (.vmt) file.
Summary of creating materials
Here is a brief summary of the steps necessary to create a material for the Source engine:
- Create the source texture as a valid targa (.tga) image (using graphics software such as MSPaint).
- (Optional) Write the compile parameters for Vtex to use.
- Use the Vtex tool to compile the targa image into a Valve Texture File (.vtf).
- Create a Valve Material (.vmt) file, where you refer to the Valve Texture File (.vtf) you've created. (See below.)
- Launch the Hammer editor (or model viewer) and check that the new material works properly.
Scale
The default texture scale in Hammer is .25
. This means that 4 pixels (in an image) = 1 Hammer unit = 1 inch (in game).
Compiling Source textures
Valve Texture Files are created from targa (.tga) images. The criteria of a valid targa image for Vtex compilation is listed here.
The Source engine uses Valve Texture Files (.vtf) to store its texture data. These files contain not only the basic source data, but also mip-levels used for rendering the texture over varying distances.
The tool Vtex (located in sourcesdk/bin
) is used to compile .tga files into the .vtf format. Vtex takes a .tga file and an optional text file that describes extra parameters for compiling the texture. Using these two files it then creates a .vtf file. The .txt file containing the parameters must share the same base name and directory as the .tga file being compiled. For example: The test.tga file must be in the same directory as the test.txt file for the tool to link the files properly.
If a .txt file does not exist, Vtex will automatically create an empty file with the correct name and in the correct location. The following section describes the compile parameters that can be inserted in this .txt file.
To compile a texture, simply drag either the .txt or .tga file onto the sourcesdk/bin/vtex.exe
icon, or supply the filename of either file as a command-line parameter to Vtex. The tool will report that it created the file and a .vtf will be created in the parallel materials sub-directory to where the source texture resided.

/materials
does not exist, you must create it in both locations before continuing.For example, if you’re compiling a .tga file named sample.tga
that resides in sourcesdk_content/hl2/materialsrc/test/MyTexture.tga
, the resulting .vtf file will be placed in /half-life 2/hl2/materials/test/MyTexture.vtf
.
Creating a Valve Material (.vmt) file
Once the Valve Texture File (.vtf) has been created, a Valve Material (.vmt) file must be created to actually use the texture inside of the engine. Materials are defined inside of a Valve Material (.vmt) file. This is a high-level script that details how a texture is to be rendered.
There are many shaders that can be used to render a texture. To begin with, we'll use a simple shader: LightmappedGeneric
. This shader is used for world surfaces that should receive lightmaps.
The simplest definition of this shader is:
"LightmappedGeneric" { "$basetexture" "test/MyTexture" }
This will render the "test/MyTexture"
.vtf file opaquely and with lightmaps applied to it. This is most generally used for textures applied to brush surfaces (like walls). With a .vtf file and .vmt file created, we can use this texture inside of Hammer on surfaces.
One of the easiest methods of creating new .vmt files is to open an existing .vmt that has similar properties to the material you are creating. Edit the contents of the file and save it with a different name to create a new material.
More about .vmt files
Let’s start by looking at an example of a .vmt file:
"LightmappedGeneric" { // String values are quoted "$basetexture" "shadertest/LightmappedTexture" "$envmap" "shadertest/LightmappedTexture_envmap" // Vector values are quoted "$color" "[1 0 0]" // Float and integer values are *not* quoted "$alpha" 0.5 "$nocull" 1 }
The first line of the .vmt file is the name of the shader to be used. The material variables for the shader are defined inside the curly braces. Note that you should not have '=' between the material variable name and its value. Also note that comment lines use '//'. Any text after the '//' on the same line will be ignored when the material is loaded.
If the shader needs to fallback to a simpler shader because it's running on a lower-end system, you can optionally specify an additional block to override material variable values specified in the original block.
Here's an example:
"LightmappedGeneric" { "$basetexture" "shadertest/LightmappedTexture" "$envmap" "shadertest/LightmappedTexture_envmap" // If the shader falls back to shader "LightmappedGeneric_DX7", // then the environment map defined in this block will be used instead of the // one defined above. Since $basetexture isn't defined in this block, // the original one will be used. "LightmappedGeneric_DX7" { "$envmap" "shadertest/OverrideEnvMap" } // If the shader falls back to shader "LightmappedGeneric_DX6", // then the base texture defined in this block will be used instead of the // one defined above. Since $envmap isn't defined in this block, the original // one will be used. "LightmappedGeneric_DX6" { "$basetexture" "shadertest/OverrideTexture" } }
For information on shader fallbacks, see Material choices and rendering performance in Controlling Geometry Visibility and Compile Times and Half-Life 2 Shader Fallbacks.
One other thing you'll see in the .vmt file format is the occasional variable starting with a '%'.
For example:
"UnlitGeneric" { $envmap" "shadertest/shadertest_envmap" %tooltexture" "shadertest/shadertest_envmap" }
This simply means that the variable is used by tools only and won't be loaded by the engine. The only variables that need '%' are '%tooltexture"
, "%keywords"
, "%detailtype"
, and all of the compile variables like "%compileWater"
or "%compileHint"
.
Using Vtex on the command-line
For advanced users, vtex.exe
can also be executed and scripted from a Windows command prompt. See Vtex for more information.
See Also
- Shader Types and Parameters
- Half-Life 2 Shader Fallbacks
- Normal Maps
- Reflective Materials
- Parallax mapping
- Third Party Tools
External links
- Creating materials, with transparency, in Paint Shop Pro