Files
tessera/web/scripts/blackhole-layout.test.mjs
Adnan Zahir 34e9afc8a4 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>
2026-11-13 21:51:35 +07:00

30 lines
1.5 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import { layoutFor } from "../src/lib/blackhole/layout.ts";
import { SCENE_WIDTH } from "../src/lib/galaxyLayout.ts";
import { CRITICAL_IMPACT } from "../src/lib/blackhole/geodesic.ts";
const panel = { left: 100, top: 50, width: 800, height: 600 };
test("the hole sits at the centre of the galaxy frame, relative to the panel", () => {
const frame = { left: 100 + 70, top: 50 + 60, width: 660, height: 480 };
const { centerX, centerY } = layoutFor(frame, panel);
assert.ok(Math.abs(centerX - (70 + 330) / 800) < 1e-9);
assert.ok(Math.abs(centerY - (60 + 240) / 600) < 1e-9);
});
test("the shadow has a fixed radius in scene units and scales with the frame", () => {
const atNative = layoutFor({ left: 0, top: 0, width: SCENE_WIDTH, height: 480 }, panel);
assert.ok(Math.abs(atNative.pxPerM * CRITICAL_IMPACT - 34) < 1e-9);
const doubled = layoutFor({ left: 0, top: 0, width: SCENE_WIDTH * 2, height: 960 }, panel);
assert.ok(Math.abs(doubled.pxPerM - atNative.pxPerM * 2) < 1e-9);
});
test("a frame moving under a transition moves the hole with it", () => {
const before = layoutFor({ left: 200, top: 100, width: 600, height: 436 }, panel);
const after = layoutFor({ left: 240, top: 140, width: 600, height: 436 }, panel);
assert.ok(Math.abs(after.centerX - before.centerX - 40 / 800) < 1e-9);
assert.ok(Math.abs(after.centerY - before.centerY - 40 / 600) < 1e-9);
assert.equal(after.pxPerM, before.pxPerM);
});