Skip to main content

Material userdata

Get this userdata from materials. Use colon calls; methods operate on native parameters. reload restores the tint captured when the userdata was created, rather than reloading a resource from disk.

The userdata holds a borrowed native material pointer. It does not keep the resource alive or revalidate it after resource replacement. Reacquire materials after map/resource changes instead of keeping them across those changes. Invalid argument types or null material references raise errors. Unloading a script does not automatically restore changes to native materials; restore tint with reload while the reference remains valid.

alpha_modulate​

material:alpha_modulate(alpha)

Returns: none.

Numeric alpha is divided by 255 and clamped to [0, 1] for g_vColorTint.w. Does nothing when that parameter is absent.

color_modulate​

material:color_modulate(red, green, blue)

Returns: none.

Numeric RGB components are divided by 255 and clamped to [0, 1] in g_vColorTint.xyz. Does nothing when that parameter is absent.

get_name​

material:get_name()

Returns: string; or nil.

Returns the native material name, or nil if the name pointer is absent.

get_shader_param​

material:get_shader_param(name)

Returns: Vector or number; or nil.

name is a string. Names beginning g_v return a Vector of xyz; other parameters return their first numeric component. Missing parameters return nil. This API does not return an alpha component.

set_shader_param​

material:set_shader_param(name, value)

Returns: none.

name is a string. Accepts a number for the first component or Vector userdata for xyz, then updates native material parameters. A missing parameter is a no-op; unsupported value types raise errors.

reload​

material:reload()

Returns: none.

Restores the captured original g_vColorTint when one was captured and the parameter remains present. Other shader parameter changes are not reset.