feat: render the black hole and sky with a WebGL2 ray tracer

Replace the SVG core and backdrop with one shader that traces each pixel
through Schwarzschild spacetime. The shadow, the arch of the far side of the
disk, the second image and the Einstein ring come from the physics rather than
artwork. The disk is a thin disk seen from a low angle, about five times the
shadow's radius, with Doppler beaming and a filtered, cloud-like texture.

- Sky: a procedural galaxy baked once into a cubemap. Point sources are small,
  few and brightness-capped so they never rival the orbit markers, which now
  carry a dark backing disc and outline.
- Quality: tiers from high to still, a startup calibration cached per canvas
  size, an fps cap, and an idle sleep. A locked realistic map draws nothing.
- Integration: the canvas follows the galaxy frame through Big Screen, draws in
  Motion's post-render step, takes the disk clock and capture absorption from
  the galaxy loop, and falls back to the SVG core without WebGL2.
- Radar view: a toolbar toggle switches to a radar look that spreads outward
  from the hole as a wave, with a sweep on its own clock. The choice is
  remembered per browser; reduced motion switches at once and holds the sweep.
- Tests for the geodesics, quality governor, look spring and layout, plus a
  standalone preview page (web/blackhole-proto.html) for tuning the look.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 21:51:35 +07:00
parent 6320b6f244
commit 34e9afc8a4
19 changed files with 2067 additions and 6 deletions

View File

@@ -0,0 +1,41 @@
import assert from "node:assert/strict";
import test from "node:test";
import { FRAME_BUDGET_MS, FREEZE_BUDGET_MS, QUALITY_TIERS, chooseTier, initialTier } from "../src/lib/blackhole/quality.ts";
const samples = (ms, count = 30) => Array.from({ length: count }, () => ms);
test("the governor steps down one tier when the median render time exceeds the budget", () => {
assert.equal(chooseTier({ tier: 0, samples: samples(FRAME_BUDGET_MS + 4), sinceChangeMs: 5000 }), 1);
assert.equal(chooseTier({ tier: 0, samples: samples(FRAME_BUDGET_MS - 4), sinceChangeMs: 5000 }), 0);
});
test("the governor ignores a lone spike, too few samples and a tier that has not settled", () => {
const spiky = [...samples(4, 29), 90];
assert.equal(chooseTier({ tier: 1, samples: spiky, sinceChangeMs: 5000 }), 1);
assert.equal(chooseTier({ tier: 1, samples: samples(40, 5), sinceChangeMs: 5000 }), 1);
assert.equal(chooseTier({ tier: 1, samples: samples(40), sinceChangeMs: 200 }), 1);
});
test("the governor stops at the lowest tier and never steps back up", () => {
const last = QUALITY_TIERS.length - 1;
assert.equal(chooseTier({ tier: last, samples: samples(80), sinceChangeMs: 5000 }), last);
assert.equal(chooseTier({ tier: 2, samples: samples(0.5), sinceChangeMs: 5000 }), 2);
});
test("motion only freezes when the lowest animated tier is clearly failing", () => {
const minimal = QUALITY_TIERS.findIndex(({ name }) => name === "minimal");
assert.equal(chooseTier({ tier: minimal, samples: samples(FREEZE_BUDGET_MS - 4), sinceChangeMs: 5000 }), minimal);
assert.equal(chooseTier({ tier: minimal, samples: samples(FREEZE_BUDGET_MS + 4), sinceChangeMs: 5000 }), minimal + 1);
assert.equal(QUALITY_TIERS[minimal + 1].maxFps, 0);
});
test("tiers get strictly cheaper and software rendering starts at the bottom", () => {
for (let i = 1; i < QUALITY_TIERS.length; i++) {
assert.ok(QUALITY_TIERS[i].scale <= QUALITY_TIERS[i - 1].scale);
assert.ok(QUALITY_TIERS[i].steps <= QUALITY_TIERS[i - 1].steps);
assert.ok(QUALITY_TIERS[i].maxFps <= QUALITY_TIERS[i - 1].maxFps);
}
assert.equal(initialTier({ software: true, pixels: 1e6 }), QUALITY_TIERS.length - 1);
assert.equal(initialTier({ software: false, cores: 8, memoryGb: 16, pixels: 2e6 }), 0);
assert.equal(initialTier({ software: false, cores: 4, pixels: 2e6 }), 1);
});