Cleanup is going to take awhile, so the site is back up but editing has been disabled.

Texture Introduction

From HalfLife 2 Knowledge Base

Jump to: navigation, search

by RomeoJGuy and Greycap

This is designed to get you acquainted to the new material system found in Half-Life 2's Source engine.

Contents

The Material System

The material system is comprised of VMTs and VTFs. These two files work together to create a single texture. Though note that many textures use more than one VTF to create a texture, but we will get into that later.

How the system works is the actual per pixel data is stored in the VTF for the texture. Then that texture is manipulated by use of a VMT. Both files are required to make up a texture. The VMT tells it how to render the texture. Here is an example:

"LightmappedGeneric"
{
  "$baseTexture" "photorealistic_marble/marble01.vtf"
}

The first thing you will notice is at the top is the word LightmappedGeneric. That is the shader the texture is using to render. There are many different shaders available for your textures right out of the box like refract and vertexlit, but in most cases you will want to stick with Lightmappedgeneric.

Next you'll notice the parameter $basetexture which points to the VTF marble01. This is how you tell it what texture it is used for. Without this line the VMT is useless.

There are many other commands that affect how a VMT is rendered but all that is required is that one parameter $basetexture. With the VTF you cannot read into it in notepad. It will come up as giberish. Though a good command to know for materials is how to define what type of surface the texture is. This is done by using the command "$surfaceprop". Then you need to pick a surface type. Some of the obvious types are dirt and wood or metal. As you can see the new material system is quite more versatile. Now I wil explain how you make your very first texture.

Making your first texture

Making your first texture can be a very confusing process. So its best to take it one step at a time. What you need to do first is decide on a texture. It can be anything you want from a metal wall to a picture of a rubber duck. Now while any picture is possible there are specific restrictions on what kind and what sizes the texture can be. Still any texture can be manipulated to fit the proper type. Here are the requirements of the texture file to allow it to become a VTF:

Requirements for creating a VTF

  • Your texture must be in a .TGA format. No other format will work. The easiest way to convert it is in Adobe Photoshop.
  • Your texture must have dimensions that represent a power of 2. Examples being: 64x128, 512x1024.
  • The limit of the dimensions on either side is 2048. This is not an engine limit, but a hardware limit. As hardware improves the engine can be scaled up to allow higher resolution textures.
  • To create a texture with transparent sections you have to add an alpha channel. Transparent parts in Photoshop will not transfer over to the VTF unless it's in an Alpha channel.

After you have a proper TGA to use as a texture you need to save it in the proper place. All textures need to be saved in \Valve\Steam\SteamApps\usernameXXX\sourcesdk_content\cstrike\materialsrc\yourtexturedirXXX\XXX.tga. What all that ruckus at the end means is that you need to create a new directory in the MaterialSRC directory presumably the name of the map they are used in, but not necessary. After you have your texture in place you are ready to rock and roll.

Now you need to go into the \Valve\Steam\SteamApps\usernameXXX\sourcesdk\bin\ directory and you need to locate the program called vtex.exe. This is the program that converts your textures from a TGA to a VTF. While most peolple use the hard way of navigating in command prompt I will teach you an easier way. Right-Click vtex.exe and create a shortcut using it. Rename the shortcut however you please, but in the target after all the file mumbo jumbo add these lines:

 -mkdir -shader LightmappedGeneric c:\path\to\Valve\Steam\SteamApps\usernameXXX\sourcesdk\cstrike_sample_content\materialsrc\yourtexturedirXXX\*.tga 

Please note that the *.tga does not change to what your texture is called. The *.tga tells it to do all textures in that directory. Let me explain all these commands one by one so it makes sense to you and does not end up being just a copy and paste job. mkdir tells the program to make a new directory if there is not already one for your texture. shader LightmappedGeneric tells the program you are using the LightmappedGeneric shader for your texture. This is the most common shader used. The final part tells it which textures to convert over, and as I said before the *.tga tells it to convert all textures in that directory. You should now have a VTF and VMT file in the same diectory in cstrike_sample_content\materials. Now I will explain setting up the VMT for your texture so its good to go.

Note: when building the shortcut, the easiest way to create the directory path that you are going to add to your properties section of your shortcut is to navigate there using windows explorer, and copy it from the address bar. Be sure to put the path surrounded with double quotes.

Setting up the VMT for the first texture

This process is very simple. Whatever you named the tga in the begininning is what the VMT and VTF will be named. Just find your VMT and open it in notepad. As you can see you will have a texture setup that is similar to the first example in that it uses the shader LightmappedGeneric and it has only the command $basetexture. You'll probably want to add the surface property command to it if you want to use it in a map because without it, it will use the default one which may look strange on wood or metal. All you need to do is add the command:

"$surfaceprop" "metal"

replace the metal with whatever material you desire. A list of CSS surface properties can be found here: Surface Properties. Now you are ready to make your map and hammer and apply your material to a brush face. When your ready to test your map be sure you copy the materials folder of your textures to the CSS materials folder so it will show up while playing the game.


Animating the Texture

First, you will need to creat the VTF from several TGAs. Follow the instructions here.

Then, you will need to add a variable named "$frame" to the VMT specifying how many frames long the VTF is.

Next, you will need to add a Proxy by the name of "AnimatedTexture" to the .VMT file.

Here is an example VMT file for an animated Texture.

"UnlitGeneric"
{
	"$basetexture" "mytexture"       
	"$frame" "3"
	"Proxies" 
	{
		"AnimatedTexture" 
		{ 
			"animatedTextureVar" "$basetexture" 
			"animatedTextureFrameNumVar" "$frame" 
			"animatedTextureFrameRate" "1" //this is the FPS that the texture will animate at
		}
	}
}
Personal tools