natiny_material_set_instanced
void natiny_material_set_instanced(NatinyMaterial material, bool instanced);
Makes the material able to draw many copies of a mesh in one draw call. The shader is not changed: the engine compiles an instanced form of it automatically.
Parameters
| Name | Type | Description |
|---|---|---|
material |
NatinyMaterial |
Material handle from natiny_material_create |
instanced |
bool |
true compiles and keeps the instanced forms; false releases them |
Example
NatinyMaterial stone = natiny_material_create(lit_shader);
natiny_material_add_tag(stone, "world");
natiny_material_set_instanced(stone, true);
for (int i = 0; i < 500; i++) {
NatinyModel model = natiny_model_create();
natiny_model_set_mesh(model, house);
natiny_model_set_material(model, stone);
natiny_entity_set_position(model, NATINY_SPACE_WORLD, i * 12.0f, 0.0f, 0.0f);
}
/* inside a camera bind: the 500 houses are one draw per mesh part */
natiny_render_tag("world", NATINY_SORT_MATERIAL);