Skip to content

spike(hdr): extended-range HDR canvas output behind ?hdr#497

Open
rulkens wants to merge 2 commits into
mainfrom
spike/hdr-mode
Open

spike(hdr): extended-range HDR canvas output behind ?hdr#497
rulkens wants to merge 2 commits into
mainfrom
spike/hdr-mode

Conversation

@rulkens

@rulkens rulkens commented Jul 23, 2026

Copy link
Copy Markdown
Owner

What

Exploratory spike proving skymap can drive an HDR display. The renderer already works in HDR internally (every pass draws into an rgba16float offscreen); a single final compositor pass tone-maps down to an 8-bit swap chain and clamps to [0,1]. This spike lets that signal reach the display.

Gated behind ?hdr + a (dynamic-range: high) display check — off by default, and the SDR path is bit-identical when the flag is off.

  • device.ts: when engaged, the swap chain becomes rgba16float + toneMapping: { mode: 'extended' } (Chrome HDR-canvas API). format is the single source of truth threaded to every swap-target renderer, so it propagates with no other wiring. hdr is threaded GpuContext → EngineGpuHandles → ReadyFrameContext.
  • Compositor: two previously-unused uniform lanes (bytes 24/28) carry hdrKneeStart + hdrHeadroom; the tone pass spills over-white energy above the knee on top of the clamped curve, so bright sources (Sun, bloom, bright stars) punch into headroom. hdrHeadroom = 0 (SDR) adds nothing.
  • renderFrame.ts: sets headroom/knee from ctx.hdr; HDR_KNEE_START / HDR_HEADROOM are tunable constants.

How to test

Open with ?hdr on an HDR display (Chrome, OS HDR on). Bright sources should punch past paper-white; mid-range looks identical to SDR. Without ?hdr or on an SDR display it silently falls back — no visible change, no wasted allocation.

Tuning knobs (HMR-hot, src/services/engine/frame/renderFrame.ts): HDR_HEADROOM (default 0.25) and HDR_KNEE_START (default 1.0).

Status

Spike, visually confirmed on an HDR display — looks good. Verified: typecheck clean (both tsconfigs), full suite green (4982 tests), SDR path bit-identical.

The investigation this spike seeded — how brightness should be rebalanced across all six layers, and how other explorers (Gaia Sky / SpaceEngine / Stellarium) handle multi-scale viewing with auto-exposure — is written up in docs/backlog/2026-07-23-hdr-brightness-rebalance.md with a needs-design backlog entry. That larger design is deliberately out of scope here.

🤖 Generated with Claude Code

rulkens and others added 2 commits July 23, 2026 01:44
The renderer already works in HDR internally (rgba16float offscreen) and
tone-maps to an 8-bit swap chain in one final compositor pass. This spike
lets that signal reach an HDR display:

- device.ts: when ?hdr is set AND the display reports (dynamic-range: high),
  the swap chain becomes rgba16float + toneMapping { mode: 'extended' }.
  Off by default; SDR path byte-identical. Threads `hdr` through GpuContext
  → EngineGpuHandles → ReadyFrameContext.
- compositor: two free uniform lanes (bytes 24/28) carry hdrKneeStart +
  hdrHeadroom; the tone pass spills over-white energy above the knee back
  on top of the clamped curve so bright sources punch into headroom. With
  headroom 0 (SDR) the output is unchanged.
- renderFrame: sets headroom/knee from ctx.hdr; constants tunable.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Captures what the ?hdr spike investigation surfaced: six incompatible
per-layer brightness "currencies" (galaxies/stars/planets/Sun/Milky Way)
under one static exposure, and how Gaia Sky / SpaceEngine / Stellarium
solve multi-scale viewing with scene-adaptive auto-exposure on a shared
magnitude scale. Adds the docs/backlog detail file + a terse BACKLOG index
line under Rendering.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
skymap a6146c6 Commit Preview URL

Branch Preview URL
Jul 23 2026, 10:14 AM

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