PBR Light Limits

Description of the problem

When adding more point lights to the PBR Light demo VIA

            for (var i = 0; i < SOME_NUMBER; i++) {
                var bGeometry = new THREE.SphereGeometry(0.02, 16, 8);
                var bLight = new THREE.PointLight(0xffee88, 1, 100, 2);

                var bMat = new THREE.MeshStandardMaterial({
                    emissive: 0xffffee,
                    emissiveIntensity: 1,
                    color: 0x000000
                });
                bLight.add(new THREE.Mesh(bGeometry, bMat));
                bLight.position.set(0, 2, i);
                bLight.castShadow = true;
                bLight.power = bulbLuminousPowers[params.bulbPower];
                bMat.emissiveIntensity = bulbLight.intensity / Math.pow(0.02, 2.0)

                scene.add(bLight);
            }

If SOME_NUMBER is > 12 everything breaks all lighting with WEBGL complaining about running out of registers.
It may be an idea to check how many lights are on the current scene, and only render with up to the (13) (12+ the original one in the example) closest to the camera ones at any given time, or do multiple renders for the excess lights?

The exact error is:
THREE.WebGLProgram: shader error: 0 gl.VALIDATE_STATUS false gl.getProgramInfoLog Fragment shader sampler count exceeds MAX_TEXTURE_IMAGE_UNITS (16).

Three.js version
  • Dev
  • r75
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, …)

Author: Fantashit

1 thought on “PBR Light Limits

  1. The exact issue you are suffering from is out of your power and even out of the power of the development team. There is nothing you can do in order to fix the problem unless you do some crazy atlas texture map that holds all the shadow information for all the lights. Even if you have a graphics card that has a very sophisticated glsl compiler where you can make a program that actually does that, performance is just going to make the whole effort pointless.

    One thing you can do is to take advantage of the limitations of the human brain where it has a hard time seeing detail in some situations but you can almost instantly see something missing in other situations. On the dim lights that don’t light up a lot of the space, just ditch the shadows and no one will probably notice any of the shadows missing. Only add shadows to lights that are very bright and light up a large amount of objects and cast a lot of shadows. Just play around with the values and see what looks good.

    Another thing you can do is if you have a lot of lights that are spaced out very far from the camera, there is no need to render them because that specific light will not effect the local space (where the camera is).

    A last ditch effort would be to remove shadows from all the lights, it might look like there is detail missing from the scene but depending on what you are trying to make, it might still be fine and playable.

Comments are closed.