Hello everyone, I am writing a shader and I need to somehow transfer the parameters to it.
In the code I found some structure, but I do not understand how it works.
Build upon @looeee example by passing an object array to the uniform value, i.e.:
var lightdef={
position: new THREE.Vector4(),
ambient: new THREE.Vector4(),
...
spotCutOff: 1.0};
const uniforms = {
Lights: { value:
[lightdef,
...
lightdef]
}
};
Per webGL 1.0 specifications, arrays allow dynamic indexing with constant expression and can’t be a variable. The only exception is for uniform access in vertex shaders, which can be indexed using any expression. The same applies when you want to access the object from the array. The implementation of this specification may depends on the platform compiler though, so for setup/test purpose I would try without a variable…
In other words:
ok: uniform Lights lights[10]; may not be ok: uniform Lights lights[count];