Skip to content

viewer: fit shadow frustum to building geometry instead of camera#348

Merged
wass08 merged 1 commit into
mainfrom
viewer/shadow-fit-to-building
May 29, 2026
Merged

viewer: fit shadow frustum to building geometry instead of camera#348
wass08 merged 1 commit into
mainfrom
viewer/shadow-fit-to-building

Conversation

@wass08

@wass08 wass08 commented May 29, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Reworks how the directional-light shadow frustum is framed. It previously followed the camera look-at, which fell apart in practice:

  • Zoomed out the fixed ±50 frustum was far too small, so most of the scene got no shadows.
  • Zoomed into an empty corner the frustum centred on nothing, leaving the building unshadowed.

Now the frustum is fit to the building geometry, independent of the camera:

  • Union the bounds of all registered scene nodes (sceneRegistry.nodes), excluding site nodes so the large ground/site plane doesn't inflate the frustum.
  • Fit a bounding sphere → stable focus (center) + radius.
  • Size the ortho shadow camera to radius * 1.15 + 3 (the building "and a bit nearby"), park the light just outside the sphere along its theme direction, and bracket near/far around the sphere.
  • Bounds are recomputed on a short interval (~0.4s) since they only change while editing; empty scenes fall back to a sensible default region at the origin.

The light direction still comes entirely from the scene theme — only the light's distance and the frustum extents change.

Follow-up to #347.

How to test

  1. Run bun dev and open a project with a building.
  2. Zoom all the way out — shadows should cover the whole building plus a small surrounding margin (not a tiny patch).
  3. Zoom into a corner / pan around — shadows stay anchored to the building rather than tracking the camera.
  4. Add, move, or resize geometry — the shadowed region should re-fit within ~0.4s.
  5. Switch scene themes (Studio, Paper, Overcast, …) — shadows should still render correctly per theme.

Screenshots / screen recording

N/A — shadow-camera framing change; verified locally with a temporary CameraHelper (removed before this PR) confirming the frustum hugs the building bounds across zoom levels.

Checklist

  • I've tested this locally with bun dev
  • My code follows the existing code style (run bun check to verify)
  • I've updated relevant documentation (if applicable)
  • This PR targets the main branch

Following the camera look-at broke when zoomed out (fixed ±50 frustum
too small to cover the scene) and when zoomed into an empty corner
(frustum centred on nothing). Instead, fit the directional light's ortho
shadow camera to the building: union the registered scene-node bounds
(excluding the site/ground plane), fit a sphere, and size + place the
shadow camera to cover that sphere plus a margin. Bounds are refreshed on
a short interval since they only change while editing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@wass08 wass08 merged commit 986d750 into main May 29, 2026
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