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:
108
web/scripts/look.test.mjs
Normal file
108
web/scripts/look.test.mjs
Normal file
@@ -0,0 +1,108 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { createLook, jumpLook, requestLook, stepLook, styleAt, waveParams, WAVE_FEATHER } from "../src/lib/blackhole/look.ts";
|
||||
import { farthestCornerM } from "../src/lib/blackhole/layout.ts";
|
||||
|
||||
const run = (look, seconds, fps = 60) => {
|
||||
const progress = [];
|
||||
for (let i = 0; i < seconds * fps; i++) {
|
||||
stepLook(look, 1 / fps);
|
||||
progress.push(look.progress);
|
||||
}
|
||||
return progress;
|
||||
};
|
||||
|
||||
test("the wave expands from the hole, never overshoots, and settles on the new look", () => {
|
||||
const look = createLook(0);
|
||||
requestLook(look, 1);
|
||||
assert.equal(look.running, true);
|
||||
assert.equal(look.progress, 0);
|
||||
const progress = run(look, 3);
|
||||
for (let i = 1; i < progress.length; i++) {
|
||||
assert.ok(progress[i] >= progress[i - 1] - 1e-12, "progress never goes backwards");
|
||||
assert.ok(progress[i] <= 1, "progress never overshoots");
|
||||
}
|
||||
assert.equal(look.running, false);
|
||||
assert.equal(look.from, 1);
|
||||
assert.equal(look.to, 1);
|
||||
const finishedAt = progress.findIndex((value) => value === 1);
|
||||
assert.ok(finishedAt > 20 && finishedAt < 150, `settled after ${finishedAt} frames`);
|
||||
});
|
||||
|
||||
test("a request made mid-wave waits for the wave to finish instead of reversing it", () => {
|
||||
const look = createLook(0);
|
||||
requestLook(look, 1);
|
||||
run(look, 0.3);
|
||||
const before = look.progress;
|
||||
requestLook(look, 0);
|
||||
assert.equal(look.queued, 0);
|
||||
assert.equal(look.to, 1, "the running wave keeps its target");
|
||||
assert.ok(look.progress >= before);
|
||||
run(look, 4);
|
||||
assert.equal(look.running, false);
|
||||
assert.equal(look.to, 0, "the queued look ran afterwards");
|
||||
});
|
||||
|
||||
test("asking for the look that is already showing does nothing, and the queue follows the latest request", () => {
|
||||
const look = createLook(1);
|
||||
requestLook(look, 1);
|
||||
assert.equal(look.running, false);
|
||||
requestLook(look, 0);
|
||||
assert.equal(look.running, true);
|
||||
requestLook(look, 1);
|
||||
assert.equal(look.queued, 1, "asking for the old look mid-wave queues it");
|
||||
requestLook(look, 0);
|
||||
assert.equal(look.queued, undefined, "asking for the running target again cancels the queue");
|
||||
assert.equal(look.to, 0);
|
||||
});
|
||||
|
||||
test("pixels inside the front show the new look and pixels outside keep the old one", () => {
|
||||
const look = createLook(0);
|
||||
requestLook(look, 1);
|
||||
run(look, 0.4);
|
||||
const wave = waveParams(look, 50);
|
||||
assert.equal(styleAt(wave, 0), 1);
|
||||
assert.equal(styleAt(wave, wave.waveRadius + 1), 0);
|
||||
const middle = styleAt(wave, wave.waveRadius - WAVE_FEATHER / 2);
|
||||
assert.ok(middle > 0 && middle < 1, "the front is soft");
|
||||
});
|
||||
|
||||
test("the front covers the whole picture by the time the wave finishes, and fades as it goes", () => {
|
||||
const look = createLook(0);
|
||||
requestLook(look, 1);
|
||||
const fronts = [];
|
||||
const radii = [];
|
||||
for (let i = 0; i < 240 && look.running; i++) {
|
||||
stepLook(look, 1 / 60);
|
||||
const wave = waveParams(look, 50);
|
||||
fronts.push(wave.waveFront);
|
||||
radii.push(wave.waveRadius);
|
||||
}
|
||||
for (let i = 1; i < fronts.length; i++) {
|
||||
assert.ok(fronts[i] <= fronts[i - 1] + 1e-12);
|
||||
assert.ok(radii[i] >= radii[i - 1] - 1e-12);
|
||||
}
|
||||
const settled = waveParams(look, 50);
|
||||
assert.equal(settled.waveFront, 0);
|
||||
assert.equal(settled.styleFrom, 1);
|
||||
assert.equal(styleAt(settled, 49), 1);
|
||||
});
|
||||
|
||||
test("the wave has to travel as far as the farthest corner", () => {
|
||||
const radius = farthestCornerM({ x: 300, y: 200 }, { width: 800, height: 600 }, 10);
|
||||
assert.ok(Math.abs(radius - Math.hypot(500, 400) / 10) < 1e-9);
|
||||
});
|
||||
|
||||
test("jumping to a look drops any wave and any queued request", () => {
|
||||
const look = createLook(0);
|
||||
requestLook(look, 1);
|
||||
run(look, 0.2);
|
||||
requestLook(look, 0);
|
||||
jumpLook(look, 1);
|
||||
assert.equal(look.running, false);
|
||||
assert.equal(look.from, 1);
|
||||
assert.equal(look.to, 1);
|
||||
assert.equal(look.queued, undefined);
|
||||
assert.equal(waveParams(look, 50).waveFront, 0);
|
||||
assert.equal(styleAt(waveParams(look, 50), 40), 1);
|
||||
});
|
||||
Reference in New Issue
Block a user