natiny.shader.reload

Lua
natiny.shader.reload(shader, nsl_source)

Replaces the source of an existing shader. The handle does not change.

Parameters

Name Type Description
shader number Live shader handle from natiny.shader.load
nsl_source number Resource handle containing the new .nsl source

Example

Lua
local shader   = natiny.shader.load(source)
local material = natiny.material.create(shader)
local replacement = natiny.resource.load("shaders/water.nsl")

-- edit the .nsl, load it again, and the material draws with the new code
natiny.shader.reload(shader, replacement)
natiny.resource.destroy(replacement)

Notes

  • Every material built from this shader keeps working and draws with the new code. Nothing has to be rebuilt by hand.
  • The new source must declare the same uniforms, textures, samplers, vertex inputs and render targets as the old one, in the same order. Source that moves, adds or removes one is refused; the shader body may change.
  • Raises an error if shader is not live, the source does not compile or its declarations changed. A failure leaves the shader exactly as it was.
  • The source bytes are consumed during the call and may be destroyed after a successful reload.