Passing an array of vectors to a uniform

浪子不回头ぞ 提交于 2019-12-03 03:34:43

gl.uniform3fv expects a flattened array of floats. Also, you are calling it multiple times with the same uniform location. So, the last one wins. Imagine that uniform3fv is a low-level copy command, and you give it (destination, source). It just copies a buffer from one place to another.

Assuming your example has only 3 lights, you could assign the location uniform this way:

var locations = [
  1.0, 0, 0,
  0, 1.0, 0,
  0, 0, 0
];
gl.uniform3fv(shaderProgram.pointLightingLocationUniform, locations);

I would also recommend using a more simple shader when you are debugging problems like this. With something like the following in your vertex shader:

for (int i = 0; i < 3; i++) {
  vColor += uPointLightingLocation[i];
}

And fragment shader:

gl_FragColor = vec4(vColor, 1);

Then, if your polygons are yellow you know it is working.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!