Skip to content

Viewer perf: occlusion culling, high tier without AO pre-pass, readable highlights - #1228

Merged
wass08 merged 4 commits into
mainfrom
perf/occlusion-culling
Nov 6, 2026
Merged

wass08 merged 4 commits into
mainfrom
perf/occlusion-culling

Conversation

@wass08

@wass08 wass08 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #1224.

Occlusion culling for baked scenes

Each time the camera moves, the building's opaque walls, slabs, roofs and ceilings are rasterized on the CPU into a 256-px depth image. Every drawn mesh (static-merge batches and the meshes left individual) whose box lies wholly behind it is skipped for that render through three's drawing pipeline (isCulled).

  • Same-frame and conservative: no readback lag, occluder image eroded by a pixel, boxes dilated, anything crossing the near plane is drawn.
  • Only renders through the main camera are culled: the sun's cached shadow map and captures still see everything.
  • Recomputed when the camera moves (1.5-3.5 ms), otherwise only when the scene changes. Shows as occlusion-cull in ?perf; ?occlusion=0 draws everything.
  • Measured (M5 Max headless, A/B in one session): rn9 overview 26 -> 32 fps (3229 -> 2302 draws), hav5 overview 38 -> 50 fps (capped; 1829 -> 1049 draws). Screenshots on vs off are identical.
  • Not added to the editor: there, the most it could save in an overview is ~4.6 ms of CPU (batched instances are cheap draws), about what culling would cost while moving.

High tier: GTAO from the scene pass

The enhanced viewer's high tier fed GTAO from a depth/normal/velocity pre-pass, which draws the whole scene a second time. On an editor scene that doubled every draw. High now uses medium's path at full resolution.

  • Editor, 5-level house, high: 40 -> 46 fps, encode 22.8 -> 12.0 ms, draws 7873 -> 3994.

Editor highlights stay readable

  • The selection tint ran at full strength: its intensity was max(material's, 0.12), and a material's default is 1. tintEmissive folds the strength into the colour (selection 0.12, wall hover 0.08, delete unchanged).
  • At night the daylight look treated the tinted clone as a glowing surface (night boost, exposure lift, bloom), and on lamp items the lamp system turned it into a lamp emitter. A selected fan lit up like a bulb. markHighlight flags highlight materials: kept out of all of that, with exposure-compensated emission so the tint reads the same day and night, and its own program cache key (three's ignores userData).

Test plan

  • check-types, viewer tests (1345), nodes tests, editor component tests, biome
  • Occlusion culler unit tests (box behind/beside/in front of walls, glass, merged walls, holes, near plane, orthographic, pipeline hook)
  • Visual A/B on rn9 and hav5 (overview, walkthrough), editor selection at night and midday

🤖 Generated with Claude Code


Note

Medium Risk
Adds a custom occlusion culler hook and reworks GTAO/daylight lighting paths, so GPU/CPU rendering behavior could regress if culling or AO math misclassifies geometry.

Overview
perf(viewer): occlusion culling, GTAO rework, highlight fixes

Introduces a conservative CPU occlusion culler for baked GLB scenes that rasterizes major shells into a tiny depth buffer and plugs into renderer.drawingPipeline.isCulled, toggleable with ?occlusion=0, rebuilding whenever static merges update. High-quality ambient occlusion now shares the single scene-pass medium-tier path at full resolution (drops the extra pre-pass), rewires daylight room lighting to match, and keeps temporal buffers consistent.

Adds an editor-highlight toolkit (markHighlight, tintEmissive) so selection clones keep stable tint strength, bespoke program keys, and skip daylight emitter/bloom boosts; wall highlights adopt the same behavior. Bloom now masks highlighted pixels via the lighting MRT channel, room emitters ignore highlight clones, and Bun tests cover the new helpers plus the occlusion module.

Risk: Medium — touches WebGPU post-processing, daylight lighting hooks, and a new render-time culling path that could mis-hide meshes if assumptions break.

Reviewed by Cursor Bugbot for commit e07a566. Bugbot is set up for automated code reviews on this repo. Configure here.

wass08 and others added 4 commits November 6, 2026 14:51
Each time the eye moves, the building's opaque walls, slabs, roofs and
ceilings are rasterized on the CPU into a 256-px depth image; every drawn
mesh (static-merge batches and the meshes left individual) whose box lies
wholly behind it is skipped for that render through three's drawing
pipeline (`isCulled`). A level's floor hides the levels under it, a facade
the rooms behind it.

- Same-frame and conservative: no readback lag, occluder image eroded by a
  pixel, boxes dilated, anything crossing the near plane drawn.
- Only renders through the main camera are culled: the sun's cached shadow
  map and captures still see everything.
- Recomputed when the camera moves (1.5-3.5 ms), otherwise only when the
  scene changes. Shows as `occlusion-cull` in `?perf`; `?occlusion=0`
  draws everything.

Measured (M5 Max headless, same session A/B): rn9 overview 26 -> 32 fps
(3229 -> 2302 draws), hav5 overview 38 -> 50 fps (capped; 1829 -> 1049
draws); renders identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The high tier fed GTAO from a depth/normal/velocity pre-pass so AO darkened
indirect light only (the enhanced viewer's `gtao-indirect`). The pre-pass
draws the whole scene a second time: on an editor scene of thousands of
meshes it doubled every draw (7873 vs 3994 on a 5-level house) and the
encode cost with it.

High now uses medium's path at full resolution: GTAO from the scene pass's
depth and normals, blended softly over the whole image. The daylight room
context loses its unused AO input.

Measured (M5 Max headless, editor, high): 40 -> 46 fps, encode 22.8 ->
12.0 ms, draws 7873 -> 3994.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The selection, hover and delete highlights tint the object with a soft
indigo emissive. Under a night exposure that crossed the bloom threshold
and hazed over the selected item, killing its readability.

Highlight materials are now marked `noBloom`; the scene pass's lighting
mask carries a bloom weight (G channel, 0 for those materials) and the
bloom input is weighted by it. The highlight itself is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The selection highlight was meant to be a soft indigo emissive (0.4 x 0.12)
but ran at full strength: its intensity was max(material's, 0.12), and a
material's default intensity is 1. At night it got worse twice over: the
daylight hooks treated the tinted clone as a glowing surface (night boost,
exposure lift), and on lamp items the lamp system swapped it for a lamp
emitter at full display brightness. A selected fan lit up like a bulb.

- `tintEmissive` folds the intensity into the colour: the material's own
  glow plus the tint at its own strength (selection 0.12, wall hover 0.08,
  delete unchanged at 0.92).
- `markHighlight` (replaces `markNoBloom`) flags the clone: kept out of the
  bloom, the night emitter boost and the lamp emitters, and its emission
  divided by the metered exposure so it reads the same at any time of day.
  It gets its own program cache key (three's ignores userData, so the clone
  otherwise reused its source's program and the hooks never saw it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e07a566. Configure here.

if (!mesh.geometry.boundingBox) mesh.geometry.computeBoundingBox()
if (!mesh.geometry.boundingSphere) mesh.geometry.computeBoundingSphere()
occludees.push(mesh)
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instanced meshes culled from local bounds

Medium Severity

list() skips skinned meshes but still treats InstancedMesh as a normal mesh. Culling then tests geometry.boundingBox transformed by matrixWorld, ignoring per-instance matrices. If that local box sits behind an occluder, every instance is skipped even when copies are visible elsewhere.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e07a566. Configure here.

@wass08
wass08 merged commit d69f614 into main Nov 6, 2026
4 checks passed
@wass08
wass08 deleted the perf/occlusion-culling branch November 6, 2026 20:04
wass08 added a commit that referenced this pull request Nov 6, 2026
…ottosson/performance) (#1232)

* Viewer CPU: one scene walk per frame, nested node batching

- scene-matrices: one dirty-tracked matrix update per frame instead of three's
  full update in every pass; subtrees nothing in the frame draws (batched
  originals, a soloed level's shadow-only content) are hidden for the render
  only and skipped by the walk while the layout revision holds.
- Node batching reaches nodes nested under hosts (cabinet modules, items on
  items, wall/ceiling-hosted items); a host's edits, gestures and tint release
  what it carries. Cabinets, cabinet modules and shelves opt in.
- Solo re-hide, shadow bounds and fences no longer walk the scene every frame.

Waterfront 41-49 -> ~16 ms frame CPU, apartment 29 -> ~15 ms (dev build,
RTX 3060 Ti, High tier).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Viewer CPU: unsorted item batches, cloud-free fog, shared level arrays

- Item batches skip the per-pass depth sort (opaque; the prepass lays depth).
- Fog samples a cloud-free horizon radiance: the clouds fade out at the fog's
  elevation, so the two fbm calls per fragment and cloudTime (which moved every
  frame) drop out of every fogged material.
- The room light's level arrays move to a shared uniform group bumped only when
  a level moves: as per-object array uniforms they were re-uploaded for every
  object in every pass (~760 writeBuffer a frame in the apartment, now 1).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Port fixes: culler sees set-aside occluders; item batches keep their sort

- The occlusion culler (#1228) runs inside the render, where
  `renderWithSceneMatrices` hides subtrees nothing draws: the merged
  originals it rasterizes as walls and slabs. They count as shown again
  (`isSetAsideForRender`), as the merged outline already does; test added.
- Item batches keep three's front-to-back sort: `sortObjects = false` was
  justified by the depth pre-pass, which #1228 removed, and on a GPU-bound
  editor the overdraw costs more than the sort saves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Moving an item: stays on its level, no floating, no rebuild storms

Moving an item (e.g. a bedside carrying a lamp) hitched for seconds and
could hop floors:

- Placement: hovering another floor's furniture, slab, wall, ceiling or
  roof (past the building edge, through a window) re-parented the item to
  that floor mid-gesture. With a level selected, the move tool now ignores
  surfaces on other levels; the floor cursor keeps following the selected
  one.
- Leaving a host back to the floor kept the surface move's live transform,
  a building-space cursor (the host's top, level height included), which
  the remounted item read level-local: a bedside left on a 4th-floor bed
  floated ~10 m up until the next floor move. The detach publishes the
  floor pose.
- Daylight rooms rebuilt (thousands of rays, ~1.6 s) on every scene edit;
  furniture edits and child-list-only changes no longer trigger it (a moved
  lamp still does, through its light's position).
- The live stair/elevator opening systems replanned on a level's child
  list changing; they now ignore child lists, as the document reconcile
  already does.
- Node batching cascaded releases from any dirty node, including a level
  whose child list changed: the whole floor's batches were released and
  rejoined. Levels, buildings and sites no longer cascade (also fixes two
  history tests that expected only a wall's own openings to release).

Measured on a 5-level condo, moving a bedside with an item on top across
the screen: worst frame 2.3 s -> 0.5-0.85 s, no level hops, correct height.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: bottosson <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@Aymericr Aymericr mentioned this pull request Nov 10, 2026
2 of 4 tasks
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