O'Reilly logo

WebGL Game Development by Sumeet Arora

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multiple lights and shaders

The provided solution in the previous section to add lights to our scene is not a scalable solution because if we wanted to add four or more lights, we would have had to add more uniforms to our shader. WebGL limits the amount of storage for uniforms. If we exceed the limit, we would get a compile-time or a runtime error. You can query the number of allowed uniforms using the following functions:

gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
gl.getParameter(gl. MAX_FRAGMENT_UNIFORM_VECTORS);

Also, the ambient color from all lights need not be calculated in the shaders as the ambient component is independent of distance and orientation of the object. We can sum the ambient color from all lights and pass the sum to the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required