您必须为每种基本类型获取一个位置。在你的例子中
struct LightInfo {
vec4 Position; // Light position in eye coords.
vec3 La; // Ambient light intensity
vec3 Ld; // Diffuse light intensity
vec3 Ls; // Specular light intensity
};
uniform LightInfo Light;
意味着你需要
var lightPosLoc = gl.getUniformLocation(program, "Light.Position");
var lightLaLoc = gl.getUniformLocation(program, "Light.La");
var lightLdLoc = gl.getUniformLocation(program, "Light.Ld");
var lightLsLoc = gl.getUniformLocation(program, "Light.Ls");
如果您有数组,则需要每个数组的每个字段的位置,如
struct LightInfo {
vec4 Position; // Light position in eye coords.
vec3 La; // Ambient light intensity
vec3 Ld; // Diffuse light intensity
vec3 Ls; // Specular light intensity
};
uniform LightInfo Lights[2];
// ---
var light0PosLoc = gl.getUniformLocation(program, "Lights[0].Position");
var light0LaLoc = gl.getUniformLocation(program, "Lights[0].La");
var light0LdLoc = gl.getUniformLocation(program, "Lights[0].Ld");
var light0LsLoc = gl.getUniformLocation(program, "Lights[0].Ls");
var light1PosLoc = gl.getUniformLocation(program, "Lights[1].Position");
var light1LaLoc = gl.getUniformLocation(program, "Lights[1].La");
var light1LdLoc = gl.getUniformLocation(program, "Lights[1].Ld");
var light1LsLoc = gl.getUniformLocation(program, "Lights[1].Ls");
和数组数组等。
struct LightInfo {
vec4 Positions[2]; // Light positions in eye coords.
vec3 La; // Ambient light intensity
vec3 Ld; // Diffuse light intensity
vec3 Ls; // Specular light intensity
};
uniform LightInfo Lights[2];
// ---
var light0Pos0Loc = gl.getUniformLocation(program, "Lights[0].Positions[0]");
var light0Pos1Loc = gl.getUniformLocation(program, "Lights[0].Positions[1]");
var light0LaLoc = gl.getUniformLocation(program, "Lights[0].La");
var light0LdLoc = gl.getUniformLocation(program, "Lights[0].Ld");
var light0LsLoc = gl.getUniformLocation(program, "Lights[0].Ls");
var light1Pos0Loc = gl.getUniformLocation(program, "Lights[1].Positions[0]");
var light1Pos1Loc = gl.getUniformLocation(program, "Lights[1].Positions[1]");
var light1LaLoc = gl.getUniformLocation(program, "Lights[1].La");
var light1LdLoc = gl.getUniformLocation(program, "Lights[1].Ld");
var light1LsLoc = gl.getUniformLocation(program, "Lights[1].Ls");
ETC...