Skip to content

materials

The materials namespace manages Source engine material instances and chams overrides.


local mat = materials.find(name: string) --> material_t | nil

Finds an existing engine material by name (e.g. "models/player/custom_player/...").


local mat = materials.create(name: string, shader: string, keyvalues: table) --> material_t

Dynamically compiles a new material.

  • shader: Engine shader name (e.g. "VertexLitGeneric", "UnlitGeneric").
  • keyvalues: Table of shader parameters. Key names are written without the leading $ prefix (e.g. basetexture, ignorez, nofog, envmap).
  • String and number values are forwarded; boolean/nested tables are omitted.
local glow_mat = materials.create("script/glow", "VertexLitGeneric", {
basetexture = "vgui/white",
ignorez = 1,
envmap = "models/effects/cube_white",
envmaptint = "[1 1 1]",
envmapfresnel = 1,
})

materials.draw_chams(mat: material_t)

Draws the model currently being intercepted inside a draw_chams callback.


Method Parameters Returns Description
mat:get_name (none) string Material name.
mat:color_modulate clr?: color color Reads or sets RGB color modulation tint.
mat:alpha_modulate alpha?: number number Reads or sets alpha modulation (0..1).
mat:var_flag flag: number, value?: boolean boolean Reads or writes a material variable flag (e.g. ignorez = 1 << 15).
mat:increment_ref_count (none) nil Increments reference count to prevent garbage collection across map changes.
mat:decrement_ref_count (none) nil Decrements reference count on cleanup.