VMT: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Moved info to TGA, VTF and Vtex. (More to follow.))
m (Setting bug notice hidetested=1 param on page where the bug might not need tested in param specified)
 
(73 intermediate revisions by 35 users not shown)
Line 1: Line 1:
{{merge|Creating a Material}}
{{LanguageBar}}


A '''material''' is what the [[Source]] engine uses to define which [[texture]]s ([[VTF|.vtf]]) and [[shader]]s (function which defines how materials are rendered to the screen) are used on a surface ([[:Category:World Models|models]], [[Brush|world surfaces]], [[env_sprite|sprites]], etc). This information is stored in a [[VMT|Valve Material (.vmt)]] file.
{{todo|Move engine-agnostic stuff to [[material]].}}
A '''VMT''' ("Valve Material") file defines the [[material]] used by a two-dimensional surface. It contains all of the information needed for {{src|4}} to simulate the surface visually, aurally, and physically.<br>If a material is missing, it will produce the infamous Source pink and black checkered pattern. A white wireframe is not a missing material, but instead a missing [[shader]].


__TOC__




== Summary of creating materials ==
The contents of a material will fall into some or all of these categories:


[[Image:TextureFlowchart.jpg]]
# [[Texture]] names
# [[$surfaceprop|Physical surface]] [[Material surface properties|types]]
# [[:Category:Shaders|Shader]] [[:Category:List of Shader Parameters|parameters]]
# [[Material Map Compile Flags|Special compile properties]]
# [[Material optimization|Fallbacks]]
# [[Material Proxy|Proxies]]


Here is a brief summary of the steps necessary to create a material for the Source engine:
== A simple example ==
 
{{CodeBlock|<nowiki>LightmappedGeneric
# 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.
# 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]].)
# 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 [[VMT|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 [[shader]]s that can be used to render a texture. To begin with, we'll use a simple shader: <code>LightmappedGeneric</code>. This shader is used for world surfaces that should receive [[lightmap]]s.
 
The simplest definition of this shader is:
 
<pre>
"LightmappedGeneric"
{
    "$basetexture" "test/MyTexture"
}
</pre>
 
This will render the <code>"test/MyTexture"</code> .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|.vmt]] file:
 
<pre>
"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
}
</pre>
 
The first line of the .vmt file is the name of the [[Shader Types and Parameters|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 <i>fallback</i> 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:
 
<pre>
"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"
    }
}
</pre>
 
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:
 
<pre>
"UnlitGeneric"
{
{
    $envmap" "shadertest/shadertest_envmap"
$basetexture "coast/shingle_01"
    %tooltexture" "shadertest/shadertest_envmap"
$surfaceprop gravel
}
}</nowiki>}}
</pre>
''This is a very basic [[Wikipedia:Shingle beach|shingle beach]] material.''
 
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 <code>'%tooltexture"</code>, <code>"%keywords"</code>, <code>"%detailtype"</code>, and all of the compile variables like <code>"%compileWater"</code> or <code>"%compileHint"</code>.


#The <code>[[LightmappedGeneric]]</code> shader is used, which means that the material is for use on surfaces with [[lightmap]]s (i.e. [[brush]]es).
#''The opening curly brace ({{Code|<nowiki>{</nowiki>}}) opens a set of parameters''
#The <code>[[$basetexture]]</code> parameter is given with <code>coast\shingle_01</code>, which is the location of a texture. This is what will be drawn on the screen.
#<code>[[$surfaceprop]]</code> gives the material the physical properties of gravel.
#''The closing curly brace ({{Code|<nowiki>}</nowiki>}}) character closes a set of parameters''


It's important to remember that this material can only be used on brushes. If it needed to be used on [[model]]s, for instance, another version would need to be created using the {{code|[[VertexLitGeneric]]}} shader.


==Using Vtex on the command-line==
Most of the time switching materials from one shader to another is as simple as changing their first line, since a great number of parameters are shared between them. Some params only work with certain shaders, like [[Phong]] effects, which are only available with {{code|[[VertexLitGeneric]]}}, but unfortunately you won't encounter any critical errors if a param isn't understood by the shader. It just won't have any effect.


For advanced users, <code>vtex.exe</code> can also be executed and scripted from a Windows command prompt. See [[Vtex]] for more information.
{{tip|If you ever need to use a space, tab, or curly brace character in a parameter value, you must wrap the whole value with "quote marks". You'll often see absolutely everything wrapped like this - save yourself some typing, as that's unnecessary.}}
{{bug|hidetested=1|Sometimes{{when}}, the first parameter defined in the VMT will fail to load. If this happens, a dummy parameter such as {{code|$bug}} can be used.}}


== Finding materials ==


=== SteamPipe ===


==See Also==
When Valve updated all {{src|4}} games to [[SteamPipe]], all materials were moved from [[GCF]] into [[VPK]] files. Third-party games (running on {{src04|1}} - {{src09|1}}) that previously used [[GCF]] files are also having it's materials moved to depot [[VPK]] files. VPK Files work with {{gcfscape|4}} and {{vpkedit|4}}.


* [[Shader Types and Parameters]]
More info on SteamPipe [https://support.steampowered.com/kb_article.php?ref=7388-QPFN-2491 here]
* [[Half-Life 2 Shader Fallbacks]]
* [[Normal Maps]]
* [[Reflective Materials]]
* [[Parallax mapping]]
* [[:Category:Third Party Tools|Third Party Tools]]


=== Non-SteamPipe Games ===


In non [[SteamPipe]] {{src|4}} games, Materials are stored in the {{Path|materials\}} folder of your game or mod. The best way to browse them is from {{hammer|4}}'s texture selection screen.


== External links ==
If you want to edit or view the code of Valve's material files you will first need to extract them from their [[GCF]] package with {{gcfscape|4}}. They tend to be stored in GCFs with 'materials' in their name.


* Creating materials, with transparency, in [http://www.sourcemapping.org/akg/tutorials/wisePSPtrans.asp Paint Shop Pro]
== See also ==


* [[Creating a Material]]
* [[Notepad++ VDF languages|Notepad++ syntax highlighting for materials]]
* [[Valve Texture Format]]
* [[Shader]]
* [[:Category:List of Shader Parameters|List of Shader Parameters]]
* [[Source VMT Editor]]
* [https://github.com/Xyphos/VMTGen VMTGen]
* [http://www.therazzerapp.de/tutorials/vmt_erstellen.html German Tutorial by TheRaZZeRApp]


[[Category:Material System]]
[[Category:Material System]]
[[Category:Tutorials]]
[[Category:Source]]
[[Category:Glossary]]
[[Category:File formats]]

Latest revision as of 07:07, 20 May 2025

English (en)Deutsch (de)Español (es)Français (fr)한국어 (ko)Русский (ru)Translate (Translate)
Todo: Move engine-agnostic stuff to material.

A VMT ("Valve Material") file defines the material used by a two-dimensional surface. It contains all of the information needed for Source Source to simulate the surface visually, aurally, and physically.
If a material is missing, it will produce the infamous Source pink and black checkered pattern. A white wireframe is not a missing material, but instead a missing shader.


The contents of a material will fall into some or all of these categories:

  1. Texture names
  2. Physical surface types
  3. Shader parameters
  4. Special compile properties
  5. Fallbacks
  6. Proxies

A simple example

LightmappedGeneric { $basetexture "coast/shingle_01" $surfaceprop gravel }

This is a very basic shingle beach material.

  1. The LightmappedGeneric shader is used, which means that the material is for use on surfaces with lightmaps (i.e. brushes).
  2. The opening curly brace ({) opens a set of parameters
  3. The $basetexture parameter is given with coast\shingle_01, which is the location of a texture. This is what will be drawn on the screen.
  4. $surfaceprop gives the material the physical properties of gravel.
  5. The closing curly brace (}) character closes a set of parameters

It's important to remember that this material can only be used on brushes. If it needed to be used on models, for instance, another version would need to be created using the VertexLitGeneric shader.

Most of the time switching materials from one shader to another is as simple as changing their first line, since a great number of parameters are shared between them. Some params only work with certain shaders, like Phong effects, which are only available with VertexLitGeneric, but unfortunately you won't encounter any critical errors if a param isn't understood by the shader. It just won't have any effect.

Tip.pngTip:If you ever need to use a space, tab, or curly brace character in a parameter value, you must wrap the whole value with "quote marks". You'll often see absolutely everything wrapped like this - save yourself some typing, as that's unnecessary.
Icon-Bug.pngBug:Sometimes[When?], the first parameter defined in the VMT will fail to load. If this happens, a dummy parameter such as $bug can be used.

Finding materials

SteamPipe

When Valve updated all Source Source games to SteamPipe, all materials were moved from GCF into VPK files. Third-party games (running on Source 2004 - Source 2009) that previously used GCF files are also having it's materials moved to depot VPK files. VPK Files work with GCFScape GCFScape and VPKEdit VPKEdit.

More info on SteamPipe here

Non-SteamPipe Games

In non SteamPipe Source Source games, Materials are stored in the 🖿materials\ folder of your game or mod. The best way to browse them is from Hammer Hammer's texture selection screen.

If you want to edit or view the code of Valve's material files you will first need to extract them from their GCF package with GCFScape GCFScape. They tend to be stored in GCFs with 'materials' in their name.

See also