I have a shader program that uses an array of a Light struct. It stores the light color and its position in world space. Problem is, i cannot use it in the scripts with go.set.:
function update(self, dt)
local light_color = lights:get_color(lights.sources[1])
go.set("#mBigCube", "lights[0].light_color", light_color)
local light_pos = lights:get_position(lights.sources[1])
go.set("#mBigCube", "lights[0].light_pos", light_pos)
end
Ah I see, no we don’t support uniform arrays like that, you have to split them into separate vec4 uniforms (or a single mat4 array) and use go.set with the index to set it to.
uniform vec4 light_pos[LIGHT_COUNT];
uniform vec4 light_color[LIGHT_COUNT];
go.set("...", "light_pos", vmath.vector4(...), {index = 1}) -- note: lua index starts at 1
or you can use arrays in constant buffers in the render script (API reference (render)):
local b = render.constant_buffer()
-- either set entire array directly
b.light_pos = { vmath.vector4(), vmath.vector4(), ... }
-- or set them using t[k] = v
b.light_color = {}
b.light_color[1] = vmath.vector4()
im going with the vec4’s approach, much thanks. I might open a feature request to support arrays like that, would come in handy dealing with materials and alike.
I was looking for an example with a matrix as uniform constant - maybe you could add a very simple example of setting a mat4 as a constant to the API docs?
What have you tried so far? You need to set the constant type to “User matrix4” in the material and then it shouldn’t be much more than doing a go.set() on the named constant.
But it doesn’t works out of the box, with previous changes and using new render with the render script (default), with the above changes before drawing tiles