Lights are a great way to add realism to your application, but real time lights can come with significant runtime performance cost. This becomes more impactful with a large number of lights, many of which are casting shadows.
Part of the solution is to limit the amount of lights affecting individual meshes. This is often implemented by finding and using lights that are nearby to each object. This has multiple disadvantages:
- As each object can use different sets of lights, a custom shader needs to be compiled to handle it.
- Large objects might need to split into smaller objects for this to be effective.
- Large number of shadow casting lights could cause the shader to run out of its available texture slots used by the shadow maps
PlayCanvas uses the clustered lighting solution to provide a performant implementation of omni and spot lights. This solves the problems listed above by storing information about the lights in textures and allows the GPU to easily use only the lights that are nearby to a fragment getting shaded.
We are in the process integrating the settings and features into the Editor for clustered lighting but in the meantime, @mvaligursky has created a PlayCanvas script that exposes the options and settings needed for this feature.
We will be looking to make clustered lighting the default system in the mid term (with option to revert back) as there is little to any disadvantage from what we have seen so far.
Over the longer term, our aim is to remove the current lighting system from the engine (reducing the file size) and only be using clustered lighting.
We also have some WIP documentation attached here: Clustered Lighting | Learn PlayCanvas
We would love to hear feedback on the feature and documentation below