Skip to content

Skip regeneration and sorting when the camera turns in place - #512

Open
vanyathecyborg wants to merge 1 commit into
sparkjsdev:mainfrom
vanyathecyborg:contrib/turn-reuse
Open

vanyathecyborg wants to merge 1 commit into
sparkjsdev:mainfrom
vanyathecyborg:contrib/turn-reuse

Conversation

@vanyathecyborg

Copy link
Copy Markdown

Generated splats are stored relative to the camera position, view-dependent color reads only that position, and the default radial sort orders splats by distance from it. None of these depend on where the camera looks, yet a turn in place regenerated meshes with spherical harmonics and queued a new sort.

SplatMesh now bumps its version for view-dependent color only when the view origin changes; enableViewToObject still bumps it on any change. SparkRenderer treats a change of direction as a view change only under directional sorting. LoD traversal reads the camera it is given, since the generated view can now be older.

Verification

  • New browser test turn.test.ts: it turns the camera in place, then forces a new generation and sort at the same pose.
    • On main the turn already regenerates and sorts, so the test fails.
    • With this change the turn reuses the generated splats and their order, and draws exactly the image the new generation and sort draw.
  • New unit tests cover radial and directional sorting, a turn and a move with spherical harmonics, enableViewToObject, and LoD following a turn.
  • Turning in place inside a 15.7M-splat scene (third-order SH, LoD at 2.5M splats, 1920×1080, Apple M4 Max, Chrome 158), every frame followed by a one-pixel readback so it waits for the GPU, two alternating runs per build: 15.03 → 14.56 ms per frame, frames with a new generation 31% → 2%, sorts 157 → 21 over 900 frames.
  • Lint, unit tests and the full browser suite pass.

Behaviour change

A custom modifier that reads the view rotation on a mesh with spherical harmonics, without enableViewToObject, no longer updates on a turn. Setting that flag restores it.

🤖 Generated with Claude Code

Generated splats are stored relative to the camera position,
view-dependent color reads that position, and the default radial sort
orders splats by their distance from it. None of these depend on where
the camera looks, yet a turn in place did the work again:

- A mesh with spherical harmonics bumped its version on every change of
  the view matrix, so turning frames generated every splat again and
  queued a sort.
- A turn of more than about 2.6 degrees counted as a view change and
  asked for a new generation and sort, also under radial sorting.

SplatMesh now bumps its version for view-dependent color only when the
view origin in object space changes. enableViewToObject still bumps it on
any change, since it promises modifiers the whole transform. SparkRenderer
counts a change of direction as a view change only under directional
sorting.

With no new generation on a turn, the generated view can be older than
the camera, so LoD traversal reads the camera it is given.

Turning in place inside a 15.7M-splat scene with third-order spherical
harmonics, drawn with LoD at 2.5M splats, 1920x1080 on an Apple M4 Max in
Chrome 158: 900 frames sweeping 60 degrees to each side, each followed by
a one-pixel readback so that it waits for the GPU, two alternating runs
per build. Frames went from 15.03 to 14.56 ms, frames with a new
generation from 31% to 2% (the LoD updates), and sorts from 157 to 21.

Unit tests cover radial and directional sorting, a mesh with spherical
harmonics on a turn and on a move, enableViewToObject, and LoD following a
turn. turn.test.ts checks in the browser that a turn draws exactly what a
new generation and sort at that pose draws.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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