VMT

From Valve Developer Community
Revision as of 13:03, 29 August 2007 by Andreasen (talk | contribs) (Moved info to TGA, VTF and Vtex. (More to follow.))
Jump to navigation Jump to search
Merge-arrows.png
It has been suggested that this article or section be merged with Creating a Material. (Discuss)

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

TextureFlowchart.jpg

Here is a brief summary of the steps necessary to create a material for the Source engine:

  1. Create the source texture as a valid targa (.tga) image (using graphics software such as MSPaint).
  2. (Optional) Write the compile parameters for Vtex to use.
  3. Use the Vtex tool to compile the targa image into a Valve Texture File (.vtf).
  4. Create a Valve Material (.vmt) file, where you refer to the Valve Texture File (.vtf) you've created. (See below.)
  5. Launch the Hammer editor (or model viewer) and check that the new material works properly.



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


External links