natiny.material.bind

Lua
natiny.material.bind(material [, fn])

Uses this material for subsequent draws until it is unbound or replaced. With a callback, the material applies to draws made inside the callback.

Binding flushes the current batch, so queued geometry keeps its previous material.

Parameters

Name Type Default Description
material number Material handle from natiny.material.create
fn function nil Callback whose draws use the material

Example

Lua
natiny.material.bind(material)

Notes

  • Binding overrides the material for every draw until unbind, including model and per-part materials. A material texture slot overrides a model texture only when the slot was explicitly assigned; an open slot inherits the texture supplied by the draw.
  • It does not change what natiny.render.tag selects; tags are read from each model's own material.
  • Each bind and unbind flushes the current batch. Bind once around a group of draws rather than once per draw.
  • Binding another material replaces the current override. natiny.material.unbind removes the override; it does not restore the previous material.
  • A surface carries the current material into its pass and restores the suspended material when unbound; see The bind stack.
  • With fn, Lua unbinds the material even if the callback raises an error, then propagates the error.