Skip to content

BUILD-1657: Keep distant map LOD chunks visible - #5244

Open
whattheflop wants to merge 1 commit into
ItsNotRexed:mainfrom
whattheflop:fix/map-lod-camera-far
Open

whattheflop wants to merge 1 commit into
ItsNotRexed:mainfrom
whattheflop:fix/map-lod-camera-far

Conversation

@whattheflop

@whattheflop whattheflop commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as BUILD-1657.

What and why

Valid map manifests can select and load distant LOD chunks that the fixed 6,000 m camera plane clips. The fixed 2,600 m fog end also blends nearer distant chunks fully into the background.

After streaming selects the visible LOD chunks, derive the camera and fog reach from their farthest 3D bounds. Keep the existing ranges as floors and leave the load, unload and selection policy intact. Include regressions for distant, cached and ordinary chunks.

The scene-wide fog extends whenever a distant tier is visible, which reduces fog on nearby geometry in that frame. When camera movement changes the required far plane, the next frame updates the projection matrix.

Tested

  • node --test tests/test_viewer_streaming.cjs: 55/55. The new regressions reproduce the stock 6,000 m / 2,600 m limits on main.
  • Synthetic T3 Preview WebGL2 readback on Windows 11, RTX 3080 driver 616.64, ANGLE/D3D11. Both revisions loaded the same three chunks. Main rendered the 4,200 m and 6,800 m probes exactly as the background (156,195,230,255). This head produced (80,155,106,255) and (153,165,204,255), respectively. The nearby pixel and the background control were byte-identical.
  • Local integration with the Add a local asset viewer and reusable parts index (ASSET-375) #4763 viewer passed 65/65 combined streaming and asset viewer tests. git diff --check passed.

AI-assisted: yes.

Checklist

  • No game data, keys or decryption (including tests and logs).
  • Translator contract documentation is not applicable.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Head 9554b73 · Windows 11, Node 24.22.3

  • node --test tests/test_viewer_streaming.cjs -> 55/55 pass, 0 fail
  • Main repro: ran this PR's test file against origin/main:viewer/index.html -> 1 pass, 3 fail (the distant-LOD test and its two subtests fail on the stock 6000/2600 limits); PR head restored, worktree clean
  • git diff --check -> clean

updateViewRange() reads def.bounds only for manifest chunks with lod set; loadManifest already validates those as six finite ordered values, so there is no undefined-destructure path. stream() runs first, so evicting the last distant LOD resets far/fog to 6000/2600 in the same frame. Trade-off: one distant LOD raises the global fog.far, so near chunks get slightly less fog; acceptable with a single global fog.

I did not reproduce the WebGL2 readback numbers in the body; evidence here is the headless suite plus the main repro.

Verdict: merge-ready.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Independent CPU review at 9554b73378883ee26cb5fb720f57346c1f878942, against upstream 3faac557b1584d39004357918e60325b4d4ff0fe. No actionable findings in this scope.

  • On Windows with Node 24.18.0, node --test tests/test_viewer_streaming.cjs passes all 55 tests.
  • Negative control: the same exact test source, with only its viewer/index.html read redirected in memory to upstream, gives 52 passes and 3 failures. These are the distant projection (far plane 6000 versus a required corner distance of 9650.91), fog end (2600), and cached fallback coverage assertions.
  • Two additional in-memory controls use the PR's full-module fixture and unchanged production source. A hidden cached HD tier remains resident but stops expanding camera/fog ranges once its replacement becomes visible. An orphan HD chunk hidden within unload slack likewise restores the stock ranges. Returning makes the cached chunks visible and expands projection again without another download.
  • Source review confirms that the range update follows streaming visibility selection on every frame, covers the farthest 3D corner, excludes hidden/unloaded/non-LOD chunks, and preserves the near plane and ordinary defaults. git diff --check is clean; the detached PR source remains unchanged.

All inputs were synthetic. This is CPU-only evidence; I did not independently rerun the GPU rendering checks.

AI-assisted: yes.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head 9554b73 (vs main 3faac55).

Commands:

  • node tests/test_viewer_streaming.cjs -> tests 55, pass 55, fail 0.
  • git diff --check: clean.

updateViewRange only counts loaded, visible LOD chunks; bounds are validated finite at world load, so the hypot cannot go NaN. It expands camera.far past the farthest bound corner and keeps fog depth <= 0.85 there, and the new test asserts both the expansion and the reset to 6000/2600 after eviction (outside LOD_SLACK). Inactive distant chunks do not inflate the projection, and plain maps, a nearby hd chunk and test-terrain mode keep the stock 6000/2600 (all asserted). The node harness does not render; only the range logic is covered.

Verdict: pass, no blockers.

@King1565

Copy link
Copy Markdown

Tested 9554b73 on Linux, Python 3.13 (CPU only, no GPU, no game files): pass with notes

Ran

  • node --test tests/test_viewer_streaming.cjs (Node 22.23.5): PR head 55/55 pass; main 51/51.
  • PR's test file against main's viewer/index.html: 52 pass / 3 fail. The distant-LOD test and both its subtests fail with projected far 6000 clips the bound 9650.9 and fog end 2600 leaves too little contrast, so the regression reproduces the bug. The stock-range test passes on both, as it should.
  • git diff --check upstream-main...pr-5244: clean. No Python touched, so no compileall.

Read
No defect found. updateViewRange() only counts LOD-tier chunks that have a loaded, visible obj. That covers orphan_hd and cached in-slack fallbacks, and skips in-flight entries and hidden tiers. It keeps 6,000 m / 2,600 m as floors and leaves load, unload and selection alone. bounds is always validated by loadWorld, so the destructure is safe.

Non-blocking notes:

  1. With a full --lod-sets world, the SLOD4 band in docs/world.md runs 6,043.5–20,000 m, so some SLOD4 cell is visible from nearly any position. Fog end then sits at about 25 km most of the time, and fog at 2,600 m drops from 100% to about 7%. That fits the goal, but it might be worth a line in the PR or in docs/world.md.
  2. camera.far follows the camera every frame, so updateProjectionMatrix() runs every frame while you move. It's cheap, just noting it.

AI-assisted (Claude Code).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 9554b73 on Windows Server 2022, CPython 3.13.12: pass

  • node tests/test_viewer_streaming.cjs -> pass 55, fail 0 (Node v24.22.2)
  • Negative control (viewer/index.html swapped to upstream/main): pass 52, fail 3

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@whattheflop

Copy link
Copy Markdown
Contributor Author

AI-assisted integration replay of this head with #7164 729126f on upstream 042c5f3 (dry tree a432af20). In T3 Preview, a deferred 6,800 m synthetic GLB rendered on the first controlled tick after its load completed, with the camera still. The far plane rose from 6,000 m to 6,958.19 m and fog end from 2,600 m to 8,696.49 m. Upstream loaded the same GLB but its pixel remained the background color. The 55 m control pixel matched between builds.

Both builds made the same two successful GLB requests. The combined viewer scanned at startup and after each completion, then skipped all other 24 stationary ticks. Upstream scanned on all 27 ticks. Node 24.16.0 viewer suites passed 72/72 on the dry tree and 65/66 on upstream, where the keyboard fixture lacks AbortController.

Synthetic assets only, Windows 11 build 26200, RTX 3080 with driver 32.0.16.1664, T3 Chromium WebGL 2 on ANGLE/D3D11 and Three.js r160. Hidden tabs used controlled ticks of the stock animation callback with ordinary HTTP, GLTFLoader and WebGL rendering. This checks the interaction between distant visibility and stationary scheduling.

@rideinstead

Copy link
Copy Markdown

✅ Automated security review: CLEAN (commit 9554b733)

  • No findings.

Scope: static analysis of added diff lines only; no code was executed. Please review findings manually.

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.

6 participants