WebGLRenderer allocates one shadow map per light even for lights that are not supposed to cast shadows
This issue is related to this question.
As you can see on shadowmap_pars_fragment.glsl, a new shadow map is allocated on GPU for every light, even for those having
castShadow = false;
#ifdef USE_SHADOWMAP ... #if NUM_DIR_LIGHTS > 0 // Reserving NUM_POINT_LIGHTS texture units uniform sampler2D directionalShadowMap[ NUM_POINT_LIGHTS ]; varying vec4 vDirectionalShadowCoord[ NUM_POINT_LIGHTS ]; #endif ... #endif
This is a problem because the GPU has a rather limited capacity of concurrent texture slots. The following error can occur when there are too much lights with
renderer.shadowMap.enabled = true :
gl.getProgramInfoLog Fragment shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (16).
On this fiddle, we’re only using 4 concurrent shadow maps by moving some
LightShadow and setting
light.castShadow = true to the 4 nearest lights.
But if you try to increase the number of lights (just change
numLightRows), You may see the error.
Additionally, You may also see the error :
Varyings over maximum register limit
Which is bound to the number of shadows coordinates that are sent to the fragment shader.
- All of them
- All of them
Hardware Requirements (graphics card, VR Device, …)
Depends on maximum texture units.
Check the Max Texture Image Units here