diff --git a/apps/site/src/layouts/Base.astro b/apps/site/src/layouts/Base.astro
index 055e500..58ca76a 100644
--- a/apps/site/src/layouts/Base.astro
+++ b/apps/site/src/layouts/Base.astro
@@ -57,24 +57,73 @@ const ogAlt =
type="font/woff2"
crossorigin
/>
+ {
+ entrance && import.meta.env.DEV && (
+
+ )
+ }
{
entrance && (
)
}
@@ -218,6 +267,13 @@ const ogAlt =
animation-name: none;
opacity: 0;
}
+ /* Coming back (`ng-return`, set in the head): the header is already up
+ and stays as it is. The title, intro and cards come in again, by
+ Huginn's homecoming or the usual entrance. */
+ html.ng-return :is(.ng-enter-pane, .ng-enter-text)[data-ng-target="header"] {
+ animation-name: none;
+ opacity: 1;
+ }
:is(.ng-enter-pane, .ng-enter-text).ng-brushed {
--ng-sweep: linear-gradient(
var(--ng-angle, 135deg),
diff --git a/apps/site/src/scripts/aurora.raven.ts b/apps/site/src/scripts/aurora.raven.ts
index d5da40e..d8ecb2e 100644
--- a/apps/site/src/scripts/aurora.raven.ts
+++ b/apps/site/src/scripts/aurora.raven.ts
@@ -8,6 +8,11 @@
// leaves into the distance, a little differently every time. His flight
// draws in the page's header, title and cards (see aurora.worker.ts).
//
+// Coming back to the page from one of its own (the GMT or worktree docs),
+// the fly-in runs the other way: a speck far off against the sky, he flies
+// home toward the viewer and sweeps past close by, out through any edge of
+// the frame. Everything but the header waits for him then.
+//
// After that each flight is planned in the camera's frame so that it crosses
// the window: usually a pass along a gentle curve 20 to 65 m away, sometimes
// a few lazy circles farther out, low over the horizon where the aurora
@@ -34,9 +39,12 @@ export type RavenView = {
/** The highest a flight's middle goes on screen (-1 bottom, 1 top): clear
* of the page's cards. */
ceiling: number;
- /** The boxes a fly-in should pass behind, header first, on screen (-1 to
- * 1, y up). Empty for a fly-in over the usual places. */
- targets: ScreenBox[];
+ /** The page's cards on screen (-1 to 1, y up), in page order: the first
+ * fly-in dives through the first. Empty for the usual place. */
+ cards: ScreenBox[];
+ /** The card for the page the visitor came back from, or null: the
+ * homecoming starts out behind it. */
+ from: ScreenBox | null;
};
/** A box on screen: left, bottom, right, top, each -1 to 1, y up. */
@@ -60,6 +68,9 @@ const G = 9.81;
/** Metres over which the bird fades in at a flight's start and out at its
* end: unseen when the ends are out of frame, as most are. */
const FADE = 12;
+/** The homecoming's quicker fade-in (metres): he starts near enough to be
+ * seen as a bird, so he shows almost at once. */
+const HOMECOMING_FADE = 4;
const RAD = Math.PI / 180;
function addVectors(a: V, b: V): V {
@@ -415,9 +426,10 @@ type Path = {
* slower the nearer he is (see timeScaleAt), so up close he is big and
* unhurried and his speed across the screen stays calm. */
slowNear: boolean;
- /** Whether to fade in over the first FADE metres: not for a fly-in, which
- * starts out of frame and close by. */
- fadeIn: boolean;
+ /** Metres to fade in over at the start (0 for none: not at an end out of
+ * frame and close by), and whether to fade out over the last FADE. */
+ fadeIn: number;
+ fadeOut: boolean;
soar: boolean;
/** Distance along the path at which to roll over, or -1 for none. */
rollAt: number;
@@ -482,7 +494,8 @@ function curve(through: V[], speed: number, soar: boolean, roll: number): Path {
speed,
speeds: null,
slowNear: false,
- fadeIn: true,
+ fadeIn: FADE,
+ fadeOut: true,
soar,
rollAt,
};
@@ -645,13 +658,25 @@ function clearOfSkyline(p: V, view: RavenView, extra = 0): V {
/** Metres either side over which a lift clear of the skyline is eased. */
const LIFT_EASE = 4;
+/** Close by he fills enough of the screen to show against the mountains
+ * too: no lift within LIFT_NEAREST metres, the full lift from LIFT_FULL,
+ * eased between. Lifting him that close would bend his line sharply, right
+ * where every bend shows. */
+const LIFT_NEAREST = 4;
+const LIFT_FULL = 12;
/** The path with every point kept clear of the skyline. */
function keptClearOfSkyline(path: Path, view: RavenView): Path {
// How far each point must rise, then eased along the path (the most
// within a few metres either side, then averaged) so that lifting him
// clear never puts a kink in his line.
- const rise = path.points.map((p) => clearOfSkyline(p, view)[1] - p[1]);
+ const rise = path.points.map(
+ (p) =>
+ (clearOfSkyline(p, view)[1] - p[1]) *
+ smoothstep(
+ (Math.hypot(...p) - LIFT_NEAREST) / (LIFT_FULL - LIFT_NEAREST),
+ ),
+ );
if (!rise.some((r) => r > 0)) return path;
function near(i: number, f: (j: number) => void): void {
const { dist } = path;
@@ -965,18 +990,16 @@ function flownPath(points: V[], speeds: number[]): Path {
speed: speeds[0]!,
speeds,
slowNear: false,
- fadeIn: true,
+ fadeIn: FADE,
+ fadeOut: true,
soar: false,
rollAt: -1,
};
}
-/** Where the header and cards usually sit on screen, for a fly-in with none
- * given (after switching sky, when the cards are already up). */
-const USUAL_TARGETS: ScreenBox[] = [
- [-1, 0.84, 1, 1],
- [-0.62, -0.25, 0.62, 0.35],
-];
+/** Where the first card usually sits on screen, for a fly-in with no cards
+ * given. */
+const USUAL_CARD: ScreenBox = [-0.62, -0.25, 0.62, 0.35];
/** The variations on a fly-in: a plain swoop, a roll while he is still
* close, a steeper and lower dive, a few wide circles in the distance, or an
@@ -1037,8 +1060,7 @@ function besideLine(p: V, a: V, b: V, k: number): V {
* left, on into the background, or off to the right. */
function entrance(view: RavenView): Path {
const { fwd, tanX, horizon, isInFrame, pointAtDepth } = frame(view);
- const boxes = view.targets.length ? view.targets : USUAL_TARGETS;
- const card = boxes[1] ?? USUAL_TARGETS[1]!;
+ const card = view.cards[0] ?? USUAL_CARD;
const flourish = FLOURISHES[Math.floor(Math.random() * FLOURISHES.length)]!;
const stoop = flourish === "stoop";
const side = Math.random() < 0.5 ? -1 : 1;
@@ -1182,7 +1204,7 @@ function entrance(view: RavenView): Path {
);
const path = flownPath(points, speeds);
path.slowNear = true;
- path.fadeIn = false;
+ path.fadeIn = 0;
// The roll comes as he pulls out of the dive.
if (flourish === "roll") {
path.rollAt =
@@ -1191,8 +1213,214 @@ function entrance(view: RavenView): Path {
return path;
}
+/** Where a homecoming leaves the frame (-1 to 1 on each axis): over the top
+ * or out either side, no lower than a quarter of the way up. Never out the
+ * bottom: diving away under the viewer looks wrong for a bird coming home. */
+function randomPointOnEdge(): [number, number] {
+ const side = Math.floor(Math.random() * 3);
+ if (side === 0) return [randomBetween(-1, 1), 1];
+ return [side === 1 ? 1 : -1, randomBetween(-0.5, 1)];
+}
+
+/** The fly-in run the other way, on coming back to the page: a speck far off
+ * against the sky, anywhere across the view or just past its sides, he
+ * flies home toward the viewer, growing as he nears, across the cards (so
+ * his passing draws them in) and sweeps past close by out through any edge
+ * of the frame. */
+function plannedHomecoming(view: RavenView, close: boolean): Path {
+ const { right, up, fwd, tanX, horizon, pointAtDepth } = frame(view);
+ // How near he comes is planned by how big he looks, the same on any
+ // screen: the share of its width his 1.2 m span fills as he closes in.
+ // Each stage of his approach is then at least that far off.
+ const size = close ? randomBetween(0.34, 0.46) : randomBetween(0.15, 0.26);
+ const closest = 1.2 / (2 * tanX * size);
+ const middleDepth = Math.max(randomBetween(5, 7), closest * 1.6);
+ const farDepth = Math.max(randomBetween(9, 12), middleDepth * 1.7);
+
+ // Across the screen he starts anywhere, or back from one of the cards'
+ // pages, out beyond that card: from its middle toward its own side.
+ function startAcross(): number {
+ if (!view.from) return randomBetween(-1.25, 1.25);
+ const middle = (view.from[0] + view.from[2]) / 2;
+ const side = Math.abs(middle) > 0.1 ? Math.sign(middle) : 0;
+ return Math.min(
+ 0.95,
+ Math.max(-0.95, middle + side * randomBetween(0, 0.35)),
+ );
+ }
+ // Far off and above the skyline, where the aurora lights the sky behind
+ // him; and where that is on screen, to draw the rest of his line from.
+ function farPoint(): { p: V; at: [number, number] } {
+ let found: { p: V; at: [number, number] } = { p: [0, 0, 0], at: [0, 0] };
+ for (let tries = 0; tries < 10; tries++) {
+ const at: [number, number] = [
+ startAcross(),
+ Math.min(0.9, horizon + randomBetween(0.06, 0.4) + tries * 0.05),
+ ];
+ found = { p: pointAtDepth(...at, farDepth), at };
+ if (skyward(found.p, view)) return found;
+ }
+ return { ...found, p: keepAboveGround(found.p, view) };
+ }
+ const far = farPoint();
+
+ // On his way, behind some part of the cards: anywhere over the whole
+ // spread of them, not only one card's middle.
+ const spread = view.cards.length ? view.cards : [USUAL_CARD];
+ const [x0, y0, x1, y1] = [
+ Math.min(...spread.map((c) => c[0])),
+ Math.min(...spread.map((c) => c[1])),
+ Math.max(...spread.map((c) => c[2])),
+ Math.max(...spread.map((c) => c[3])),
+ ];
+ const middle = keepAboveGround(
+ pointAtDepth(
+ lerpNumber(x0, x1, randomBetween(0.15, 0.85)),
+ lerpNumber(y0, y1, randomBetween(0.15, 0.85)),
+ middleDepth,
+ ),
+ view,
+ LOW,
+ );
+ // Whether any of him still shows: his middle within the frame widened by
+ // his half-span on screen (with a little to spare), so that he ends only
+ // once his wing tips are out of view too.
+ function stillShowing(p: V): boolean {
+ const z = dotProduct(p, fwd);
+ if (z < 0.3) return false;
+ const reach = 0.9 / z;
+ return (
+ Math.abs(dotProduct(p, right) / z) < tanX + reach &&
+ Math.abs(dotProduct(p, up) / z) < view.tanY + reach
+ );
+ }
+ // Out past an edge he can reach: not under the water or below the
+ // ground, which would leave him gliding along the bottom of the frame.
+ function exitPoint(): { closing: V; out: V; beyond: V } {
+ let found = {
+ closing: [0, 0, 0] as V,
+ out: [0, 0, 0] as V,
+ beyond: [0, 0, 0] as V,
+ };
+ for (let tries = 0; tries < 8; tries++) {
+ const [ex, ey] =
+ tries < 7 ? randomPointOnEdge() : [Math.sign(far.at[0]) || 1, 0];
+ // Closing in at the size planned, heading for the edge, then out
+ // past it a little nearer, and on out sideways rather than into the
+ // lens.
+ const depth = closest * randomBetween(0.7, 0.85);
+ found = {
+ closing: keepAboveGround(
+ pointAtDepth(ex * 0.6, ey * 0.6, closest),
+ view,
+ LOW,
+ ),
+ out: keepAboveGround(
+ pointAtDepth(ex * 1.5, ey * 1.5, depth),
+ view,
+ LOW,
+ ),
+ beyond: keepAboveGround(pointAtDepth(ex * 3, ey * 3, depth), view, LOW),
+ };
+ if (!stillShowing(found.beyond)) return found;
+ }
+ return found;
+ }
+ const { closing, out, beyond } = exitPoint();
+
+ // Flown like the first fly-in. Only the far waypoints are kept clear of
+ // the skyline: close by he shows against the mountains too.
+ const { points, speeds } = fly(
+ [far.p, clearOfSkyline(middle, view, 1.5), closing, out, beyond],
+ // About his best glide: a raven's own unhurried pace.
+ randomBetween(7, 8),
+ LOW - view.eye,
+ stillShowing,
+ );
+ // Should his line still end in view, he glides on straight until he is
+ // out of it, rather than vanish.
+ const last = points[points.length - 1]!;
+ const heading = normalize(
+ subtractVectors(last, points[Math.max(0, points.length - 2)]!),
+ );
+ for (let i = 1; i <= 300 && stillShowing(points[points.length - 1]!); i++) {
+ points.push(addVectors(last, scaleVector(heading, i * 0.1)));
+ speeds.push(speeds[speeds.length - 1]!);
+ }
+ const path = flownPath(points, speeds);
+ path.slowNear = true;
+ // He comes out of the distance and leaves out of frame close by.
+ path.fadeIn = HOMECOMING_FADE;
+ path.fadeOut = false;
+ return path;
+}
+
+/** How often a homecoming is a close pass, sweeping by as near as the
+ * first fly-in comes in, and how big he gets: the most of the screen's
+ * width his wingspan fills while he is in view. A close pass matches the
+ * first fly-in (about a third to a half); the others stay smaller. */
+const CLOSE_PASSES = 0.4;
+const CLOSE_PASS_SIZE: [number, number] = [0.3, 0.5];
+const USUAL_SIZE: [number, number] = [0.1, 0.3];
+/** The longest a homecoming may take, seconds, slow motion and all. The
+ * page is drawn in well before he is gone (see the worker). */
+const HOMECOMING_LONGEST = 5;
+/** Seconds before a homecoming, once the sky is up: he sets off at once. */
+const HOMECOMING_WAIT: [number, number] = [0.1, 0.3];
+
+/** How long the path takes to fly, seconds, slow motion and all. */
+function flightSeconds(path: Path): number {
+ let seconds = 0;
+ for (let i = 1; i < path.points.length; i++) {
+ const s = path.dist[i]!;
+ const ds = s - path.dist[i - 1]!;
+ seconds += ds / (speedAt(path, s) * timeScaleAt(path, s) || 1);
+ }
+ return seconds;
+}
+
+/** A homecoming of the size wanted and no longer than HOMECOMING_LONGEST:
+ * his momentum can carry him nearer or farther than planned, so a few are
+ * planned and the first that fits is flown, or failing that the nearest
+ * fit. He never waits on a plan. */
+function homecoming(view: RavenView): Path {
+ const { fwd, tanX, isInFrame } = frame(view);
+ const close = Math.random() < CLOSE_PASSES;
+ const [least, most] = close ? CLOSE_PASS_SIZE : USUAL_SIZE;
+ // The most of the screen's width his wingspan fills while in view.
+ function biggest(path: Path): number {
+ return Math.max(
+ 0,
+ ...path.points
+ .filter((p) => isInFrame(p, 1))
+ .map((p) => 1.2 / (2 * tanX * dotProduct(p, fwd))),
+ );
+ }
+ // How far a plan is from fitting: 0 when it fits.
+ function misfit(path: Path): number {
+ const size = biggest(path);
+ return (
+ Math.max(0, least - size, size - most) * 10 +
+ Math.max(0, flightSeconds(path) - HOMECOMING_LONGEST) +
+ (path.length > 6 ? 0 : 100)
+ );
+ }
+ let best = plannedHomecoming(view, close);
+ let bestMisfit = misfit(best);
+ for (let tries = 1; tries < 12 && bestMisfit > 0; tries++) {
+ const path = plannedHomecoming(view, close);
+ const off = misfit(path);
+ if (off < bestMisfit) [best, bestMisfit] = [path, off];
+ }
+ return best;
+}
+
// ---------------------------------------------------------------------------
+/** Which fly-in starts the page: "first", in over the viewer's shoulder, or
+ * "return", the homecoming. */
+export type FlyIn = "first" | "return";
+
export type Raven = {
/** Fly on by dt seconds, planning a new flight in this view when one is
* due. */
@@ -1204,6 +1432,11 @@ export type Raven = {
enter(wait: number): void;
/** Whether the flight under way is a fly-in. */
entering: boolean;
+ /** The flight under way, in world space: its points and the distance
+ * flown to each. Null between flights. */
+ flight: { points: V[]; dist: number[]; fadeIn: number } | null;
+ /** How far along the flight he is, metres. */
+ flown: number;
/** Where the bird is, in world space. */
position: V;
/** The bird's triangles in world space (RAVEN_STRIDE floats a vertex). */
@@ -1214,10 +1447,16 @@ export type Raven = {
alpha: number;
};
-export function raven(timing: RavenTiming = RAVEN_TIMING): Raven {
+export function raven(
+ timing: RavenTiming = RAVEN_TIMING,
+ flyIn: FlyIn = "first",
+): Raven {
const mesh = new Float32Array(TRIS * 3 * RAVEN_STRIDE);
- let wait = randomBetween(...timing.entrance);
- let flyIn = true;
+ let wait =
+ flyIn === "return"
+ ? randomBetween(...HOMECOMING_WAIT)
+ : randomBetween(...timing.entrance);
+ let entranceDue = true;
let path: Path | null = null;
let s = 0;
let size = 1;
@@ -1239,23 +1478,28 @@ export function raven(timing: RavenTiming = RAVEN_TIMING): Raven {
count: 0,
alpha: 0,
entering: false,
+ flight: null,
+ flown: 0,
position: [0, 0, 0],
reset(next) {
path = null;
+ bird.flight = null;
bird.count = 0;
bird.entering = false;
wait = next ?? randomBetween(...timing.gap);
},
enter(next) {
bird.reset(next);
- flyIn = true;
+ entranceDue = true;
},
step(dt, view) {
if (!path) {
wait -= dt;
if (wait > 0) return;
- path = flyIn
- ? entrance(view)
+ path = entranceDue
+ ? flyIn === "return"
+ ? homecoming(view)
+ : entrance(view)
: Math.random() < 0.3
? circles(view)
: pass(view);
@@ -1263,8 +1507,13 @@ export function raven(timing: RavenTiming = RAVEN_TIMING): Raven {
// sky empty for a whole gap.
if (!path) return bird.reset(randomBetween(1, 2));
path = keptClearOfSkyline(path, view);
- bird.entering = flyIn;
- flyIn = false;
+ bird.entering = entranceDue;
+ bird.flight = {
+ points: path.points,
+ dist: path.dist,
+ fadeIn: path.fadeIn,
+ };
+ entranceDue = false;
s = 0;
size = randomBetween(0.94, 1.08);
// Slower, deeper wingbeats on the fly-in.
@@ -1281,9 +1530,10 @@ export function raven(timing: RavenTiming = RAVEN_TIMING): Raven {
const speed = speedAt(path, s);
s += speed * dt;
if (s >= path.length) return bird.reset();
+ bird.flown = s;
bird.alpha =
- (path.fadeIn ? smoothstep(s / FADE) : 1) *
- smoothstep((path.length - s) / FADE);
+ (path.fadeIn ? smoothstep(s / path.fadeIn) : 1) *
+ (path.fadeOut ? smoothstep((path.length - s) / FADE) : 1);
// Heading and bank. The lift must carry the bird's weight and turn it,
// so it leans along gravity plus the turn's acceleration (a coordinated
diff --git a/apps/site/src/scripts/aurora.shaders.ts b/apps/site/src/scripts/aurora.shaders.ts
index 6c0e859..00d9b55 100644
--- a/apps/site/src/scripts/aurora.shaders.ts
+++ b/apps/site/src/scripts/aurora.shaders.ts
@@ -18,13 +18,18 @@ precision highp float;
#define MAP_H ${MAP_H}.0
#define CURTAINS ${CURTAINS}
uniform float uT;
+// How active the aurora is, 0 (quiet arcs) to 1 (a substorm), and a clock
+// that runs faster the more active it is, for the rays (see the worker).
+uniform float uAct, uFastT;
uniform vec3 uSpring, uCyan, uPurple;
+// Emission colours: oxygen green and red, nitrogen's pink-magenta fringe.
+uniform vec3 uAuroraGreen, uAuroraRed, uAuroraFringe;
// Ground shift per km of altitude along a field line (toward magnetic south).
uniform vec2 uTilt;
const float H0 = 100.0; // lower border, km
const float RE = 6371.0; // Earth radius, km
const float SIG = 8.0; // sheet half-thickness (gaussian sigma), km
-float tt;
+float tt, ft;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
@@ -37,9 +42,10 @@ float noise(vec2 p) {
uniform vec3 uC0, uC1;
vec3 curtain(float k) { return k < 0.5 ? uC0 : uC1; }
vec2 span(float k) { return curtain(k).yz; }
-// Ground distance north of the viewer: a base plus folds at three scales.
+// Ground distance north of the viewer: a base plus folds at three scales,
+// deeper while the aurora is active.
float path(float x, float k) {
- float s = 1.0 + 0.6 * k;
+ float s = (1.0 + 0.6 * k) * (1.0 + 0.6 * uAct);
float z = curtain(k).x;
z += 90.0 * s * (noise(vec2(x / 420.0 + k * 7.0, tt * 0.0012 + k)) - 0.5);
z += 35.0 * s * (noise(vec2(x / 140.0 + k * 3.0, tt * 0.003 + 2.0 * k)) - 0.5);
@@ -53,28 +59,35 @@ float lit(float x, float k) {
return 0.08 + 0.92 * smoothstep(0.38, 0.62, n);
}
float knots(float x, float k) {
- return 0.45 + 0.55 * noise(vec2(x / 55.0 + tt * 0.004, k * 5.0 + tt * 0.01));
+ return 0.45 + 0.55 * noise(vec2(x / 55.0 + ft * 0.004, k * 5.0 + ft * 0.01));
}
-// How rayed (rather than smooth) this stretch of the arc is.
+// How rayed (rather than smooth) this stretch of the arc is: quiet arcs are
+// mostly smooth; an active aurora breaks into rays along most of its length.
float rayed(float x, float k) {
- return smoothstep(0.3, 0.7, noise(vec2(x / 180.0 + k * 4.0, tt * 0.003 + k)));
+ float a = 0.25 * uAct;
+ return smoothstep(0.3 - a, 0.7 - a,
+ noise(vec2(x / 180.0 + k * 4.0, tt * 0.003 + k)));
}
-// Fine striations along the arc, drifting about 0.5 km/s.
+// Fine striations along the arc, drifting about 0.5 km/s when quiet and
+// racing along it when active.
float rays(float x, float k, float c) {
- float r = 0.6 * noise(vec2(x / 3.5 + tt * 0.15, k * 13.0 + tt * 0.02))
- + 0.4 * noise(vec2(x / 1.6 - tt * 0.1, k * 17.0));
+ float r = 0.6 * noise(vec2(x / 3.5 + ft * 0.15, k * 13.0 + ft * 0.02))
+ + 0.4 * noise(vec2(x / 1.6 - ft * 0.1, k * 17.0));
return mix(1.0, r * 1.4, c);
}
float rayHeight(float x, float k) {
return rayed(x, k) * (0.3 + 0.7 * noise(vec2(x / 90.0 + k, tt * 0.002)));
}
-// Colour by altitude: bright spring-cyan at the border, cyan to blue above,
-// faint purple at the top.
+// Colour by altitude, as the emissions are. Oxygen's green from the lower
+// border to about 200 km, where the air is too thin for it; above that,
+// oxygen's red, faint and slow, so it shows mostly atop tall rays (the sheet
+// fades with height; see profile). While the aurora is active, nitrogen's
+// pink-magenta along the lower edge, which then dips a little lower.
vec3 ramp(float h) {
- vec3 blue = mix(uCyan, uPurple, 0.5);
- vec3 c = mix(mix(uSpring, uCyan, 0.55), uCyan, smoothstep(100.0, 125.0, h));
- c = mix(c, blue, smoothstep(125.0, 180.0, h));
- return mix(c, uPurple, smoothstep(180.0, 260.0, h));
+ float green = 1.0 - smoothstep(170.0, 240.0, h);
+ float red = 2.5 * smoothstep(160.0, 250.0, h) * (0.35 + 0.65 * uAct);
+ float fringe = 1.6 * uAct * (1.0 - smoothstep(97.0, 106.0, h));
+ return uAuroraGreen * green + uAuroraRed * red + uAuroraFringe * fringe;
}
`;
@@ -91,6 +104,7 @@ export const FOOT_FS = `${COMMON}
varying vec2 vUv;
void main() {
tt = uT;
+ ft = uFastT;
float row = floor(vUv.y * MAP_H);
float k = floor(row / 2.0);
vec2 sp = span(k);
@@ -124,6 +138,10 @@ uniform vec2 uShadowR; // umbra and penumbra radii, moon radii
uniform float uMoonlight;
uniform float uGlow; // city light near the horizon, 0..1
uniform float uLights; // lit windows and streets, 0..1
+// The skyline's elevation by azimuth, two bytes a texel (see the worker):
+// first azimuth and span (radians), and texels (0 for no skyline).
+uniform sampler2D uRidge;
+uniform vec3 uRidgeSpan;
varying vec2 vUv;
const float H1 = ${top}.0;
const float PI = 3.14159265;
@@ -151,8 +169,24 @@ float fetchCoarse(float x, float k) {
return c * c;
}
// Sharp lower border, then an exponential tail whose height grows with g.
+// An active aurora reaches a little deeper.
float profile(float h, float g) {
- return smoothstep(94.0, 106.0, h) * exp(-max(h - 106.0, 0.0) / (25.0 + 45.0 * g));
+ return smoothstep(94.0 - 4.0 * uAct, 106.0, h)
+ * exp(-max(h - 106.0, 0.0) / (25.0 + 45.0 * g));
+}
+// The sine of the skyline's elevation at azimuth az (radians), or -1 where
+// there is none. Two fetches and a manual lerp: the two-byte value cannot
+// be filtered.
+float ridgeSine(float az) {
+ if (uRidgeSpan.z < 2.0) return -1.0;
+ float u = (az - uRidgeSpan.x) / uRidgeSpan.y * (uRidgeSpan.z - 1.0);
+ if (u < 0.0 || u > uRidgeSpan.z - 1.0) return -1.0;
+ float i = floor(u), f = u - i;
+ vec4 a = texture2D(uRidge, vec2((i + 0.5) / uRidgeSpan.z, 0.5));
+ vec4 b = texture2D(uRidge, vec2((i + 1.5) / uRidgeSpan.z, 0.5));
+ float ea = (a.r * 255.0 * 256.0 + a.g * 255.0) / 65535.0;
+ float eb = (b.r * 255.0 * 256.0 + b.g * 255.0) / 65535.0;
+ return sin(radians(mix(ea, eb, f) * 50.0 - 10.0));
}
// Earth's shadow on the moon: how far the surface point n (moon radii from
// its centre) is from the shadow's axis, and the sunlight left there
@@ -291,10 +325,16 @@ vec3 skyColour(vec3 rd, float j) {
}
float e = max(rd.y, 0.0);
float air = exp(-0.12 * (1.0 / (e + 0.04) - 1.0));
- vec3 col = uVoid + uTeal * 0.05 * exp(-e * 8.0)
+ // Airglow: oxygen's green again, from the whole sky at about 95 km. Seen
+ // edge-on it is a faint band some ten degrees above the horizon.
+ float band = (e - 0.17) / 0.12;
+ vec3 col = uVoid + uTeal * 0.03 * exp(-e * 8.0)
+ + uAuroraGreen * 0.006 * exp(-band * band)
+ uGlow * (uTeal * 0.09 * exp(-e * 9.0) + uIce * 0.035 * exp(-e * 22.0))
+ uMoonlight * (uIce * 0.02 + uTeal * 0.05) * (0.5 + 0.5 * exp(-e * 3.0));
- return col + (acc * 0.035 + moon(rd) + sun(rd)) * air;
+ // Quiet arcs are faint; a surge is several times brighter.
+ float bright = 0.6 + 1.2 * uAct;
+ return col + (acc * 0.035 * bright + moon(rd) + sun(rd)) * air;
}
// City lights along the shore, by azimuth bin: on or off, and how bright.
float shoreLight(float az) {
@@ -312,15 +352,24 @@ void main() {
if (rd.y >= 0.0) {
col = skyColour(rd, j);
} else {
- // Water: the sky mirrored and broken by slow ripples that crowd toward
- // the horizon; strongest at grazing angles (Fresnel).
+ // Water: a mirror of what is above it, broken by slow ripples that
+ // crowd together toward the far shore. Each ripple tilts the surface a
+ // little, so its reflection comes from a little higher or lower in the
+ // sky (twice the tilt: a degree or two on a quiet night). Below the
+ // skyline it mirrors the mountains or the city, dark; above, the aurora,
+ // strongest at grazing angles (Fresnel). Across a fjord with mountains
+ // on the far side, the aurora shows mostly as glints where a ripple
+ // tilts enough to catch it.
float d = -rd.y;
float az = atan(rd.x, rd.z);
vec2 q = vec2(az * 700.0, 0.06 / d);
float w = noise(q + vec2(0.0, uT * 0.35)) + 0.5 * noise(q * 2.3 - vec2(0.0, uT * 0.25)) - 0.75;
- vec3 rr = normalize(vec3(rd.x, d * max(0.15, 1.0 + 0.9 * w), rd.z));
+ vec3 rr = normalize(vec3(rd.x, max(0.0005, d + 0.045 * w), rd.z));
float fresnel = 0.02 + 0.98 * pow(1.0 - d, 5.0);
- col = uVoid * 0.5 + skyColour(rr, j) * fresnel * 0.85;
+ vec3 above = rr.y < ridgeSine(az)
+ ? uVoid * 0.45 + uIce * 0.02 * uMoonlight
+ : skyColour(rr, j);
+ col = uVoid * 0.5 + above * fresnel * 0.85;
// City lights stretched into broken vertical streaks.
float streak = shoreLight(az + w * 0.0004) * exp(-d * 45.0)
* smoothstep(0.35, 0.75, noise(vec2(az * 900.0, d * 260.0 - uT * 0.6)));
@@ -358,6 +407,7 @@ void main() {
vec2 sp = span(k);
float x0 = sp.x + (aSeed.x * 2.0 - 1.0) * sp.y * 0.9;
float lift = 1.0 + 12.0 * pow(fract(aSeed.w * 13.7), 2.0);
+ ft = uFastT;
tt = uT + (0.4 - ph) * life;
float z0 = path(x0, k) + (fract(aSeed.w * 5.3) - 0.5) * 2.0 * SIG;
float bright = lit(x0, k) * knots(x0, k);
@@ -369,7 +419,8 @@ void main() {
+ 0.03 * (h - hit) * vec2(cos(spin), sin(spin));
vec4 c = project(vec3(g.x, h - dot(g, g) / (2.0 * RE), g.y));
float glow = smoothstep(0.45, 0.65, ph) * (1.0 - smoothstep(0.75, 1.0, ph));
- vCol = mix(uCyan, ramp(hit), glow) * 0.3 * glow * bright;
+ vCol = mix(uAuroraGreen, ramp(hit), glow) * 0.3 * glow * bright
+ * (0.6 + 1.2 * uAct);
gl_PointSize = 1.3 * clamp(250.0 / max(c.w, 1.0), 0.6, 2.0) * uPx;
gl_Position = c;
}
diff --git a/apps/site/src/scripts/aurora.worker.ts b/apps/site/src/scripts/aurora.worker.ts
index 434c8e5..8c7adc0 100644
--- a/apps/site/src/scripts/aurora.worker.ts
+++ b/apps/site/src/scripts/aurora.worker.ts
@@ -35,6 +35,8 @@ import {
RAVEN_STRIDE,
RAVEN_TIMING,
raven,
+ type FlyIn,
+ type Raven,
type ScreenBox,
} from "./aurora.raven";
import { SITES, type Site } from "./aurora.sites";
@@ -64,9 +66,16 @@ const RAVEN_TEX = 512;
/** The shortest and longest sweep that draws a page box in, seconds. */
const BRUSH_QUICKEST = 0.6;
const BRUSH_LONGEST = 1;
-/** Seconds after the first card that the second always starts. His flight
- * does not cross the second card soon enough to start it himself. */
-const SECOND_CARD_FOLLOWS = 0.6;
+/** Seconds after a box starts drawing in that the next one along his line
+ * always starts: his flight may pass it late, or not at all. On a first
+ * visit only the cards follow on; coming back the title and intro do too,
+ * closer behind, so the page is back quickly. */
+const CARD_FOLLOWS = 0.6;
+const RETURN_FOLLOWS = 0.3;
+/** Coming back, the latest (seconds into his flight) that the first box
+ * along his line starts, whether or not he has reached it: the page is
+ * back within about 3 s, never left waiting on him. */
+const RETURN_FIRST_BY = 1;
// Wall-clock epoch milliseconds from Temporal (via gmt): the stars, planets,
// moon and sun need the real time. Frame timing uses rAF stamps, not the wall
@@ -77,7 +86,16 @@ function readWallClock(): number {
}
type Rgb = [number, number, number];
-type Skyline = typeof ISAFJORDUR;
+/** A site's skyline (see scripts/build-skyline.mjs): `near` only where
+ * water shows below the far shore as seen from land. */
+type Skyline = {
+ from: number;
+ step: number;
+ elev: string;
+ dist: string;
+ base: string;
+ near?: string;
+};
// Skylines by site id (see scripts/build-skyline.mjs).
const SKYLINES: Record
= {
@@ -96,13 +114,24 @@ export type AuroraMessage =
site: number;
still: boolean;
hidden: boolean;
- /** The page's header, cards, title and intro, to draw in as the
- * fly-in reaches them, in CSS pixels: left, top, width, height. Later
- * fly-ins aim at them too. Empty when the page draws them in itself. */
- targets: PageBox[];
+ /** The page's boxes to draw in as the fly-in reaches them (the
+ * header, title, intro and cards, or on coming back all but the
+ * header).
+ * Later fly-ins aim at the cards too. Empty when the page draws them
+ * in itself. */
+ targets: PageTarget[];
+ /** Which fly-in to start with. */
+ flyIn: FlyIn;
+ /** The card for the page the visitor came back from (an index into
+ * targets), or -1: the homecoming starts behind it, and the title
+ * and intro sweep in from it. */
+ from: number;
+ /** How active the aurora is, 0 to 1, to hold it there (a preview in
+ * development); -1 to let it come and go. */
+ activity: number;
}
| { type: "site"; site: number }
- | { type: "size"; width: number; height: number; targets: PageBox[] }
+ | { type: "size"; width: number; height: number; targets: PageTarget[] }
| { type: "still"; still: boolean }
| { type: "hidden"; hidden: boolean }
/** What is drawn near this point (CSS pixels), within reach pixels. */
@@ -116,6 +145,10 @@ export type AuroraMessage =
/** A box on the page in CSS pixels: left, top, width, height. */
export type PageBox = [number, number, number, number];
+/** A box for the fly-in to draw in, and what it is: the cards and header
+ * are each reached their own way. */
+export type PageTarget = { kind: "header" | "card" | "text"; box: PageBox };
+
/** One unbroken run of a constellation line in CSS pixels, [x, y, x, y, …],
* drawn from the end nearer the hovered star; step counts lines out from it. */
export type SkyLine = { step: number; points: number[] };
@@ -183,6 +216,9 @@ function parseColours(values: string[]): Rgb[] {
return values.map((value) => {
if (!ctx) return [0, 0, 0];
ctx.clearRect(0, 0, 1, 1);
+ // A missing token ("") leaves fillStyle as it was: start from black so
+ // it reads as no colour, not the token before it.
+ ctx.fillStyle = "#000";
ctx.fillStyle = value;
ctx.fillRect(0, 0, 1, 1);
const [r = 0, g = 0, b = 0] = ctx.getImageData(0, 0, 1, 1).data;
@@ -221,12 +257,33 @@ function decodeBase64(b64: string): Uint8Array {
}
/** Ridge strip: for each azimuth, the ridge direction, then the far shore
- * over water or a direction far below the frame. */
+ * over water or a direction far below the frame. Where water shows from
+ * land, a second strip after it: the near shore down to below the frame. */
function ridgeMesh(skyline: Skyline): Float32Array {
const elev = new Int16Array(decodeBase64(skyline.elev).buffer);
const dist = new Uint16Array(decodeBase64(skyline.dist).buffer);
const base = new Int16Array(decodeBase64(skyline.base).buffer);
- const out = new Float32Array(elev.length * 8);
+ const near = skyline.near
+ ? new Int16Array(decodeBase64(skyline.near).buffer)
+ : null;
+ const out = new Float32Array(elev.length * (near ? 16 : 8));
+ near?.forEach((n, i) => {
+ const az = (skyline.from + i * skyline.step) * RAD;
+ for (const [j, el] of [
+ [0, (n / 100) * RAD],
+ [1, -40 * RAD],
+ ] as const) {
+ out.set(
+ [
+ Math.sin(az) * Math.cos(el),
+ Math.sin(el),
+ Math.cos(az) * Math.cos(el),
+ j ? -1 : 0,
+ ],
+ (elev.length + i) * 8 + j * 4,
+ );
+ }
+ });
elev.forEach((e, i) => {
const az = (skyline.from + i * skyline.step) * RAD;
// 0 within 1 km of the viewer, rising to 1 at 31 km: paler, and lit if a city.
@@ -249,6 +306,47 @@ function ridgeMesh(skyline: Skyline): Float32Array {
return out;
}
+/** The skyline's elevation by azimuth as one row of texels for the water to
+ * mirror: two bytes each, -10° to 40°. At most `most` texels: a wider
+ * skyline keeps the highest of each run. The first azimuth and the span
+ * (radians) go with it. */
+function ridgeTexels(
+ skyline: Skyline,
+ most: number,
+): { data: Uint8Array; texels: number; from: number; span: number } {
+ const elev = new Int16Array(decodeBase64(skyline.elev).buffer);
+ const run = Math.ceil(elev.length / most);
+ const texels = Math.ceil(elev.length / run);
+ const data = new Uint8Array(texels * 4);
+ for (let i = 0; i < texels; i++) {
+ const top = Math.max(...elev.subarray(i * run, (i + 1) * run)) / 100;
+ const v = Math.round(Math.min(1, Math.max(0, (top + 10) / 50)) * 65535);
+ data.set([v >> 8, v & 255, 0, 255], i * 4);
+ }
+ return {
+ data,
+ texels,
+ from: skyline.from * RAD,
+ span: (texels - 1) * run * skyline.step * RAD,
+ };
+}
+
+/** How active the aurora is at t seconds, 0 (quiet arcs) to 1 (a
+ * substorm): mostly quiet, now and then a surge that builds over a minute
+ * or so and dies back. `seed` starts each load somewhere different. */
+function auroraActivity(seconds: number, seed: number): number {
+ const x = seconds / 75 + seed;
+ const i = Math.floor(x);
+ const f = x - i;
+ const [a, b] = [i, i + 1].map((n) => {
+ const v = Math.sin(n * 127.1) * 43758.5453;
+ return v - Math.floor(v);
+ });
+ const n = a! + (b! - a!) * f * f * (3 - 2 * f);
+ const s = Math.min(1, Math.max(0, (n - 0.62) / 0.3));
+ return s * s * (3 - 2 * s);
+}
+
/** Catalogue records (see scripts/build-stars.mjs) to direction + magnitude. */
function starData(buf: ArrayBuffer): Float32Array {
const view = new DataView(buf);
@@ -463,7 +561,8 @@ function start(init: Extract): void {
const ravenProgram = compile(gl, RAVEN_VS, RAVEN_FS);
const ravenBlit = compile(gl, RAVEN_BLIT_VS, RAVEN_BLIT_FS);
- const [voidC, spring, cyan, teal, purple, ice] = parseColours(init.colours);
+ const [voidC, spring, cyan, teal, purple, ice, green, red, fringe] =
+ parseColours(init.colours);
const colours: Record = {
uVoid: voidC,
uSpring: spring,
@@ -471,6 +570,9 @@ function start(init: Extract): void {
uTeal: teal,
uPurple: purple,
uIce: ice,
+ uAuroraGreen: green,
+ uAuroraRed: red,
+ uAuroraFringe: fringe,
};
// Footprint texture and framebuffer on unit 0.
const map = gl.createTexture();
@@ -591,7 +693,14 @@ function start(init: Extract): void {
Float32Array.from({ length: SPARKS * 4 }, Math.random),
);
const ridgeBuf = gl.createBuffer();
+ // Vertices in the ridge strip, and in the near shore's strip after it.
let ridgeCount = 0;
+ let nearCount = 0;
+ // The skyline for the water to mirror, on unit 3: first azimuth, span and
+ // texels (0 for none).
+ const ridgeTex = gl.createTexture();
+ let ridgeSpan: [number, number, number] = [0, 0, 0];
+ const mostTexels = Math.min(4096, gl.getParameter(gl.MAX_TEXTURE_SIZE));
const planetBuf = gl.createBuffer();
let starBuf: WebGLBuffer | null = null;
let starCount = 0;
@@ -607,6 +716,7 @@ function start(init: Extract): void {
gl.uniform1i(gl.getUniformLocation(program, "uMap"), 0);
gl.uniform1i(gl.getUniformLocation(program, "uMoonTex"), 1);
gl.uniform1i(gl.getUniformLocation(program, "uRaven"), 2);
+ gl.uniform1i(gl.getUniformLocation(program, "uRidge"), 3);
}
for (const p of [foot, skyProgram, sparks, stars, ridge]) setFixedUniforms(p);
if (ravenProgram && ravenBlit)
@@ -648,7 +758,7 @@ function start(init: Extract): void {
({ cam, tanY, portrait } = camera(site, width, height));
}
// The raven, planned in the view as it is when a flight starts.
- const bird = raven(RAVEN_TIMING);
+ const bird = raven(RAVEN_TIMING, init.flyIn);
function currentRavenView() {
return {
cam,
@@ -659,28 +769,50 @@ function start(init: Extract): void {
// Landscape: below the middle of the cards. Portrait: the cards sit
// below the horizon, so up toward the top of the frame.
ceiling: 0.3 + 0.55 * portrait,
- // Where the page's boxes are, for every fly-in, so the one after a
- // sky switch flies the same line as the first.
- targets: targets.map(onScreen),
+ // Where the cards are, for every fly-in, so the one after a sky switch
+ // flies the same line as the first.
+ cards: targets
+ .filter((target) => target.kind === "card")
+ .map((target) => onScreen(target.box)),
+ from:
+ init.from >= 0 && targets[init.from]
+ ? onScreen(targets[init.from]!.box)
+ : null,
};
}
- // The page's header, title, intro and cards, hidden until the fly-in
- // reaches them: his flight draws each one in. As he reaches a box the page
- // starts a quick sweep across it the way he is flying (its edge enters the
- // box a quarter of the way into the sweep and crosses it in the middle
- // half; see Base.astro). A box he has not reached is drawn in once he is
- // past its middle on his way down the screen (top left to bottom right). The
- // second card starts a fixed time after the first, so the two keep the same
- // timing against him on every load.
- let targets: PageBox[] = init.targets;
+ // The page's boxes hidden until the fly-in reaches them: on a first visit
+ // the header, title, intro and cards; on coming back all but the header. His
+ // flight draws each one in. As he reaches a box the page starts a quick
+ // sweep across it the way he is flying (its edge enters the box a quarter
+ // of the way into the sweep and crosses it in the middle half; see
+ // Base.astro). A box he does not fly over is drawn in as he makes his
+ // closest pass by its middle on screen. Each card (and coming back, the
+ // title and intro) also starts no later than a set time after the one
+ // before it along his line, so those he passes late, or never, keep the
+ // same timing against him on every load.
+ let targets: PageTarget[] = init.targets;
let painted = targets.map(() => false);
+ // When each box started drawing in (t, seconds).
+ let paintedAt = targets.map(() => 0);
+ // How far along the fly-in (metres) he makes his closest pass by each box,
+ // and the boxes that follow on, in the order he passes them, worked out
+ // for each fly-in and again when the boxes move.
+ let passes: number[] = [];
+ let following: number[] = [];
+ const returning = init.flyIn === "return";
+ const followGap = returning ? RETURN_FOLLOWS : CARD_FOLLOWS;
+ let passesFor: Raven["flight"] = null;
+ let flewIn = false;
+ // When the fly-in started (t, seconds).
+ let flewInAt = 0;
+ // His last position on the page that the heading was taken from, and the
+ // seconds since; his heading across the page and his speed along it, CSS
+ // pixels a second.
let seen: [number, number] | null = null;
- let heading: [number, number] = [Math.SQRT1_2, Math.SQRT1_2];
- // His speed across the screen, CSS pixels a second, and the seconds since
- // the first card started drawing in.
+ let sinceSeen = 0;
+ let heading: [number, number] | null = null;
let pace = 0;
- let sinceFirstCard = 0;
/** A page box on screen, -1 to 1 with y up, as the raven plans in. */
function onScreen([x, y, w, h]: PageBox): ScreenBox {
const [W, H] = [width || 1, height || 1];
@@ -691,25 +823,45 @@ function start(init: Extract): void {
1 - (2 * y) / H,
];
}
- /** The box's corners along the heading: the nearest, and how far across. */
- function spanAlongHeading([x, y, w, h]: PageBox): [number, number] {
+ /** From the middle of one box toward the middle of another, unit length. */
+ function directionBetween(
+ [ax, ay, aw, ah]: PageBox,
+ [bx, by, bw, bh]: PageBox,
+ ): [number, number] {
+ const [dx, dy] = [bx + bw / 2 - ax - aw / 2, by + bh / 2 - ay - ah / 2];
+ const n = Math.hypot(dx, dy) || 1;
+ return [dx / n, dy / n];
+ }
+ /** The box's corners along a heading: the nearest, and how far across. */
+ function spanAlong(
+ [x, y, w, h]: PageBox,
+ [hx, hy]: [number, number],
+ ): [number, number] {
const along = [
[x, y],
[x + w, y],
[x, y + h],
[x + w, y + h],
- ].map(([cx, cy]) => cx! * heading[0] + cy! * heading[1]);
+ ].map(([cx, cy]) => cx! * hx + cy! * hy);
const lead = Math.min(...along);
return [lead, Math.max(...along) - lead];
}
function paint(i: number): void {
- const [, span] = spanAlongHeading(targets[i]!);
+ const { kind, box } = targets[i]!;
+ const from = targets[init.from];
+ // Back from one of the cards' pages, the title and intro sweep in from
+ // that card. Otherwise his heading, or down the screen before he has
+ // moved far enough to take one.
+ const way =
+ kind === "text" && from
+ ? directionBetween(from.box, box)
+ : (heading ?? [Math.SQRT1_2, Math.SQRT1_2]);
+ const [, span] = spanAlong(box, way);
painted[i] = true;
+ paintedAt[i] = t;
scope.postMessage({
brush: i,
- angle: Math.round(
- (Math.atan2(heading[0], -heading[1]) / RAD + 360) % 360,
- ),
+ angle: Math.round((Math.atan2(way[0], -way[1]) / RAD + 360) % 360),
// The sweep's edge crosses the box in the middle half of the sweep, at
// about his pace where the limits allow. A large box or a slowing bird
// hits BRUSH_LONGEST, and then the edge can overtake him.
@@ -727,37 +879,88 @@ function start(init: Extract): void {
if (!done) paint(i);
});
}
+ /** Where along the fly-in he comes nearest each box's middle on the page,
+ * counting only while he is on it; and so the order he passes the cards.
+ * It counts from once he has faded in, so a card he starts out behind
+ * does not draw in the moment he shows. */
+ function plotPasses(): void {
+ const flight = bird.flight;
+ passesFor = flight;
+ if (!flight) return;
+ const [W, H] = [width || 1, height || 1];
+ const track = flight.points.map((p, j) => {
+ if (flight.dist[j]! < flight.fadeIn) return null;
+ const at = project({ cam, tanY }, width, height, p);
+ return at && at[0] >= 0 && at[0] <= W && at[1] >= 0 && at[1] <= H
+ ? at
+ : null;
+ });
+ passes = targets.map(({ box: [x, y, w, h] }) => {
+ const [cx, cy] = [x + w / 2, y + h / 2];
+ let [nearest, pass] = [Infinity, Infinity];
+ track.forEach((at, j) => {
+ if (!at) return;
+ const d = Math.hypot(at[0] - cx, at[1] - cy);
+ if (d < nearest) [nearest, pass] = [d, flight.dist[j]!];
+ });
+ return pass;
+ });
+ following = targets
+ .map((target, i) =>
+ target.kind === "card" || (returning && target.kind === "text")
+ ? i
+ : -1,
+ )
+ .filter((i) => i >= 0)
+ .sort((a, b) => passes[a]! - passes[b]!);
+ }
+ /** Follows his heading and pace across the page, from wherever he has
+ * moved to since it was last taken: far off he may cover less than a
+ * pixel a frame. Smoothed, so a wobble in the curve does not swing the
+ * sweep. */
+ function followHeading(at: [number, number], dt: number): void {
+ sinceSeen += dt;
+ if (!seen) {
+ [seen, sinceSeen] = [at, 0];
+ return;
+ }
+ const [dx, dy] = [at[0] - seen[0], at[1] - seen[1]];
+ const moved = Math.hypot(dx, dy);
+ if (moved <= 0.5 || sinceSeen <= 0) return;
+ const [ux, uy] = [dx / moved, dy / moved];
+ if (heading) {
+ const [hx, hy] = [
+ heading[0] * 0.6 + ux * 0.4,
+ heading[1] * 0.6 + uy * 0.4,
+ ];
+ const n = Math.hypot(hx, hy) || 1;
+ heading = [hx / n, hy / n];
+ } else {
+ heading = [ux, uy];
+ }
+ pace = moved / sinceSeen;
+ [seen, sinceSeen] = [at, 0];
+ }
function paintInWake(dt: number): void {
if (!painted.includes(false)) return;
if (!bird.entering) {
// The fly-in is over and he never passed some: paint them now.
- if (seen) paintTheRest();
+ if (flewIn) paintTheRest();
return;
}
+ if (!flewIn) [flewIn, flewInAt] = [true, t];
+ if (bird.flight !== passesFor) plotPasses();
const at = project({ cam, tanY }, width, height, bird.position);
if (!at) return;
- if (seen) {
- const [dx, dy] = [at[0] - seen[0], at[1] - seen[1]];
- const moved = Math.hypot(dx, dy);
- if (moved > 0.5 && dt > 0) {
- // Smoothed, so a wobble in the curve does not swing the wave.
- const hx = heading[0] * 0.6 + (dx / moved) * 0.4;
- const hy = heading[1] * 0.6 + (dy / moved) * 0.4;
- const n = Math.hypot(hx, hy) || 1;
- heading = [hx / n, hy / n];
- pace = moved / dt;
- }
- }
- seen = at;
+ followHeading(at, dt);
const [bx0, by0, bx1, by1] = birdOnPage();
- targets.forEach((box, i) => {
+ targets.forEach(({ kind, box: [x, y, w, h] }, i) => {
if (painted[i]) return;
- const [x, y, w, h] = box;
// His body reaching it, not just a wing tip: his middle within a
// quarter of his size of the box. The header, a thin strip across the
// top, he sweeps with a wing as he comes in: any of him will do.
const [mx, my] =
- i === 0
+ kind === "header"
? [(bx1 - bx0) / 2, (by1 - by0) / 2]
: [(bx1 - bx0) / 4, (by1 - by0) / 4];
const over =
@@ -765,15 +968,29 @@ function start(init: Extract): void {
at[0] < x + w + mx &&
at[1] > y - my &&
at[1] < y + h + my;
- // Along the screen's diagonal, which his swoop follows overall; his
- // heading at the moment can swing back as he turns.
- const [W, H] = [width || 1, height || 1];
- const past = at[0] * W + at[1] * H >= (x + w / 2) * W + (y + h / 2) * H;
- const follows =
- i === 2 && painted[1] && sinceFirstCard >= SECOND_CARD_FOLLOWS;
- if (over || past || follows) paint(i);
+ if (over || bird.flown >= passes[i]!) paint(i);
+ });
+ const first = following[0];
+ if (
+ returning &&
+ first !== undefined &&
+ !painted[first] &&
+ t - flewInAt >= RETURN_FIRST_BY
+ ) {
+ paint(first);
+ }
+ // Each follows the one before it along his line.
+ following.forEach((i, k) => {
+ const before = following[k - 1];
+ if (
+ !painted[i] &&
+ before !== undefined &&
+ painted[before] &&
+ t - paintedAt[before]! >= followGap
+ ) {
+ paint(i);
+ }
});
- if (painted[1]) sinceFirstCard += dt;
}
/** The bird's extent on the page in CSS pixels: left, top, right, bottom. */
function birdOnPage(): [number, number, number, number] {
@@ -803,7 +1020,28 @@ function start(init: Extract): void {
ridgeAt = ridgeFor(site);
gl.bindBuffer(gl.ARRAY_BUFFER, ridgeBuf);
gl.bufferData(gl.ARRAY_BUFFER, mesh, gl.STATIC_DRAW);
- ridgeCount = mesh.length / 4;
+ nearCount = skyline?.near ? mesh.length / 8 : 0;
+ ridgeCount = mesh.length / 4 - nearCount;
+ ridgeSpan = [0, 0, 0];
+ if (skyline) {
+ const row = ridgeTexels(skyline, mostTexels);
+ gl.activeTexture(gl.TEXTURE3);
+ gl.bindTexture(gl.TEXTURE_2D, ridgeTex);
+ gl.texImage2D(
+ gl.TEXTURE_2D,
+ 0,
+ gl.RGBA,
+ row.texels,
+ 1,
+ 0,
+ gl.RGBA,
+ gl.UNSIGNED_BYTE,
+ row.data,
+ );
+ setTextureParams(gl.NEAREST, gl.CLAMP_TO_EDGE);
+ gl.activeTexture(gl.TEXTURE0);
+ ridgeSpan = [row.from, row.span, row.texels];
+ }
}
let width = init.width;
let height = init.height;
@@ -817,6 +1055,16 @@ function start(init: Extract): void {
let still = init.still;
let hidden = init.hidden;
let t = 120;
+ // How active the aurora is now, and the faster clock its rays run on.
+ const activitySeed = Math.random() * 1000;
+ let activity = 0;
+ let fastT = t;
+ function updateActivity(dt: number): void {
+ activity =
+ init.activity >= 0 ? init.activity : auroraActivity(t, activitySeed);
+ fastT += dt * (1 + 3 * activity);
+ }
+ updateActivity(0);
let raf = 0;
let last = 0;
let samples = 0;
@@ -1080,6 +1328,9 @@ function start(init: Extract): void {
gl.uniformMatrix3fv(uniformLocation(program, "uCam"), false, cam);
gl.uniform2fv(uniformLocation(program, "uTan"), tan);
gl.uniform1f(uniformLocation(program, "uT"), t);
+ gl.uniform1f(uniformLocation(program, "uAct"), activity);
+ gl.uniform1f(uniformLocation(program, "uFastT"), fastT);
+ gl.uniform3fv(uniformLocation(program, "uRidgeSpan"), ridgeSpan);
gl.uniform1f(uniformLocation(program, "uPx"), px);
gl.uniform1f(uniformLocation(program, "uMoonlight"), now.moonlight);
gl.uniform2fv(uniformLocation(program, "uTilt"), tilt);
@@ -1165,6 +1416,7 @@ function start(init: Extract): void {
setViewUniforms(ridge);
const r = bindAttribute(ridge, "aRidge", ridgeBuf, 4);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, ridgeCount);
+ if (nearCount) gl.drawArrays(gl.TRIANGLE_STRIP, ridgeCount, nearCount);
gl.disableVertexAttribArray(r);
// 5. The raven, in front of everything.
@@ -1285,6 +1537,10 @@ function start(init: Extract): void {
// frames lately (ms).
let smooth = true;
let paceMs = FLY_IN_FRAME_MS;
+ // Whether the last frame planned a new flight. Planning can take a few
+ // milliseconds on a slow phone, so the gap after it says nothing about
+ // whether frames keep up, and is left out of paceMs.
+ let planned = false;
function onFrame(stamp: number): void {
raf = nextFrame(onFrame);
const elapsed = stamp - last;
@@ -1293,14 +1549,18 @@ function start(init: Extract): void {
// 30.
const fast = bird.entering && smooth && Math.hypot(...bird.position) < 15;
if (elapsed < (fast ? FLY_IN_FRAME_MS : FRAME_MS) - 2) return;
- if (fast && last && elapsed < 200) {
+ if (fast && last && elapsed < 200 && !planned) {
paceMs = paceMs * 0.9 + elapsed * 0.1;
if (paceMs > 22) smooth = false;
}
+ planned = false;
if (last) {
const dt = Math.min(elapsed, 100) / 1000;
t += dt;
+ updateActivity(dt);
+ const flight = bird.flight;
bird.step(dt, currentRavenView());
+ planned = !!bird.flight && bird.flight !== flight;
paintInWake(dt);
adaptQuality(elapsed);
}
@@ -1371,7 +1631,11 @@ function start(init: Extract): void {
} else if (data.type === "size") {
width = data.width;
height = data.height;
- if (data.targets.length === targets.length) targets = data.targets;
+ if (data.targets.length === targets.length) {
+ targets = data.targets;
+ // His closest passes by them, again where they are now.
+ passesFor = null;
+ }
resizeCanvas();
drawFrame();
followHeld();
diff --git a/apps/site/src/scripts/skylines/isafjordur.ts b/apps/site/src/scripts/skylines/isafjordur.ts
index 16bb1a0..14a1a6f 100644
--- a/apps/site/src/scripts/skylines/isafjordur.ts
+++ b/apps/site/src/scripts/skylines/isafjordur.ts
@@ -3,10 +3,13 @@
// elev: Int16 little-endian, hundredths of a degree above the horizontal.
// dist: Uint16 little-endian, tens of metres to the ridge.
// base: Int16, hundredths of a degree: the far shore over water, or -40°.
+// near: Int16, hundredths of a degree: the near shore of the water seen
+// from land, or -40°.
export const SKYLINE = {
from: -80,
step: 0.2,
elev: "dwd4B3oHeweAB4wHmAekB7EHvgfKB9YH4wfwB/0HCggXCCQIMgg9CEkIVQhhCG0IdQh8CIMIiQiOCI8IjgiMCIsIiwiLCIwIigiJCIgIhwiGCIcIhgiGCIYIhwiJCIsIjQiNCIwIiwiLCIwIjQiMCIwIiwiLCIoIiQiHCIYIhQiFCIUIhgiICIoIjgiRCJMIkgiSCJQIlgiXCJcIlwiXCJcIlQiUCJMIlAiVCJgImwidCJ0ImwidCKAIpQinCKcIpgimCKcIqQisCK4IrgivCLAIsgizCLIIsgiwCLAIsQi0CLgIuQi3CLYItgi4CLoIvgi9CLoIuAi3CLYItwi3CLcIsgiuCK0Ir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/+L/4v/zf7N/s3+zf7N/s3+zf7N/s3+zf7N/s3+zf7N/s3+zf7N/s3+zf7N/s3+zf6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/mDwof6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of6h/qH+of5n/mf+Z/5n/mf+Z/5n/mf+Z/5n/mf+Z/5n/mf+Z/5n/mf+Z/5n/mDwYPBg8GDwYPBg8GDwYPBg8GDwYPBg8GDwYPBg8GDwYPBg8GDwYPBg8GDwYPBg8GDwYPBg8A==",
};
diff --git a/packages/theme/README.md b/packages/theme/README.md
index 8e1c501..f4c09ca 100644
--- a/packages/theme/README.md
+++ b/packages/theme/README.md
@@ -1,18 +1,22 @@
# @northguild/theme
-CSS only. Private; never published to a registry. Each file's header names its
-source file and the GMT commit it was copied from.
+CSS only. Private; never published to a registry. Each file copied from GMT
+names its source file and the GMT commit in its header. `tokens-aurora.css` is
+NorthGuild's own.
## Files
- `tokens.css`: dark `:root` tokens and the Michroma `@font-face`.
- `tokens-light.css`: the `[data-theme="light"]` overrides; omit for dark-only.
+- `tokens-aurora.css`: the aurora's colours for the sky (NorthGuild's own).
- `primitives.css`: component recipes below.
- `fonts/michroma-latin-400-normal.woff2`: the display font.
## Token groups (`--gmt-*`)
- Colour roles: `void`, `cyan`, `spring`, `teal`, `ice` (and `-dim`, `-bright` variants).
+- Aurora light, for the sky: `aurora-green`, `aurora-red`, `aurora-fringe`,
+ in `tokens-aurora.css` (NorthGuild's own, not copied from GMT).
- Surfaces and fills: `surface`, `fill`, `fill-subtle`, `fill-strong`, `glass-tint*`.
- Lines: `border`, `border-strong`, `hairline`, `highlight`, `glow`.
- Type: `font-mono`, `font-display`.
diff --git a/packages/theme/package.json b/packages/theme/package.json
index b276348..e71ed59 100644
--- a/packages/theme/package.json
+++ b/packages/theme/package.json
@@ -6,6 +6,7 @@
"files": [
"tokens.css",
"tokens-light.css",
+ "tokens-aurora.css",
"primitives.css",
"fonts"
],
@@ -16,6 +17,7 @@
"exports": {
"./tokens.css": "./tokens.css",
"./tokens-light.css": "./tokens-light.css",
+ "./tokens-aurora.css": "./tokens-aurora.css",
"./primitives.css": "./primitives.css",
"./fonts/*": "./fonts/*",
"./package.json": "./package.json"
diff --git a/packages/theme/tokens-aurora.css b/packages/theme/tokens-aurora.css
new file mode 100644
index 0000000..9840ff9
--- /dev/null
+++ b/packages/theme/tokens-aurora.css
@@ -0,0 +1,15 @@
+/*
+ * NorthGuild's own tokens, not from the GMT palette: kept out of tokens.css,
+ * which is copied from GMT and would lose them when copied again.
+ *
+ * The aurora's light, for the sky behind the page: oxygen's green line
+ * (557.7 nm) that most aurora shows, oxygen's red line (630 nm) atop tall
+ * rays, and the pink-magenta of nitrogen along an active aurora's lower
+ * edge. As a camera records them, so the brightest cores still wash out
+ * toward white.
+ */
+:root {
+ --gmt-aurora-green: #4dff88;
+ --gmt-aurora-red: #e8213c;
+ --gmt-aurora-fringe: #f04ab8;
+}
diff --git a/scripts/build-skyline.mjs b/scripts/build-skyline.mjs
index 59551f4..bd54b71 100644
--- a/scripts/build-skyline.mjs
+++ b/scripts/build-skyline.mjs
@@ -3,7 +3,8 @@
// trees and buildings), optionally adds OpenStreetMap building heights, and
// keeps the highest elevation angle, allowing for Earth curvature and standard
// refraction. Where the site looks over water it also records the far shore,
-// so the page can draw the water below it.
+// so the page can draw the water below it; from land, where water shows
+// between the far shore and a near one (a fjord below the town), both.
// Writes apps/site/src/scripts/skylines/.ts.
//
// Run: node scripts/build-skyline.mjs [site id ...] (default: all sites)
@@ -30,6 +31,7 @@ const FAR = 80_000;
const BUILDINGS_FAR = 12_000; // OSM buildings beyond this are below a pixel
const LAND = 1.5; // metres above sea level that count as land, not water
const NO_SHORE = -40; // degrees: the strip runs below the frame
+const WATER_LEAST = 0.03; // degrees: thinner water seen from land is left out
const R_EARTH = 6_371_000;
const R_EFF = (R_EARTH * 7) / 6; // standard refraction
const OUT = new URL("../apps/site/src/scripts/skylines/", import.meta.url);
@@ -246,10 +248,26 @@ async function build(site) {
const best = new Float64Array(count).fill(-Infinity);
const bestR = new Float64Array(count).fill(FAR);
const shore = new Float64Array(count).fill(NO_SHORE / DEG);
+ // From land: the nearest shore of the water seen, or NO_SHORE.
+ const nearShore = new Float64Array(count).fill(NO_SHORE / DEG);
for (let i = 0; i < count; i++) {
const az = (from + i * AZ_STEP) / DEG;
let landAt = 0;
+ // From land, the water seen (not hidden by nearer land): its nearest
+ // and farthest angles.
+ let [seaLow, seaHigh] = [Infinity, -Infinity];
+ // Water inside the first stretch counts too, from just past the viewer:
+ // its houses and walls are left out of the skyline, so they hide none
+ // of it either.
+ for (let r = 20; !site.water && r < near; r += 10) {
+ const lat = site.lat + (r * Math.cos(az) * DEG) / R_EARTH;
+ const lon =
+ site.lon + (r * Math.sin(az) * DEG) / (R_EARTH * Math.cos(latRad));
+ if (terrainHeight(lat, lon) <= LAND) {
+ seaLow = Math.min(seaLow, elevationAngle(0, r));
+ }
+ }
// Step grows with distance: 15 m near, about 130 m far.
for (let r = near; r <= FAR; r += Math.max(15, r / 600)) {
const lat = site.lat + (r * Math.cos(az) * DEG) / R_EARTH;
@@ -258,6 +276,10 @@ async function build(site) {
const z = terrainHeight(lat, lon);
if (!landAt && z > LAND) landAt = r;
const angle = elevationAngle(z, r);
+ if (!site.water && z <= LAND && angle > best[i]) {
+ seaLow = Math.min(seaLow, angle);
+ seaHigh = Math.max(seaHigh, angle);
+ }
if (angle > best[i]) {
best[i] = angle;
bestR[i] = r;
@@ -266,6 +288,13 @@ async function build(site) {
// Over water the strip stops at the first land, however near: the
// island's own shore curves down toward the frame.
if (site.water && landAt) shore[i] = elevationAngle(0, landAt);
+ // From land, a strip of water worth drawing (a few hundredths of a
+ // degree at least) splits the strip: the far shore above it, the near
+ // shore below.
+ if (seaHigh - seaLow >= WATER_LEAST / DEG) {
+ shore[i] = seaHigh;
+ nearShore[i] = seaLow;
+ }
}
if (site.buildings) {
@@ -368,6 +397,8 @@ async function build(site) {
Math.min(65535, Math.round(r / 10)),
);
const base = Int16Array.from(shore, (a) => Math.round(a * DEG * 100));
+ const nearBase = Int16Array.from(nearShore, (a) => Math.round(a * DEG * 100));
+ const seesWater = !site.water && nearBase.some((a) => a > NO_SHORE * 100);
function toBase64(a) {
return Buffer.from(a.buffer).toString("base64");
@@ -378,13 +409,19 @@ async function build(site) {
// ${site.name}: ${site.lat} N, ${site.lon} E, eye ${site.eye} m above ground (${h0.toFixed(1)} m).
// elev: Int16 little-endian, hundredths of a degree above the horizontal.
// dist: Uint16 little-endian, tens of metres to the ridge.
-// base: Int16, hundredths of a degree: the far shore over water, or ${NO_SHORE}°.
+// base: Int16, hundredths of a degree: the far shore over water, or ${NO_SHORE}°.${
+ seesWater
+ ? `
+// near: Int16, hundredths of a degree: the near shore of the water seen
+// from land, or ${NO_SHORE}°.`
+ : ""
+ }
export const SKYLINE = {
from: ${from},
step: ${AZ_STEP},
elev: "${toBase64(elev)}",
dist: "${toBase64(dist)}",
- base: "${toBase64(base)}",
+ base: "${toBase64(base)}",${seesWater ? `\n near: "${toBase64(nearBase)}",` : ""}
};
`,
);
@@ -398,7 +435,8 @@ export const SKYLINE = {
const i = Math.round((az - from) / AZ_STEP);
console.log(
` ${String(az).padStart(4)}° ${deg[i].toFixed(2).padStart(6)}° ` +
- `${(dist[i] / 100).toFixed(1).padStart(5)} km shore ${(base[i] / 100).toFixed(2)}°`,
+ `${(dist[i] / 100).toFixed(1).padStart(5)} km shore ${(base[i] / 100).toFixed(2)}°` +
+ (seesWater ? ` near shore ${(nearBase[i] / 100).toFixed(2)}°` : ""),
);
}
}