Skip to content

Clustered light culling for scenes with many lights (ABI 1.21) - #126

Merged
dmccoystephenson merged 2 commits into
mainfrom
feat/clustered-lights
Nov 26, 2026
Merged

dmccoystephenson merged 2 commits into
mainfrom
feat/clustered-lights

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Clustered light culling is added so a scene can hold hundreds or thousands of point and spot lights. ABI minor 20 → 21, STRATA_ABI_VERSION stays 1. Culling is off by default, and then every earlier golden is drawn bit for bit (all existing goldens are unchanged).

What is added (ABI 1.21)

  • strata_set_light_culling(engine, STRATA_LIGHT_CULLING_CLUSTERED): strata_set_point_lights and strata_set_spot_lights take up to STRATA_MAX_CLUSTERED_LIGHTS (4096) each instead of 32. Each lit frame the view frustum is cut into 16 × 9 tiles × 24 depth slices; the lights whose range reaches each cluster are listed on the CPU (at most STRATA_MAX_LIGHTS_PER_CLUSTER, 256, brightest kept), packed into an RGBA32F texture on unit 10 (a ring of three, so uploads never wait on a frame in flight), and each lit fragment evaluates only its cluster's list via texelFetch, so the same path runs on WebGL 2. Shadowed lights still share the four cube maps. Switching back to STRATA_LIGHT_CULLING_NONE while more than 32 lights of a kind are set is STRATA_ERROR_INVALID_STATE.
  • StrataLightStats + strata_get_light_stats: lights in view, lit clusters, list entries, longest list, overflowed clusters and culling CPU time for the last frame.
  • The GLES device saves and restores unit 10 for a host context, so it needs 12 fragment texture units instead of 11.
  • Scene keyword light_culling none|clustered; strata-golden prints the light stats for clustered scenes; C# and Python bindings with layout tests; tests/unit/test_clusters.cpp; design, limits and timings in docs/LIGHTING.md.

Rough llvmpipe numbers from docs/LIGHTING.md (ratios only; shared, busy machine): 32 lamps unculled 250 ms/frame vs 60 ms clustered; 256 lamps clustered 192 ms. Culling CPU time stayed under 1 ms at 1024 lights.

Golden

One new scene, light_clustered_street_night: a synthetic town at midnight with 240 street lamps and 16 spot lights, written by tools/gen_street_lights_scene.py. It is new, so there is no "before":

light_clustered_street_night

The web-swiftshader.png golden is taken from this pull request's first golden-out-web artifact in a follow-up commit.

Testing

Local (Mesa 21 llvmpipe): build, ctest, strata-golden check (37 scenes; the only failure is tex_globe_sun, whose golden is CI-blessed for CI's Mesa and is known to differ on Mesa 21). This builds on the ABI 1.20 materials change (#124), now on main.


drafted by Claude on behalf of Daniel Stephenson

🤖 Generated with Claude Code

https://claude.ai/code/session_01LYNeunMSrWW3U3RS97BYKD

dmccoystephenson and others added 2 commits November 25, 2026 19:15
strata_set_light_culling(engine, STRATA_LIGHT_CULLING_CLUSTERED) lets the
point and spot light lists hold up to 4096 lights each. Every lit frame the
view frustum is cut into 16 x 9 x 24 clusters, the lights reaching each one
are listed on the CPU (at most 256 per cluster) and packed into an RGBA32F
texture on unit 10, and each lit fragment evaluates only its cluster's list;
the same path runs on WebGL 2. StrataLightStats and strata_get_light_stats
report the last frame's culling. Off by default, and then every earlier
golden is drawn bit for bit.

Scene keyword light_culling, golden light_clustered_street_night (a
synthetic town, tools/gen_street_lights_scene.py), C# and Python bindings,
unit tests and docs/LIGHTING.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYNeunMSrWW3U3RS97BYKD
Taken from CI run 45740342622's golden-out-web artifact (SwiftShader,
WebGL 2); it is within 0.15% of the llvmpipe golden.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LYNeunMSrWW3U3RS97BYKD
@dmccoystephenson
dmccoystephenson merged commit 5c729cf into main Nov 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant