Clustered lighting

We’ve started using clustered lighting.

our code to turn it on is:
pc.WorldClusters.enabled = true; = true;
const lighting =;
lighting.cells = new pc.Vec3(10, 2, 10);
lighting.maxLightsPerCell = 8; = new pc.Vec3(10, 2, 10); = 8;

We use both the method described here and the code from the example here
(they differ and there are no proper docs on the feature)

First time I move a light and increase the intensity above 0 we get a spike and I can see that setShader is called. I didn’t expect this to happen when not enabling or disabling any lights.

So I’m thinking is clustered lights even active?
returns 1 while
returns 0 or 0.1 (flickers between them and the 0.1 is peculiarly stable between 0.0999 and 0.1001.

Calling @mvaligursky

At the moment, if there are no omni/spot lights, the lighting code is not added at all to standard shaders, as that increases their compilation time. When the first of those is added to the scene, the shaders recompile to support clustered lights, and when you add / remove lights (unless all are removed), the same shader is used.

You can confirm this here: PlayCanvas Examples
adding and removing lights does not rebuild shaders. I just tried local built of this, starting with 0 lights, and adding a first one recompiles shaders.
There’s still some cost there when other lights are added, which will get further reduced / removed when we fully switch to clustered lights.

For the future I am considering some way to force clustered lighting to shaders even when no lights are there (or disable lighting even when lights exist), but this has not been done yet.

So as a workaround for this for now, maybe have a tiny dark light permanently somewhere?

I created an issue for tracking: