ERROR: Too many uniform interface blocks in vertex shader (18 exceeds max 16)

Error spotted by @Necips on my Forest beta, that I haven’t seen before. The culprit is a rig of lights (16) affecting a material that’s been given material.maxSimultaneousLights=16; to support all of them. WebGL 2 browsers throw this error and fail to compile the shader.

Does anyone know, is this a hard limit in WebGL 2? Is it implementation-specific?

Edit: Nope, cloning the lights doesn't help.

I’m going to try using the DirectionalLight.clone() method to create the lights in the rig, to see if perhaps that allows the shader to pack them into a single uniform.

Any advice is appreciated. (Meantime, I’m using fewer lights as a stopgap.)

Babylon is using one UBO (Uniform Buffer Object) per light to pass light information to the shader.

On my GTX 1080 I have 24 UBOs available in WebGL2. It seems on your card the limit is 16. Note that Babylon is also using one UBO for scene data and one UBO for the material data, so in the end you would need 18 UBOs (hence the 18 in the error message).

Note that 18 lights is a very high number, you normally don’t want so many lights active for a mesh!

1 Like

In other words, it’s going to be video card specific. Gotcha. It looks like 12 is the spec minimum for WebGL 2, but on a 4 year old laptop both the integrated and discreet graphics report 16. So 10 lights per mesh is the absolute safe maximum, but you’ll probably get away with 14. You should be able to ask for the max with:

var glContext = canvas.getContext('webgl');
var maxUniforms = glContext.getParameter(glContext.MAX_COMBINED_UNIFORM_BLOCKS));

(Although I can’t get it working.)

As for 16 lights, well… without shadows, they’re really not that expensive to render. Back in the special effects world, that’d be nothing! :wink: Thanks, @Evgeni_Popov