I am trying to pass a dynamic size array of Vector3 into fragment shader. I get that there are methods like setFloats which I could use to add dynamic size array of floats, but I want the shader to automatically update uniform value whenever values in Vector3 changes. I want something like
const v1 = new Vector3(1,2,3);
const v2 = new Vector3(4,5,6);
const material = new ShaderMaterial(...my params...);
material.setVector3s("uMyVectors", [v1, v2]);
Then inside fragment shader
uniform int uSize;
uniform vec3 uMyVectors[uSize];
The size of array, uSize, is flexible, that is why I try to avoid calling setVector3 for each vector. This is possible in OpenGL. I’m curious if Babylon has that support?
Thank you for your reply!
So what if I want to use the values directly from vector/color? For example, I want to pass a position of object A. So when I move A, which changes values in its x y z of position, I want the shader to update automatically just like setVector3 or setColor3, except there may be any number of vectors/colors. Is it possible?
Currently in my project I’m working on, I create a custom class that extends ShaderMaterial, then dynamically call setVector3 and setColor3 multiple times with dynamic name assigning, then dynamically edit the shader string in the constructor.