Creating a Material

From Valve Developer Community
Revision as of 14:01, 21 February 2009 by Other (talk | contribs)

Jump to: navigation, search

Этот пример научит вас пошаговому созданию материалов material, включая создания текстур texture.

Создание текстур

Любое изображение(файл) может быть использовано для создания текстуры, но его размеры обязательно должны быть кратны двум, к примеру: 2, 4, 8, 16, 256, 1024, и тому подобные. Стандартное разрешение, которое используют разработчики Valve -512x512, но вы можете использовать то разрешение которое будет удобно вам. Изображение с высоким разрешением будет выглядеть лучше, реалистичнее, но для этого нужно будеть больше системных ресурсов.

Different classes of object have different standard resolutions (e.g. character models' are very high). Check Valve's choices in source materials.gcf with GCFScape if you are ever confused.

Note:Texture source files should be saved in a lossless format like TGA pre-compile, to prevent unnecessary loss in quality.

Converting the texture

Textures must be converted to the Valve Texture Format before Source can use them. The tool Valve provide for this is VTEX. It's a command line tool with quite a few limitations however, and the third-party tool VTFEdit is preferable. VTFEdit provides a graphical user interface, allows you to change a texture's properties without re-compiling it from scratch, accepts a wide range of image formats, and doesn't require the creation of script files for each and every texture. There are a handful of situations where you'll need to fall back on VTEX — but only a handful.

(The author of VTFEdit has also created VTF plug-ins that let you save to the format directly from Photoshop and Paint.NET, but this tutorial will not cover them as not everyone uses those tools.)

To import your texture with VTFEdit, use File > Import or press Ctrl+I. Select your image and you will be presented with the import screen:

VTFEdit's import screen

General settings

These settings are the most important. There are three:

Normal format
The sub-format the texture should be stored in if it is opaque.
Alpha format
The sub-format the texture should be stored in if it has an alpha channel.
Texture type
How this texture will be used; normally as an Animated Texture, even if it doesn't actually have animation.

If you're making a plain and simple world texture you won't need to change any of these. If you're making a texture with fine gradient detail however, you'll need to choose formats that don't compress the image.

Mipmap settings

These settings define how the texture is scaled when viewed from far away, or when the game is running with medium or low texture detail. The only time you will realistically need to worry about it is when creating interface textures, for which you should disable the check box. This ensures that your menu images are always sharp and readable, even if the very lowest texture detail setting is being used.

Normal map settings

These (mis-labelled) settings allow you to automatically generate a bump map from your input image. You'll want to do this properly with an image editor for the material you ship, but the automated option is there regardless if you want quick results or a base to work from.

Configuring the VTF

When you hit OK the input file is converted (there may be a quite lengthy pause for large images) and the output VTF appears. Now all that is left is configuring the texture with the options in the checkbox list on the left-hand side of the screen. See Valve Texture Format#Image_flags for descriptions of each.

Creating a material

Source doesn't access textures directly. They must first be included in a material.

Materials can be created in any text editor, but it's recommended that you use Notepad++ in conjunction with the community-made syntax highlighting rules. You must save the material under your game or mod's materials\ folder with the file extension ".vmt".


A material file looks like this:

	<parameter> <value>
	$basetexture coast\shingle_01
	$surfaceprop gravel

There are many shaders to choose from, but most materials will use either LightmappedGeneric (brushes) or VertexLitGeneric (models). The third most common shader is UnlitGeneric, which is used for UI materials and the occasional tool texture.


For a list of all documented shader parameters, see Category:List of Shader Parameters.

With a shader chosen you're onto parameters. There are hundreds of options for what to put in a material so this article will only cover the most common, which are accepted by more or less all shaders. They are:

Tip:If you ever need to use a space or tab 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.

See also