natiny_material_set_vertex_constant

C
void natiny_material_set_vertex_constant(NatinyMaterial material, const char* name,
                                     uint32_t 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 NatinyMaterial Material handle
name const char* Member name inside one of the shader's uniform blocks
constant_type uint32_t One of the defines below

Constant type defines

Define Value Meaning
NATINY_CONSTANT_USER 0 whatever you set
NATINY_CONSTANT_WORLD 1 the drawn object's world transform
NATINY_CONSTANT_VIEW 2 camera view
NATINY_CONSTANT_PROJECTION 3 projection
NATINY_CONSTANT_WORLDVIEW 4 view × world
NATINY_CONSTANT_VIEWPROJ 5 projection × view
NATINY_CONSTANT_WORLDVIEWPROJ 6 projection × view × world
NATINY_CONSTANT_NORMAL 7 inverse transpose of worldview
NATINY_CONSTANT_INV_VIEW 8 inverse of the camera view
NATINY_CONSTANT_INV_PROJECTION 9 inverse projection
NATINY_CONSTANT_INV_VIEWPROJ 10 inverse of projection × view
NATINY_CONSTANT_CAMERA_POS 11 vec4: the eye in world space
NATINY_CONSTANT_TARGET_SIZE 12 vec4: width, height, 1/width, 1/height

Example

C
natiny_material_set_vertex_constant(material, "u_mvp", NATINY_CONSTANT_WORLDVIEWPROJ);

Notes

  • Matrix constants (NATINY_CONSTANT_WORLD through NATINY_CONSTANT_INV_VIEWPROJ) require a mat4 member. NATINY_CONSTANT_CAMERA_POS and NATINY_CONSTANT_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.