I\'ve been trying to make a structure that will contain all the lights of my WebGL app, and I\'m having troubles setting up it\'s values from JS. The structure is as follows
You're doing it right. You could try to tighten it up a bit as in
lightLocations = [
"position",
"diffuse",
"specular",
"ambient",
"spotDirection",
"spotCutOff",
"constantAttenuation",
"linearAttenuation",
"quadraticAttenuation",
"spotExponent",
"spotLightCosCutOff",
];
var program = {
uniform: {
lights: [];
}
};
for (var ll = 0; ll < numLights; ++ll) {
var locations = { };
for (var jj = 0; jj < lightLocations.length; ++jj) {
var name = lightLocaitons[jj];
locations = gl.getUniformLocation(program, "lights[" + ll + "]." + name);
}
program.uniform.lights[ll] = locations;
}