Large number of shadows - WebGPU

Been working on shadows for local lights for Shade. Still WiP

There are 131 lights in the scene:
1 directional light, which is shadowed with a 3-cascade CSM as before
130 point lights

The system is fairly complex, with all shadows being drawn to the same atlas, including the CSM.

Here’s what the atlas looks like

The lights are scored each frame, and we have a fixed update budget, prioritizing most visible lights that occupy largest area of the screen.

There is a catch-up mechanic, that guarantees that if a light is on-screen, it will eventually be updated.

The second piece of the puzzle is automatic resizing. Lights don’t specify a shadow resolution. Instead - we update resolution each frame… well, not really, but we we allow the resolution for each shadow to change each frame.

So if a light is occupying a very small area of the screen - it gets a very small area in the atlas allocated to it. If the light is not even seen currently - it gets the tiniest area possible - 32x32 in this case.

If you look at the atlas, you’ll be able to notice, there are 5 point lights with 1024 resolution,

a couple with 512,

a handful with 128

and a bunch with 64x64

There’s a one light that happens to be 32x32

And if we move the camera around a bit, the lights that we never seen before get populated as well


There’s a lot of trickery that goes into making this work, but it does work, and it runs pretty well. I’m still going to work on separate render pipeline for local lights to squeeze out extra performance for them, but I’m very happy with the current results.

Theoretically - there is no limit on the number of lights, even if the space in the atlas is always going to be limited.

4 Likes

I am in awe:)

1 Like

Here’s another one, Bistro scene, 129 light sources in here, all shadowed in real-time.

All 3 types of lights are present:

  • Point lights: light bulbs, hanging pendant lights, street lights
  • Spot lights: flood lights on the building facade, bike front light
  • Directional light: there’s a faint moon illumination in the scene

Here are just the point lights that can be seen in the screenshot

And spot lights

4 Likes

Looks amazing and scary photorealistic.

Eager to witness the moment when you introduce light sources of any shape (think of rectangular light panels, neon light texts, light billboards of irregular shapes).

2 Likes