natiny.material.set_vertex_constant

Lua
natiny.material.set_vertex_constant(material, name, constant_type)

Declares that the engine owns a constant: before every draw it is refilled with an engine-provided value instead of keeping whatever you set.

Members named mtx_world, mtx_view, mtx_proj, mtx_worldview, mtx_viewproj, mtx_worldviewproj and mtx_normal are declared this way for you. Use this call when your shader names them differently, or to turn one back into a plain user constant.

Parameters

Name Type Description
material number Material handle
name string Member name inside one of the shader's uniform blocks
constant_type number One of the constants below

Constant types

Constant Meaning
natiny.material.USER whatever you set
natiny.material.WORLD the drawn object's world transform
natiny.material.VIEW camera view
natiny.material.PROJECTION projection
natiny.material.WORLDVIEW view × world
natiny.material.VIEWPROJ projection × view
natiny.material.WORLDVIEWPROJ projection × view × world
natiny.material.NORMAL inverse transpose of worldview
natiny.material.INV_VIEW inverse of the camera view
natiny.material.INV_PROJECTION inverse projection
natiny.material.INV_VIEWPROJ inverse of projection × view
natiny.material.CAMERA_POS vec4: the eye in world space
natiny.material.TARGET_SIZE vec4: width, height, 1/width, 1/height

Example

Lua
natiny.material.set_vertex_constant(material, "u_mvp", natiny.material.WORLDVIEWPROJ)

Notes

  • Matrix constants (WORLD through INV_VIEWPROJ) require a mat4 member. CAMERA_POS and TARGET_SIZE require a vec4 member. Members too small for the selected value are skipped.
  • With no camera bound the view is identity and the projection is the 2D ortho of the current target.
  • A name stands for one value, so the type it is given holds wherever the name appears - both stages, if both declare it.