EDIT: Uh oh, I may have spoken too soon. It works fine… in the trivial case with just one light in the array. I can’t get it to work with two lights yet. I’ll keep poking at it and I’ll update this again when I have a solution.
EDIT AGAIN: Okay I fixed it, it was a goof on my part elsewhere in my sketch, and I can confirm that my solution does indeed work with a dynamic number of point lights (up to my shader’s arbitrary maximum).
Thank you so much! That link contained just the answer I was looking for. For posterity, I have a uniform array of LightInputData in my fragment shader, like this:
uniform LightInputData uPointLights[MAX_POINT_LIGHT_COUNT];
and I want to use
setUniform to send data from my sketch to this array. The correct way to do it is to access each named field in the struct individually, by name, within the array, like this:
…and so on for each element in the array. My solution for doing it with the array of lights I have in my sketch is to loop like this (and this does seem to work):
for (let i = 0; i < pointLightCount; ++i)
let pointLight = pointLights[i];