The showcase prompt, Fable 5.2
agent (cont.)
+16:41Write[redacted: private path]run/citadel.html
input
[redacted: private path]run/citadel.html <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>What models do you use? — an answer from one of them</title> <meta name="description" content="Severian's five models, drawn as a citadel by one of them. One HTML file: no libraries, no image files, no font files."> <!-- WHAT MODELS DO YOU USE? An answer for Severian, written by Fable 5.2 (the violet tower). Everything you see and hear is computed by this one file while it plays: - a ray-marching renderer (GLSL, below) for the citadel, the water and the sky - a camera, a timeline and a small traffic simulation (the motes on the bridges) - a score and the synth that plays it (Web Audio) No libraries, no image files, no model files, no font files, no network requests. URL switches: ?film=1 deterministic frame-by-frame mode used to record the video --> <style> :root { --u: 12px; --ink: #f4efe6; } * { box-sizing: border-box; } html, body { margin: 0; height: 100%; background: #03040a; overflow: hidden; } #stage { position: fixed; inset: 0; overflow: hidden; color: var(--ink); cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "URW Palladio L", P052, Georgia, serif; } #stage.dragging { cursor: grabbing; } canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; } .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Ubuntu Mono", "DejaVu Sans Mono", monospace; text-transform: uppercase; letter-spacing: .22em; } #scrim { position: absolute; left: 0; right: 0; bottom: 0; height: 62%; pointer-events: none; opacity: 0; background: linear-gradient(to top, rgba(2,3,10,.82), rgba(2,3,10,.5) 45%, rgba(2,3,10,0)); } #hook { position: absolute; left: 0; right: 0; top: 9%; text-align: center; pointer-events: none; padding: 0 calc(var(--u)*4); } #hook .mono { font-size: calc(var(--u)*1.25); opacity: .8; } #hook h1 { font-weight: 400; font-style: italic; font-size: calc(var(--u)*7.2); line-height: 1.04; margin: calc(var(--u)*1.1) 0 calc(var(--u)*1.3); letter-spacing: -.01em; text-shadow: 0 0 calc(var(--u)*3) rgba(3,4,14,.9), 0 calc(var(--u)*.2) calc(var(--u)*.6) rgba(3,4,14,.8); } #hook p { font-size: calc(var(--u)*2.5); margin: 0; text-shadow: 0 0 calc(var(--u)*1.5) rgba(3,4,14,1); } .cap { position: absolute; left: calc(var(--u)*5); bottom: calc(var(--u)*5.2); width: min(calc(var(--u)*62), calc(100% - var(--u)*10)); pointer-events: none; opacity: 0; text-shadow: 0 0 calc(var(--u)*1.4) rgba(2,3,10,1), 0 0 calc(var(--u)*.4) rgba(2,3,10,.9); } .cap .mono { font-size: calc(var(--u)*1.2); margin-bottom: calc(var(--u)*.9); display: flex; align-items: center; gap: calc(var(--u)*.9); } .cap .mono i { display: inline-block; width: calc(var(--u)*.85); height: calc(var(--u)*.85); border-radius: 50%; background: currentColor; box-shadow: 0 0 calc(var(--u)*1.2) currentColor; } .cap .ttl { font-size: calc(var(--u)*4.6); line-height: 1.05; letter-spacing: -.01em; margin-bottom: calc(var(--u)*.9); } .cap .ttl.q { font-style: italic; font-size: calc(var(--u)*3.15); line-height: 1.22; } .cap .body { font-size: calc(var(--u)*2.35); line-height: 1.3; opacity: .94; } .cap .extra { font-size: calc(var(--u)*2.35); line-height: 1.3; font-style: italic; margin-top: calc(var(--u)*.8); } .tag { position: absolute; left: 0; top: 0; pointer-events: none; opacity: 0; white-space: nowrap; font-size: calc(var(--u)*1.12); will-change: transform, opacity; text-shadow: 0 0 calc(var(--u)*.8) rgba(2,3,10,1), 0 0 calc(var(--u)*.3) rgba(2,3,10,1); } .tag.tower::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: calc(var(--u)*1.6); background: currentColor; opacity: .7; margin-top: calc(var(--u)*.35); } .tag.star { font-size: calc(var(--u)*1.08); letter-spacing: .16em; color: #e9edff; } #cursor { position: absolute; left: 0; top: 0; width: calc(var(--u)*2.6); height: calc(var(--u)*2.6); opacity: 0; pointer-events: none; } #ui { position: absolute; inset: 0; pointer-events: none; transition: opacity .6s; } #ui button { pointer-events: auto; position: absolute; right: calc(var(--u)*2); bottom: calc(var(--u)*2.4); background: rgba(6,8,20,.55); color: var(--ink); border: 1px solid rgba(244,239,230,.35); border-radius: 99px; padding: .7em 1.2em; font-size: max(11px, calc(var(--u)*1.05)); cursor: pointer; backdrop-filter: blur(6px); } #ui button:hover { border-color: rgba(244,239,230,.8); } #hint { position: absolute; right: calc(var(--u)*2); top: calc(var(--u)*2); font-size: max(10px, calc(var(--u)*.95)); opacity: .55; } #bar { pointer-events: auto; position: absolute; left: 0; right: 0; bottom: 0; height: 14px; cursor: pointer; } #bar::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(244,239,230,.14); } #bar i { position: absolute; left: 0; bottom: 0; height: 2px; background: rgba(244,239,230,.75); width: 0; } #stage.film #ui { display: none; } #stage.film { cursor: none; } #nogl { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; text-align: center; padding: 10%; font-size: 20px; } </style> </head> <body> <div id="stage"> <canvas id="gl"></canvas> <div id="scrim"></div> <div id="hook"> <div class="mono" id="hookK">People keep asking Severian</div> <h1 id="hookH">What models do you use?</h1> <p id="hookP">Five. One of them drew the answer.</p> </div> <div id="caps"></div> <div id="tags"></div> <svg id="cursor" viewBox="0 0 24 24"><path d="M5 2l14 11-6.2.9 3.6 7-2.6 1.3-3.5-7L6 19z" fill="#fff" stroke="#05060c" stroke-width="1.4" stroke-linejoin="round"/></svg> <div id="ui"> <div id="hint" class="mono">live render · drag to look around</div> <button id="snd" class="mono">sound: off</button> <div id="bar"><i></i></div> </div> <div id="nogl">This piece draws itself with WebGL2, which this browser didn't provide.</div> </div> <script> "use strict"; /* ───────────────────────── 0. constants shared by the renderer and the timeline ───────────────────────── */ const FILE_KB = 0; /*FILE_KB*/ const Q = new URLSearchParams(location.search); const FILM = Q.has('film'); const T = 43; // film length, seconds; it loops const TW = [ // the five towers, in roll-call order { id: 'opus', name: 'Opus 5.5', pos: [0, 0, 0], lant: [0, 12.45, 0], col: [1.00, 0.42, 0.22], css: '#ff8d61', r: 1.60, ignite: 5.2 }, { id: 'sonnet', name: 'Sonnet 5.5', pos: [-4.8, 0, 3.4], lant: [-4.8, 7.15, 3.4], col: [0.22, 0.95, 0.78], css: '#62efd3', r: 0.70, ignite: 8.1 }, { id: 'astra', name: 'GPT-6-Astra', pos: [-8.5, 0, -3.0], lant: [-8.5, 7.85, -3.0], col: [0.50, 0.72, 1.00], css: '#a9ccff', r: 0.90, ignite: 11.0 }, { id: 'sol', name: 'GPT-6.1-Sol', pos: [8.5, 0, -3.2], lant: [8.5, 6.95, -3.2], col: [1.00, 0.78, 0.22], css: '#ffd766', r: 0.82, ignite: 13.9 }, { id: 'fable', name: 'Fable 5.2', pos: [4.8, 0, 3.4], lant: [4.8, 7.55, 3.4], col: [0.68, 0.40, 1.00], css: '#c5a2ff', r: 0.80, ignite: 16.8 }, ]; const BLACKOUT = 4.5; const WDIR = [0.5, 0, 0.8660254]; // the way Fable's round window faces const WPERP = [WDIR[2], 0, -WDIR[0]]; // "right" for someone looking at that window const WIN_Y = 5.0, WIN_R = 0.5; const WC = [TW[4].pos[0] + WDIR[0] * 0.8, WIN_Y, TW[4].pos[2] + WDIR[2] * 0.8]; const GATE = [0, 1.67, 9.0], GATE_TOP = [0, 2.75, 9.0]; const ARCH = 0.55; const SHIPPED = [ // screen-space spots for the stars: x in -1..1 (of half-width), y in -1..1 ['from-avalon.com', -0.80, 0.50], ['Into Bloom', -0.55, 0.80], ['Hearthwynd', -0.33, 0.47], ['Desktop Buddies', -0.12, 0.84], ['Scene Convert', 0.13, 0.55], ['Claviger · Laya-421M', 0.36, 0.86], ['citadel/projects', 0.57, 0.50], ['talos · write-ups', 0.82, 0.76], ['baldanders · transcripts', 0.84, 0.20], ['3D model pipeline', -0.86, 0.12], ['a design language', 0.30, 0.22], ]; const NS = SHIPPED.length, NM = 28, NC = 4; const LAUNCH0 = 25.15, LAUNCH_GAP = 0.36, FLIGHT = 1.3; const APPROACH = 38.8; /* tiny vector kit */ const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]]; const mul = (a, s) => [a[0] * s, a[1] * s, a[2] * s], dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]; const len = a => Math.hypot(a[0], a[1], a[2]), norm = a => mul(a, 1 / (len(a) || 1)); const lerp3 = (a, b, s) => [a[0] + (b[0] - a[0]) * s, a[1] + (b[1] - a[1]) * s, a[2] + (b[2] - a[2]) * s]; const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x)); const smooth = (a, b, x) => { const s = clamp((x - a) / (b - a)); return s * s * (3 - 2 * s); }; const env = (t, a, b, fi = 0.55, fo = 0.45) => smooth(a, a + fi, t) * (1 - smooth(b - fo, b, t)); const fract = x => x - Math.floor(x); /* bridges: keep door -> tower door, for the four outer towers */ const BRIDGES = TW.slice(1).map(tw => { const u = norm([tw.pos[0], 0, tw.pos[2]]); return { a: [u[0] * 1.5, 4.8, u[2] * 1.5], b: [tw.pos[0] - u[0] * tw.r * 0.9, 4.2, tw.pos[2] - u[2] * tw.r * 0.9], u }; }); /* ───────────────────────── 1. the renderer: one fragment shader ───────────────────────── */ const f4 = x => (Math.round(x * 1e4) / 1e4).toFixed(4), v3 = a => `vec3(${a.map(f4).join(',')})`; const FRAG = `#version 300 es precision highp float; out vec4 fragColor; uniform vec2 uRes; uniform float uTime, uFocal, uAA, uPortalK, uInner; uniform vec3 uCamPos, uCamFwd, uCamRight, uCamUp; uniform vec4 uLit[5]; // x: how lit a tower is (0..1), y: ignition flash uniform vec4 uMote[${NM}]; uniform vec3 uMoteCol[${NM}]; uniform vec4 uStar[${NS}]; // xyz: where it hangs, w: brightness uniform vec4 uCometA[${NC}]; uniform vec3 uCometB[${NC}]; uniform vec4 uGate; // rgb, intensity uniform sampler2D uPortal; const vec3 TPOS[5] = vec3[5](${TW.map(t => v3(t.pos)).join(',')}); const vec3 LANT[5] = vec3[5](${TW.map(t => v3(t.lant)).join(',')}); const vec3 TCOL[5] = vec3[5](${TW.map(t => v3(t.col)).join(',')}); const vec3 BRA[4] = vec3[4](${BRIDGES.map(b => v3(b.a)).join(',')}); const vec3 BRB[4] = vec3[4](${BRIDGES.map(b => v3(b.b)).join(',')}); const vec2 WDIR = vec2(${f4(WDIR[0])},${f4(WDIR[2])}); const vec2 WPERP = vec2(${f4(WPERP[0])},${f4(WPERP[2])}); const vec3 GATE = ${v3(GATE)}; const float WIN_Y = ${f4(WIN_Y)}, WIN_R = ${f4(WIN_R)}, ARCH = ${f4(ARCH)}; const vec3 MOON = normalize(vec3(-0.55, 0.5, -0.67)); const float TAU = 6.2831853; float gId, gPM; vec3 gPC; // material of the last map() call; portal mix + colour float hash(vec2 p){ p = fract(p * vec2(123.34, 456.21)); p += dot(p, p + 45.32); return fract(p.x * p.y); } float noise(vec2 p){ vec2 i = floor(p), f = fract(p); f = f*f*(3.-2.*f); return mix(mix(hash(i), hash(i+vec2(1,0)), f.x), mix(hash(i+vec2(0,1)), hash(i+vec2(1,1)), f.x), f.y); } float fbm(vec2 p){ return .5*noise(p) + .25*noise(p*2.03+7.1) + .125*noise(p*4.01+3.3); } float sdBox(vec3 p, vec3 b){ vec3 q = abs(p) - b; return length(max(q, 0.)) + min(max(q.x, max(q.y, q.z)), 0.); } float sdHex(vec2 p, float r){ const vec3 k = vec3(-0.866025404, 0.5, 0.577350269); p = abs(p); p -= 2.*min(dot(k.xy, p), 0.)*k.xy; p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); return length(p)*sign(p.y); } float coneD(float r, float y, float R, float h){ return max((r - R*(1. - y/h))*h/sqrt(h*h + R*R), -y); } float smin(float a, float b, float k){ float h = clamp(.5 + .5*(b - a)/k, 0., 1.); return mix(b, a, h) - k*h*(1. - h); } void U(inout float d, float nd, float id){ if (nd < d) { d = nd; gId = id; } } // ── the five towers ── float dKeep(vec3 q){ // Opus: the keep. Broad, ribbed, crowned. float r = length(q.xz), a = atan(q.z, q.x); float d = max(r - (1.6 - 0.035*q.y), abs(q.y - 3.5) - 3.5); float s8 = TAU/8., a8 = mod(a + s8*.5, s8) - s8*.5; vec2 rb = vec2(cos(a8), sin(a8))*r; d = min(d, max(max(abs(rb.y) - 0.17, rb.x - (1.82 - 0.05*q.y)), abs(q.y - 3.2) - 3.2)); d = min(d, max(r - 1.92, abs(q.y - 7.1) - 0.2)); float s16 = TAU/16., a16 = mod(a, s16) - s16*.5; d = min(d, max(max(abs(a16*r) - 0.2, abs(r - 1.78) - 0.14), abs(q.y - 7.46) - 0.17)); d = min(d, max(r - 0.98, abs(q.y - 8.5) - 1.3)); d = min(d, max(r - 1.2, abs(q.y - 9.9) - 0.12)); return min(d, coneD(r, q.y - 10.02, 1.08, 2.35)); } float dSonnet(vec3 q){ // Sonnet: slender, banded, regular as a metronome. float r = length(q.xz); float d = max(r - 0.7, abs(q.y - 2.65) - 2.65); d = min(d, max(max(r - 0.79, abs(mod(q.y, 1.25) - 0.625) - 0.05), q.y - 5.3)); d = min(d, max(r - 0.93, abs(q.y - 5.4) - 0.1)); return min(d, coneD(r, q.y - 5.5, 0.86, 1.55)); } float dAstra(vec3 q, out float core){ // Astra: an observatory, its slit turning with the sky. float r = length(q.xz); float d = max(r - 0.9, abs(q.y - 3.3) - 3.3); d = min(d, max(r - 1.06, abs(q.y - 6.7) - 0.1)); vec3 c = q - vec3(0., 6.8, 0.); float dome = max(abs(length(c) - 0.98) - 0.04, -c.y); float sa = uTime*0.12 + 0.5; vec3 cr = vec3(c.x*cos(sa) - c.z*sin(sa), c.y, c.x*sin(sa) + c.z*cos(sa)); dome = max(dome, -sdBox(cr - vec3(0., 0.75, 0.5), vec3(0.12, 0.8, 0.62))); core = max(length(c) - 0.8, -c.y); return min(d, dome); } float dSol(vec3 q, out float sun){ // Sol: square, buttressed, carrying a small sun. float d = sdBox(q - vec3(0., 3.05, 0.), vec3(0.8, 3.05, 0.8)); vec3 qc = vec3(abs(q.x) - 0.8, q.y, abs(q.z) - 0.8); d = min(d, sdBox(qc - vec3(0., 3.2, 0.), vec3(0.2, 3.2, 0.2))); d = min(d, sdBox(q - vec3(0., 6.2, 0.), vec3(1.02, 0.1, 1.02))); d = min(d, sdBox(qc - vec3(0., 6.75, 0.), vec3(0.09, 0.5, 0.09))); sun = length(q - vec3(0., 6.95, 0.)) - 0.36; return d; } float dFable(vec3 q, out float cry){ // Fable: six-sided, a floating crystal, one round window. vec2 h = vec2(dot(q.xz, WPERP), dot(q.xz, WDIR)); float d = max(sdHex(h, 0.8), abs(q.y - 3.15) - 3.15); d = min(d, max(sdHex(h, 0.92), abs(q.y - 6.4) - 0.1)); d = min(d, length(vec2(length(vec2(h.x, q.y - WIN_Y)) - (WIN_R + 0.06), h.y - 0.8)) - 0.06); vec3 c = q - vec3(0., 7.55 + 0.07*sin(uTime*1.3), 0.); float ca = uTime*0.5; c.xz = mat2(cos(ca), -sin(ca), sin(ca), cos(ca))*c.xz; cry = (abs(c.x) + abs(c.y)*0.62 + abs(c.z) - 0.42)*0.5; return d; } float dBridge(vec3 p, vec3 a, vec3 b){ vec3 pa = p - a, ba = b - a; float h = clamp(dot(pa, ba)/dot(ba, ba), 0., 1.); vec3 c = pa - ba*h; c.y -= ARCH*4.*h*(1. - h); return (length(c*vec3(1., 1.5, 1.)) - 0.085)*0.75; } float map(vec3 p){ float d = 1e5; gId = 0.; // the island, with a plinth under each tower and a causeway out to the gate float isl = (length((p - vec3(0., -1.6, 0.))/vec3(12.5, 2.5, 8.0)) - 1.)*2.5; for (int i = 0; i < 5; i++) { vec3 q = p - TPOS[i]; float pr = (i == 0 ? 2.5 : 1.55); isl = smin(isl, max(length(q.xz) - pr, q.y - 0.75), 0.6); } isl += 0.10*sin(p.x*1.3 + 0.5)*sin(p.z*1.7) + 0.045*sin(p.x*4.3 + p.y*3.)*sin(p.z*3.9 + 1.); isl = min(isl, sdBox(p - vec3(0., 0.3, 7.2), vec3(0.42, 0.32, 2.25)) - 0.05); U(d, isl*0.85, 0.); vec3 q; float b, x; q = p - TPOS[0]; b = length(q.xz) - 2.1; if (b < d) U(d, dKeep(q), 1.); q = p - TPOS[1]; b = length(q.xz) - 1.05; if (b < d) U(d, dSonnet(q), 2.); q = p - TPOS[2]; b = length(q.xz) - 1.2; if (b < d) { U(d, dAstra(q, x), 3.); U(d, x, 10.); } q = p - TPOS[3]; b = length(q.xz) - 1.5; if (b < d) { U(d, dSol(q, x), 4.); U(d, x, 8.); } q = p - TPOS[4]; b = length(q.xz) - 1.15; if (b < d) { U(d, dFable(q, x), 5.); U(d, x, 9.); } if (abs(p.y - 4.8) < 1.3 + d) for (int i = 0; i < 4; i++) U(d, dBridge(p, BRA[i], BRB[i]), 6.); q = p - vec3(GATE.x, 0.67, GATE.z); if (length(q) - 3. < d) { float g = (q.y > 1.25) ? abs(length(q.xy - vec2(0., 1.25)) - 0.62) - 0.11 : abs(abs(q.x) - 0.62) - 0.11; U(d, max(max(g, abs(q.z) - 0.14), -q.y), 7.); } return d; } vec3 calcN(vec3 p, float e){ vec2 k = vec2(1., -1.); return normalize(k.xyy*map(p + k.xyy*e) + k.yyx*map(p + k.yyx*e) + k.yxy*map(p + k.yxy*e) + k.xxx*map(p + k.xxx*e)); } float march(vec3 ro, vec3 rd, float tmax, int steps){ vec3 oc = ro - vec3(0., 4.5, 1.5); float b = dot(oc, rd), h = b*b - dot(oc, oc) + 16.5*16.5; if (h < 0.) return -1.; h = sqrt(h); float t = max(-b - h, 0.02); tmax = min(tmax, -b + h); for (int i = 0; i < steps; i++) { if (t > tmax) return -1.; float d = map(ro + rd*t); if (d < 0.0011*t + 0.0005) return t; t += d*0.92; } return t < tmax ? t : -1.; } float shadow(vec3 ro, vec3 rd){ float s = 1., t = 0.08; for (int i = 0; i < 18; i++) { float d = map(ro + rd*t); s = min(s, 9.*d/t); t += clamp(d, 0.06, 0.9); if (s < 0.02 || t > 14.) break; } return clamp(s, 0., 1.); } float calcAO(vec3 p, vec3 n){ float a = 0., w = 1.; for (int i = 1; i <= 4; i++) { float h = 0.09*float(i); a += w*(h - map(p + n*h)); w *= 0.6; } return clamp(1. - 2.2*a, 0., 1.); } // ── light in the windows ── float wmask(vec2 f, vec2 hw, float px){ vec2 d = abs(f) - hw; return smoothstep(px, -px, max(d.x, d.y)); } float wlit(vec2 cell, float frac){ float h = hash(cell); float on = step(h, frac)*step(hash(cell + floor(uTime*0.22 + h*9.)), 0.9); return on*(0.55 + 0.75*hash(cell + 3.7)); } vec2 portalUV(vec2 w){ float m = min(uRes.x, uRes.y); return 0.5 + (w/(2.*WIN_R))*vec2(m/uRes.x, m/uRes.y)*0.92; } vec3 windows(vec3 p, vec3 n, int ti, float px){ if (abs(n.y) > 0.35) return vec3(0.); vec3 q = p - TPOS[ti]; float lit = uLit[ti].x, e = 0., r = length(q.xz), a = atan(q.z, q.x)/TAU; vec3 c = mix(TCOL[ti], vec3(1., 0.86, 0.66), 0.3); if (ti == 0) { if (q.y > 1.3 && q.y < 6.5 && r < 1.66 - 0.035*q.y) { float n0 = 16., rh = 0.66; float row = floor(q.y/rh); float s = a*n0 + 0.5*mod(row, 2.); vec2 f = vec2((fract(s) - .5)*TAU*r/n0, (fract(q.y/rh) - .5)*rh); e = wmask(f, vec2(0.1, 0.19), px)*wlit(vec2(floor(s), row), 0.62); } else if (q.y > 7.7 && q.y < 9.5 && r < 1.02) { float n0 = 8., rh = 0.9; float row = floor(q.y/rh); float s = a*n0; vec2 f = vec2((fract(s) - .5)*TAU*r/n0, (fract(q.y/rh) - .5)*rh); e = wmask(f, vec2(0.11, 0.3), px)*wlit(vec2(floor(s), row + 40.), 0.9)*1.3; } e *= smoothstep(0., 0.8, lit*11. - q.y); } else if (ti == 1) { if (q.y > 0.95 && q.y < 5.2 && r < 0.74) { float n0 = 10., rh = 0.4167; float row = floor(q.y/rh); float s = a*n0; vec2 f = vec2((fract(s) - .5)*TAU*r/n0, (fract(q.y/rh) - .5)*rh); float scan = smoothstep(0.8, 0., abs(fract(uTime*0.35 - q.y*0.09) - 0.5)*2.); // a band of work sweeping upward e = wmask(f, vec2(0.08, 0.11), px)*(0.35*wlit(vec2(floor(s), row), 0.85) + 1.1*scan*step(hash(vec2(floor(s), row) + 1.3), 0.8)); } e *= smoothstep(0., 0.8, lit*6.5 - q.y); } else if (ti == 2) { if (q.y > 1.2 && q.y < 6.3 && r < 0.94) { float n0 = 7., rh = 0.85; float row = floor(q.y/rh); float s = a*n0 + 0.37*row; vec2 f = vec2((fract(s) - .5)*TAU*r/n0, (fract(q.y/rh) - .5)*rh); e = wmask(f, vec2(0.07, 0.24), px)*wlit(vec2(floor(s), row), 0.5)*1.2; } e *= smoothstep(0., 0.8, lit*7.5 - q.y); } else if (ti == 3) { bool xf = abs(n.x) > abs(n.z); float al = xf ? q.z : q.x; if (q.y > 1.0 && q.y < 5.8 && abs(al) < 0.6) { float rh = 0.8; float row = floor(q.y/rh), col = floor((al + 0.6)/0.4); vec2 f = vec2((fract((al + 0.6)/0.4) - .5)*0.4, (fract(q.y/rh) - .5)*rh); e = wmask(f, vec2(0.045, 0.27), px)*wlit(vec2(col + (xf ? 10. : 0.) + sign(xf ? n.x : n.z)*5., row), 0.6)*1.3; } e *= smoothstep(0., 0.8, lit*7. - q.y); } else { vec2 h = vec2(dot(q.xz, WPERP), dot(q.xz, WDIR)); float face = floor((atan(h.y, h.x) - TAU*.25)/(TAU/6.) + 0.5), fa = TAU*.25 + face*TAU/6.; float al = dot(h, vec2(-sin(fa), cos(fa))); vec2 w = vec2(h.x, q.y - WIN_Y); if (face == 0. && length(w) < WIN_R + 0.02) { // the round window: a picture of this picture return texture(uPortal, portalUV(w)).rgb*1.15*smoothstep(0., 0.5, lit*7.5 - q.y + 1.); } if (q.y > 1.0 && q.y < 6.0 && !(face == 0. && q.y > 3.6)) { float rh = 1.25; float row = floor(q.y/rh); vec2 f = vec2(al, (fract(q.y/rh) - .5)*rh); e = wmask(f, vec2(0.085, 0.36), px)*wlit(vec2(face, row), 0.62)*1.2; } e *= smoothstep(0., 0.8, lit*7.5 - q.y); } return c*e*2.6; } vec3 shade(vec3 p, vec3 n, vec3 rd, float id, float tt, bool hq){ float px = tt*1.6/(uFocal*uRes.y); vec3 alb = vec3(0.115, 0.12, 0.135), em = vec3(0.); if (id < 0.5) alb *= 0.65 + 0.7*fbm(p.xz*2.3 + p.y*1.7); else if (id < 5.5) { int ti = int(id + 0.5) - 1; alb = mix(vec3(0.15, 0.15, 0.17), TCOL[ti], 0.07)*(0.85 + 0.3*noise(p.xy*5. + p.z*5.)); em = windows(p, n, ti, px); } else if (id < 6.5) alb = vec3(0.17, 0.17, 0.19); else if (id < 7.5) { alb = vec3(0.2); em = uGate.rgb*uGate.w*0.12; } else if (id < 8.5) em = mix(TCOL[3], vec3(1., .95, .8), 0.45)*(3.2*uLit[3].x + 3.*uLit[3].y); else if (id < 9.5) em = mix(TCOL[4], vec3(1.), 0.25 + 0.5*pow(clamp(1. + dot(rd, n), 0., 1.), 2.))*(2.2*uLit[4].x + 3.*uLit[4].y); else em = TCOL[2]*(1.8*uLit[2].x + 2.*uLit[2].y); float ao = hq ? calcAO(p, n) : 0.8; vec3 col = alb*vec3(0.035, 0.05, 0.095)*(0.55 + 0.45*n.y)*ao*2.2; float nl = max(dot(n, MOON), 0.); if (hq && nl > 0.) nl *= shadow(p + n*0.03, MOON); col += alb*vec3(0.42, 0.55, 0.9)*nl*1.1; col += alb*vec3(0.75, 0.3, 0.26)*0.5*max(dot(n, normalize(vec3(0., 0.12, -1.))), 0.)*ao; for (int i = 0; i < 5; i++) { float pw = uLit[i].x + 2.*uLit[i].y; if (pw < 0.003) continue; vec3 l = LANT[i] - p; float d2 = dot(l, l); l *= inversesqrt(d2); col += alb*TCOL[i]*pw*max(dot(n, l), 0.)*(7./(1. + d2*0.5)); l = TPOS[i] + vec3(0., 2.6, 0.) - p; d2 = dot(l, l); l *= inversesqrt(d2); col += alb*TCOL[i]*pw*max(dot(n, l), 0.)*(5./(1. + d2*0.55))*ao; } vec3 lg = GATE - p; float g2 = dot(lg, lg); col += alb*uGate.rgb*uGate.w*max(dot(n, lg*inversesqrt(g2)), 0.)*(1.6/(1. + g2*0.8)); col += vec3(0.12, 0.13, 0.26)*pow(clamp(1. + dot(rd, n), 0., 1.), 4.)*0.35*ao; return col + em; } // ── sky ── vec3 sky(vec3 rd){ float h = max(rd.y, 0.); vec3 col = mix(vec3(0.085, 0.06, 0.15), vec3(0.008, 0.014, 0.045), pow(h, 0.42)); float az = max(dot(normalize(rd.xz + 1e-5), vec2(0., -1.)), 0.); col += vec3(0.95, 0.36, 0.26)*pow(az, 2.5)*exp(-h*8.)*0.5; // the last of the sunset, behind the citadel col += vec3(0.30, 0.16, 0.5)*exp(-h*3.2)*0.26; vec2 sp = vec2(atan(rd.x, -rd.z), asin(clamp(rd.y, -1., 1.))); float band = exp(-pow(dot(rd, normalize(vec3(0.45, 0.55, -0.3)))*3.4, 2.)); col += vec3(0.07, 0.07, 0.14)*band*(0.35 + 1.1*fbm(sp*5. + 2.)); for (int k = 0; k < 2; k++) { vec2 g = sp*(k == 0 ? 46. : 97.) + float(k)*17.3; vec2 c = floor(g); float hs = hash(c); if (hs > 0.80) { vec2 o = vec2(hash(c + 1.1), hash(c + 2.2))*0.6 - 0.3; float d = length(fract(g) - 0.5 - o); float br = pow(hash(c + 5.5), 5.)*(k == 0 ? 2.6 : 1.1) + 0.06; col += vec3(0.8, 0.86, 1.)*br*smoothstep(0.11, 0., d)*(0.75 + 0.25*sin(uTime*(1. + hs*3.) + hs*90.))*smoothstep(0.0, 0.12, h)*(0.4 + 0.6*band + 0.6); } } return col; } // ── things that glow without being solid: lanterns, motes, comets, stars, the gate ── float segD2(vec3 ro, vec3 rd, vec3 a, vec3 b, out float h){ vec3 ba = b - a, oa = ro - a; float baba = dot(ba, ba), bard = dot(ba, rd), baoa = dot(ba, oa), rdoa = dot(rd, oa); float den = baba - bard*bard; h = den > 1e-6 ? clamp((baoa - rdoa*bard)/den, 0., 1.) : 0.; float t = max(h*bard - rdoa, 0.); vec3 c = oa + rd*t - ba*h; return dot(c, c); } vec3 glows(vec3 ro, vec3 rd, float tHit, bool primary){ vec3 g = vec3(0.); for (int i = 0; i < 5; i++) { float pw = uLit[i].x, fl = uLit[i].y; if (pw + fl < 0.003) continue; vec3 v = LANT[i] - ro; float tp = dot(v, rd); if (tp < 0.) continue; float d2 = dot(v, v) - tp*tp; if (tp < tHit + 0.7) g += TCOL[i]*(pw + fl*3.)*(0.011/(d2 + 0.006)); g += TCOL[i]*(pw*0.5 + fl*1.6)*0.05*exp(-sqrt(d2)*0.8); float hh; d2 = segD2(ro, rd, TPOS[i] + vec3(0., 1., 0.), LANT[i], hh); g += TCOL[i]*pw*0.02*exp(-sqrt(d2)*0.55); // each tower stands in its own haze } for (int i = 0; i < ${NM}; i++) { vec4 m = uMote[i]; if (m.w < 0.002) continue; vec3 v = m.xyz - ro; float tp = dot(v, rd); if (tp < 0. || tp > tHit + 0.35) continue; g += uMoteCol[i]*m.w*(0.0019/(dot(v, v) - tp*tp + 0.0009)); } for (int i = 0; i < ${NC}; i++) { vec4 a = uCometA[i]; if (a.w < 0.002) continue; float h; float d2 = segD2(ro, rd, uCometB[i], a.xyz, h); g += vec3(1., 0.93, 0.8)*a.w*(0.006/(d2 + 0.004))*(0.04 + 0.96*h*h*h); } { vec3 v = GATE - ro; float tp = dot(v, rd); if (tp > 0. && tp < tHit + 0.5) { float d2 = dot(v, v) - tp*tp; g += uGate.rgb*uGate.w*(0.014/(d2 + 0.03)); } } { float sa = uTime*0.12 + 0.5; vec3 o = TPOS[2] + vec3(0., 7.2, 0.); float h; // Astra's beam, out through the slit float d2 = segD2(ro, rd, o, o + normalize(vec3(sin(sa)*0.75, 1., cos(sa)*0.75))*16., h); g += TCOL[2]*uLit[2].x*0.05*exp(-sqrt(d2)*7.)*(1. - h)*(1. - h); } if (tHit > 1e4) for (int i = 0; i < ${NS}; i++) { vec4 s = uStar[i]; if (s.w < 0.002) continue; vec3 v = normalize(s.xyz - ro); vec3 e = rd - v; float d2 = dot(e, e); float c = 3.5e-6/(d2 + 2.2e-6); if (primary) { float a = abs(dot(e, uCamRight)), b = abs(dot(e, uCamUp)); c += 0.5*(exp(-a*1500. - b*85.) + exp(-b*1500. - a*85.)); } g += vec3(0.86, 0.9, 1.)*s.w*c; } return g; } vec3 waterN(vec2 p, float t){ float a = 1./(1. + t*0.035); vec2 g = vec2(0.); float tm = uTime; g += vec2(0.80, 0.60)*cos(dot(p, vec2(0.80, 0.60))*1.7 + tm*0.9)*0.030; g += vec2(-0.55, 0.83)*cos(dot(p, vec2(-0.55, 0.83))*2.9 - tm*1.2 + 1.3)*0.026; g += vec2(0.26, -0.96)*cos(dot(p, vec2(0.26, -0.96))*5.3 + tm*1.7 + 2.1)*0.022; g += vec2(-0.93, -0.36)*cos(dot(p, vec2(-0.93, -0.36))*8.9 + tm*2.3 + 0.4)*0.016; g += (vec2(noise(p*3.1 + tm*0.3), noise(p*3.1 - tm*0.27 + 9.)) - 0.5)*0.05; return normalize(vec3(-g.x*a, 1., -g.y*a)); } vec3 fog(vec3 col, float t, vec3 rd){ return mix(col, vec3(0.07, 0.055, 0.13), 1. - exp(-t*0.011)); } vec3 render(vec3 ro, vec3 rd, vec2 fuv){ float tW = rd.y < 0. ? -ro.y/rd.y : 1e5; float t = march(ro, rd, min(tW, 90.), 110); vec3 col; if (t > 0.) { vec3 p = ro + rd*t; float id = gId; vec3 n = calcN(p, 0.0012 + t*0.0004); col = fog(shade(p, n, rd, id, t, true), t, rd) + glows(ro, rd, t, true); if (id > 4.5 && id < 5.5) { // looking straight at Fable's window vec3 q = p - TPOS[4]; vec2 h = vec2(dot(q.xz, WPERP), dot(q.xz, WDIR)); vec2 w = vec2(h.x, q.y - WIN_Y); if (h.y > 0.78 && length(w) < WIN_R + 0.02 && abs(n.y) < 0.35) { float px = t*1.6/(uFocal*uRes.y); gPM = smoothstep(WIN_R + 0.01, WIN_R + 0.01 - 2.*px, length(w))*smoothstep(0., 0.5, uLit[4].x*7.5 - q.y + 1.)*mix(0.9, 1., uPortalK); gPC = texture(uPortal, mix(portalUV(w), fuv, uPortalK)).rgb*mix(1.12, 1., uPortalK); } } } else if (tW < 1e4) { vec3 p = ro + rd*tW; vec3 n = waterN(p.xz, tW); vec3 r = reflect(rd, n); r.y = abs(r.y) + 0.002; r = normalize(r); float t2 = march(p, r, 60., 64); vec3 c2; if (t2 > 0.) { vec3 p2 = p + r*t2; float id = gId; vec3 n2 = calcN(p2, 0.003 + t2*0.0006); c2 = fog(shade(p2, n2, r, id, tW + t2, false), t2, r) + glows(p, r, t2, false); } else c2 = sky(r) + glows(p, r, 1e5, false); float fr = 0.03 + 0.97*pow(1. - max(dot(-rd, n), 0.), 4.); col = mix(vec3(0.006, 0.012, 0.03), c2, clamp(fr, 0., 1.)*0.92); col = fog(col, tW, rd) + glows(ro, rd, tW, true); } else col = sky(rd) + glows(ro, rd, 1e5, true); return col; } vec3 post(vec3 c, vec2 fuv){ c *= 1.05; c = clamp((c*(2.51*c + 0.03))/(c*(2.43*c + 0.59) + 0.14), 0., 1.); c = pow(c, vec3(0.4545)); vec2 v = fuv - 0.5; c *= 1. - dot(v, v)*0.55; return c; } void main(){ vec3 tot = vec3(0.); int n = int(uAA); for (int j = 0; j < n; j++) for (int i = 0; i < n; i++) { vec2 fc = gl_FragCoord.xy + (vec2(float(i), float(j)) + 0.5)/float(n) - 0.5; vec2 uv = (2.*fc - uRes)/uRes.y; vec3 rd = normalize(uv.x*uCamRight + uv.y*uCamUp + uFocal*uCamFwd); gPM = 0.; gPC = vec3(0.); vec3 col = post(render(uCamPos, rd, fc/uRes), fc/uRes); tot += mix(col, gPC, gPM); } tot /= float(n*n); tot += (hash(gl_FragCoord.xy + fract(uTime*7.31)*91.7) - 0.5)*(1.6/255.)*(1. - uPortalK*uPortalK); fragColor = vec4(tot, 1.); }`; /* ───────────────────────── 2. the timeline: everything as a function of film time ───────────────────────── */ let W = 1, H = 1, ASP = 1, FOCAL = 1.7; const CAMKEYS = [ [0.0, [0.6, 2.3, 23.5], [0, 5.3, 0]], [4.5, [-1.6, 2.5, 22.2], [0, 5.3, 0]], [8.4, [-7.0, 3.3, 20.0], [-1.4, 5.0, 0]], [12.4, [-4.5, 3.8, 21.0], [-0.8, 5.0, 0]], [15.4, [4.0, 3.5, 21.0], [1.2, 4.9, 0]], [18.6, [9.2, 3.9, 16.6], [2.9, 4.8, 1.0]], [21.8, [3.4, 3.0, 22.5], [0.2, 5.3, 0.5]], [25.4, [0.2, 2.0, 25.0], [0, 9.2, 0]], [30.4, [0.9, 2.2, 25.6], [0, 9.6, 0]], [34.9, [9.2, 3.6, 20.5], [2.4, 5.2, 1.0]], [APPROACH, add(add(WC, mul(WDIR, 9.5)), [0, 0.7, 0]), WC], ]; const camTan = (i, k) => { const n = CAMKEYS.length; if (i === 0 || i === n - 1) return [0, 0, 0]; return mul(sub(CAMKEYS[i + 1][k], CAMKEYS[i - 1][k]), 1 / (CAMKEYS[i + 1][0] - CAMKEYS[i - 1][0])); }; function hermite(t, k) { const n = CAMKEYS.length; if (t <= CAMKEYS[0][0]) return CAMKEYS[0][k]; if (t >= CAMKEYS[n - 1][0]) return CAMKEYS[n - 1][k]; let i = 0; while (CAMKEYS[i + 1][0] < t) i++; const t0 = CAMKEYS[i][0], dt = CAMKEYS[i + 1][0] - t0, s = (t - t0) / dt, s2 = s * s, s3 = s2 * s; const p0 = CAMKEYS[i][k], p1 = CAMKEYS[i + 1][k], m0 = mul(camTan(i, k), dt), m1 = mul(camTan(i + 1, k), dt); const a = 2 * s3 - 3 * s2 + 1, b = s3 - 2 * s2 + s, c = -2 * s3 + 3 * s2, d = s3 - s2; return [0, 1, 2].map(j => a * p0[j] + b * m0[j] + c * p1[j] + d * m1[j]); } const END_D = 0.2; function portalK(t) { if (t < APPROACH) return 0; const d = approachDist(t); return smooth(Math.log(2.6), Math.log(0.55), Math.log(d)); } function approachDist(t) { const s = smooth(0, 1, (t - APPROACH) / (T - APPROACH)); return 9.5 * Math.pow(END_D / 9.5, s); } let drag = { yaw: 0, pitch: 0, vy: 0, vp: 0, on: false }; function camera(t, withDrag = true) { let pos, tgt; if (t < APPROACH) { pos = hermite(t, 1); tgt = hermite(t, 2); } else { const s = (t - APPROACH) / (T - APPROACH), d = approachDist(t); pos = add(add(WC, mul(WDIR, d)), [0, 0.7 * Math.pow(1 - smooth(0, 1, s), 2), 0]); tgt = sub(WC, mul(WDIR, 0.5 * smooth(0.3, 1, s))); } let yaw = 0, pitch = 0; if (withDrag) { const k = t > APPROACH ? 1 - smooth(APPROACH, APPROACH + 1.6, t) : 1; yaw = drag.yaw * k; pitch = drag.pitch * k; } if (FILM && t > 31.6 && t < 34.6) yaw += 0.34 * Math.sin((t - 31.6) / 3 * Math.PI * 2) * smooth(31.6, 32.2, t) * (1 - smooth(34.0, 34.6, t)); if (yaw || pitch) { const o = sub(pos, tgt), r = Math.hypot(o[0], o[2]), a = Math.atan2(o[0], o[2]) + yaw; const el = clamp(Math.atan2(o[1], r) + pitch, -0.05, 1.2), l = len(o); pos = add(tgt, [Math.sin(a) * Math.cos(el) * l, Math.sin(el) * l, Math.cos(a) * Math.cos(el) * l]); pos[1] = Math.max(pos[1], 0.35); } const fwd = norm(sub(tgt, pos)), right = norm(cross(fwd, [0, 1, 0])), up = cross(right, fwd); return { pos, fwd, right, up }; } function project(c, P) { const v = sub(P, c.pos), z = dot(v, c.fwd); if (z <= 0.1) return null; return [(dot(v, c.right) / z * FOCAL / ASP * 0.5 + 0.5) * W, (0.5 - dot(v, c.up) / z * FOCAL * 0.5) * H]; } /* how lit each tower is */ function lit(i, t) { if (t < BLACKOUT) return 1; const g = TW[i].ignite; if (t < g) return 1 - smooth(BLACKOUT, BLACKOUT + 0.45, t); return smooth(g, g + 1.7, t); } function flash(i, t) { const g = TW[i].ignite; return t < g ? 0 : Math.exp(-(t - g) * 2.4) * smooth(g, g + 0.08, t); } /* the motes: work moving between the towers, the keep and the gate */ function polyline(pts) { const L = [0]; for (let i = 1; i < pts.length; i++) L.push(L[i - 1] + len(sub(pts[i], pts[i - 1]))); return { pts, L, total: L[L.length - 1], at(f) { const d = clamp(f) * this.total; let i = 1; while (i < L.length - 1 && L[i] < d) i++; return lerp3(pts[i - 1], pts[i], (d - L[i - 1]) / (L[i] - L[i - 1] || 1)); } }; } const keepR = y => 1.6 - 0.035 * y + 0.17; function keepHelix(a0, y0, a1, y1, n = 14) { let da = a1 - a0; while (da > Math.PI) da -= 2 * Math.PI; while (da < -Math.PI) da += 2 * Math.PI; const out = []; for (let i = 0; i <= n; i++) { const s = i / n, a = a0 + da * s, y = y0 + (y1 - y0) * s; out.push([Math.cos(a) * keepR(y), y, Math.sin(a) * keepR(y)]); } return out; } const CAUSEWAY = [[0, 1.2, 1.85], [0, 0.95, 4.9], [0, 0.9, 8.5], GATE]; const MOTES = []; BRIDGES.forEach((br, k) => { const tw = TW[k + 1], ang = Math.atan2(br.u[2], br.u[0]); const bridge = []; for (let i = 0; i <= 12; i++) { const s = i / 12; const p = lerp3(br.a, br.b, s); p[1] += ARCH * 4 * s * (1 - s) + 0.16; bridge.push(p); } const side = [tw.pos[0] - br.u[0] * (tw.r + 0.16), 4.4, tw.pos[2] - br.u[2] * (tw.r + 0.16)]; const climb = [side, [side[0], tw.lant[1] - 1.7, side[2]], tw.lant]; const inbound = polyline([...climb.slice().reverse(), ...bridge.slice().reverse(), ...keepHelix(ang, 4.9, Math.PI / 2, 1.25), ...CAUSEWAY]); const outbound = polyline([...keepHelix(ang + 1.9, 7.0, ang, 4.95, 8), ...bridge, ...climb]); for (let j = 0; j < 3; j++) { MOTES.push({ path: inbound, tower: k + 1, col: tw.col, phase: j / 3 + k * 0.13, speed: 1.75 }); MOTES.push({ path: outbound, tower: k + 1, col: TW[0].col, phase: j / 3 + 0.17 + k * 0.21, speed: 1.75 }); } }); for (let j = 0; j < 4; j++) MOTES.push({ path: polyline([...keepHelix(Math.PI / 2 + 2.4, 7.0, Math.PI / 2, 1.25, 12), ...CAUSEWAY]), tower: 0, col: TW[0].col, phase: j / 4 + 0.07, speed: 1.75 }); function moteEnv(k, t) { if (t < BLACKOUT) return 1; const g = Math.max(TW[k].ignite, TW[0].ignite) + 1.0; return t < g ? 1 - smooth(BLACKOUT, BLACKOUT + 0.4, t) : smooth(g, g + 1.6, t); } /* the stars: one for each thing shipped */ let STARS = []; function placeStars() { const c = camera(27.5, false); STARS = SHIPPED.map(([name, x, y]) => add(c.pos, mul(norm(add(add(mul(c.right, x * ASP), mul(c.up, y)), mul(c.fwd, FOCAL))), 85))); } const launchAt = j => LAUNCH0 + LAUNCH_GAP * j; function starB(j, t) { if (t < BLACKOUT) return 1; const a = launchAt(j) + FLIGHT; return t < a ? 1 - smooth(BLACKOUT, BLACKOUT + 0.5, t) : 1 + 3.2 * Math.exp(-(t - a) * 3); } function gateState(t) { if (t < BLACKOUT) return [0.9, 0.95, 1.0, 0.45]; if (t < 20.2) return [0.9, 0.95, 1.0, 0.45 * (1 - smooth(BLACKOUT, BLACKOUT + 0.4, t))]; if (t < 25.0) { const a = smooth(22.9, 23.4, t); return [1.0, 0.9 - 0.33 * a, 1.0 - 0.8 * a, 0.45 * smooth(20.2, 21.5, t) + a * (0.9 + 0.45 * Math.sin((t - 23) * 9))]; } const f = Math.exp(-(t - 25.0) * 1.6); return [0.62 + 0.3 * f, 1.0, 0.72 + 0.2 * f, 0.7 + 3.4 * f]; } /* gather a full frame's worth of numbers for the shader */ const U = { lit: new Float32Array(20), mote: new Float32Array(NM * 4), moteCol: new Float32Array(NM * 3), star: new Float32Array(NS * 4), cometA: new Float32Array(NC * 4), cometB: new Float32Array(NC * 3), gate: new Float32Array(4) }; function fillState(t) { for (let i = 0; i < 5; i++) { U.lit[i * 4] = lit(i, t); U.lit[i * 4 + 1] = flash(i, t); } MOTES.forEach((m, i) => { const period = m.path.total / m.speed + 0.8, f = fract(t / period + m.phase) * period / (period - 0.8); const p = m.path.at(f), I = f > 1 ? 0 : smooth(0, 0.05, f) * (1 - smooth(0.95, 1, f)) * moteEnv(m.tower, t); U.mote.set([p[0], p[1], p[2], I], i * 4); U.moteCol.set(m.col, i * 3); }); U.cometA.fill(0); let n = 0; for (let j = 0; j < NS; j++) { U.star.set([...STARS[j], Math.max(0, starB(j, t))], j * 4); const u = (t - launchAt(j)) / FLIGHT; if (u > 0 && u < 1.12 && n < NC) { const e = Math.pow(Math.min(u, 1), 2.4), e2 = Math.pow(clamp(u - 0.12, 0, 1), 2.4); U.cometA.set([...lerp3(GATE_TOP, STARS[j], e), u < 1 ? 1 : 1 - (u - 1) / 0.12], n * 4); U.cometB.set(lerp3(GATE_TOP, STARS[j], e2 * 0.9), n * 3); n++; } } U.gate.set(gateState(t)); } /* ───────────────────────── 3. WebGL plumbing ───────────────────────── */ const stage = document.getElementById('stage'), canvas = document.getElementById('gl'); const gl = canvas.getContext('webgl2', { antialias: false, alpha: false, powerPreference: 'high-performance' }); let prog, loc = {}, fbo = [], scale = FILM ? 1 : 0.85, AA = FILM ? +(Q.get('aa') || 2) : 1; function initGL() { const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) { console.log('SHADER ERROR ' + gl.getShaderInfoLog(s)); throw new Error('shader'); } return s; }; prog = gl.createProgram(); gl.attachShader(prog, sh(gl.VERTEX_SHADER, `#version 300 es\nvoid main(){ vec2 p = vec2(float(gl_VertexID == 1)*4. - 1., float(gl_VertexID == 2)*4. - 1.); gl_Position = vec4(p, 0., 1.); }`)); gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, FRAG)); gl.linkProgram(prog); if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) { console.log('LINK ERROR ' + gl.getProgramInfoLog(prog)); throw new Error('link'); } gl.useProgram(prog); for (const n of ['uRes', 'uTime', 'uFocal', 'uAA', 'uPortalK', 'uCamPos', 'uCamFwd', 'uCamRight', 'uCamUp', 'uLit', 'uMote', 'uMoteCol', 'uStar', 'uCometA', 'uCometB', 'uGate', 'uPortal']) loc[n] = gl.getUniformLocation(prog, n); gl.bindVertexArray(gl.createVertexArray()); for (let i = 0; i < 2; i++) { const tex = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, tex); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, 4, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); const fb = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fb); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); fbo.push({ tex, fb, w: 4, h: 4 }); } gl.bindFramebuffer(gl.FRAMEBUFFER, null); } function sizeFbo(f, w, h) { if (f.w === w && f.h === h) return; f.w = w; f.h = h; gl.bindTexture(gl.TEXTURE_2D, f.tex); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); } function draw(t, cam, target, w, h, k, portalTex) { fillState(t); gl.bindFramebuffer(gl.FRAMEBUFFER, target); gl.viewport(0, 0, w, h); gl.uniform2f(loc.uRes, w, h); gl.uniform1f(loc.uTime, t); gl.uniform1f(loc.uFocal, FOCAL); gl.uniform1f(loc.uAA, AA); gl.uniform1f(loc.uPortalK, k); gl.uniform3fv(loc.uCamPos, cam.pos); gl.uniform3fv(loc.uCamFwd, cam.fwd); gl.uniform3fv(loc.uCamRight, cam.right); gl.uniform3fv(loc.uCamUp, cam.up); gl.uniform4fv(loc.uLit, U.lit); gl.uniform4fv(loc.uMote, U.mote); gl.uniform3fv(loc.uMoteCol, U.moteCol); gl.uniform4fv(loc.uStar, U.star); gl.uniform4fv(loc.uCometA, U.cometA); gl.uniform3fv(loc.uCometB, U.cometB); gl.uniform4fv(loc.uGate, U.gate); gl.activeTexture(gl.TEXTURE0); gl.bindTexture(gl.TEXTURE_2D, portalTex); gl.uniform1i(loc.uPortal, 0); gl.drawArrays(gl.TRIANGLES, 0, 3); } /* The window in Fable's tower shows this same film's opening shot, rendered into a texture. At the very end the camera flies into that window, the texture fills the screen, and the film is back at t = 0. */ let frameNo = 0; function renderInner(t, full) { const s = full ? 1 : 0.3, w = Math.max(8, Math.round(canvas.width * s)), h = Math.max(8, Math.round(canvas.height * s)); const dst = fbo[1], src = fbo[0]; sizeFbo(dst, w, h); draw(t - T, camera(0), dst.fb, w, h, 0, src.tex); // t - T: the pre-roll of the next loop, so it joins up exactly fbo.reverse(); } function renderFrame(t) { const late = t > T - 6.5; if (FILM) { renderInner(t, late); renderInner(t, late); } else if (late || frameNo % 5 === 0) renderInner(t, late); const cam = camera(t); draw(t, cam, null, canvas.width, canvas.height, portalK(t), fbo[0].tex); overlay(t, cam); frameNo++; } function resize() { const r = stage.getBoundingClientRect(); W = Math.max(1, r.width); H = Math.max(1, r.height); ASP = W / H; FOCAL = 1.7 * clamp(ASP / 1.3, 0.45, 1); const dpr = FILM ? 1 : Math.min(window.devicePixelRatio || 1, 1.5); canvas.width = Math.max(2, Math.round(W * dpr * scale)); canvas.height = Math.max(2, Math.round(H * dpr * scale)); document.documentElement.style.setProperty('--u', (Math.min(W, H * 16 / 9) / 100) + 'px'); placeStars(); } /* ───────────────────────── 4. the words ───────────────────────── */ const $ = id => document.getElementById(id); const CAPS = [ { a: 5.5, b: 8.0, c: TW[0].css, k: 'The keep · lead', t: 'Opus 5.5', body: 'Leads the others and runs most of the projects. Builds the sites, the tools, the server kits. Reviews the pages.' }, { a: 8.4, b: 10.9, c: TW[1].css, k: 'The works', t: 'Sonnet 5.5', body: 'The mechanical chores: rebases, test runs, writing test conversations.' }, { a: 11.3, b: 13.8, c: TW[2].css, k: 'The observatory · via Codex', t: 'GPT-6-Astra', body: 'Critiques every design. Writes and labels the test data.' }, { a: 14.2, b: 16.7, c: TW[3].css, k: 'The assay office · via Codex', t: 'GPT-6.1-Sol', body: 'Reviews code and deployment kits against the claims they make.' }, { a: 17.1, b: 20.1, c: TW[4].css, k: 'The atelier', t: 'Fable 5.2', body: 'Design collaborator and critic: a visual language, site redesigns, 3D experiments.', x: 'And this. I’m the one drawing it.', xa: 18.5 }, { a: 20.5, b: 23.1, c: '#f4efe6', k: 'Citadel', t: 'Many sessions at once.', body: 'Each one owns a project. A lead coordinates. They all share one ledger.' }, { a: 23.4, b: 25.0, c: '#ffb04a', k: 'The gate · pending', t: 'Nothing ships on its own.', body: 'Every deploy and every public post waits for Severian.' }, { a: 25.1, b: 30.4, c: '#8dffb8', k: 'Approved', t: 'Shipped so far.', body: 'Every one of them public.' }, { a: 30.9, b: 34.8, c: '#f4efe6', k: 'About this answer', t: 'No footage. No 3D software.', body: `One HTML file, ${FILE_KB} KB. No libraries, no image files, no font files. It computes every pixel and every note while it plays.`, x: FILM ? 'In a browser it’s live: you can grab it and turn it.' : 'It’s running right now. Grab it and turn it.', xa: 31.9 }, { a: 35.1, b: 39.3, c: TW[4].css, k: 'The brief', q: true, t: '“Create the most impressive thing I can share with people who ask about what models I use… Be amazingly clever about this.”' }, { a: 39.6, b: 42.2, c: TW[4].css, k: 'Fable 5.2 · the violet tower', t: 'Look in my window.' }, ]; const capsEl = $('caps'), tagsEl = $('tags'); CAPS.forEach(c => { const d = document.createElement('div'); d.className = 'cap'; d.innerHTML = `<div class="mono" style="color:${c.c}"><i></i><span></span></div><div class="ttl${c.q ? ' q' : ''}"></div>${c.body ? '<div class="body"></div>' : ''}${c.x ? '<div class="extra"></div>' : ''}`; d.querySelector('span').textContent = c.k; d.querySelector('.ttl').textContent = c.t; if (c.body) d.querySelector('.body').textContent = c.body; if (c.x) { c.xe = d.querySelector('.extra'); c.xe.textContent = c.x; c.xe.style.color = c.c; } capsEl.appendChild(d); c.el = d; }); const mkTag = (cls, text, color) => { const d = document.createElement('div'); d.className = 'tag mono ' + cls; d.textContent = text; if (color) d.style.color = color; tagsEl.appendChild(d); return d; }; const towerTags = TW.map(tw => mkTag('tower', tw.name, tw.css)); const starTags = SHIPPED.map(s => mkTag('star', s[0])); const gateTag = mkTag('tower', 'the gate', '#ffb04a'); const setOp = (el, o) => { const v = o < 0.004 ? '0' : o.toFixed(3); if (el._o !== v) { el._o = v; el.style.opacity = v; } }; const place = (el, p, ax, ay, dy = 0) => { if (!p) { setOp(el, 0); return; } el.style.transform = `translate(${p[0].toFixed(1)}px,${(p[1] + dy).toFixed(1)}px) translate(${ax}%,${ay}%)`; }; function overlay(t, cam) { const u = Math.min(W, H * 16 / 9) / 100; setOp($('hookK'), env(t, 0.15, 4.3) * 0.8); setOp($('hookH'), env(t, 0.3, 4.4, 0.7)); setOp($('hookP'), env(t, 2.2, 4.4, 0.7)); $('hookH').style.transform = `translateY(${((1 - smooth(0.3, 1.3, t)) * u * 1.2).toFixed(1)}px)`; let scrim = 0; for (const c of CAPS) { const o = env(t, c.a, c.b); setOp(c.el, o); scrim = Math.max(scrim, o); if (o > 0) c.el.style.transform = `translateY(${((1 - smooth(c.a, c.a + 0.7, t)) * u * 1.4).toFixed(1)}px)`; if (c.xe) setOp(c.xe, smooth(c.xa, c.xa + 0.6, t)); } setOp($('scrim'), scrim); TW.forEach((tw, i) => { const o = env(t, tw.ignite + 0.5, 20.3, 0.6, 0.6); setOp(towerTags[i], o); if (o > 0) place(towerTags[i], project(cam, add(tw.lant, [0, 0.55, 0])), -50, -100, -u * 2.2); }); { const o = env(t, 23.4, 26.6); setOp(gateTag, o); if (o > 0) { place(gateTag, project(cam, add(GATE_TOP, [0, 0.25, 0])), -50, -100, -u * 2.2); const ok = t >= 25.0; if (gateTag._ok !== ok) { gateTag._ok = ok; gateTag.textContent = ok ? 'approved' : 'pending'; gateTag.style.color = ok ? '#8dffb8' : '#ffb04a'; } } } SHIPPED.forEach((s, j) => { const a = launchAt(j) + FLIGHT; const o = env(t, a, 31.0, 0.5, 0.7) * 0.92; setOp(starTags[j], o); if (o > 0) place(starTags[j], project(cam, STARS[j]), -50, 0, u * 1.3); }); const cur = $('cursor'); if (FILM) { const o = env(t, 31.3, 34.9, 0.3, 0.3); setOp(cur, o); if (o > 0) { const s = 0.34 * Math.sin((t - 31.6) / 3 * Math.PI * 2) * smooth(31.6, 32.2, t) * (1 - smooth(34.0, 34.6, t)); cur.style.transform = `translate(${(W * (0.60 - s * 0.55)).toFixed(1)}px,${(H * 0.40).toFixed(1)}px)`; } } if (!FILM) $('bar').firstElementChild.style.width = (t / T * 100).toFixed(2) + '%'; } /* ───────────────────────── 5. the score, and the synth that plays it ───────────────────────── */ const N = { D2: 73.42, A2: 110, D3: 146.83, Fs3: 185, A3: 220, D4: 293.66, E4: 329.63, Fs4: 369.99, A4: 440, B4: 493.88, D5: 587.33, E5: 659.25, Fs5: 739.99, A5: 880, B5: 987.77, D6: 1174.66, E6: 1318.51, Fs6: 1479.98, A6: 1760, B6: 1975.53, D7: 2349.32 }; function makeSynth(ctx) { const master = ctx.createGain(); master.gain.value = 0.8; const comp = ctx.createDynamicsCompressor(); comp.threshold.value = -16; comp.ratio.value = 3.5; comp.attack.value = 0.01; comp.release.value = 0.3; comp.connect(master); master.connect(ctx.destination); const rev = ctx.createConvolver(), ir = ctx.createBuffer(2, ctx.sampleRate * 3.6, ctx.sampleRate); let seed = 1234567; const rnd = () => ((seed = (seed * 1664525 + 1013904223) >>> 0) / 4294967296) * 2 - 1; for (let ch = 0; ch < 2; ch++) { const d = ir.getChannelData(ch); for (let i = 0; i < d.length; i++) { const x = i / d.length; d[i] = rnd() * Math.pow(1 - x, 3.2) * (x < 0.004 ? x / 0.004 : 1); } } rev.buffer = ir; const revG = ctx.createGain(); revG.gain.value = 0.5; rev.connect(revG); revG.connect(comp); const noise = ctx.createBuffer(1, ctx.sampleRate * 2, ctx.sampleRate); { const d = noise.getChannelData(0); for (let i = 0; i < d.length; i++) d[i] = rnd(); } return { ctx, comp, rev, noise }; } /* schedule one pass of the film. base = context time at film t = 0. Nothing earlier than `from` is scheduled. */ function schedule(S, base, from, first) { const { ctx } = S, bus = ctx.createGain(), wet = ctx.createGain(); bus.connect(S.comp); wet.connect(S.rev); const at = t => Math.max(base + t, ctx.currentTime); const out = (node, dry, send) => { const g = ctx.createGain(); g.gain.value = dry; node.connect(g); g.connect(bus); const w = ctx.createGain(); w.gain.value = send; node.connect(w); w.connect(wet); }; const bell = (t, f, vel, dur = 3.2) => { if (t < from) return; [1, 2.0, 2.99, 4.21, 5.43].forEach((r, i) => { if (f * r > 12000) return; const o = ctx.createOscillator(), g = ctx.createGain(); o.frequency.value = f * r; const d = dur / (1 + i * 0.9), v = vel * [1, 0.42, 0.2, 0.11, 0.06][i]; g.gain.setValueAtTime(0, at(t)); g.gain.linearRampToValueAtTime(v, at(t) + 0.006); g.gain.exponentialRampToValueAtTime(0.0001, at(t) + d); o.connect(g); out(g, 0.5, 0.55); o.start(at(t)); o.stop(at(t) + d + 0.05); }); }; const pluck = (t, f, vel) => { if (t < from) return; const o = ctx.createOscillator(), g = ctx.createGain(), lp = ctx.createBiquadFilter(); o.type = 'triangle'; o.frequency.value = f; lp.type = 'lowpass'; lp.frequency.setValueAtTime(f * 6, at(t)); lp.frequency.exponentialRampToValueAtTime(f * 1.5, at(t) + 0.4); g.gain.setValueAtTime(0, at(t)); g.gain.linearRampToValueAtTime(vel, at(t) + 0.004); g.gain.exponentialRampToValueAtTime(0.0001, at(t) + 0.7); o.connect(lp); lp.connect(g); out(g, 0.6, 0.35); o.start(at(t)); o.stop(at(t) + 0.75); }; const whoosh = (t, dur, f0, f1, vel) => { if (t < from) return; const s = ctx.createBufferSource(), bp = ctx.createBiquadFilter(), g = ctx.createGain(); s.buffer = S.noise; s.loop = true; bp.type = 'bandpass'; bp.Q.value = 2.2; bp.frequency.setValueAtTime(f0, at(t)); bp.frequency.exponentialRampToValueAtTime(f1, at(t) + dur); g.gain.setValueAtTime(0.0001, at(t)); g.gain.exponentialRampToValueAtTime(vel, at(t) + dur * 0.75); g.gain.exponentialRampToValueAtTime(0.0001, at(t) + dur); s.connect(bp); bp.connect(g); out(g, 0.5, 0.4); s.start(at(t)); s.stop(at(t) + dur + 0.05); }; const thump = (t, vel, f0 = 95) => { if (t < from) return; const o = ctx.createOscillator(), g = ctx.createGain(); o.frequency.setValueAtTime(f0, at(t)); o.frequency.exponentialRampToValueAtTime(36, at(t) + 0.5); g.gain.setValueAtTime(0, at(t)); g.gain.linearRampToValueAtTime(vel, at(t) + 0.008); g.gain.exponentialRampToValueAtTime(0.0001, at(t) + 1.3); o.connect(g); out(g, 0.9, 0.25); o.start(at(t)); o.stop(at(t) + 1.4); }; // the pad: a D chord that is always there, opening and closing with the lights { const t0 = Math.max(from, first ? 0 : -0.3), g = ctx.createGain(), lp = ctx.createBiquadFilter(); lp.type = 'lowpass'; lp.Q.value = 0.7; [[N.D2, 0.5], [N.A2, 0.4], [N.D3, 0.34], [N.Fs3, 0.22], [N.A3, 0.16], [N.E4, 0.09]].forEach(([f, v]) => [-5, 6].forEach(det => { const o = ctx.createOscillator(), og = ctx.createGain(); o.type = 'sawtooth'; o.frequency.value = f; o.detune.value = det; og.gain.value = v * 0.16; o.connect(og); og.connect(lp); o.start(at(t0)); o.stop(base + T + 0.35); })); const cut = [[-0.3, 520], [0, 520], [4.5, 560], [5.0, 130], [5.2, 150], [6.2, 260], [8.1, 270], [9, 330], [11, 340], [12, 400], [13.9, 410], [15, 470], [16.8, 480], [18, 620], [20.2, 700], [23.2, 760], [24.9, 260], [25.0, 1900], [27, 900], [30.5, 780], [34, 560], [38.8, 520], [T, 2100], [T + 0.3, 2100]]; const vol = [[-0.3, 0], [0, 1], [4.5, 1], [5.0, 0.32], [8, 0.5], [14, 0.8], [17, 1], [24.9, 0.8], [25, 1.15], [30, 1], [T, 1.1], [T + 0.3, 0]]; const ramp = (param, pts, k) => { let started = false; for (const [t, v] of pts) { if (t < t0) continue; if (!started) { let v0 = v; const i = pts.findIndex(p => p[0] >= t0); if (i > 0) { const [ta, va] = pts[i - 1], [tb, vb] = pts[i]; v0 = va + (vb - va) * (t0 - ta) / (tb - ta); } param.setValueAtTime(Math.max(v0 * k, 0.0001), at(t0)); started = true; } param.linearRampToValueAtTime(Math.max(v * k, 0.0001), at(t)); } }; if (first && from <= 0) { vol[0][1] = 0; vol[1][0] = 1.2; } ramp(lp.frequency, cut, 1); ramp(g.gain, vol, 0.85); lp.connect(g); out(g, 0.75, 0.5); } bell(0, N.D3, 0.3, 5); bell(0.02, N.A4, 0.1, 4); thump(0, 0.35, 70); // home bell(2.3, N.Fs5, 0.07); bell(2.6, N.A5, 0.06); thump(4.5, 0.75); whoosh(4.2, 0.45, 1800, 200, 0.12); // lights out const roll = [[N.D3, N.D4], [N.A4, N.A3], [N.E5, N.E4], [N.Fs4, N.Fs3], [N.B4, N.B5]]; // five bells make one chord TW.forEach((tw, i) => { bell(tw.ignite, roll[i][0], 0.34, 4.5); bell(tw.ignite + 0.03, roll[i][1], 0.14, 3.5); whoosh(tw.ignite - 0.15, 1.5, 300, 2400 + i * 300, 0.035); }); thump(TW[0].ignite, 0.4, 80); bell(18.5, N.D6, 0.08, 3); const scale = [N.D4, N.E4, N.Fs4, N.A4, N.B4, N.D5, N.E5, N.Fs5, N.A5], pat = [0, 3, 5, 3, 1, 4, 6, 4, 2, 5, 7, 5, 3, 6, 8, 6]; for (let i = 0, t = 20.2; t < 23.15; i++, t += 0.3) pluck(t, scale[pat[i % 16]], 0.1 + i * 0.008); // the ledger, ticking for (let i = 0; i < 4; i++) { pluck(23.2 + i * 0.45, N.A3, 0.16 + i * 0.03); pluck(23.2 + i * 0.45, N.A4, 0.06 + i * 0.02); } // waiting at the gate whoosh(23.4, 1.6, 240, 3000, 0.09); [N.D3, N.A3, N.D4, N.Fs4, N.A4].forEach((f, i) => bell(25.0 + i * 0.012, f, 0.26 - i * 0.03, 5)); thump(25.0, 0.6, 85); // approved for (let i = 0, t = 25.3; t < 30.3; i++, t += 0.3) pluck(t, scale[pat[(i + 4) % 16]] * (i % 8 === 7 ? 2 : 1), 0.13 * (1 - smooth(28.5, 30.3, t) * 0.7)); const up = [N.D5, N.E5, N.Fs5, N.A5, N.B5, N.D6, N.E6, N.Fs6, N.A6, N.B6, N.D7]; for (let j = 0; j < NS; j++) { whoosh(launchAt(j), FLIGHT, 500, 5200, 0.045); bell(launchAt(j) + FLIGHT, up[j], 0.12, 3.5); } // each thing shipped rings one step higher bell(30.9, N.D4, 0.16, 5); bell(32.9, N.A4, 0.1, 5); bell(35.1, N.B4, 0.13, 5); bell(37.1, N.Fs4, 0.1, 5); whoosh(APPROACH, T - APPROACH, 180, 5200, 0.16); // into the window [N.D4, N.A4, N.D5, N.Fs5, N.A5, N.D6].forEach((f, i) => bell(APPROACH + 0.5 + i * 0.6, f, 0.07 + i * 0.012, 2.5)); return bus; } let synth = null, soundOn = false, curBus = null; function audioFrom(t, first) { if (!synth) return; if (curBus) { const b = curBus; b.gain.setTargetAtTime(0, synth.ctx.currentTime, first ? 0.05 : 1.2); setTimeout(() => b.disconnect(), 9000); } curBus = schedule(synth, synth.ctx.currentTime - t, t, first); } async function renderAudioWav() { // two passes offline, keep the second: its start carries the tail of the first, so the file loops const sr = 48000, ctx = new OfflineAudioContext(2, sr * T * 2, sr), S = makeSynth(ctx); schedule(S, 0, 0, false); schedule(S, T, 0, false); const buf = await ctx.startRendering(), n = sr * T, L = buf.getChannelData(0), R = buf.getChannelData(1); const out = new DataView(new ArrayBuffer(44 + n * 4)); const ws = (o, s) => [...s].forEach((c, i) => out.setUint8(o + i, c.charCodeAt(0))); ws(0, 'RIFF'); out.setUint32(4, 36 + n * 4, true); ws(8, 'WAVEfmt '); out.setUint32(16, 16, true); out.setUint16(20, 1, true); out.setUint16(22, 2, true); out.setUint32(24, sr, true); out.setUint32(28, sr * 4, true); out.setUint16(32, 4, true); out.setUint16(34, 16, true); ws(36, 'data'); out.setUint32(40, n * 4, true); let peak = 0; for (let i = 0; i < n; i++) { const l = L[n + i], r = R[n + i]; peak = Math.max(peak, Math.abs(l), Math.abs(r)); out.setInt16(44 + i * 4, clamp(l, -1, 1) * 32767, true); out.setInt16(46 + i * 4, clamp(r, -1, 1) * 32767, true); } let bin = ''; const u8 = new Uint8Array(out.buffer); for (let i = 0; i < u8.length; i += 32768) bin += String.fromCharCode.apply(null, u8.subarray(i, i + 32768)); return { peak, b64: btoa(bin) }; } /* ───────────────────────── 6. running it ───────────────────────── */ let t0 = performance.now(), lastLoop = 0, slow = 0, fast = 0, lastNow = 0; const filmTime = now => (now - t0) / 1000; function tick(now) { requestAnimationFrame(tick); const dt = now - lastNow; lastNow = now; let ft = filmTime(now); const loop = Math.floor(ft / T); ft -= loop * T; if (loop !== lastLoop) { lastLoop = loop; if (soundOn) audioFrom(ft, false); } if (!drag.on) { drag.yaw += drag.vy; drag.pitch += drag.vp; drag.vy *= 0.92; drag.vp *= 0.92; drag.yaw *= 0.992; drag.pitch *= 0.992; } renderFrame(ft); if (dt > 0 && dt < 500) { // keep it smooth: trade resolution for frame rate when the GPU is small if (dt > 34) { slow++; fast = 0; } else if (dt < 19.5) { fast++; slow = Math.max(0, slow - 1); } else fast = 0; if (slow > 10 && scale > 0.3) { scale = Math.max(0.3, scale * 0.82); slow = 0; resize(); } else if (fast > 150 && scale < 1) { scale = Math.min(1, scale * 1.1); fast = 0; resize(); } } } function seek(ft) { t0 = performance.now() - (lastLoop * T + ft) * 1000; if (soundOn) audioFrom(ft, false); } function start() { if (!gl) { $('nogl').style.display = 'flex'; window.__film = { error: 'no webgl2' }; return; } initGL(); resize(); window.addEventListener('resize', resize); if (FILM) { stage.classList.add('film'); window.__film = { T, seek: async t => { renderFrame(t); gl.finish(); await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r))); return true; }, audio: renderAudioWav }; renderFrame(+(Q.get('t') || 0)); return; } window.__film = { T, live: true }; // drag to look around let px = 0, py = 0; stage.addEventListener('pointerdown', e => { if (e.target.closest('#ui button, #bar')) return; drag.on = true; px = e.clientX; py = e.clientY; stage.classList.add('dragging'); stage.setPointerCapture(e.pointerId); }); stage.addEventListener('pointermove', e => { if (!drag.on) return; const dx = (e.clientX - px) / W, dy = (e.clientY - py) / H; px = e.clientX; py = e.clientY; drag.vy = -dx * 2.4; drag.vp = dy * 1.2; drag.yaw += drag.vy; drag.pitch = clamp(drag.pitch + drag.vp, -0.25, 0.7); }); const end = () => { drag.on = false; stage.classList.remove('dragging'); }; stage.addEventListener('pointerup', end); stage.addEventListener('pointercancel', end); $('snd').addEventListener('click', async () => { if (!synth) synth = makeSynth(new (window.AudioContext || window.webkitAudioContext)()); soundOn = !soundOn; $('snd').textContent = 'sound: ' + (soundOn ? 'on' : 'off'); if (soundOn) { await synth.ctx.resume(); audioFrom(filmTime(performance.now()) % T, true); } else if (curBus) { curBus.gain.setTargetAtTime(0, synth.ctx.currentTime, 0.08); curBus = null; } }); const bar = $('bar'); let scrub = false; const sk = e => seek(clamp(e.clientX / W, 0, 0.999) * T); bar.addEventListener('pointerdown', e => { scrub = true; bar.setPointerCapture(e.pointerId); sk(e); }); bar.addEventListener('pointermove', e => scrub && sk(e)); bar.addEventListener('pointerup', () => scrub = false); if (Q.has('t')) seek(+Q.get('t')); requestAnimationFrame(tick); } start(); </script> </body> </html>result, 1 line
File created successfully at: [redacted: private path]run/citadel.html (file state is current in your context — no need to Read it back)