Tutorial: Sound Effects for Textures (materials.txt) Last edited 3 months ago2024-08-19 02:44:47 UTC

This tutorial will explain how to use materials to make custom textures play different sounds when you run on them or shoot at them. Materials will add a lot of depth to your map and increase the level of immersion for players, and can be used to balance your map for games such as Counter-Strike in which sound effects play a key part.

Usage of the materials file

The sound effect that plays when a player interacts with a surface is determined by the materials file. It's a plaintext file which you can find or create in the game's sound folder (Half-Life\game\sound\materials.txt).

The materials file contains a list of most of the textures in the game. Each line is reserved for each texture and is prefixed by a specific character to determine which texture type the game will match the texture to. A couple of texture types unique to Counter-Strike are included in the following table, be sure to check your particular materials file for the game you are working with as you may have more options than this.
Prefix Texture Type Example
M Metal M C1A1_FLR1
V Ventilation V DUCT_FLR01
D Dirt D OUT_MUD1
S Slosh liquid S GENERIC_114
T Tile T FIFTIES_FLR01
G Grate G TNNL_FLR12
W Wood W BCRATE02
P Computer P C1A1_GAD1
Y Glass Y GLASS_DARK
N Snow (cstrike only) N A_Snow
X Grass (cstrike only) X ikgrndj
R Gravel (czeror only) R CRATE_COKET02
A Grass (czeror only) A GRD_GRASS_2
E Carpet (czeror only) E CARPET_GRN01
O Snow (opfor only) O SNOW_01
Additionally, only the first 12 characters of the texture's name are needed for most games built with this engine. One exception is Counter-Strike, while still checking the first 12 characters for bullet impact sounds, will actually use the full length of the name for footstep sounds.

Distributing materials with your map

Players that download your map in multiplayer won't be able to download the materials configured for it, they will only hear the default sounds for your custom textures. It's not possible to force a player to download your materials file in online play, but there are some workarounds.

Sharing your file

The easiest method is to share your own materials file, or the relevant lines from it, and expect players to manually install it. Packing your own materials file with a large archive is not recommended as players might accidentally overwrite changes they've made to their own file.

Using default texture names

Another method is to copy the exact name of a default texture and use it for the name of your custom texture. Make sure the default texture you choose is already configured in the materials file, as not all of them are. For example, your custom texture would be called OUT_MUD1, which is already a default texture from halflife.wad.

In order for the map editor to always display your custom texture instead of the default one with the exact name, make sure your custom WAD is loaded before the default one in the configuration settings.
Custom wad first, default wad afterCustom wad first, default wad after
However, the game can still load the default WAD into memory first, ignoring the custom texture from your WAD. The best solution for this is to use the -wadinclude compile parameter for your custom WAD. When loading your map, the game will prioritise the embedded custom texture and it will be loaded every single time.

Another solution is to avoid using the default WAD altogether in your editor. When you export the map for the compiler, the map editor will create a keyvalue in the worldspawn entity which contains the entire list of the WADs in use by the editor. You can see this list in the compile log, excluding unused WADs:
Wad files required to run the map: "halflife.wad;materialstest.wad;cs_havana.wad;"
If you don't use any textures from the default WAD and remove it from the list, the game won't load the default WAD into memory and only load your custom WAD instead:
Wad files required to run the map: "halflife.wad;materialstest.wad;"

Default texture names as a prefix

If you find a default texture with at least 12 characters in its name, such as C2A3TURBINE1, you can use the first 12 characters as a prefix for the name of your own custom texture, for example C2A3TURBINE1zzz. This is because Half-Life will only check the first 12 characters of a texture's name before matching it to the materials file. The following is a list of texture types which have textures with at least 12 characters in their names. You can build upon these names for your custom textures.
Texture Type Example
Metal C2A3TURBINE1
Tile FIFTIES_FLR5
Grate LAB1_STAIR2A
Wood FIFTIES_DSK1
Computer DRKMTL_SCRN2
Glass GLASS_BRIGHT
While this method works in Half-Life, it won't work for all games. In the case of Counter-Strike, the game matches all possible characters of the texture's name for footsteps. However, it still checks only the first 12 characters for bullet impacts.

2 Comments

Commented 1 year ago2023-01-19 22:47:59 UTC Comment #105011
This is brilliant, seedee! I think this could be merged with Tutorial: Materials.txt
Commented 1 year ago2023-02-03 17:23:38 UTC Comment #105052
I didnt see that other one, how do we go about merging it?

You must log in to post a comment. You can login or register a new account.