Template:Archived page history/VMT: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (revert)
No edit summary
Line 1: Line 1:
A '''Valve Material''' is a file type with the file extention ''.vmt'', used to define a material for use with the [[Source]] engine. It contains a high-level script that refers to textures ([[VTF|Valve Texture Files (.vtf)]]) and shaders, defining how the surface of the material appears and behaves in the game.
'''VMT (Valve Material Type) file tells the Source 'Graphics Rendering Engine' how the surface of a brush or model should appear in game. '''
 
* The Source [[Material System]] is built on VMT files.
* VMT files are all kept in the '''<code>game_directory/materials</code>''' folder (or sub-folders thereof) and use the '''<code>.vmt</code>''' extension so that the Source Engine knows where to find them.
 
The contents of a (text-based) VMT file specify which '''[[Shader]]''' (or Shaders) should be used to render the surface, and define a configuration of the various '''[[Shader Parameters]]''' for a particular material type surface.
 
Probably the most important Shader Parameter, [[$basetexture]], defines which '''[[VTF]]''' (Valve Texture File) texture or textures to use on that surface.
 
Almost all Shader Parameters define 'visual' properties of a surface, with the notable exception of [[$surfaceprop]] ('surface properties') which affects such things as the sound made when an object collides with the surface. The more sophisticated 'Physics Interaction' characteristics of a world object (which apply to models but not brushes) are specified within the object's [[QC]] file.
 
An example of the one of the simplest common VMT files:
 
"LightmappedGeneric"
{
    "$basetexture" "Subfolder/Filename"
}
 
Here the VMT simply says that the "[[LightmappedGeneric]]" shader should be used to render this material type, and it should apply it to the Filename.vtf (its [[$basetexture]]) which can be found inside the <code>game_directory/materials/Subfolder</code> directory.
{{note|that the [[$basetexture]] path is ''always'' relative to the <code>game_directory/materials</code> folder and the <code>.vtf</code> file extension is ''not'' necessary.}}
 
[[Category:List of Shader Parameters]]
[[Category:List of Shaders]]
 


== Creating a Valve Material (.vmt) file ==
== Creating a Valve Material (.vmt) file ==
Line 14: Line 37:
</pre>
</pre>


This will render the <code>"test/MyTexture"</code> texture file (.vtf) opaquely and with lightmaps applied to it. This is most generally used for textures applied to brush surfaces (like walls).
This will render the <code>"test/MyTexture"</code> texture file (.vtf) opaquely and with lightmaps applied to it. This is most generally used for textures applied to brush surfaces (like walls).  
 
 





Revision as of 13:14, 8 November 2007

VMT (Valve Material Type) file tells the Source 'Graphics Rendering Engine' how the surface of a brush or model should appear in game.

  • The Source Material System is built on VMT files.
  • VMT files are all kept in the game_directory/materials folder (or sub-folders thereof) and use the .vmt extension so that the Source Engine knows where to find them.

The contents of a (text-based) VMT file specify which Shader (or Shaders) should be used to render the surface, and define a configuration of the various Shader Parameters for a particular material type surface.

Probably the most important Shader Parameter, $basetexture, defines which VTF (Valve Texture File) texture or textures to use on that surface.

Almost all Shader Parameters define 'visual' properties of a surface, with the notable exception of $surfaceprop ('surface properties') which affects such things as the sound made when an object collides with the surface. The more sophisticated 'Physics Interaction' characteristics of a world object (which apply to models but not brushes) are specified within the object's QC file.

An example of the one of the simplest common VMT files:

"LightmappedGeneric"
{
   "$basetexture" "Subfolder/Filename"
}

Here the VMT simply says that the "LightmappedGeneric" shader should be used to render this material type, and it should apply it to the Filename.vtf (its $basetexture) which can be found inside the game_directory/materials/Subfolder directory.

Note.pngNote:that the $basetexture path is always relative to the game_directory/materials folder and the .vtf file extension is not necessary.


Creating a Valve Material (.vmt) file

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" texture file (.vtf) opaquely and with lightmaps applied to it. This is most generally used for textures applied to brush surfaces (like walls).



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 material files

Let’s start by looking at an example of a material 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 material 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 Valve Material files 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".

See also