natiny.material.set_instanced

Lua
natiny.material.set_instanced(material [, 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 Default Description
material number Material handle from natiny.material.create
instanced boolean true true compiles and keeps the instanced forms; false releases them

Example

Lua
local stone = natiny.material.create(natiny.shader.load(natiny.resource.load("shaders/lit.nsl")))
natiny.material.add_tag(stone, "world")
natiny.material.set_instanced(stone, true)

local house = natiny.mesh.load(natiny.resource.load("models/house.glb"))
for i = 1, 500 do
    local model = natiny.model.create(house, stone)
    natiny.entity.set_position(model, natiny.entity.SPACE_WORLD, i * 12, 0, 0)
end

-- inside a camera bind: the 500 houses are one draw per mesh part
natiny.render.tag("world")