Garry's Mod Wiki

Materials and Textures

This page is WIP

Textures and Materials are an important integral features of the Source engine. However, they can be very confusing and intimidating for anyone not familiar with them. This article will attempt to explain what they are and how to use them.

See Also: Valve Developers Wiki links

What is a texture?

A texture is a , meaning it has a concrete width and height in pixels, and each pixel has a certain color (and in some cases, an ). Textures are used for various purposes. The most obvious use for them is to define what an object should look like, in color, but a texture can also be used as a bumpmaps - where the red, green and blue values of each pixel are creatively used to specify its 3D direction. There are other ways that textures are used, but the way a texture is used doesn't change how the texture is stored - it is always a bitmap image.

Textures in Garry's Mod are stored in the Valve Texture Format, or VTF. A good third-party tool for creating, viewing and editing VTF textures is VTFEdit (download).

to do: discuss different texture formats and flags

In Lua, a texture is represented with ITexture

What is a material?

A material is a collection of one and any number of parameters. In almost all cases, at least one of the parameters will refer to a texture.

Materials are used mostly for rendering, but also have other effects - for example, the material will decide what sound a surface should make when it is hit.

Materials (besides those created with CreateMaterial) are stored in the Valve Material Type or VMT format, which is a plain-text format describing the shader and all material parameters.

Perhaps the easiest way to understand this is through example. In Garry's Mod, the material "phoenix_storms/plastic" is saved as "phoenix_storms/plastic.vmt", and contains:

"VertexLitGeneric" { "$basetexture" "phoenix_storms/plastic" "$surfaceprop" "plastic" "$bumpmap" "phoenix_storms/plastic_bump" "$phong" "1" "$halflambert" 1 "$phongexponent" "60" "$phongboost" "2" "$phongfresnelranges" "[.5 .8 1]" }

Here, the shader is VertexLitGeneric and there are 8 parameters. The "$basetexture" parameter "phoenix_storms/plastic" is a texture's name (garrysmod/materials/phoenix_storms/plastic.vtf), and defines the visual look of the material. The "$bumpmap" parameter also refers to a texture, but this one defines the "3D effect" applied to the otherwise flat texture. The "$surfaceprop" parameter affects various things, for example the sound the surface makes when it's hit or the sound of the footsteps when walked on.

The other parameters further affect the way it is rendered - mostly how lighting should affect it.

to do: pictures here of the textures involved, plus the in-game result

List of default textures