Skip to content

fix(forest): cull and LOD chunks by their own box, grow boxes over instances, far dock and string lights - #514

Merged
kitlangton merged 1 commit into
mainfrom
fix/forest-cull-bounds
Oct 23, 2026
Merged

kitlangton merged 1 commit into
mainfrom
fix/forest-cull-bounds

Conversation

@kitlangton

@kitlangton kitlangton commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #512.

What it does

After #512 the Barbara dock could still vanish or switch LOD at the wrong distance. Each forest chunk was culled and LOD-switched from its cell centre, and its box ignored the instanced trees and props that stick out of it. Now each chunk is culled by its own box. The far LOD also draws the dock and the camp string lights, so they don't disappear when the camera pulls back.

How it works

  1. Each chunk keeps two boxes. bakedBox covers only the baked geometry. box is bakedBox grown to cover every instance's template extent.
  2. box drives only the frustum test, so a tree leaning into view is never culled.
  3. bakedBox drives the near/far switch, out-of-view retention and torch-caster reach. These use XZ distance to the box rather than to the cell centre, so the terrain near ring stays at 70 m. Instance LOD still uses cell distance.
  4. The pure helpers (boxDistanceXZ, nearStatic, boxInFrustum) live in the new packages/kit/forest/cull.ts.
  5. The far mesh adds a low-poly dock slab with posts and the string-light bulbs with posts, about 456 triangles.

Risk

The change is limited to the forest renderer in packages/kit/forest. Barbara is the only game that uses it. Growing the boxes keeps a few more chunks in view, which adds triangles but no measurable GPU time (table below). If a box were wrong, chunks would pop at the screen edge or the near/far switch would move.

At night, the dock still can't be seen from across the lake (70–100 m away), before or after this change. At that distance the deck is only a few pixels tall and nearly unlit. A test checks that the far mesh contains the deck, so it's covered even where a screenshot can't show it.

Proof

GPU frame time on the Mac mini at High quality, 5 alternating rounds, without → with instance extents (noise is about ±1 ms):

Shot Median ms Fastest ms Triangles
beam 79.7 → 80.2 78.4 → 79.0 2.52M → 2.89M
k1 66.8 → 65.7 64.75 → 64.93 1.21M → 1.41M
dockFar 49.4 → 49.0 48.6 → 48.9 1.37M → 2.12M
camp 36.95 → 36.98 36.83 → 36.93 0.79M → 0.89M

campEast zoom, before (left) and after (right): before, only the glows showed; now the bulbs are drawn too.

  • bun run verify: 49 steps pass
  • kit forest tests 32/32, Barbara tests/forest-cull.test.ts 2/2 (the dock is kept in view from mid range, near/far uses box distance, the far mesh contains the deck)

campEast-zoom

@kitlangton
kitlangton merged commit 67ba4a9 into main Oct 23, 2026
14 of 15 checks passed
@kitlangton
kitlangton deleted the fix/forest-cull-bounds branch October 23, 2026 20:07
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