VMT Tip: $patch

$patch is a useful VMT ‘shader’ for creating unified sets of materials.

The $patch ‘shader’ works by specifying an existing material, in this example “materials/glitchvid/plaster/cleanplaster_base.vmt” and allowing you to add, or replace existing parameters, in the $patch’d material.  Unifying similar assets, and streamlining your material set.

Real world examples:

cleanplaster_base.vmt

The “base” material defines all of our standardized presets for our set

“LightmappedGeneric”
{
“$basetexture” “ERROR”
“$bumpmap” “glitchvid/plaster/plaster_normalmap”
“$envmap” “env_cubemap”
“$normalmapalphaenvmapmask” “1”
“$envmaptint” “[ 0.25 0.25 0.25 ]”
“$surfaceprop” “plaster”
// “$reflectivity” “[0.5 0.5 0.5]” // VTF is doing fine automatically
“$detail” “glitchvid/detail/plaster_detail_2”
“$detailscale” “5”
// “%notooltexture” “1” // We would use this if it didn’t cause key value issues
}

cleanplaster_white.vmt

And here is the white version

patch
{
include “materials/glitchvid/plaster/cleanplaster_base.vmt”
insert
{
“$basetexture” “glitchvid/plaster/cleanplaster_white”
}
}

 

As you can see, the ‘insert’ function lets us replace values in the base.  Here it sets the basetexture to the white diffuse.

cleanplaster_orange.vmt

patch
{
include “materials/glitchvid/plaster/cleanplaster_base.vmt”
insert
{
“$basetexture” “glitchvid/plaster/cleanplaster_orange”
“$envmaptint” “{204 68 30}”
“$reflectivity” “{382 166 0}” // this value is doubled
}
}

 

This one is a bit more complex, overriding envmaptint and reflectivity.

Why do it?

$patch allows you to unify basic parameters about materials.  In this case I’m making a set of plaster materials, meaning they’re all going to sound like plaster, reflect similar to plaster, and have the same $detail texture.  Utilizing $patch allows me to change the detail texture, normalmap, etc on all the materials at once, removing the need to change each sub material individually.

 

Bookmark the permalink.

Comments are closed

  • Meta