mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Serves the standalone Meetings showcase from public/meetings/ at /hex/meetings/ (the Worker 301s /hex/meetings there so relative paths resolve). `bun run import:meetings <bundle>` copies only the files the page loads and drops session ids and the bundle's social tags; the build writes the canonical address, Open Graph and Twitter tags for its origin and refuses missing references or files over 25 MiB. Adds og-meetings.png (Hex mark, "Hex Meetings", a meeting pill), Meetings links in the landing page header and footer, and sitemap and llms.txt entries.
10 lines
151 KiB
JavaScript
10 lines
151 KiB
JavaScript
// Generated by wgsl/pack.mjs from wgsl/*.wgsl. Edit those, not this.
|
|
export const BODY = "// The whole frame in one uniform buffer. Offsets are mirrored by G in cast.js.\nstruct Head {\n pos: vec4f, // cx, cy, R, roll\n tile: vec4f, // cx, cy, half w, half h\n tileFx: vec4f, // alpha (0: no tile), corner radius, speaking ring, dim\n tilt3: vec4f, // tile lean x, y, face turn x, y\n eye: vec4f, // gaze x, y, upper lid L, R (0 open .. 1 shut)\n eye2: vec4f, // lower lid L, R, pupil dilation, eye size\n brow: vec4f, // raise L, R, angle L, R (+ furrowed: inner end down)\n brow2: vec4f, // arch L, R, weight, eye spacing\n mouth: vec4f, // open, wide, round, smile\n mouth2: vec4f, // smirk, tongue, jaw drop, -\n rim: vec4f, // rgb, strength\n look: vec4f, // glasses, gloss, the monitor's emerald in the eyes, alpha\n shape: vec4f, // rx, ry, stretch (y scale), rim angle\n vel: vec4f, // the face: x, y in px/s, growth per second, -\n tvel: vec4f, // the tile: x, y, half w, half h in px/s\n spare: vec4f, // seed, time, key light level, warmth\n flesh: vec4f, // veins under the lacquer, breath (-1..1), heartbeat (0..1), how liquid the surface is\n morph: vec4f, // -, third eye open, -, vein surge (emerald)\n fuse: vec4f, // where the tendril enters the face: x, y (in head radii), how far the walls of its tile have gone, which way the middle of the grid lies in x (-1, 0, 1)\n more: vec4f, // which way the middle of the grid lies in y (-1, 0, 1), what it wears (0 nothing, 1 a knitted hat, 2 a top-knot and a headset), how much wider its crown is than its jaw, 1 if the one mass draws it\n one: vec4f, // how far this head has run into the one mass, the calm dark wet look that comes after, terror, the drips' clock\n eyes: vec4f, // eyes pushed out through the brow (0 shut .. 1 open), brows (1 there .. 0 absorbed), how real the eyes are (bloodshot, wet), glasses knocked crooked\n pods: vec4f, // headphones: 0 above his head .. 1 on it, alpha, glasses sunk into the flesh, -\n more2: vec4f, // how unequal its two eyes are, 1 if a lens has cracked, which of the five it is, -\n}\nstruct Light { pos: vec4f, col: vec4f } // x, y, radius, intensity | rgb, -\nstruct Ring { a: vec4f, b: vec4f } // x, y, radius, width | strength, rgb\nstruct Burst { a: vec4f, b: vec4f, c: vec4f } // x, y, age, kind | half w, half h, speed, seed | count, life, size, -\nstruct Win { rect: vec4f, fx: vec4f } // cx, cy, half w, half h | alpha, corner radius, how alive, focus\nstruct Tendril { a: vec4f, b: vec4f, c: vec4f, d: vec4f } // p0, p1 | p2, p3 | grown 0..1, radius px, phase, kind (0 tendril, 1 strand, 2 sinew) | rgb, tip speed px/s\nstruct U {\n view: vec4f, // w, h, shake x, y\n misc: vec4f, // time, heads, dpr, flesh (how far the metamorphosis has gone)\n post: vec4f, // aberration, flash, grain, vignette\n pulse: vec4f, // heartbeat 0..1, breath -1..1, breath amount, seconds since the last beat\n blur: vec4f, // shake velocity x, y in px/s, seconds the shutter is open, 1 if anything blurs\n blur2: vec4f, // the screen's own breath: centre x, y, swell (px per px), -\n grade: vec4f, // crimson wash, tungsten, exposure, cold\n seam: vec4f, // how fused the two windows are, how far the walls between the four tiles have gone, 1 if the windows stack (seam is horizontal), -\n host: vec4f, // the one mass the four become: its middle x, y, a head's radius, how far it has gone\n grid: vec4f, // the four tiles as one box: cx, cy, half w, half h\n host2: vec4f, // the bead that hangs under the mass: where it hangs to (y), how far it has fallen (0 hanging .. 1 landed), where it lands (y), how open the eye in the middle of the mass is\n wins: array<Win, 2>,\n lights: array<Light, 4>,\n rings: array<Ring, 8>,\n bursts: array<Burst, 4>,\n heads: array<Head, 5>,\n tendrils: array<Tendril, 32>,\n}\n@group(0) @binding(0) var<uniform> u: U;\n\nconst CORNERS = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));\nconst MINT = vec3f(0.20, 0.95, 0.56);\nconst AMBER = vec3f(1.0, 0.56, 0.16);\nconst CRIMSON = vec3f(0.86, 0.07, 0.05);\nconst VIOLET = vec3f(0.50, 0.05, 0.44);\nconst PAGE = vec3f(0.02745);\n\nfn rot(a: f32) -> mat2x2f { let c = cos(a); let s = sin(a); return mat2x2f(c, s, -s, c); }\nfn sq(x: f32) -> f32 { return x * x; }\nfn toClip(w: vec2f) -> vec4f { return vec4f(w.x / u.view.x * 2.0 - 1.0, 1.0 - w.y / u.view.y * 2.0, 0.0, 1.0); }\nfn hash11(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }\nfn hash21(p: vec2f) -> f32 {\n var q = fract(p * vec2f(123.34, 456.21));\n q = q + dot(q, q + 45.32);\n return fract(q.x * q.y);\n}\nfn vnoise(p: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), w.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), w.x), w.y);\n}\nfn sdSegment(p: vec2f, a: vec2f, b: vec2f) -> f32 {\n let pa = p - a; let ba = b - a;\n let k = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n return length(pa - ba * k);\n}\nfn sdBox(p: vec2f, b: vec2f, r: f32) -> f32 {\n let q = abs(p) - b + vec2f(r);\n return length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - r;\n}\n// Smooth union: two shapes k px apart or less run together.\nfn smin(a: f32, b: f32, k: f32) -> f32 {\n let h = max(k - abs(a - b), 0.0) / max(k, 1e-3);\n return min(a, b) - h * h * k * 0.25;\n}\n// A living edge: how far (px) a surface swells at a point, with the breath.\nfn swell(w: vec2f, t: f32) -> f32 {\n return sin(w.y * 0.013 + t * 0.9) * sin(w.x * 0.011 - t * 0.7) * 5.0 + sin(w.y * 0.031 - t * 1.3 + w.x * 0.017) * 2.5 + u.pulse.y * 5.0 + u.pulse.x * 2.5;\n}\n// What runs under every living surface: the vessels texture (vessels.js: red the vessels,\n// green the hairs off them, blue the light they throw).\n@group(1) @binding(0) var veinTex: texture_2d<f32>;\n@group(1) @binding(1) var veinSamp: sampler;\n// The flesh under the lacquer (flesh.wgsl, baked once): red its height (sinew, vessels), green\n// where it blisters, blue and alpha its slope. It tiles.\n@group(1) @binding(2) var fleshTex: texture_2d<f32>;\nfn flesh(uv: vec2f, lod: f32) -> vec4f { return textureSampleLevel(fleshTex, veinSamp, uv, lod); }\n// 1 on a vessel, 0 between them, with a little of the light round it. p is in cells: about\n// 65 px of the page, or a third of a head.\nfn veins(p: vec2f) -> f32 {\n let s = textureSampleLevel(veinTex, veinSamp, p * 0.0425, 0.0).rgb;\n return max(s.r, s.g * 0.42) + s.b * 0.30;\n}\n// The same vessels as something you could feel: swollen tubes under the skin. x, y: which way\n// the surface leans over them (from the wide soft halo each vessel has in the texture's blue,\n// so it is smooth however close you look); z: the vessel itself, as veins() gives it; w: how\n// far the skin stands up over it.\nfn veinRelief(p: vec2f) -> vec4f {\n let uv = p * 0.0425;\n // (Eight texels apart: the halo is eight bits deep, and a finer difference shows its steps.)\n let e = 8.0 / 2048.0;\n let s = textureSampleLevel(veinTex, veinSamp, uv, 0.0).rgb;\n let bx = (textureSampleLevel(veinTex, veinSamp, uv + vec2f(e, 0.0), 0.0).b - s.b) * 2.0;\n let by = (textureSampleLevel(veinTex, veinSamp, uv + vec2f(0.0, e), 0.0).b - s.b) * 2.0;\n // Only where the skin really stands up: out in the halo's tail there is nothing to lean on.\n return vec4f(-vec2f(bx, by) * smoothstep(0.06, 0.30, s.b), max(s.r, s.g * 0.42) + s.b * 0.30, s.r * 0.35 + s.b);\n}\n// Liquid obsidian under a softbox: the colour of a membrane whose height falls away at its\n// edge. d is the distance inside it (negative), grad the direction out of it.\nfn membrane(d: f32, grad: vec2f, w: vec2f) -> vec3f {\n let e = clamp(-d / 15.0, 0.0, 1.0);\n let N = normalize(vec3f(grad * (1.0 - e) * (1.0 - e) * 1.5, 0.30 + e));\n let H = normalize(vec3f(-0.50, -0.62, 1.55));\n let nh = max(dot(N, H), 0.0);\n var c = vec3f(0.010, 0.009, 0.011) + vec3f(0.055, 0.056, 0.064) * pow(clamp(0.5 + 0.5 * dot(N, vec3f(-0.42, -0.55, 0.72)), 0.0, 1.0), 2.0);\n // (A broad soft sheen, not a line: a tight one along a seam is split into colours by the lens.)\n c += vec3f(0.95, 0.97, 1.0) * (pow(nh, 36.0) * 0.38 + pow(nh, 10.0) * 0.10);\n c += vec3f(0.42, 0.50, 0.66) * 0.20 * pow(1.0 - N.z, 3.0);\n // What runs under it.\n let v = veins(w * 0.016 + vec2f(u.misc.x * 0.02, 0.0));\n let wave = 0.35 + 0.65 * pow(0.5 + 0.5 * sin(w.x * 0.02 + w.y * 0.013 - u.misc.x * 2.4), 3.0);\n c += mix(CRIMSON, AMBER, v * v * 0.3 + 0.2 * u.pulse.x) * v * (0.3 + 0.6 * u.pulse.x) * wave * e;\n return c;\n}\n// The desktop: two windows on black. The call, and OpenCode. Both are drawn here (the page\n// lays their text over them), so that when the wall comes down their edges can swell, lean\n// toward each other and run together like something poured.\nstruct VO { @builtin(position) pos: vec4f, @location(0) uv: vec2f }\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n let c = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u));\n o.pos = vec4f(c * 2.0 - vec2f(1.0), 0.0, 1.0);\n o.uv = vec2f(c.x, 1.0 - c.y);\n return o;\n}\nstruct FO { @location(0) c: vec4f }\n\n// The two windows, alive: d of each, and of both run together.\nfn fields(w: vec2f, F: f32, t: f32) -> vec3f {\n let A = u.wins[0];\n let B = u.wins[1];\n var dA = sdBox(w - A.rect.xy, A.rect.zw, A.fx.y);\n var dB = sdBox(w - B.rect.xy, B.rect.zw, B.fx.y);\n if (F > 0.001) {\n let s = swell(w, t);\n dA -= s * A.fx.z;\n dB -= s * B.fx.z;\n }\n dA += (1.0 - step(0.004, A.fx.x)) * 1e4;\n dB += (1.0 - step(0.004, B.fx.x)) * 1e4;\n // Where along the seam they have run together: strands at first, then all of it.\n let along = mix(w.y, w.x, u.seam.z);\n let strand = smoothstep(0.30, 0.72, 0.5 + 0.5 * sin(along * 0.019 + t * 0.31 + 1.3) * sin(along * 0.0071 - t * 0.17 + 0.4));\n let k = u.seam.x * u.seam.x * 110.0 * mix(strand, 1.0, smoothstep(0.62, 1.0, u.seam.x));\n return vec3f(dA, dB, smin(dA, dB, k));\n}\n// The four tiles of the call, the same way: they run together at the middle of the grid first.\nfn tiles(w: vec2f, t: f32) -> f32 {\n let s = swell(w, t);\n let strand = smoothstep(0.25, 0.7, 0.5 + 0.5 * sin(w.y * 0.027 - t * 0.37 + 0.6) * sin(w.x * 0.0093 + t * 0.21));\n let mid = 1.0 - smoothstep(0.0, 1.0, length((w - u.grid.xy) / u.grid.zw));\n let k = u.seam.y * u.seam.y * 70.0 * mix(max(strand, mid), 1.0, smoothstep(0.55, 1.0, u.seam.y));\n var d = 1e4;\n for (var n = 0u; n < 4u; n++) {\n let a = u.heads[n];\n d = smin(d, sdBox(w - a.tile.xy, a.tile.zw, a.tileFx.y) - s * a.flesh.x + (1.0 - step(0.004, a.tileFx.x)) * 1e4, k);\n }\n return d;\n}\n\n@fragment fn fs(i: VO) -> FO {\n let w = i.uv * u.view.xy;\n let px = 1.0 / u.misc.z;\n let t = u.misc.x;\n let F = u.misc.w;\n let A = u.wins[0];\n let B = u.wins[1];\n var col = PAGE;\n let f = fields(w, F, t);\n // Each window: a soft shadow under it, a dark pane, a hairline, a little light on its top edge.\n for (var n = 0; n < 2; n++) {\n let W = u.wins[n];\n let d = select(f.x, f.y, n == 1);\n let a = W.fx.x;\n if (a < 0.004) { continue; }\n col *= 1.0 - 0.55 * a * exp(-max(d, 0.0) / 34.0) * (1.0 - step(d, 0.0));\n let q = (w - W.rect.xy) / W.rect.zw;\n var pane = mix(vec3f(0.076, 0.076, 0.078), vec3f(0.060, 0.060, 0.062), smoothstep(-1.0, 1.0, q.y));\n pane += vec3f(0.012) * W.fx.w * smoothstep(-0.2, -1.0, q.y);\n let cv = 1.0 - smoothstep(-px, px, d);\n col = mix(col, pane, cv * a);\n let hair = 1.0 - smoothstep(0.0, px * 1.5, abs(d + px * 0.75) - px * 0.5);\n col += vec3f(1.0) * hair * a * (0.085 + 0.045 * W.fx.w + 0.05 * smoothstep(0.2, -1.0, q.y));\n }\n if (F > 0.001) {\n // Alive. The edges are wet: a line of the softbox runs along them, vessels show through\n // the pane near its border, and where the two have run together there is one surface.\n let dU = f.z;\n let inside = 1.0 - smoothstep(-px, px, dU);\n let rimW = 5.0 + 14.0 * F;\n let reach = 26.0 + 150.0 * F * F;\n // The wet edge is only a few px deep, and the bridge is only between the windows: the\n // slope of the surface is worked out only there.\n if (dU < px && dU > -rimW * 6.0) {\n let e = vec2f(1.5, 0.0);\n let fx = fields(w + e.xy, F, t);\n let fy = fields(w + e.yx, F, t);\n let grad = normalize(vec2f(fx.z - f.z, fy.z - f.z) + vec2f(1e-5));\n let own = max(1.0 - smoothstep(-px, px, f.x), 1.0 - smoothstep(-px, px, f.y));\n let m = membrane(dU, grad, w);\n // The bridge itself, and a meniscus a few px into each window.\n let bridge = inside * (1.0 - own);\n let rimIn = inside * exp(dU / rimW) * smoothstep(0.02, 0.3, F);\n col = mix(col, m, max(bridge, rimIn * 0.92));\n }\n // Vessels creeping in from the border, under the glass: as far in as they have got.\n let depth = inside * exp(dU / reach);\n if (depth > 0.008) {\n let v = veins(w * 0.014 + vec2f(0.0, t * 0.015));\n let wave = 0.3 + 0.7 * pow(0.5 + 0.5 * sin(dU * 0.045 + t * 2.2), 3.0);\n col += mix(CRIMSON, AMBER, v * v * 0.25 + 0.2 * u.pulse.x) * v * depth * F * (0.20 + 0.40 * u.pulse.x) * wave * 1.5;\n col += CRIMSON * 0.035 * F * depth * (0.5 + u.pulse.x);\n }\n }\n // Between the four tiles, the same: where they have run together, one surface. (Only in\n // and round the grid.)\n let S = u.seam.y;\n let gq = abs(w - u.grid.xy) - u.grid.zw;\n if (S > 0.001 && max(gq.x, gq.y) < 24.0) {\n let dT = tiles(w, t);\n if (dT < 2.0) {\n let e = vec2f(1.5, 0.0);\n let grad = normalize(vec2f(tiles(w + e.xy, t) - dT, tiles(w + e.yx, t) - dT) + vec2f(1e-5));\n col = mix(col, membrane(dT, grad, w) + CRIMSON * 0.05 * u.pulse.x, 1.0 - smoothstep(-px, px, dT));\n }\n }\n return FO(vec4f(col, 1.0));\n}\n"
|
|
export const HEADS = "diagnostic(off, derivative_uniformity);\n// The whole frame in one uniform buffer. Offsets are mirrored by G in cast.js.\nstruct Head {\n pos: vec4f, // cx, cy, R, roll\n tile: vec4f, // cx, cy, half w, half h\n tileFx: vec4f, // alpha (0: no tile), corner radius, speaking ring, dim\n tilt3: vec4f, // tile lean x, y, face turn x, y\n eye: vec4f, // gaze x, y, upper lid L, R (0 open .. 1 shut)\n eye2: vec4f, // lower lid L, R, pupil dilation, eye size\n brow: vec4f, // raise L, R, angle L, R (+ furrowed: inner end down)\n brow2: vec4f, // arch L, R, weight, eye spacing\n mouth: vec4f, // open, wide, round, smile\n mouth2: vec4f, // smirk, tongue, jaw drop, -\n rim: vec4f, // rgb, strength\n look: vec4f, // glasses, gloss, the monitor's emerald in the eyes, alpha\n shape: vec4f, // rx, ry, stretch (y scale), rim angle\n vel: vec4f, // the face: x, y in px/s, growth per second, -\n tvel: vec4f, // the tile: x, y, half w, half h in px/s\n spare: vec4f, // seed, time, key light level, warmth\n flesh: vec4f, // veins under the lacquer, breath (-1..1), heartbeat (0..1), how liquid the surface is\n morph: vec4f, // -, third eye open, -, vein surge (emerald)\n fuse: vec4f, // where the tendril enters the face: x, y (in head radii), how far the walls of its tile have gone, which way the middle of the grid lies in x (-1, 0, 1)\n more: vec4f, // which way the middle of the grid lies in y (-1, 0, 1), what it wears (0 nothing, 1 a knitted hat, 2 a top-knot and a headset), how much wider its crown is than its jaw, 1 if the one mass draws it\n one: vec4f, // how far this head has run into the one mass, the calm dark wet look that comes after, terror, the drips' clock\n eyes: vec4f, // eyes pushed out through the brow (0 shut .. 1 open), brows (1 there .. 0 absorbed), how real the eyes are (bloodshot, wet), glasses knocked crooked\n pods: vec4f, // headphones: 0 above his head .. 1 on it, alpha, glasses sunk into the flesh, -\n more2: vec4f, // how unequal its two eyes are, 1 if a lens has cracked, which of the five it is, -\n}\nstruct Light { pos: vec4f, col: vec4f } // x, y, radius, intensity | rgb, -\nstruct Ring { a: vec4f, b: vec4f } // x, y, radius, width | strength, rgb\nstruct Burst { a: vec4f, b: vec4f, c: vec4f } // x, y, age, kind | half w, half h, speed, seed | count, life, size, -\nstruct Win { rect: vec4f, fx: vec4f } // cx, cy, half w, half h | alpha, corner radius, how alive, focus\nstruct Tendril { a: vec4f, b: vec4f, c: vec4f, d: vec4f } // p0, p1 | p2, p3 | grown 0..1, radius px, phase, kind (0 tendril, 1 strand, 2 sinew) | rgb, tip speed px/s\nstruct U {\n view: vec4f, // w, h, shake x, y\n misc: vec4f, // time, heads, dpr, flesh (how far the metamorphosis has gone)\n post: vec4f, // aberration, flash, grain, vignette\n pulse: vec4f, // heartbeat 0..1, breath -1..1, breath amount, seconds since the last beat\n blur: vec4f, // shake velocity x, y in px/s, seconds the shutter is open, 1 if anything blurs\n blur2: vec4f, // the screen's own breath: centre x, y, swell (px per px), -\n grade: vec4f, // crimson wash, tungsten, exposure, cold\n seam: vec4f, // how fused the two windows are, how far the walls between the four tiles have gone, 1 if the windows stack (seam is horizontal), -\n host: vec4f, // the one mass the four become: its middle x, y, a head's radius, how far it has gone\n grid: vec4f, // the four tiles as one box: cx, cy, half w, half h\n host2: vec4f, // the bead that hangs under the mass: where it hangs to (y), how far it has fallen (0 hanging .. 1 landed), where it lands (y), how open the eye in the middle of the mass is\n wins: array<Win, 2>,\n lights: array<Light, 4>,\n rings: array<Ring, 8>,\n bursts: array<Burst, 4>,\n heads: array<Head, 5>,\n tendrils: array<Tendril, 32>,\n}\n@group(0) @binding(0) var<uniform> u: U;\n\nconst CORNERS = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));\nconst MINT = vec3f(0.20, 0.95, 0.56);\nconst AMBER = vec3f(1.0, 0.56, 0.16);\nconst CRIMSON = vec3f(0.86, 0.07, 0.05);\nconst VIOLET = vec3f(0.50, 0.05, 0.44);\nconst PAGE = vec3f(0.02745);\n\nfn rot(a: f32) -> mat2x2f { let c = cos(a); let s = sin(a); return mat2x2f(c, s, -s, c); }\nfn sq(x: f32) -> f32 { return x * x; }\nfn toClip(w: vec2f) -> vec4f { return vec4f(w.x / u.view.x * 2.0 - 1.0, 1.0 - w.y / u.view.y * 2.0, 0.0, 1.0); }\nfn hash11(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }\nfn hash21(p: vec2f) -> f32 {\n var q = fract(p * vec2f(123.34, 456.21));\n q = q + dot(q, q + 45.32);\n return fract(q.x * q.y);\n}\nfn vnoise(p: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), w.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), w.x), w.y);\n}\nfn sdSegment(p: vec2f, a: vec2f, b: vec2f) -> f32 {\n let pa = p - a; let ba = b - a;\n let k = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n return length(pa - ba * k);\n}\nfn sdBox(p: vec2f, b: vec2f, r: f32) -> f32 {\n let q = abs(p) - b + vec2f(r);\n return length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - r;\n}\n// Smooth union: two shapes k px apart or less run together.\nfn smin(a: f32, b: f32, k: f32) -> f32 {\n let h = max(k - abs(a - b), 0.0) / max(k, 1e-3);\n return min(a, b) - h * h * k * 0.25;\n}\n// A living edge: how far (px) a surface swells at a point, with the breath.\nfn swell(w: vec2f, t: f32) -> f32 {\n return sin(w.y * 0.013 + t * 0.9) * sin(w.x * 0.011 - t * 0.7) * 5.0 + sin(w.y * 0.031 - t * 1.3 + w.x * 0.017) * 2.5 + u.pulse.y * 5.0 + u.pulse.x * 2.5;\n}\n// What runs under every living surface: the vessels texture (vessels.js: red the vessels,\n// green the hairs off them, blue the light they throw).\n@group(1) @binding(0) var veinTex: texture_2d<f32>;\n@group(1) @binding(1) var veinSamp: sampler;\n// The flesh under the lacquer (flesh.wgsl, baked once): red its height (sinew, vessels), green\n// where it blisters, blue and alpha its slope. It tiles.\n@group(1) @binding(2) var fleshTex: texture_2d<f32>;\nfn flesh(uv: vec2f, lod: f32) -> vec4f { return textureSampleLevel(fleshTex, veinSamp, uv, lod); }\n// 1 on a vessel, 0 between them, with a little of the light round it. p is in cells: about\n// 65 px of the page, or a third of a head.\nfn veins(p: vec2f) -> f32 {\n let s = textureSampleLevel(veinTex, veinSamp, p * 0.0425, 0.0).rgb;\n return max(s.r, s.g * 0.42) + s.b * 0.30;\n}\n// The same vessels as something you could feel: swollen tubes under the skin. x, y: which way\n// the surface leans over them (from the wide soft halo each vessel has in the texture's blue,\n// so it is smooth however close you look); z: the vessel itself, as veins() gives it; w: how\n// far the skin stands up over it.\nfn veinRelief(p: vec2f) -> vec4f {\n let uv = p * 0.0425;\n // (Eight texels apart: the halo is eight bits deep, and a finer difference shows its steps.)\n let e = 8.0 / 2048.0;\n let s = textureSampleLevel(veinTex, veinSamp, uv, 0.0).rgb;\n let bx = (textureSampleLevel(veinTex, veinSamp, uv + vec2f(e, 0.0), 0.0).b - s.b) * 2.0;\n let by = (textureSampleLevel(veinTex, veinSamp, uv + vec2f(0.0, e), 0.0).b - s.b) * 2.0;\n // Only where the skin really stands up: out in the halo's tail there is nothing to lean on.\n return vec4f(-vec2f(bx, by) * smoothstep(0.06, 0.30, s.b), max(s.r, s.g * 0.42) + s.b * 0.30, s.r * 0.35 + s.b);\n}\n// Liquid obsidian under a softbox: the colour of a membrane whose height falls away at its\n// edge. d is the distance inside it (negative), grad the direction out of it.\nfn membrane(d: f32, grad: vec2f, w: vec2f) -> vec3f {\n let e = clamp(-d / 15.0, 0.0, 1.0);\n let N = normalize(vec3f(grad * (1.0 - e) * (1.0 - e) * 1.5, 0.30 + e));\n let H = normalize(vec3f(-0.50, -0.62, 1.55));\n let nh = max(dot(N, H), 0.0);\n var c = vec3f(0.010, 0.009, 0.011) + vec3f(0.055, 0.056, 0.064) * pow(clamp(0.5 + 0.5 * dot(N, vec3f(-0.42, -0.55, 0.72)), 0.0, 1.0), 2.0);\n // (A broad soft sheen, not a line: a tight one along a seam is split into colours by the lens.)\n c += vec3f(0.95, 0.97, 1.0) * (pow(nh, 36.0) * 0.38 + pow(nh, 10.0) * 0.10);\n c += vec3f(0.42, 0.50, 0.66) * 0.20 * pow(1.0 - N.z, 3.0);\n // What runs under it.\n let v = veins(w * 0.016 + vec2f(u.misc.x * 0.02, 0.0));\n let wave = 0.35 + 0.65 * pow(0.5 + 0.5 * sin(w.x * 0.02 + w.y * 0.013 - u.misc.x * 2.4), 3.0);\n c += mix(CRIMSON, AMBER, v * v * 0.3 + 0.2 * u.pulse.x) * v * (0.3 + 0.6 * u.pulse.x) * wave * e;\n return c;\n}\n// A tile of the call and the bean in it.\n//\n// The bean is drawn as a sculpture under studio lights, not as a flat drawing: every part has\n// a surface normal and is lit by the same studio.\n// body obsidian lacquer on an egg. A softbox (upper left) reflects as a curved window, a\n// rim light wraps the silhouette in the face's own colour, and whatever is going off\n// in the room (an emerald launch) bounces off the cheekbones and brow.\n// eyes balls set in sockets: shaded as spheres, shadowed by their lids, with a dark glassy\n// iris, two catchlights, and the monitor's emerald in them when a change ships.\n// lids upper and lower, lacquer like the body, each with its own curve.\n// brows tapered tubes, lit from above, that cast a shadow on the forehead.\n// mouth closed, a carved line; open, a black cavity with a strip of teeth and a coral tongue.\n//\n// That is Me, from the first frame to the last, under a pair of over-ear headphones. The four\n// on the call start the same (each with a shape and something on its head of its own) and do\n// not stay that way:\n// flesh the lacquer blisters, cracks and peels back off wet muscle (the baked flesh texture:\n// one read for the peel, the colour and the slope every highlight breaks over). No\n// softbox on meat: oxblood and liver, one tight wet glint, red through its thin edges\n// eyes real ones: bloodshot whites, amber irises, wet lids; more of them push out through\n// the brow and the forehead\n// veins swollen, crimson to violet, raised under the skin, and they throb with the heart\n// slime it is wet: beads slide down it and leave a track, and more hangs off its underside\n// lumps it swells where it likes, and nowhere twice\n// mass the four heads run into one (a smooth union of all four eggs), and it drips. It is\n// drawn once, in a quad of its own (vsMass, fsMass), after every tile: each pixel of\n// it shades the features of whichever head's part of it that is. Between the faces\n// it is one surface: long smooth swells of sinew along the cross where they meet\n// (folds()), wet, with no seam\n\nstruct VO {\n @builtin(position) pos: vec4f,\n @location(0) world: vec2f,\n @location(1) @interpolate(flat) idx: u32,\n}\n\n@vertex fn vs(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> VO {\n let h = u.heads[ii];\n var o: VO;\n o.idx = ii;\n if (h.look.w <= 0.002) {\n o.pos = vec4f(9.0, 9.0, 9.0, 1.0);\n o.world = vec2f(0.0);\n return o;\n }\n // The tile's box, grown for its lean. A face with no tile needs its own box.\n // (A face is clipped to its tile until it is flesh: then it swells out past the frame, by up\n // to 88 px, and by 48 more toward the seam.)\n let te = h.tile.zw * (1.05 + 0.3 * length(h.tilt3.xy)) + vec2f(4.0 + h.flesh.x * 16.0) + vec2f(h.fuse.z * 14.0);\n let R = h.pos.z * 1.5;\n let framed = step(0.5, h.tileFx.x);\n // The box grows only where the head itself has come out over the frame, so the room's\n // pixels are not paid for twice.\n // (Not once it is part of the one mass, which is drawn on its own.)\n let out = smoothstep(0.25, 0.7, h.flesh.x) * (1.0 - h.more.w) * 34.0;\n let tlo = min(h.tile.xy - te, max(h.pos.xy - vec2f(R), h.tile.xy - te - vec2f(out)));\n let thi = max(h.tile.xy + te, min(h.pos.xy + vec2f(R, R * 1.25), h.tile.xy + te + vec2f(out)));\n let lo = mix(h.pos.xy - vec2f(R), tlo, framed);\n let hi = mix(h.pos.xy + vec2f(R, R * 1.25), thi, framed);\n // Room for the blur a moving tile leaves outside itself.\n let pad = (abs(h.vel.xy) + abs(h.tvel.xy) + abs(h.tvel.zw)) * u.blur.z * 0.5;\n let w = mix(lo - pad, hi + pad, CORNERS[vi]);\n o.pos = toClip(w);\n o.world = w;\n return o;\n}\n\nfn sdEllipse(p: vec2f, r: vec2f) -> f32 {\n let k0 = length(p / r);\n let k1 = length(p / (r * r));\n return k0 * (k0 - 1.0) / max(k1, 1e-4);\n}\nfn sdRoundBox(p: vec2f, b: vec2f, r: f32) -> f32 { return sdBox(p, b, r); }\nfn cov(dist: f32, aa: f32) -> f32 { return 1.0 - smoothstep(-aa, aa, dist); }\n// A soft bump on the surface: its slope in x and y.\nfn bump(p: vec2f, c: vec2f, s: vec2f, a: f32) -> vec2f {\n let d = (p - c) / s;\n return -2.0 * d / s * a * exp(-dot(d, d));\n}\n\n// The key light, for everything that is not lacquer (eyes, brows, teeth).\nconst KEY = vec3f(-0.50, -0.60, 0.62);\n// The softbox, as the lacquer sees it: where it hangs, and its long and short axes.\nconst SB_K = vec3f(-0.741, -0.601, 0.300);\nconst SB_T1 = vec3f(0.630, -0.777, 0.0);\nconst SB_T2 = vec3f(0.233, 0.189, 0.954);\nconst FILL = vec3f(-0.42, -0.55, 0.72);\nconst IVORY = vec3f(0.955, 0.95, 0.925);\n\nstruct FO { @location(0) c: vec4f, @location(1) v: vec4f }\n\n// A brow: an arched, tapered tube. Returns the distance to its surface and where the pixel sits\n// across it (-1 its upper edge, 1 its lower).\nfn browAt(p: vec2f, bc: vec2f, X: vec2f, Y: vec2f, L: f32, arch: f32, T: f32) -> vec2f {\n let d = p - bc;\n let bx = dot(d, X) / L;\n let by = dot(d, Y);\n let cx = clamp(bx, -1.0, 1.0);\n let yc = -arch * L * (1.0 - cx * cx);\n let slope = 2.0 * arch * cx;\n let th = T * mix(1.0, 0.62, smoothstep(-0.3, 1.0, cx));\n let perp = (by - yc) / sqrt(1.0 + slope * slope);\n let over = max(abs(bx) - 1.0, 0.0) * L;\n return vec2f(length(vec2f(over, perp)) - th, perp / th);\n}\n\n// The mouth. m is the pixel in the mouth's own space. lit is the room's light on white things.\nfn mouthAt(fc0: vec3f, m: vec2f, mo: vec4f, mo2: vec4f, aa: f32, lit: vec3f, keyK: f32, real: f32) -> vec3f {\n let open = mo.x;\n let wide = mo.y;\n let rnd = mo.z;\n let smile = mo.w;\n let smirk = mo2.x;\n let o1 = min(open, 1.0);\n let yell = max(open - 1.0, 0.0);\n let jaw = mo2.z;\n let W = (0.215 + 0.08 * wide + 0.115 * o1 * (0.4 + 0.6 * wide) + 0.03 * max(smile, 0.0)) * (1.0 - 0.46 * rnd) * (1.0 - 0.3 * jaw * real);\n let hU = (0.010 + 0.05 * rnd) * o1 + 0.02 * yell + 0.22 * jaw * o1 * real;\n let hL = (0.47 * o1 + 0.13 * yell) * (1.0 + 0.1 * rnd);\n let lift = 0.115 * abs(smile) + 0.08 * abs(smirk) + 0.06;\n if (abs(m.x) > W + 0.15 || m.y < -hU - lift - 0.04 || m.y > hL + lift + 0.05) { return fc0; }\n\n let t = clamp(m.x / W, -1.0, 1.0);\n let rem = max(1.0 - t * t, 0.0);\n // Where the corners sit: lifted by a smile, one of them by a smirk.\n let yC = -smile * 0.105 * t * t - smirk * 0.075 * t * (0.55 + 0.45 * abs(t));\n let pL = mix(0.86, 0.62, rnd);\n let yU = yC - hU * pow(rem, 0.6);\n let yL = yC + hL * pow(rem, pL);\n let H = hU + hL;\n let openK = smoothstep(0.02, 0.07, H);\n // Distances to the opening's edges, corrected for how steep the bowl is.\n let sL = min(hL * pL * pow(max(rem, 0.02), pL - 1.0) * 2.0 * abs(t) / W, 5.0);\n let dLow = (m.y - yL) / sqrt(1.0 + sL * sL);\n let dUp = yU - m.y;\n let dX = abs(m.x) - W;\n // Past a corner, the distance is to the corner itself (no wall there to catch the light).\n let dM = select(max(dUp, dLow), length(vec2f(dX, m.y - yC)), dX > 0.0);\n\n // Inside: pure black, a coral tongue on the floor of it, a white strip of teeth along the top.\n var ic = vec3f(0.003, 0.003, 0.004);\n let tw = W * (0.52 - 0.12 * rnd);\n let tH = max(hL * (0.40 + 0.22 * mo2.y), 0.02);\n let cyT = hL - tH * 0.26;\n let lob = vec2f(tw * 0.62, tH);\n let d1 = sdEllipse(m - vec2f(-tw * 0.40, cyT), lob);\n let d2 = sdEllipse(m - vec2f(tw * 0.40, cyT), lob);\n let kT = 0.05;\n let hT = clamp(0.5 + 0.5 * (d2 - d1) / kT, 0.0, 1.0);\n let dT = mix(d2, d1, hT) - kT * hT * (1.0 - hT);\n let up = clamp((cyT - m.y) / tH * 0.55 + 0.5, 0.0, 1.0);\n var tc = mix(vec3f(0.74, 0.17, 0.22), vec3f(1.0, 0.44, 0.41), up);\n tc += vec3f(1.0, 0.82, 0.78) * 0.20 * exp(-sq((m.y - (cyT - tH * 0.52)) / (tH * 0.24))) * exp(-sq((abs(m.x) - tw * 0.38) / (tw * 0.32)));\n tc *= 1.0 - 0.10 * exp(-sq(m.x / (tw * 0.05))) * smoothstep(cyT - tH * 1.1, cyT - tH * 0.2, m.y);\n tc *= 1.0 - 0.35 * smoothstep(-0.03, 0.0, dT);\n ic = mix(ic, tc * (0.9 + 0.5 * lit), cov(dT, aa) * smoothstep(0.15, 0.30, hL) * (1.0 - 0.7 * rnd));\n\n let arch = pow(rem, 0.30);\n let thk = min(0.07 + 0.05 * o1, H * 0.45) * arch * (1.0 - 0.35 * real);\n let dTe = m.y - yU - thk;\n var white = mix(vec3f(0.99, 0.99, 0.975), vec3f(0.90, 0.86, 0.74), real) * mix(0.74, 1.0, smoothstep(0.0, thk * 0.5, m.y - yU)) * (1.0 - 0.11 * t * t);\n white *= 1.0 - 0.3 * real * step(0.5, fract(t * 4.0 + 0.5) + 0.44);\n white = mix(white, vec3f(0.74, 0.78, 0.86), 0.55 * smoothstep(-0.022, 0.0, dTe));\n ic = mix(ic, white * (0.94 + 0.6 * lit), cov(dTe, aa) * smoothstep(0.03, 0.08, H));\n if (real > 0.002) {\n // A real mouth: gums over the teeth, a lower row, and a wet throat instead of plain black.\n ic = mix(ic, vec3f(0.50, 0.10, 0.11) * (0.8 + 0.4 * lit), cov(m.y - yU - thk * 0.30, aa) * smoothstep(0.03, 0.08, H) * real * 0.9);\n let thL = min(0.05 + 0.03 * o1, H * 0.3) * arch;\n let dTl = (yL - thL) - m.y;\n var low2 = vec3f(0.93, 0.91, 0.84) * mix(1.0, 0.7, smoothstep(0.0, thL, yL - m.y - thL * 0.2)) * (1.0 - 0.3 * t * t);\n low2 *= 0.75 + 0.25 * step(0.5, fract(t * 4.5 + 0.5) + 0.42);\n ic = mix(ic, low2 * (0.8 + 0.5 * lit), cov(dTl, aa) * smoothstep(0.2, 0.5, hL) * real * (1.0 - 0.6 * cov(dT, aa)));\n ic += vec3f(0.16, 0.012, 0.012) * real * smoothstep(0.0, 0.3, hL) * (1.0 - cov(dTe, aa));\n }\n // The cavity's own shadow, just inside the lips.\n ic *= 0.55 + 0.45 * smoothstep(0.0, -0.035, dM);\n\n var fc = fc0;\n // The lips: a raised rim of lacquer round the opening. The lower one faces the key.\n let low = smoothstep(-0.2, 0.55, (m.y - yC) / max(hL, 0.03));\n let rimL = exp(-sq((dM - 0.017) / 0.011));\n fc += (mix(vec3f(0.36, 0.37, 0.40), vec3f(0.95, 0.42, 0.38), real) * keyK + lit * 0.5) * rimL * openK * (0.14 + 0.86 * low);\n // Lips, once there is flesh to make them of.\n fc = mix(fc, vec3f(0.42, 0.05, 0.05) * (0.7 + 0.6 * low), real * exp(-sq((dM - 0.03) / 0.03)) * openK * 0.8);\n fc *= 1.0 - 0.6 * exp(-sq((dM - 0.036) / 0.016)) * openK * low * 0.6;\n fc = mix(fc, ic, cov(dM, aa) * openK);\n\n // Closed: a line carved in the lacquer, with the light caught along its lower lip.\n let capX = cov(dX + 0.012, aa * 1.5) * (0.35 + 0.65 * pow(rem, 0.5));\n let shut = (1.0 - openK) * capX;\n let dLine = abs(m.y - yC);\n fc *= 1.0 - 0.92 * cov(dLine - 0.0105, aa) * shut;\n fc += (vec3f(0.50, 0.51, 0.54) * keyK + lit * 0.5) * cov(abs(m.y - yC - 0.021) - 0.0065, aa * 1.6) * shut;\n fc += vec3f(0.10, 0.10, 0.11) * keyK * exp(-sq((m.y - yC - 0.05) / 0.03)) * shut;\n fc = mix(fc, vec3f(0.44, 0.055, 0.05) * (0.6 + 0.8 * smoothstep(-0.04, 0.05, m.y - yC)), real * shut * exp(-sq(dLine / 0.042)) * (1.0 - cov(dLine - 0.0105, aa)) * 0.85);\n fc += vec3f(1.0, 0.8, 0.76) * keyK * real * shut * exp(-sq((m.y - yC - 0.036) / 0.012)) * 0.4 * pow(rem, 2.0);\n\n // The creases a wide mouth pushes into the cheeks.\n let cs = select(-1.0, 1.0, m.x > 0.0);\n let cq = vec2f(abs(m.x) - W, m.y - (-smile * 0.105 - smirk * 0.075 * cs));\n let dCr = abs(length(cq - vec2f(-0.045, 0.03)) - 0.085) - 0.007;\n let crease = cov(dCr, aa * 1.5) * smoothstep(-0.02, 0.03, cq.x) * smoothstep(0.09, -0.02, cq.y) * clamp(max(smile, 0.0) * 1.2 * smoothstep(0.15, 0.6, o1) + abs(smirk) * 0.5 * step(0.0, smirk * cs), 0.0, 1.0);\n fc = mix(fc, fc * 0.3 + vec3f(0.20, 0.205, 0.22) * keyK, crease * 0.8);\n return fc;\n}\n\n// The egg: everything about where a point sits on a head. q0 is the point in units of the\n// head's radius, from its centre.\nstruct Egg { d: f32, p: vec2f, pe: vec2f, k0: f32 }\nfn egg(q0: vec2f, h: Head) -> Egg {\n let pr0 = rot(-h.pos.w) * q0;\n // Squash and stretch, keeping its volume.\n let st = max(h.shape.z, 0.3);\n let p = vec2f(pr0.x * sqrt(st), pr0.y / st);\n let open = clamp(h.mouth.x, 0.0, 1.35);\n let o1 = min(open, 1.0);\n // The jaw drops with the mouth: the chin lengthens and the cheeks draw in.\n let drop = smoothstep(0.22, 1.0, o1) * 0.15 + h.mouth2.z * 0.12 + max(open - 1.0, 0.0) * 0.22;\n let below = smoothstep(-0.15, 0.9, p.y);\n let rx = h.shape.x * (1.0 - h.more.z * p.y) * (1.0 - 0.22 * drop * below);\n let ry = h.shape.y * select(1.0, 1.0 + drop, p.y > 0.0);\n let pe = vec2f(p.x / rx, p.y / ry);\n let k0 = length(pe);\n var d = k0 * (k0 - 1.0) / max(length(pe / vec2f(rx, ry)), 1e-4);\n // Alive, the silhouette is never quite still: a slow wave runs round it.\n let liq = h.flesh.w;\n if (liq > 0.001) {\n d -= liq * 0.015 * sin(atan2(pe.y, pe.x) * 5.0 + h.spare.y * 1.7 + h.spare.x) * (0.65 + 0.35 * sin(h.spare.y * 0.9 + h.spare.x));\n // And it swells: a lump at the temple and one at the jaw, on the side away from the\n // other one, and they are not the same size on the two of them.\n let sd = h.fuse.w;\n let big = step(5.0, h.spare.x);\n let sy = h.more.x;\n let b1 = pe - vec2f(-0.66 * sd, -0.52 * sy);\n let b2 = pe - vec2f(-0.78 * sd, 0.16 * sy + 0.2);\n d -= liq * (mix(0.095, 0.055, big) * exp(-dot(b1, b1) * 7.0) + mix(0.050, 0.090, big) * exp(-dot(b2, b2) * 8.0)) * (1.0 + 0.22 * h.flesh.z);\n }\n return Egg(d, p, pe, k0);\n}\n\n// The one mass the four become, as a distance in px (negative inside): all four eggs run\n// together, lumps where a body would not put them, what drips off its two lower lobes, and one\n// rope of slime with a heavy bead on the end of it. d.y is the distance to the drips and the\n// rope, d.z to the bead alone. idx is whose part of the mass this pixel is in (whichever egg it\n// is nearest, so the join between two of them lies in the crease between them), and E that\n// head's egg.\nstruct Mass { d: vec3f, E: Egg, idx: u32 }\nfn mass(w: vec2f) -> Mass {\n let R = u.host.z;\n let k = u.host.w;\n let c = (w - u.host.xy) / R;\n var idx = 0u;\n var near = 1e4;\n var E = Egg(1e4, vec2f(0.0), vec2f(0.0), 9.0);\n var d = 1e4;\n let kk = k * R * 1.1;\n for (var n = 0u; n < 4u; n++) {\n let h = u.heads[n];\n let q = (w - h.pos.xy) / h.pos.z;\n let l2 = dot(q, q);\n var e = Egg(sqrt(l2) - 1.1, vec2f(0.0), vec2f(0.0), 9.0);\n // (Further off than this, it is too far to run together with anything.)\n if (l2 < 5.8) { e = egg(q, h); }\n let dn = e.d * h.pos.z;\n if (dn < near) { near = dn; idx = n; E = e; }\n d = smin(d, dn, kk);\n }\n // Lumps: four of them, no two alike, each swelling with the heart.\n let kl = smoothstep(0.25, 0.9, k) * (1.0 + 0.07 * u.pulse.x);\n if (kl > 0.0) {\n let a = u.heads[0]; let b = u.heads[1]; let e2 = u.heads[2]; let f = u.heads[3];\n let l1 = length(w - a.pos.xy - a.pos.z * vec2f(-0.72, -0.50)) - a.pos.z * 0.37 * kl;\n let l2b = length(w - f.pos.xy - f.pos.z * vec2f(0.70, 0.46)) - f.pos.z * 0.30 * kl * smoothstep(0.3, 0.9, f.one.x);\n let l3 = length(w - b.pos.xy - b.pos.z * vec2f(0.40, -0.86)) - b.pos.z * 0.26 * kl;\n let l4 = length(w - e2.pos.xy - e2.pos.z * vec2f(-0.80, 0.20)) - e2.pos.z * 0.22 * kl * smoothstep(0.3, 0.9, e2.one.x);\n d = smin(d, min(min(l1, l2b), min(l3, l4)), k * R * 0.34);\n }\n let t = u.heads[0].one.w;\n var dDrip = 1e4;\n var dBead = 1e4;\n if (c.y > 0.6 && k > 0.35) {\n // Drips, off the underside of the two lower lobes: a thread that lengthens, a bead that\n // swells at the end of it and lets go.\n for (var n = 0; n < 8; n++) {\n let f = f32(n);\n let hb = u.heads[2u + u32(n % 2)];\n let on = smoothstep(0.35, 0.9, hb.one.x);\n let hc = (hb.pos.xy - u.host.xy) / R;\n let off = mix(-0.62, 0.62, (floor(f * 0.5) + 0.2 + 0.6 * fract(f * 0.618 + 0.13)) / 4.0);\n let dx = c.x - (hc.x + off);\n if (abs(dx) < 0.20 && on > 0.0) {\n let ph = fract(t / (3.6 + 1.9 * hash11(f * 7.1)) + hash11(f * 1.9));\n let hang = smoothstep(0.0, 0.8, ph);\n let fall = max(ph - 0.8, 0.0) / 0.2;\n // Where the underside is, at this drip.\n let ys = hc.y + sqrt(max(1.0 - sq(off / 0.80), 0.0)) * hb.shape.y;\n let tip = ys + 0.03 + (0.16 + 0.34 * hash11(f * 5.7)) * mix(hang, 0.5, smoothstep(0.0, 0.3, fall)) * on;\n // Thick where it leaves, drawn thin, and a heavy bead on the end of it.\n let thread = sdSegment(vec2f(dx, c.y), vec2f(0.0, ys * 0.8), vec2f(0.0, tip)) - (0.014 + 0.022 * (1.0 - smoothstep(ys * 0.8, tip, c.y))) * on;\n let bead = length(vec2f(dx, (c.y - (tip + 0.02 + fall * fall * 1.6)) * 0.72)) - (0.026 + 0.048 * hang) * on * (1.0 - 0.3 * fall);\n dDrip = min(dDrip, smin(thread, bead, 0.05) * R);\n }\n }\n }\n if (u.host2.x > 0.0 && abs(c.x) < 0.5 && c.y > 0.5) {\n // And one long rope of it from the middle, with a heavy bead that swings and stretches\n // with the heart, just over his headband. On \"have a good one\" it lets go.\n let fall = u.host2.y;\n let top = u.host.xy + R * vec2f(0.05, 1.0);\n let sw = R * 0.035 * sin(t * 1.3) * (1.0 - min(fall, 1.0));\n let tipY = mix(u.host2.x + R * 0.03 * u.pulse.x, top.y + R * 0.4, smoothstep(0.0, 0.7, fall));\n let tip = vec2f(top.x + sw, tipY);\n let along = clamp((w.y - top.y) / max(tipY - top.y, 1.0), 0.0, 1.0);\n let rope = sdSegment(w, top, tip) - R * (0.014 + 0.05 * (1.0 - along) * (1.0 - along));\n let f1 = min(fall, 1.0);\n let by = mix(u.host2.x + R * 0.03 * u.pulse.x, u.host2.z, f1 * f1) + R * 0.05;\n // Landed, it flattens on the band, and is gone.\n let flat = smoothstep(1.0, 1.15, fall);\n let br = R * 0.085 * (1.0 + 0.10 * u.pulse.x) * (1.0 - smoothstep(1.3, 2.0, fall));\n dBead = length(vec2f((w.x - tip.x) / (1.0 + 0.9 * flat), (w.y - by - R * 0.03 * flat) * mix(0.8, 2.2, flat))) - br;\n let dRope = smin(rope, dBead, R * 0.05);\n dDrip = min(dDrip, dRope);\n // (The rope hangs from the crease between the lower two. It is all Dev's, so no join\n // runs down the middle of it.)\n if (dRope < near && idx != 3u) { idx = 3u; let h3 = u.heads[3]; E = egg((w - h3.pos.xy) / h3.pos.z, h3); }\n }\n d = smin(d, dDrip, 0.13 * R);\n return Mass(vec3f(d, dDrip, dBead), E, idx);\n}\n\n// Sinew, between the two faces of the one mass: broad bands that hang from one cheek to the\n// other, and long flutes up the trunk and down the stalk that they turn into. c is the point\n// from the middle of the mass, in head radii. Returns which way the surface leans in x and y,\n// and its height (-1 in a fold .. 1 on a swell). Nothing in it is mirrored about the middle,\n// no fold runs down it, and a swell lies over it in the trunk and the stalk.\nfn folds(c: vec2f) -> vec3f {\n let yy = c.y - 0.08;\n let t = clamp((abs(yy) - 0.34) / 0.52, 0.0, 1.0);\n let a = t * t * (3.0 - 2.0 * t);\n var B = vec3f(0.0);\n var F = vec3f(0.0);\n if (a < 0.999) {\n // The bands. They sag in the middle and tip a little to one side.\n let sa = sin(2.7 * c.x);\n let ca = cos(2.7 * c.x);\n let v = c.y - 0.17 * ca + 0.07 * sa;\n let vx = 0.459 * sa + 0.189 * ca;\n let q1 = 8.4 * v + 0.9;\n let q2 = 15.3 * v + 2.0 + 1.1 * sa;\n let s1 = sin(q1);\n let s2 = 0.26 * sin(q2);\n B = vec3f(-s1 * 8.4 * vx - s2 * (15.3 * vx + 2.97 * ca), -(s1 * 8.4 + s2 * 15.3), cos(q1) + 0.26 * cos(q2));\n }\n if (a > 0.001) {\n // The flutes. They wander as they go.\n let sy = sin(1.9 * c.y + 0.7);\n let cy = cos(1.9 * c.y + 0.7);\n let uu = 1.9 * c.x + 0.16 * sy;\n let r1 = 5.2 * uu;\n let r2 = 9.7 * uu + 1.3 + 0.8 * sy;\n let t1 = sin(r1);\n let t2 = 0.28 * sin(r2);\n F = vec3f(-(t1 * 5.2 + t2 * 9.7) * 1.9, -(t1 * 1.581 + t2 * 4.469) * cy, cos(r1) + 0.28 * cos(r2));\n }\n let ay = 6.0 * t * (1.0 - t) / 0.52 * sign(yy);\n let m = mix(B, F, a);\n return vec3f(-m.x, -(m.y + ay * (F.z - B.z)), m.z) / 1.27;\n}\n\n// Slime, running down it: in each of many narrow lanes a bead slides down and leaves a wet\n// track above itself. c is the point in head radii, t the clock. Returns the slope the bead\n// gives the surface (x, y), the bead (z), and its track (w). Lanes do not touch, so there is\n// no line between them, and c is the page's own space on the one mass, so nothing changes\n// down the middle of it.\nfn slime(c: vec2f, t: f32) -> vec4f {\n let lane = c.x * 6.5;\n let hs = fract(floor(lane) * 0.618 + 0.37);\n let dx = (fract(lane) - 0.32 - 0.36 * hs) / 0.13;\n let yb = fract(t * (0.055 + 0.075 * hs) + hs * 9.0) * 3.2 - 1.3;\n let dy = (c.y - yb) / 0.060;\n let ex = exp(-dx * dx);\n // A teardrop: round below, drawn out above.\n let bead = ex * exp(-dy * dy * select(1.0, 0.22, dy < 0.0));\n let track = ex * ex * exp(min(c.y - yb, 0.0) * 1.5) * step(c.y, yb);\n return vec4f(-1.5 * dx * bead, -1.1 * clamp(dy, -1.5, 1.5) * bead, bead, track);\n}\n\n// The softbox, as a surface that faces nw sees it: the window, the glow round it, and the\n// smaller light that answers it.\nfn softbox(nw: vec2f, wob: f32) -> vec3f {\n let rad = length(nw);\n let c1 = vec2f(-0.664, -0.748);\n let ang1 = atan2(c1.x * nw.y - c1.y * nw.x, dot(c1, nw));\n let sd1 = sdRoundBox(vec2f(rad - 0.80, ang1 * 0.80 - 0.02), vec2f(0.050, 0.205), 0.050) + wob;\n let win = (1.0 - smoothstep(-0.034, 0.016, sd1)) * (0.80 + 0.30 * smoothstep(0.25, -0.2, ang1));\n let halo = exp(-max(sd1, 0.0) / 0.075);\n let sd2 = sdEllipse(nw - vec2f(0.50, -0.66), vec2f(0.075, 0.040)) + wob;\n return vec3f(win, halo, 1.0 - smoothstep(-0.03, 0.02, sd2));\n}\n\n// An eye that has pushed out through the flesh: a wet ball in a ring of swollen lid. e is the\n// pixel from its centre, r its radius, open how far its lids have parted.\nfn orb(fc: vec3f, e: vec2f, r: f32, open: f32, gaze: vec2f, pd: f32, seed: f32, lit: vec3f, keyK: f32, aa: f32) -> vec3f {\n let l = length(e);\n if (l > r * 1.7 || open < 0.004) { return fc; }\n var c = fc;\n let d = l - r;\n let up = smoothstep(0.0, 0.3, open);\n let rn = e / max(l, 1e-4);\n // The ring: it bulges, catches the key on its upper left, and creases where it meets the brow.\n let ring = exp(-sq((d - 0.17 * r) / (0.17 * r)));\n let toKey = dot(rn, vec2f(-0.6, -0.72));\n c = mix(c, vec3f(0.46, 0.075, 0.06) * (0.50 + 0.65 * clamp(toKey * 0.5 + 0.5, 0.0, 1.0)) * (0.5 + 0.5 * keyK) + lit * 0.25, ring * 0.8 * up);\n c += vec3f(1.0, 0.9, 0.86) * pow(clamp(toKey, 0.0, 1.0), 7.0) * exp(-sq((d - 0.14 * r) / (0.07 * r))) * 0.65 * up * keyK;\n c *= 1.0 - 0.62 * exp(-sq((d - 0.44 * r) / (0.10 * r))) * up;\n let n = e / r;\n let half = open * (1.0 - 0.32 * n.x * n.x) * 1.02;\n let dLid = (abs(n.y) - half) * r;\n let dO = max(d, dLid);\n let inBall = cov(d, aa);\n let openC = cov(dO, aa);\n // What is not open is lid: skin drawn over the ball, split by a seam until it parts.\n c = mix(c, vec3f(0.34, 0.05, 0.048) * (0.55 + 0.6 * clamp(0.5 - n.y * 0.5 - n.x * 0.3, 0.0, 1.0)) * (0.5 + 0.5 * keyK), inBall * (1.0 - openC) * up);\n c *= 1.0 - 0.8 * cov(abs(e.y) - 0.010, aa) * cov(abs(e.x) - r * 0.8, aa) * (1.0 - smoothstep(0.0, 0.1, open)) * up;\n if (openC > 0.001) {\n let z = sqrt(max(1.0 - dot(n, n), 0.0));\n let N = normalize(vec3f(n * 0.86, z + 0.22));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n var s = mix(vec3f(0.56, 0.34, 0.33), vec3f(0.94, 0.90, 0.84), smoothstep(0.0, 0.72, z)) * (0.60 + 0.52 * kd);\n let ln = length(n);\n let sv = veins(n * 1.9 + vec2f(seed, seed * 1.7)) * smoothstep(0.16, 0.9, ln);\n // Bloodshot: red in from the rim, and every capillary standing out.\n s = mix(s, vec3f(0.86, 0.30, 0.24), 0.62 * smoothstep(0.30, 1.0, ln));\n s = mix(s, vec3f(0.70, 0.035, 0.035), clamp(sv * 1.7, 0.0, 1.0));\n s *= 1.0 - 0.5 * exp(-max(half - abs(n.y), 0.0) * r / 0.022);\n s += lit * 0.4;\n let ip = e - gaze * r * 0.30;\n let ri = r * 0.50;\n let dI = length(ip);\n let rp = ri * (0.30 + 0.34 * pd);\n let th = atan2(ip.y, ip.x);\n let fib = 0.5 + 0.5 * sin(th * 34.0 + 2.0 * sin(th * 7.0 + seed));\n var ir = mix(vec3f(0.17, 0.065, 0.022), vec3f(0.76, 0.43, 0.13), fib * smoothstep(rp, ri * 0.92, dI));\n ir = mix(ir, vec3f(0.90, 0.60, 0.22), exp(-sq((dI - rp * 1.3) / (ri * 0.13))) * 0.6);\n ir *= (0.50 + 0.65 * kd) * (1.0 - 0.8 * smoothstep(ri * 0.76, ri, dI));\n var eye = mix(s, ir, cov(dI - ri, aa));\n eye = mix(eye, vec3f(0.004), cov(dI - rp, aa));\n let c1 = sdRoundBox(rot(-0.55) * (ip - vec2f(-0.34, -0.36) * ri), vec2f(0.21, 0.13) * ri, 0.09 * ri);\n eye = mix(eye, vec3f(1.5, 1.52, 1.56) * (0.35 + 0.65 * keyK), cov(c1, aa));\n eye = mix(eye, vec3f(0.85, 0.9, 0.95) * keyK, cov(length(ip - vec2f(0.36, 0.4) * ri) - 0.1 * ri, aa) * 0.8);\n // Wet and red where the ball meets its lids, and a line of light along the lower one.\n eye = mix(eye, vec3f(0.56, 0.07, 0.06), smoothstep(-0.07 * r, 0.0, dO) * 0.8);\n eye += vec3f(1.0, 0.95, 0.9) * exp(-sq((dLid + 0.05 * r) / (0.016 * r))) * step(0.0, n.y) * 0.5 * keyK * (1.0 - abs(n.x));\n c = mix(c, eye, openC);\n }\n return c;\n}\n\n// The headphones: over-ear, matte anodized graphite. A sprung band that follows the crown, a\n// padded section on top of it, a metal slider down each side, and a cup on each ear with a\n// plush cushion between its shell and his head. They come down onto him from above. Returns\n// premultiplied colour, with the shadow they leave on whatever is under them.\nfn phonesAt(q0: vec2f, h: Head, aa: f32) -> vec4f {\n let k = h.pods.x;\n let far = 1.36 + 0.70 * (1.0 - k);\n if (dot(q0, q0) > far * far) { return vec4f(0.0); }\n var p = rot(-h.pos.w) * q0;\n p.y += (1.0 - k) * 0.62;\n let open = (1.0 - k) * 0.10;\n if (abs(p.x) > 1.24 + open || p.y < -1.22 || p.y > 0.44) { return vec4f(0.0); }\n let s = select(-1.0, 1.0, p.x > 0.0);\n let ax = abs(p.x) - open;\n // The band: an arc that hugs the crown, thicker where it is padded.\n let bc = vec2f(ax, p.y - 0.02);\n let br = vec2f(0.992, 1.052);\n let dE = sdEllipse(bc, br);\n let top = smoothstep(0.80, 0.42, ax);\n let thB = mix(0.034, 0.060, top);\n let dBand = max(abs(dE) - thB, p.y + 0.32);\n // The slider, out of the band's end and into the cup.\n let sa = vec2f(0.968, -0.40);\n let sb = vec2f(0.990, -0.18);\n let dSl = sdSegment(vec2f(ax, p.y), sa, sb) - 0.020;\n // The cup's shell, and the cushion pressed against his head.\n let cc = vec2f(ax - 1.005, p.y - 0.035);\n let cs = vec2f(0.118, 0.300);\n let dCup = sdRoundBox(cc, cs, 0.106);\n let pc = vec2f(ax - 0.858, p.y - 0.035);\n let ps = vec2f(0.064, 0.262);\n let dPad = sdRoundBox(pc, ps, 0.064);\n let d = min(min(dBand, dSl), min(dCup, dPad));\n if (d > 0.12) { return vec4f(0.0); }\n let keyK = 0.45 + 0.55 * h.spare.z;\n let warm = h.spare.w;\n let Hk = normalize(KEY + vec3f(0.0, 0.0, 1.0));\n let rimDir = vec2f(cos(h.shape.w), sin(h.shape.w));\n let keyCol = mix(vec3f(0.95, 0.975, 1.0), vec3f(1.0, 0.84, 0.62), warm);\n var col = vec3f(0.0);\n var al = 0.0;\n // Band: a tube bent round the head. Anodized metal at the sides, soft leather over the top.\n let cB = cov(dBand, aa);\n if (cB > 0.001) {\n let rd = normalize(bc / (br * br) + vec2f(1e-4));\n let across = clamp(dE / thB, -1.0, 1.0);\n let N = normalize(vec3f(rd.x * s * across * 0.94, rd.y * across * 0.94, sqrt(max(1.0 - across * across, 0.0)) + 0.14));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n let metal = vec3f(0.185, 0.192, 0.210) * (0.20 + 1.10 * kd) + keyCol * pow(max(dot(N, Hk), 0.0), 26.0) * 0.62;\n var pad = vec3f(0.070, 0.072, 0.080) * (0.30 + 1.05 * kd) + keyCol * pow(max(dot(N, Hk), 0.0), 9.0) * 0.12;\n // Its stitching: one fine line each side of the padded section.\n pad *= 1.0 - 0.5 * exp(-sq((abs(across) - 0.62) / 0.09));\n var c = mix(metal, pad, top);\n // Where the padding ends and the metal begins.\n c *= 1.0 - 0.55 * exp(-sq((ax - 0.61) / 0.012));\n c += h.rim.rgb * 0.70 * pow(1.0 - N.z, 2.0) * clamp(0.5 + 0.5 * dot(N.xy, rimDir), 0.0, 1.0);\n // A fine bright edge along the top of it, where the light from above catches the metal.\n c += keyCol * 0.20 * smoothstep(0.45, 0.98, across) * clamp(0.35 - rd.y * 0.75 - rd.x * s * 0.35, 0.0, 1.0);\n c *= 1.0 - 0.22 * smoothstep(-0.012, 0.0, abs(dE) - thB);\n col = c;\n al = cB;\n }\n // Slider: polished, lit along its length.\n let cS = cov(dSl, aa);\n if (cS > 0.001) {\n let ab = normalize(sb - sa);\n let off = dot(vec2f(ax, p.y) - sa, vec2f(ab.y, -ab.x)) / 0.020;\n let o1 = clamp(off, -1.0, 1.0);\n let N = normalize(vec3f(s * o1, 0.0, sqrt(max(1.0 - o1 * o1, 0.0)) + 0.1));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n let c = vec3f(0.34, 0.35, 0.38) * (0.18 + 1.0 * kd) + keyCol * pow(max(dot(N, Hk), 0.0), 40.0) * 0.9;\n col = mix(col, c, cS);\n al = al + (1.0 - al) * cS;\n }\n // Cushion: plush and nearly black, rounded all the way over, with a soft sheen.\n let cP = cov(dPad, aa);\n if (cP > 0.001) {\n let q = clamp(pc / ps, vec2f(-1.0), vec2f(1.0));\n let n2 = vec2f(q.x, q.y * abs(q.y) * abs(q.y));\n let N = normalize(vec3f(n2.x * s * 0.92, n2.y * 0.92, sqrt(max(1.0 - min(dot(n2, n2), 1.0), 0.0)) + 0.16));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n var c = vec3f(0.058, 0.060, 0.068) * (0.30 + 1.05 * kd) + keyCol * pow(max(dot(N, Hk), 0.0), 7.0) * 0.11;\n c += h.rim.rgb * 0.26 * pow(1.0 - N.z, 2.0) * clamp(0.5 + 0.5 * dot(N.xy, rimDir), 0.0, 1.0);\n // Dark where it meets the shell.\n c *= 1.0 - 0.5 * smoothstep(0.02, 0.064, pc.x);\n col = mix(col, c, cP);\n al = al + (1.0 - al) * cP;\n }\n // Shell: a machined cap. Flat across its face, bevelled at its edge, with one fine bright\n // ring set into it and the softbox drawn down its upper flank.\n let cC = cov(dCup, aa);\n if (cC > 0.001) {\n let q = clamp(cc / cs, vec2f(-1.0), vec2f(1.0));\n let n2 = vec2f(q.x * abs(q.x), q.y * abs(q.y) * abs(q.y));\n let bev = smoothstep(-0.030, 0.0, dCup);\n let g2 = normalize(vec2f(cc.x / (cs.x * cs.x), cc.y / (cs.y * cs.y)) + vec2f(1e-4));\n let nn = mix(n2 * 0.62, g2 * 0.86, bev);\n let N = normalize(vec3f(nn.x * s, nn.y, sqrt(max(1.0 - min(dot(nn, nn), 1.0), 0.0)) + 0.10));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n var c = vec3f(0.125, 0.130, 0.145) * (0.20 + 1.05 * kd);\n c += keyCol * pow(max(dot(N, Hk), 0.0), 20.0) * 0.34;\n c += keyCol * pow(max(dot(N, Hk), 0.0), 90.0) * 0.55;\n // The softbox, as a long soft bar on the flank that faces it.\n c += keyCol * 0.16 * exp(-sq((cc.x * s + 0.030) / 0.022)) * smoothstep(0.24, -0.20, cc.y) * (1.0 - bev);\n // The ring: polished aluminium, a hair inside the edge.\n let ring = exp(-sq((dCup + 0.034) / 0.0075));\n c = mix(c, vec3f(0.50, 0.52, 0.56) * (0.25 + 1.0 * kd) + keyCol * 0.5 * pow(kd, 6.0), ring * 0.85);\n c += h.rim.rgb * 0.50 * pow(1.0 - N.z, 2.0) * clamp(0.5 + 0.5 * dot(N.xy, rimDir), 0.0, 1.0);\n c += vec3f(0.42, 0.52, 0.70) * 0.08 * pow(1.0 - N.z, 2.0) * clamp(0.5 - 0.5 * dot(N.xy, rimDir), 0.0, 1.0);\n col = mix(col, c, cC);\n al = al + (1.0 - al) * cC;\n }\n col = mix(col, col * vec3f(1.0, 0.88, 0.74), warm * 0.7) * keyK;\n let shade = 0.42 * exp(-max(d, 0.0) / 0.040) * (1.0 - al);\n return vec4f(col * al, al + shade) * h.pods.y;\n}\n\n// The bean. q0 is the pixel in units of the head's radius, from its centre. dU is the distance\n// (in the same units) to the edge of the one mass, if this head is part of one (else large),\n// and dDr to its drips. Returns premultiplied colour.\nfn bean(q0: vec2f, wpos: vec2f, h: Head, aa: f32, dU: f32, dDr: f32, gM: vec2f, E: Egg) -> vec4f {\n let p = E.p;\n let pe = E.pe;\n let k0 = E.k0;\n let open = clamp(h.mouth.x, 0.0, 1.35);\n let o1 = min(open, 1.0);\n let time = h.spare.y;\n let fl = h.flesh.x;\n let liq = h.flesh.w;\n let beat = h.flesh.z;\n let real = h.eyes.z;\n let chim = h.one.y;\n let metaK = h.one.x;\n let dHead = E.d;\n // Its silhouette: its own, or the mass's once it is part of one.\n let dSil0 = min(dHead, dU);\n if (dSil0 > aa + 0.14 * fl) { return vec4f(0.0); }\n // Flesh: one read of the baked texture at the scale of the head, one finer. As the two run\n // together both come to read it by where they are on the page, so it flows, and then runs\n // across the seam unbroken.\n var T1 = vec4f(0.0, 0.0, 0.5, 0.5);\n var T2 = T1;\n var mx = 9.0;\n var cW = vec2f(0.0);\n if (dU < 1e3) {\n cW = (wpos - u.host.xy) / u.host.z;\n // (How far it is from the cross where the four meet.)\n mx = min(abs(cW.x), abs(cW.y) * 1.5);\n }\n if (fl > 0.002) {\n let texel = 1024.0 / (h.pos.z * u.misc.z);\n let pu = mix(p + vec2f(h.spare.x * 1.2, h.spare.x * 0.37), cW, smoothstep(0.0, 0.85, metaK));\n // (A mip coarser than the screen needs: swells and blisters, wet, with nothing crinkled.)\n T1 = flesh(pu * 0.30, clamp(log2(texel * 0.30) + 1.7, 0.0, 3.0));\n // (Calm, only the coarse one shows.)\n if (chim < 0.7) { T2 = flesh(pu * 0.83 + vec2f(0.31, 0.2), clamp(log2(texel * 0.83) + 2.2, 0.0, 3.0)); } else { T2 = vec4f(T1.xy, 0.5, 0.5); }\n }\n // Blisters push its outline about too.\n let dSil = dSil0 - (0.100 * T1.y + 0.035 * T1.x) * smoothstep(0.2, 0.62, fl) * (1.0 - 0.55 * chim);\n if (dSil > aa) { return vec4f(0.0); }\n let cover = cov(dSil, aa);\n let keyK = h.spare.z;\n let warm = h.spare.w;\n let gloss = h.look.y;\n let em = h.look.z;\n\n // Where the features sit: the face turns a little on the egg.\n let pf = p - h.tilt3.zw;\n let right = pf.x > 0.0;\n let side = select(-1.0, 1.0, right);\n // (No two eyes in the mass are the same size.)\n let size = h.eye2.w * (1.0 + side * h.more2.x);\n let spacing = h.brow2.w;\n let eyeY = -0.105;\n let er = vec2f(0.160, 0.206) * size;\n let ep = pf - vec2f(side * spacing, eyeY);\n let en = ep / er;\n let e2 = dot(en, en);\n let e1 = sqrt(e2);\n let dEye = e1 * (e1 - 1.0) / max(length(en / er), 1e-4);\n\n // Lids. Each has a curve: the upper bows up when open, lies flat half shut, and sags when\n // it closes; a furrowed brow presses its inner end down. The lower rises in the middle.\n let lidU = select(h.eye.z, h.eye.w, right);\n let lidL = select(h.eye2.x, h.eye2.y, right);\n let browUp = select(h.brow.x, h.brow.y, right);\n let browAng = select(h.brow.z, h.brow.w, right);\n let browArch = select(h.brow2.x, h.brow2.y, right);\n let xn = en.x * side;\n let yLo = 1.06 - lidL * (0.98 - 0.36 * en.x * en.x);\n let yUp = mix(-1.06, yLo + 0.04, lidU) + mix(0.24, -0.26, lidU) * en.x * en.x - browAng * 0.42 * xn * (1.0 - 0.6 * lidU);\n let dTop = (yUp - en.y) * er.y;\n let dBot = (en.y - yLo) * er.y;\n let dOpen = max(dEye, max(dTop, dBot));\n let eyeCov = cov(dOpen, aa);\n let inEye = cov(dEye, aa);\n let onLid = inEye * (1.0 - eyeCov);\n\n // The surface normal: an egg, with a brow ridge and cheekbones modelled into it, a fine\n // orange peel in the clear coat, and the lids as domes of their own.\n var g = pe;\n // (Raw, it takes both brows wherever it is, so nothing changes down the middle of the face.)\n g += bump(pf, vec2f(side * spacing, eyeY - 0.30), vec2f(0.26, 0.10), 0.035);\n if (fl > 0.002) { g += bump(pf, vec2f(-side * spacing, eyeY - 0.30), vec2f(0.26, 0.10), 0.035); }\n g += bump(pf, vec2f(side * 0.44, 0.17), vec2f(0.22, 0.17), 0.03 + 0.03 * max(h.mouth.w, 0.0));\n g = mix(g, en * 0.62 + pe * 0.5, onLid * 0.8);\n var nd = normalize(pe + vec2f(1e-4));\n // Down the middle of the mass nothing belongs to one head or the other.\n let mid0 = smoothstep(0.3, 0.9, metaK);\n let midK = mid0 * (1.0 - smoothstep(0.16, 0.50, mx));\n // (So there it is lit as the page sees it, not as either head is tipped.)\n let rollA = h.pos.w * (1.0 - midK);\n var sinew = vec3f(0.0);\n var wF = 0.0;\n if (dU < 1e3) {\n // Part of the mass: away from its own egg the surface is the mass's, a rounded slab whose\n // slope comes from the distance to its edge. The two halves meet in a cleft.\n // Down the middle it is all the mass's, so the two halves are lit as one.\n let wB = max(max(clamp((dHead - dU) / 0.25, 0.0, 1.0), smoothstep(-0.12, 0.0, dHead)), midK);\n if (wB > 0.002) {\n let gU = rot(-rollA) * normalize(gM + vec2f(1e-6));\n let depth = mix(0.42, 0.03, step(dDr, dU + 0.012));\n // (The mass has no edge along its middle to lean away from: flat there, and no crease.)\n let gB = gU * (1.0 - smoothstep(0.0, depth, -dU)) * mix(1.0, smoothstep(0.03, 0.30, mx), mid0);\n g = mix(g, gB, wB);\n nd = normalize(mix(nd, gU, wB) + vec2f(1e-4));\n }\n // Between the faces, and up the trunk and down the stalk: sinew. The faces stay smooth.\n wF = smoothstep(0.25, 0.9, metaK) * (1.0 - smoothstep(0.20, 0.52, mx)) * smoothstep(0.0, -0.10, dU);\n if (wF > 0.002) { sinew = folds(cW); }\n }\n // Liquid: the surface rolls, and the softbox in it rolls with it.\n if (liq > 0.001) { g += liq * (1.0 - midK) * (1.0 - 0.6 * real) * 0.10 * vec2f(sin(p.y * 8.0 + time * 2.1 + h.spare.x), sin(p.x * 7.0 - time * 1.6 + h.spare.x * 2.0)); }\n\n // Where the shell has peeled, the flesh pushes the surface about.\n var peel = 0.0;\n var lip = 0.0;\n var gF = g;\n var hgt = 0.0;\n var hTex = 0.0;\n var v = 0.0; // on a vessel\n var vh = 0.0; // how far the skin stands up over it\n var vein = 0.0; // how lit it is from inside\n var wave = 0.0; // the heartbeat, running out along them\n var hue = 0.0; // crimson .. violet\n var wetK = 0.0;\n var wet = vec4f(0.0);\n var pkRing = 0.0; // where a tendril went in: the swollen ring round it,\n var pkHole = 0.0; // the hole,\n var pkGlow = 0.0; // and the light under the skin\n if (fl > 0.002) {\n let n1 = T1.zw * 2.0 - vec2f(1.0);\n let n2 = T2.zw * 2.0 - vec2f(1.0);\n // Vessels: swollen tubes under the skin, lit from inside. They spread from where the\n // tendril enters, every heartbeat runs out along them, and on the beat they stand up.\n let one = smoothstep(0.0, 0.85, metaK);\n let vr = veinRelief(mix(p * 2.0 + vec2f(h.spare.x * 3.0, h.spare.x), cW * 2.0 + vec2f(3.1, 1.7), one));\n v = vr.z;\n vh = vr.w;\n let dist0 = mix(length(pf - h.fuse.xy), length(cW), one);\n wave = 0.30 + 0.70 * pow(0.5 + 0.5 * sin(dist0 * 5.5 - time * 3.0), 3.0);\n hue = 0.5 + 0.5 * sin(dist0 * 2.6 + h.spare.x + 1.3 * cW.y * one);\n let reach = 1.0 - smoothstep(3.0 * fl - 0.30, 3.0 * fl + 0.25, dist0);\n let deep = 0.10 + 0.90 * smoothstep(0.30, 1.0, k0);\n let grown = reach * smoothstep(0.10, 0.5, fl);\n vein = v * deep * grown;\n g += vr.xy * (0.62 + 0.36 * beat) * grown;\n vh *= grown;\n // Where each tendril went in: the flesh has closed round it.\n // (vfx.js lands its three thickest in each of them at exactly these.)\n let ys = vec2f(1.0, h.more.x);\n let q1 = q0 - select(vec2f(0.60, -0.14), vec2f(0.40, 0.66) * ys, h.fuse.w > 0.0);\n let q2 = q0 - select(vec2f(0.50, -0.44), vec2f(0.56, 0.48) * ys, h.fuse.w > 0.0);\n let q3 = q0 - select(vec2f(0.58, 0.24), vec2f(0.22, 0.80) * ys, h.fuse.w > 0.0);\n var qn = q1;\n if (dot(q2, q2) < dot(qn, qn)) { qn = q2; }\n if (dot(q3, q3) < dot(qn, qn)) { qn = q3; }\n let qq = dot(qn, qn);\n let burrow = smoothstep(0.30, 0.42, fl) * (1.0 - 0.5 * chim);\n if (qq < 0.16 && burrow > 0.0) {\n let ql = sqrt(qq);\n let off = (ql - 0.105) / 0.05;\n pkRing = exp(-off * off) * burrow;\n pkHole = exp(-qq / 0.0050) * burrow;\n pkGlow = exp(-qq / 0.045) * burrow;\n g += qn / max(ql, 1e-3) * pkRing * off * 0.75;\n }\n // Slime: beads sliding down the lower half of it.\n wetK = smoothstep(0.5, 0.85, fl);\n let sc = mix(p, cW, one);\n if (wetK > 0.002 && sc.y > -0.6) {\n wet = slime(sc, time) * wetK * smoothstep(-0.6, 0.1, sc.y);\n }\n hgt = 0.6 * T1.x + 0.4 * T2.x;\n // Where it gives first: round where the tendril went in. Where it holds longest: the back\n // of the skull, away from the other one.\n let dn = pf - h.fuse.xy;\n let near = 0.34 * exp(-dot(dn, dn) * 1.3);\n let keep = 0.62 * smoothstep(0.42, 1.0, k0) * clamp(0.62 - 0.8 * h.fuse.w * nd.x - 0.6 * h.more.x * nd.y, 0.0, 1.0) * (1.0 - smoothstep(0.0, 0.5, metaK)) * (1.0 - smoothstep(0.98, 1.06, k0));\n let crack = 0.55 * T1.x + 0.38 * T1.y + 0.22 * T2.x + near - keep;\n let th = 1.22 - 1.42 * fl;\n peel = smoothstep(th - 0.05, th + 0.05, crack);\n lip = exp(-sq((crack - th) / 0.04)) * smoothstep(0.1, 0.3, fl);\n // Before it splits it blisters: domes come up under the clear coat.\n g += n1 * 0.75 * smoothstep(0.04, 0.22, fl) * smoothstep(0.08, 0.5, T1.y) * (1.0 - peel);\n // Calm, it smooths over: the raw ridges go, and what is left between the faces is the\n // sinew's own long swells under a wet skin.\n let raw = 1.0 - smoothstep(0.0, 0.7, max(chim, wF));\n gF = g + ((n1 * mix(0.07 * (1.0 - wF), 0.80, raw) + n2 * 0.22 * raw) + sinew.xy * 0.068 * wF) * peel + wet.xy;\n hTex = hgt;\n hgt = mix(hgt, 0.60 + 0.40 * sinew.z * wF, 1.0 - raw);\n }\n let gg = min(dot(g, g), 1.0);\n let Ns = normalize(vec3f(g, sqrt(max(1.0 - gg, 0.0)) + 0.02));\n let fr = 1.0 - clamp(Ns.z, 0.0, 1.0);\n\n // Lacquer under the studio. The softbox hangs upper left and shows in the clear coat as a\n // soft window bent round the egg, close to its edge; a second, smaller light answers it\n // upper right. They stay where the studio is when the head tips. The clear coat is not\n // perfectly flat, so the window's edge wanders by a hair.\n let roll = rot(rollA);\n let nw = roll * g + (h.tilt3.zw * 0.35 + liq * 0.05 * vec2f(sin(p.y * 6.5 + time * 1.9 + h.spare.x), cos(p.x * 6.0 + time * 1.4))) * (1.0 - midK);\n // (Where the shell is gone there is no clear coat to show it.)\n var sb = vec3f(0.0);\n if (peel < 0.995) { sb = softbox(nw, (vnoise(p * 30.0) - 0.5) * 0.004); }\n let lift = pow(clamp(0.5 + 0.5 * dot(Ns, FILL), 0.0, 1.0), 2.2);\n let keyCol = mix(vec3f(0.95, 0.975, 1.0), vec3f(1.0, 0.84, 0.62), warm);\n var fc = vec3f(0.008, 0.008, 0.011) + mix(vec3f(0.105, 0.110, 0.128), vec3f(0.125, 0.098, 0.066), warm) * (lift + 0.10 * sqrt(lift)) * keyK;\n var N = Ns;\n if (fl > 0.002) {\n // Under the lacquer: the vessels' light, crimson running to violet.\n let blood = mix(CRIMSON, VIOLET, hue * 0.7);\n fc += mix(blood, AMBER, clamp(v * v * 0.22 + 0.3 * beat, 0.0, 1.0)) * vein * (0.8 + 1.5 * beat) * wave;\n fc += MINT * pkGlow * (0.06 + 0.10 * beat);\n fc += MINT * vein * h.morph.w * 1.5;\n fc += CRIMSON * fl * (0.015 + 0.10 * beat) * pow(fr, 1.6);\n fc += keyCol * (sb.x + sb.y * 0.085 + sb.z * 0.26) * gloss * keyK;\n if (peel > 0.002) {\n // The meat. Nearly black in its creases and dark red on its ridges, paler where a\n // blister stretches it, bright where a vessel runs; and wet, so the softbox and two\n // harder lights break over every ridge. Calm, it goes darker still: obsidian, but meat.\n let g2 = min(dot(gF, gF), 1.0);\n let Nf = normalize(vec3f(gF, sqrt(max(1.0 - g2, 0.0)) + 0.02));\n var alb = mix(vec3f(0.060, 0.004, 0.010), vec3f(0.52, 0.035, 0.040), smoothstep(0.15, 0.85, hgt));\n // Blisters: deep red running to purple, not rust.\n alb = mix(alb, vec3f(0.50, 0.06, 0.17), T1.y * 0.45 * (1.0 - chim));\n // The top of every blister is thin, and full.\n alb = mix(alb, vec3f(0.78, 0.20, 0.17), smoothstep(0.55, 0.95, T1.y) * 0.5 * (1.0 - chim));\n // Calm, it is liver and oxblood, with pale fat in patches. Not chocolate.\n alb = mix(alb, mix(vec3f(0.150, 0.014, 0.024), vec3f(0.36, 0.030, 0.045), max(smoothstep(0.2, 0.8, hgt), wF * smoothstep(-0.2, 0.9, sinew.z))), chim * 0.84);\n alb = mix(alb, vec3f(0.62, 0.40, 0.33), smoothstep(0.62, 0.92, T2.x) * smoothstep(0.5, 0.2, T1.y) * 0.34 * chim);\n // Each vessel as wide as the skin it lifts, and wider on the beat.\n let vk = max(smoothstep(0.17 - 0.07 * beat, 0.46, vh), clamp(v * 1.15, 0.0, 1.0)) * (1.0 - 0.45 * wF);\n alb = mix(alb, mix(vec3f(0.80, 0.045, 0.035), vec3f(0.40, 0.030, 0.33), hue * 0.8), vk * mix(0.8, 0.95, chim));\n alb = mix(alb, vec3f(0.30, 0.025, 0.12), pkRing * 0.7);\n let dif = pow(clamp(0.5 + 0.5 * dot(Nf, KEY), 0.0, 1.0), 1.6);\n var ff = alb * (0.06 + 1.3 * dif) * keyK;\n ff *= 0.40 + 0.60 * smoothstep(0.05, 0.45, hgt);\n ff += vec3f(0.55, 0.03, 0.02) * pow(1.0 - Nf.z, 2.4) * (0.22 + 0.5 * beat) * (1.0 - 0.4 * chim);\n // Light comes through it where it is thin: red, at its edge.\n ff += vec3f(0.95, 0.07, 0.03) * exp(dSil / 0.07) * (0.30 + 0.25 * beat) * keyK;\n ff += blood * vk * (0.25 + 0.9 * beat) * wave * chim * 0.6;\n ff += MINT * vk * h.morph.w * 0.9;\n // (No softbox on meat: that is a product shot. One tight wet glint, and a broad dull one.)\n let hk = max(dot(Nf, normalize(KEY + vec3f(0.0, 0.0, 1.0))), 0.0);\n let sp = pow(hk, 64.0);\n ff += vec3f(1.0, 0.95, 0.92) * (sp * 1.15 + pow(hk, 9.0) * 0.07) * keyK;\n // Slime over all of it: a broad soft sheen, a pale film where it turns away, a bright\n // bead wherever one is sliding, and the track it leaves.\n let hk4 = sq(sq(hk));\n ff += vec3f(0.90, 1.0, 0.84) * (hk4 * hk4 * 0.11 + pow(1.0 - Nf.z, 2.0) * 0.065) * keyK * wetK;\n ff = mix(ff, ff * 1.35 + vec3f(0.075, 0.07, 0.05) * keyK, clamp(wet.z, 0.0, 1.0) * 0.55);\n ff += keyCol * wet.w * 0.085 * keyK;\n // Where a tendril went in: black down the hole, and the agent's colour under the skin.\n ff *= 1.0 - 0.88 * pkHole;\n ff += MINT * pkGlow * (0.10 + 0.20 * beat + 0.5 * h.morph.w);\n ff += vec3f(1.0, 0.80, 0.74) * pow(max(dot(Nf, vec3f(0.50, -0.30, 0.81)), 0.0), 60.0) * 0.55 * keyK;\n ff += vec3f(0.60, 0.72, 1.0) * pow(1.0 - Nf.z, 3.0) * 0.10 * chim * keyK;\n if (wF > 0.002) {\n // Wet sinew: a long light down the flank of every swell that faces the softbox, a\n // tighter glint inside it, and its folds in shadow.\n let strip = max(dot(Nf, vec3f(-0.42, -0.16, 0.893)), 0.0);\n let s2 = strip * strip;\n let s8 = sq(sq(s2));\n let s24 = s8 * s8 * s8;\n ff += keyCol * (s24 * 0.05 + sq(sq(s24)) * s24 * 0.42) * wF * keyK;\n ff *= 1.0 - 0.50 * wF * smoothstep(0.25, -1.0, sinew.z);\n }\n fc = mix(fc, ff, peel);\n N = normalize(mix(Ns, Nf, peel));\n }\n // The edge of what is left of the shell: curled up, bright along its lip, and a shadow\n // under it on the meat.\n fc += (vec3f(0.55, 0.56, 0.62) * keyK) * lip * (1.0 - peel) * 0.9;\n fc *= 1.0 - 0.6 * lip * peel;\n } else {\n fc += keyCol * (sb.x + sb.y * 0.085 + sb.z * 0.26) * gloss * keyK;\n }\n // The rim: light from behind, wrapping one side of the silhouette in the face's own colour.\n // A broad soft band where it faces the light, a bright line at the very edge, and almost\n // nothing on the far side.\n let rimDir = vec2f(cos(h.shape.w), sin(h.shape.w));\n let facing = clamp(0.5 + 0.5 * dot(nd, rimDir), 0.0, 1.0);\n let wrap = pow(facing, 1.7);\n let band = exp(dSil / (0.030 + 0.070 * wrap));\n let line = exp(dSil / 0.011);\n // (A drip gets no bright edge: outlined, it looks hollow.)\n let onDrip = step(dDr, dU + 0.012) * step(dU, 1e3);\n fc += h.rim.rgb * h.rim.w * (wrap * (band * 0.50 + line * 1.25) + 0.035 * line) * (1.0 - 0.45 * peel) * (1.0 - onDrip);\n // The far side picks up a little of the room: cool, and a warm bounce under the chin.\n fc += vec3f(0.42, 0.52, 0.70) * 0.11 * pow(1.0 - facing, 2.0) * (exp(dSil / 0.05) * 0.6 + line * 0.5) * keyK * (1.0 - peel);\n fc += vec3f(1.0, 0.70, 0.46) * 0.04 * smoothstep(0.25, 0.95, pe.y) * pow(fr, 1.5) * keyK;\n // Whatever is going off in the room: it wraps the side of the face turned to it, glints in\n // the clear coat, and lifts the whole face a little.\n var lit = vec3f(0.0);\n for (var l = 0; l < 4; l++) {\n let L = u.lights[l];\n if (L.pos.w > 0.004) {\n let dv = L.pos.xy - wpos;\n let dist = length(dv);\n let att = L.pos.w * exp(-dist / max(L.pos.z, 1.0));\n let Ld = normalize(vec3f(dv / max(dist, 1.0) * 0.9, 0.42));\n let nl = max(dot(N, Ld), 0.0);\n let hl = max(dot(N, normalize(Ld + vec3f(0.0, 0.0, 1.0))), 0.0);\n let toward = pow(max(dot(nd, normalize(Ld.xy + vec2f(1e-4))), 0.0), 1.4);\n fc += L.col.rgb * att * (0.03 + (0.15 + 0.35 * peel) * nl * nl + pow(hl, mix(260.0, 70.0, peel)) * (0.7 + 0.6 * peel) * gloss + toward * (exp(dSil / 0.10) * 0.85 + line * 1.3));\n lit += L.col.rgb * att;\n }\n }\n // The sockets: the lacquer dips to meet each eye, dark where it turns from the light and\n // bright along the wall that faces it.\n let out = max(dEye, 0.0);\n fc *= 1.0 - 0.66 * exp(-out / 0.034) * (1.0 - inEye);\n let eDir = normalize(ep + vec2f(1e-4));\n let wall = clamp(dot(eDir, vec2f(0.56, 0.78)), 0.0, 1.0);\n fc += (mix(vec3f(0.30, 0.31, 0.345), vec3f(0.70, 0.22, 0.19), real) * keyK + lit * 0.6) * exp(-sq((dEye - 0.020) / 0.012)) * wall * (1.0 - inEye);\n if (real > 0.002) {\n // Real lids: swollen, raw, a wet line of light on the one that faces the key.\n let toKey = dot(eDir, vec2f(-0.6, -0.72));\n let puff = exp(-sq((dEye - 0.050) / 0.042)) * (1.0 - inEye);\n fc = mix(fc, vec3f(0.44, 0.07, 0.058) * (1.0 - 0.6 * chim) * (0.42 + 0.75 * clamp(toKey * 0.5 + 0.5, 0.0, 1.0)) * keyK + lit * 0.25, puff * 0.72 * real);\n fc += vec3f(1.0, 0.9, 0.86) * pow(clamp(toKey, 0.0, 1.0), 6.0) * exp(-sq((dEye - 0.040) / 0.017)) * 0.7 * real * keyK * (1.0 - inEye);\n fc *= 1.0 - 0.5 * exp(-sq((dEye - 0.115) / 0.03)) * real * (1.0 - inEye);\n }\n\n // The lid's own edge, a fine bright margin, and a crease where it folds into the socket.\n if (onLid > 0.001) {\n let dEdge = max(min(dTop, 1.0) * step(0.0, dTop), min(dBot, 1.0) * step(0.0, dBot));\n let margin = (1.0 - smoothstep(0.004, 0.024, dEdge)) * onLid;\n fc = mix(fc, vec3f(0.30, 0.045, 0.04) * (1.0 - 0.6 * chim) * (0.5 + 0.7 * clamp(0.5 - en.y * 0.5 - en.x * 0.3, 0.0, 1.0)) * keyK, onLid * real * 0.85);\n fc = mix(fc, (mix(vec3f(0.24, 0.245, 0.27), vec3f(0.52, 0.17, 0.15), real) * keyK + lit * 0.5) * (0.5 + 0.7 * clamp(0.6 - en.x * 0.5 - en.y * 0.3, 0.0, 1.0)), margin * 0.9);\n fc *= 1.0 - 0.35 * exp(-sq((dEye + 0.012) / 0.012)) * onLid;\n }\n\n // The brow's shadow on the forehead, then (below) the brow. Once it has gone far enough\n // there are no brows: the flesh has them.\n let browK = h.eyes.y;\n let a = browAng * 0.62;\n let X = vec2f(side * cos(a), -sin(a));\n let Y = vec2f(side * sin(a), cos(a));\n let bc = vec2f(side * (spacing + 0.012), eyeY - 0.290 * size - 0.050 - browUp * 0.12);\n let bL = 0.172;\n let bT = 0.050 * h.brow2.z;\n let nearBrow = browK > 0.004 && abs(pf.y - bc.y) < 0.24;\n var bro = vec2f(1.0, 0.0);\n if (nearBrow) {\n bro = browAt(pf, bc, X, Y, bL, browArch, bT);\n let sh = browAt(pf - vec2f(0.016, 0.040), bc, X, Y, bL, browArch, bT).x;\n fc *= 1.0 - 0.62 * (1.0 - smoothstep(-0.022, 0.034, sh)) * browK;\n }\n\n // The eye: a ball. White that falls off to a cool grey round its curve, shadowed by the\n // upper lid; a dark glassy iris; two catchlights. Once it is flesh: yellowed and bloodshot,\n // with an amber iris and a pupil gone small with fright.\n if (eyeCov > 0.001) {\n let ez = sqrt(max(1.0 - e2, 0.0));\n let Ne = normalize(vec3f(en * 0.86, ez + 0.22));\n let kd = clamp(dot(Ne, KEY) * 0.5 + 0.5, 0.0, 1.0);\n var sc = mix(vec3f(0.43, 0.48, 0.60), mix(IVORY, h.rim.rgb, 0.06 * (1.0 - real)), smoothstep(0.0, 0.66, ez)) * (0.70 + 0.44 * kd) * mix(1.0, 0.8, 1.0 - keyK);\n if (real > 0.002) {\n var rs = mix(vec3f(0.58, 0.33, 0.32), vec3f(0.95, 0.90, 0.82), smoothstep(0.0, 0.7, ez)) * (0.62 + 0.50 * kd);\n let sv = veins(en * 1.75 + vec2f(h.spare.x * 2.0, side * 3.0)) * smoothstep(0.18, 0.95, e1);\n // Bloodshot: red in from the rim, every capillary standing out, redder on the beat.\n rs = mix(rs, vec3f(0.88, 0.30, 0.24), 0.60 * smoothstep(0.26, 1.0, e1));\n rs = mix(rs, vec3f(0.72, 0.035, 0.035), clamp(sv * (1.5 + 0.8 * beat), 0.0, 1.0));\n sc = mix(sc, rs, real);\n }\n sc *= 1.0 - (0.30 + 0.34 * smoothstep(0.1, 0.6, lidU)) * exp(-max(en.y - yUp, 0.0) / 0.30);\n sc *= 1.0 - 0.22 * exp(-max(yLo - en.y, 0.0) / 0.16);\n sc += lit * (0.30 + 0.5 * smoothstep(-0.4, 1.0, en.y));\n let ip = ep - vec2f(h.eye.x * 0.058, h.eye.y * 0.066) * size;\n let ri = 0.086 * size * (1.0 + 0.16 * real);\n let rp = ri * mix(0.60 + 0.30 * h.eye2.z, 0.24 + 0.40 * h.eye2.z, real);\n let dI = length(ip);\n let dP = dI - rp;\n let irisCov = cov(dI - ri, aa);\n sc *= 1.0 - 0.28 * exp(-max(dI - ri, 0.0) / (0.22 * ri)) * (1.0 - irisCov);\n var iris = vec3f(0.030, 0.034, 0.044) + vec3f(0.11, 0.13, 0.17) * smoothstep(-0.2, 1.0, ip.y / ri) * smoothstep(rp * 0.9, ri, dI);\n if (real > 0.002) {\n let th = atan2(ip.y, ip.x);\n let fib = 0.5 + 0.5 * sin(th * 34.0 + 2.0 * sin(th * 7.0 + h.spare.x));\n var ir = mix(vec3f(0.17, 0.065, 0.022), vec3f(0.78, 0.44, 0.13), fib * smoothstep(rp, ri * 0.92, dI));\n ir = mix(ir, vec3f(0.92, 0.62, 0.22), exp(-sq((dI - rp * 1.3) / (ri * 0.13))) * 0.6);\n iris = mix(iris, ir * (0.50 + 0.65 * kd), real);\n }\n iris += MINT * em * (0.22 + 0.7 * smoothstep(0.0, 1.0, ip.y / ri)) * smoothstep(rp * 0.5, ri, dI);\n iris *= 1.0 - mix(0.6, 0.8, real) * smoothstep(ri * 0.80, ri, dI);\n var eye = mix(sc, iris, irisCov);\n eye = mix(eye, vec3f(0.003), cov(dP, aa));\n // A softbox window, upper left, and a small round echo of it, lower right.\n // (It slides down as the lid comes down, so a half-shut eye still has some of it.)\n let c1 = sdRoundBox(rot(-0.55) * (ip - vec2f(-0.36, mix(-0.37, 0.16, smoothstep(0.25, 0.8, lidU))) * ri), vec2f(0.215, 0.135) * ri, 0.09 * ri);\n let c2 = length(ip - vec2f(0.37, 0.40) * ri) - 0.105 * ri;\n eye = mix(eye, mix(vec3f(1.55, 1.58, 1.62), vec3f(1.5, 1.3, 1.0), warm) * (0.35 + 0.65 * keyK), cov(c1, aa));\n eye = mix(eye, vec3f(0.86, 0.90, 0.96) * keyK, cov(c2, aa) * 0.8);\n // The monitor, in emerald, low in the eye.\n let c3 = sdRoundBox(ip - vec2f(0.0, 0.50) * ri, vec2f(0.40, 0.085) * ri, 0.06 * ri);\n eye = mix(eye, MINT * 2.4, cov(c3, aa) * em * cov(dI - ri * 0.96, aa));\n // The wet edge where the ball meets its lids: a shadow, or raw and red with a line of light.\n eye *= 1.0 - 0.5 * smoothstep(-0.020, 0.0, dOpen) * (1.0 - real);\n eye = mix(eye, vec3f(0.56, 0.065, 0.055), smoothstep(-0.030, 0.0, dOpen) * 0.85 * real);\n eye += vec3f(1.0, 0.95, 0.9) * exp(-sq((dBot + 0.014) / 0.006)) * 0.55 * keyK * real * (1.0 - en.x * en.x);\n fc = mix(fc, eye, eyeCov);\n }\n\n if (nearBrow && bro.x < aa) {\n let across = clamp(bro.y, -1.0, 1.0);\n let Nb = normalize(vec3f(Y * across * 0.92 + X * 0.06, sqrt(max(1.0 - across * across, 0.0)) + 0.16));\n let kd = clamp(dot(Nb, KEY), 0.0, 1.0);\n var bcol = mix(IVORY, h.rim.rgb, 0.05) * (0.52 + 0.60 * kd) * mix(1.0, 0.72, 1.0 - keyK);\n bcol *= mix(1.0, 0.72, smoothstep(0.2, 1.0, across));\n bcol += vec3f(1.0) * 0.16 * pow(max(dot(Nb, normalize(KEY + vec3f(0.0, 0.0, 1.0))), 0.0), 24.0) * keyK;\n bcol += lit * 0.55;\n fc = mix(fc, bcol, cov(bro.x, aa) * browK);\n }\n\n // More eyes. One in the middle of the forehead, which stays; two through the brow, and a\n // small one high on the cheek, which come while it is at its worst and close again after.\n let third = h.morph.y;\n let extra = h.eyes.x;\n if (pf.y < 0.2 && max(third, extra) > 0.004) {\n let gz = h.eye.xy;\n let pdx = h.eye2.z;\n let sd = h.spare.x;\n fc = orb(fc, pf - vec2f(0.03 * sin(sd * 3.0), -0.665), 0.150 * (0.62 + 0.62 * fract(sd * 0.73)), third, gz, pdx, sd + 1.0, lit, keyK, aa);\n if (extra > 0.004) {\n fc = orb(fc, rot(0.42) * (pf - vec2f(-0.50, -0.50)), 0.112, extra, gz * vec2f(1.0, 0.8) + vec2f(0.2, 0.0), pdx, sd + 2.0, lit, keyK, aa);\n fc = orb(fc, rot(-0.36) * (pf - vec2f(0.47, -0.545)), 0.098, extra * extra, gz + vec2f(-0.25, 0.1), pdx, sd + 3.0, lit, keyK, aa);\n fc = orb(fc, rot(-0.2 * h.fuse.w) * (pf - vec2f(-0.63 * h.fuse.w, 0.165)), 0.074, extra * extra, gz * 0.7, pdx, sd + 4.0, lit, keyK, aa);\n }\n }\n\n if (h.look.x > 0.5) {\n // Glasses: gold wire, with the light along the top of each rim, a sweep of the softbox in\n // each lens, and the monitor's lines of emerald when a change ships. They get knocked\n // crooked, and then the flesh takes them: what is left shows only where it rides high.\n let crook = h.eyes.w;\n let sunk = h.pods.z;\n let gf = rot(-0.21 * crook) * (pf - vec2f(0.03 * crook, eyeY - 0.005 + 0.07 * crook));\n let gs = select(-1.0, 1.0, gf.x > 0.0);\n let gp = gf - vec2f(gs * spacing, 0.0);\n let dLens = sdRoundBox(gp, vec2f(0.232, 0.180), 0.072);\n let inLens = step(dLens, 0.0);\n let shown = 1.0 - 0.7 * sunk * smoothstep(0.34, 0.56, hTex + 0.10 * gs * h.fuse.w);\n fc += vec3f(0.85, 0.92, 1.0) * 0.06 * keyK * exp(-sq((gp.x * 0.7 - gp.y - 0.05) / 0.045)) * inLens * shown;\n let rows = smoothstep(0.55, 0.9, sin((gp.y + time * 0.35) * 150.0)) * step(hash11(floor((gp.y + time * 0.35) * 23.9)), 0.3 + 0.5 * abs(gp.x) * 2.0);\n fc += MINT * em * inLens * (0.07 + 0.5 * rows * smoothstep(0.24, 0.0, abs(gp.x + 0.02 * gs)));\n let wire = 0.0125;\n let ring = abs(dLens) - wire;\n let tube = clamp(dLens / wire, -1.0, 1.0);\n let up = clamp(0.55 - 0.45 * tube * sign(gp.y) - gp.y * 1.9 - gs * gp.x * 0.5, 0.0, 1.0);\n var gold = vec3f(0.26, 0.15, 0.035) + vec3f(1.0, 0.72, 0.30) * (0.20 + 1.1 * pow(up, 2.0)) * keyK;\n gold += vec3f(1.0, 0.95, 0.8) * pow(up, 9.0) * 0.8 * keyK + lit * 0.5;\n // Its shadow on the face, then the wire.\n fc *= 1.0 - 0.45 * cov(abs(sdRoundBox(gp - vec2f(0.012, 0.022), vec2f(0.232, 0.180), 0.072)) - wire, aa * 2.0) * shown;\n fc = mix(fc, gold, cov(ring, aa) * shown);\n if (h.more2.y > 0.5 && gs > 0.0) {\n // One lens has cracked: three bright lines from where it was hit, and it is milky round them.\n let k0c = vec2f(0.07, -0.05);\n let cr = min(min(sdSegment(gp, k0c, vec2f(0.21, -0.16)), sdSegment(gp, k0c, vec2f(-0.14, 0.15))), min(sdSegment(gp, k0c, vec2f(0.19, 0.12)), sdSegment(gp, vec2f(-0.03, 0.05), vec2f(-0.20, -0.02))));\n fc = mix(fc, fc * 0.6 + vec3f(0.42, 0.46, 0.50) * keyK, inLens * exp(-cr / 0.05) * 0.5 * shown);\n fc += vec3f(1.0, 0.98, 0.94) * cov(cr - 0.0045, aa) * inLens * shown * (0.6 + 0.4 * keyK);\n }\n let dBridge = abs(length(vec2f(gf.x, (gf.y + 0.005) * 1.6)) - (spacing - 0.236)) - wire * 0.9;\n fc = mix(fc, gold, cov(dBridge, aa) * step(gf.y, -0.005) * shown);\n let dArm = sdSegment(vec2f(abs(gf.x), gf.y), vec2f(spacing + 0.24, -0.03), vec2f(1.0, -0.075)) - 0.0095;\n fc = mix(fc, gold * 0.85, cov(dArm, aa) * shown);\n }\n\n let mc = vec2f(h.mouth2.x * 0.03, 0.362 + 0.04 * o1) + h.tilt3.zw * 0.9;\n fc = mouthAt(fc, p - mc, h.mouth, h.mouth2, aa, lit, keyK, real);\n return vec4f(fc * cover, cover);\n}\n\n// What they wear. q0 is the pixel in units of the head's radius, from its centre. Returns\n// premultiplied colour.\n// 1 a knitted hat: a ribbed dome, a folded cuff low on the brow, a bobble on top\n// 2 a top-knot, and a headset: a capsule on the ear and a boom down to the corner of the\n// mouth with a ball of foam on the end\nfn hatAt(q0: vec2f, h: Head, aa: f32) -> vec4f {\n let kind = h.more.y;\n let p = rot(-h.pos.w) * q0;\n if (p.y > 0.75 || dot(p, p) > 2.2) { return vec4f(0.0); }\n let keyK = 0.45 + 0.55 * h.spare.z;\n let fl = h.flesh.x;\n let chim = h.one.y;\n let rimDir = vec2f(cos(h.shape.w), sin(h.shape.w));\n let Hk = normalize(KEY + vec3f(0.0, 0.0, 1.0));\n var col = vec3f(0.0);\n var al = 0.0;\n if (kind < 1.5) {\n if (p.y > -0.40) { return vec4f(0.0); }\n let rxh = h.shape.x * 0.845;\n // The dome, over the crown.\n let dc = p - vec2f(0.0, -0.56);\n let dr = vec2f(rxh, h.shape.y * 0.54);\n let dDome = max(sdEllipse(dc, dr), p.y + 0.56);\n // The cuff, folded up.\n let cc = p - vec2f(0.0, -0.585);\n let dCuff = sdRoundBox(cc, vec2f(rxh + 0.035, 0.095), 0.085);\n // The bobble.\n let bc = p - vec2f(0.06, -0.56 - dr.y - 0.07);\n let dBob = length(bc) - 0.135;\n let d = min(min(dDome, dCuff), dBob);\n if (d > aa + 0.05) { return vec4f(0.0); }\n let wool = mix(vec3f(0.60, 0.40, 0.085), vec3f(0.30, 0.035, 0.035), 0.55 * smoothstep(0.2, 0.8, fl)) * (1.0 - 0.35 * chim);\n // Dome: ribs that run up to the crown.\n let cD = cov(dDome, aa);\n if (cD > 0.001) {\n let nq = dc / dr;\n let z = sqrt(max(1.0 - min(dot(nq, nq), 1.0), 0.0));\n let rib = sin(atan2(nq.x, max(z, 0.05)) * 17.0);\n let N = normalize(vec3f(nq.x * 0.9 + 0.16 * rib * z, nq.y * 0.9, z + 0.12));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n var c = wool * (0.16 + 1.05 * kd * kd) * (0.86 + 0.14 * rib);\n c += h.rim.rgb * 0.5 * pow(1.0 - N.z, 2.0) * clamp(0.5 + 0.5 * dot(normalize(nq + vec2f(1e-4)), rimDir), 0.0, 1.0);\n col = c;\n al = cD;\n }\n let cB = cov(dBob, aa);\n if (cB > 0.001) {\n let nq = bc / 0.135;\n let z = sqrt(max(1.0 - min(dot(nq, nq), 1.0), 0.0));\n // (Fluff: its light is broken up.)\n let fz = vnoise(bc * 90.0 + vec2f(h.spare.x));\n let N = normalize(vec3f(nq * 0.9 + (fz - 0.5) * 0.5, z + 0.1));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n let c = wool * 1.12 * (0.18 + 1.05 * kd * kd) * (0.8 + 0.4 * fz) + h.rim.rgb * 0.4 * pow(1.0 - z, 2.0) * clamp(0.5 + 0.5 * dot(normalize(nq + vec2f(1e-4)), rimDir), 0.0, 1.0);\n col = mix(col, c, cB);\n al = al + (1.0 - al) * cB;\n }\n let cC = cov(dCuff, aa);\n if (cC > 0.001) {\n let v = clamp(cc.y / 0.095, -1.0, 1.0);\n let ux = clamp(cc.x / (rxh + 0.035), -1.0, 1.0);\n let rib = sin(cc.x * 58.0);\n let N = normalize(vec3f(ux * abs(ux) * 0.8 + 0.2 * rib, v * 0.72, sqrt(max(1.0 - v * v * 0.6, 0.0)) + 0.12));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n var c = wool * 0.92 * (0.16 + 1.08 * kd * kd) * (0.84 + 0.16 * rib);\n c += h.rim.rgb * 0.5 * pow(abs(ux), 5.0) * clamp(0.5 + 0.5 * sign(ux) * rimDir.x, 0.0, 1.0);\n // Dark where the cuff meets the dome above it.\n c *= 1.0 - 0.4 * smoothstep(-0.4, -1.0, v);\n col = mix(col, c, cC);\n al = al + (1.0 - al) * cC;\n }\n col *= keyK;\n // The shadow the cuff leaves on the forehead.\n let shade = 0.5 * exp(-max(dCuff, 0.0) / 0.035) * step(-0.56, p.y) * (1.0 - al);\n return vec4f(col * al, al + shade * step(length(p / vec2f(h.shape.x, h.shape.y)), 1.0));\n }\n // The top-knot: lacquer, like the head it is on, with a band round its root.\n let kc = p - vec2f(-0.03, -h.shape.y - 0.115);\n let dKnot = length(kc * vec2f(1.0, 1.12)) - 0.205;\n let cK = cov(dKnot, aa) * (1.0 - smoothstep(0.25, 0.6, fl));\n if (cK > 0.001) {\n let nq = kc / 0.205;\n let z = sqrt(max(1.0 - min(dot(nq, nq), 1.0), 0.0));\n let N = normalize(vec3f(nq * 0.92, z + 0.06));\n var c = vec3f(0.008, 0.008, 0.011) + vec3f(0.105, 0.110, 0.128) * pow(clamp(0.5 + 0.5 * dot(N, FILL), 0.0, 1.0), 2.2);\n c += vec3f(0.95, 0.975, 1.0) * (pow(max(dot(N, Hk), 0.0), 60.0) * 1.1 + pow(max(dot(N, Hk), 0.0), 8.0) * 0.06);\n let facing = clamp(0.5 + 0.5 * dot(normalize(nq + vec2f(1e-4)), rimDir), 0.0, 1.0);\n c += h.rim.rgb * pow(facing, 1.7) * (exp(dKnot / 0.05) * 0.5 + exp(dKnot / 0.011) * 1.25);\n // The band.\n c = mix(c, h.rim.rgb * 0.55 + vec3f(0.1), cov(abs(kc.y - 0.15) - 0.022, aa) * 0.9);\n col = c * keyK;\n al = cK;\n }\n // The headset, on the side away from the others.\n let s = -h.fuse.w;\n let ear = vec2f(s * (h.shape.x - 0.035), 0.0);\n let tipM = vec2f(s * 0.40, 0.52);\n let mid = vec2f(s * (h.shape.x + 0.02), 0.44);\n // (The boom: two straight runs, round the cheek.)\n let dBoom = min(sdSegment(p, ear + vec2f(0.0, 0.12), mid), sdSegment(p, mid, tipM)) - 0.021;\n let dCap = sdRoundBox(p - ear, vec2f(0.058, 0.135), 0.058);\n let dFoam = length(p - tipM) - 0.082;\n let dH = min(min(dBoom, dCap), dFoam);\n let gone = 1.0 - smoothstep(0.45, 0.8, fl);\n if (dH < aa + 0.04 && gone > 0.0) {\n var c = vec3f(0.11, 0.115, 0.13);\n let cb = cov(dBoom, aa);\n c = c * (0.5 + 0.9 * clamp(-dBoom / 0.021, 0.0, 1.0)) + vec3f(0.9, 0.93, 1.0) * 0.5 * exp(-sq((dBoom + 0.012) / 0.005));\n let cc2 = cov(dCap, aa);\n if (cc2 > 0.001) {\n let nq = (p - ear) / vec2f(0.058, 0.135);\n let z = sqrt(max(1.0 - min(dot(nq, nq), 1.0), 0.0));\n let N = normalize(vec3f(nq * 0.8, z + 0.2));\n let kd = clamp(dot(N, KEY) * 0.5 + 0.5, 0.0, 1.0);\n c = mix(c, vec3f(0.15, 0.155, 0.175) * (0.2 + 1.1 * kd) + vec3f(0.95, 0.97, 1.0) * pow(max(dot(N, Hk), 0.0), 30.0) * 0.6 + h.rim.rgb * 0.5 * pow(1.0 - z, 2.0), cc2);\n }\n let cf = cov(dFoam, aa);\n if (cf > 0.001) {\n let nq = (p - tipM) / 0.082;\n let z = sqrt(max(1.0 - min(dot(nq, nq), 1.0), 0.0));\n let kd = clamp(dot(normalize(vec3f(nq * 0.9, z + 0.1)), KEY) * 0.5 + 0.5, 0.0, 1.0);\n c = mix(c, vec3f(0.050, 0.052, 0.060) * (0.3 + 1.2 * kd) * (0.85 + 0.3 * vnoise(p * 140.0)) + h.rim.rgb * 0.12 * pow(1.0 - z, 2.0), cf);\n }\n let ch = max(max(cb, cc2), cf) * gone;\n let shade = 0.4 * exp(-max(dH, 0.0) / 0.03) * (1.0 - ch) * gone;\n col = mix(col, c * keyK, ch);\n al = al + (1.0 - al) * ch;\n return vec4f(col * al, al + shade * (1.0 - al));\n }\n return vec4f(col * al, al);\n}\n\n// A tile: the room, and (until it is part of the one mass) the head in it.\n@fragment fn fs(i: VO) -> FO {\n // The only derivative, taken before anything branches.\n let px = max(fwidth(i.world.x), fwidth(i.world.y));\n let h = u.heads[i.idx];\n let R = max(h.pos.z, 1.0);\n let aa = px * 1.1 / R;\n let tA = h.tileFx.x;\n let half = max(h.tile.zw, vec2f(1.0));\n\n // Into the tile's own space, with its lean (a pane tipped back in 2.5D).\n var tl = i.world - h.tile.xy;\n tl = tl / max(0.7, 1.0 + dot(tl / half, h.tilt3.xy) * 0.22);\n var dT = sdRoundBox(tl, h.tile.zw, h.tileFx.y);\n let fl = h.flesh.x;\n var sw = 0.0;\n if (fl > 0.001) { sw = swell(i.world, u.misc.x) * fl; }\n dT -= sw;\n var tileCov = cov(dT, px * 0.75);\n // The walls between the four are gone: toward the middle of the grid the room has no edge\n // any more, it thins out into the membrane. From the middle of the grid outward.\n let wallK = h.fuse.z;\n if (wallK > 0.001) {\n let sv = vec2f(h.fuse.w * tl.x, h.more.x * tl.y) - half;\n let fw = min(46.0, half.y * 0.34);\n let all = smoothstep(0.3, 0.85, wallK);\n let cx = smoothstep(-fw, -4.0, sv.x) * mix(1.0 - smoothstep(0.0, half.y * 1.5, -sv.y), 1.0, all);\n let cy = smoothstep(-fw, -4.0, sv.y) * mix(1.0 - smoothstep(0.0, half.x * 1.5, -sv.x), 1.0, all);\n tileCov *= 1.0 - 0.94 * smoothstep(0.0, 0.3, wallK) * max(cx, cy);\n }\n let tq = tl / half;\n let q = (tl - (h.pos.xy - h.tile.xy)) / R;\n\n var rgb = vec3f(0.0);\n var a = 0.0;\n var bg = vec3f(0.0);\n var hc = vec4f(0.0);\n // (A head on its own is nowhere near two of its radii from its middle. One that is part of\n // the mass is the mass's to draw.)\n if (h.more.w < 0.5 && dot(q, q) < 3.6) {\n let E = egg(q, h);\n hc = bean(q, i.world, h, aa, 1e4, 1e4, vec2f(0.0), E);\n if (h.more.y > 0.5) {\n let hat = hatAt(q, h, aa);\n hc = hat + hc * (1.0 - hat.a);\n }\n }\n // A face stays inside its tile until it is flesh. Flesh does not keep to a frame: a swollen\n // cheek comes out over the edge (no straight cut down the side of a screaming head).\n let ext = wallK * 12.0;\n let burst = smoothstep(0.25, 0.7, fl) * 30.0;\n let dTc = sdRoundBox(tl - vec2f(h.fuse.w, h.more.x) * ext, h.tile.zw + vec2f(ext) + vec2f(burst), h.tileFx.y + burst) - sw;\n let clip = mix(1.0, cov(dTc, px * 0.75), step(0.002, tA));\n var ha = hc * clip;\n if (h.pods.y > 0.002) {\n let pod = phonesAt(q, h, aa) * mix(1.0, tileCov, step(0.002, tA));\n ha = pod + ha * (1.0 - pod.a);\n }\n // (Behind a face there is no room to see, so none is worked out.)\n if (tA > 0.002 && ha.a < 0.998) {\n // The room each of them sits in: a dark wall, a pool of their own light behind the head,\n // and two lamps out of focus.\n let warm = h.spare.w;\n bg = mix(vec3f(0.066, 0.072, 0.080), vec3f(0.020, 0.022, 0.025), smoothstep(-1.0, 1.0, tq.y));\n bg = mix(bg, bg * vec3f(1.25, 1.0, 0.78), warm);\n let pool = (tl - (h.pos.xy - h.tile.xy)) / half - vec2f(0.0, 0.10);\n bg += h.rim.rgb * 0.085 * exp(-dot(pool, pool) * 2.0) * h.spare.z;\n let seed = h.spare.x;\n for (var k = 0; k < 2; k++) {\n let fk = f32(k);\n let c0 = vec2f(mix(-0.72, 0.72, hash11(seed * 3.1 + fk * 7.7)), mix(-0.78, -0.30, hash11(seed * 5.3 + fk * 2.9)));\n let rb = (0.11 + 0.09 * hash11(seed + fk * 11.0)) * half.y / half.x;\n let dB = length((tq - c0) * vec2f(1.0, half.y / half.x)) - rb;\n bg += mix(h.rim.rgb, vec3f(1.0, 0.86, 0.66), 0.35 + 0.4 * fk) * 0.032 * (1.0 - smoothstep(-0.05, 0.02, dB)) * (0.6 + 0.4 * h.spare.z);\n }\n bg *= 1.0 - 0.34 * dot(tq, tq) * 0.7;\n // The bean keeps the wall just behind it in shadow.\n let near = length(q / vec2f(h.shape.x, h.shape.y * 1.05)) - 1.0;\n bg *= 1.0 - 0.3 * exp(-max(near, 0.0) * 5.0);\n for (var l = 0; l < 4; l++) {\n let L = u.lights[l];\n if (L.pos.w > 0.004) { bg += L.col.rgb * L.pos.w * exp(-length(L.pos.xy - i.world) / max(L.pos.z, 1.0)) * 0.05; }\n }\n // A hairline at rest; a ring while this face has the floor; a bevel along the top edge.\n let ringOn = h.tileFx.z;\n let ringCol = mix(vec3f(0.78, 0.84, 0.94), mix(AMBER, CRIMSON, 0.45) * 1.25, clamp(fl * 3.0, 0.0, 1.0));\n if (fl > 0.002) {\n // The room is alive too: vessels come in from its border, and the wall warms. They\n // thin out round the head, so its outline has a dark margin.\n let v = veins(i.world * 0.015 + vec2f(h.spare.x, 0.0));\n // (A little way in while it is only breathing; all the way once it is one of them.)\n let depth = exp(dT / (20.0 + 110.0 * fl + 330.0 * fl * fl * fl));\n bg += mix(CRIMSON, AMBER, v * v * 0.25 + 0.2 * h.flesh.z) * v * depth * smoothstep(0.0, 0.15, fl) * (0.45 + 0.55 * smoothstep(0.34, 0.85, fl)) * (0.30 + 0.8 * h.flesh.z) * 1.6 * smoothstep(0.05, 0.75, near);\n bg += CRIMSON * 0.045 * fl * (0.4 + h.flesh.z);\n }\n // (Both are gone with the walls, at once: a bright line left along a seam is split into\n // colours by the lens.)\n let edges = 1.0 - smoothstep(0.0, 0.2, wallK);\n bg += vec3f(0.11, 0.115, 0.125) * cov(abs(dT + 0.75) - 0.5, px * 0.75) * (1.0 - ringOn) * (0.5 + 0.5 * smoothstep(0.4, -1.0, tq.y)) * edges;\n bg = mix(bg, ringCol * 1.05, cov(abs(dT + 1.0) - 1.0, px * 0.75) * ringOn * 0.9 * edges);\n bg += ringCol * 0.07 * ringOn * exp(dT / 14.0);\n }\n let ta = tileCov * tA;\n rgb = bg * ta * (1.0 - ha.a) + ha.rgb;\n a = ta + (1.0 - ta) * ha.a;\n // Dimmed, while Hex's offer is the only thing to look at.\n rgb *= 1.0 - h.tileFx.w;\n\n var o: FO;\n o.c = vec4f(rgb, a) * h.look.w;\n // How far this pixel moves while the shutter is open: with its face if it is on one, else\n // with its tile. A moving tile also claims the few pixels its blur will spill onto.\n let open = u.blur.z;\n o.v = vec4f(0.0);\n if (open > 0.0) {\n let vH = h.vel.xy + (i.world - h.pos.xy) * h.vel.z;\n let vT = h.tvel.xy + tq * h.tvel.zw;\n let v = mix(mix(vH, vT, step(0.002, tA)), vH, clamp(ha.a, 0.0, 1.0)) * open;\n let reach = length(v) * 0.5;\n let outside = max(mix(length(i.world - h.pos.xy) - R * 1.25, dT, step(0.002, tA)), 0.0);\n let spill = step(0.35, reach * u.misc.z) * (1.0 - smoothstep(0.0, reach + 1.0, outside));\n let va = max(a, spill) * h.look.w;\n o.v = vec4f(v * va, 0.0, va);\n }\n return o;\n}\n\n// The one mass, drawn once: a quad round all four heads, what hangs off them, and the bead.\n@vertex fn vsMass(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n o.idx = 0u;\n if (u.host.w <= 0.002) {\n o.pos = vec4f(9.0, 9.0, 9.0, 1.0);\n o.world = vec2f(0.0);\n return o;\n }\n var lo = vec2f(1e6);\n var hi = vec2f(-1e6);\n var pad = vec2f(0.0);\n for (var n = 0u; n < 4u; n++) {\n let h = u.heads[n];\n let r = h.pos.z * vec2f(1.5, 1.72);\n lo = min(lo, h.pos.xy - r);\n hi = max(hi, h.pos.xy + r);\n pad = max(pad, abs(h.vel.xy) * u.blur.z * 0.5);\n }\n // What drips off it falls as far as the bottom of the grid; the bead, a little further.\n let bottom = u.grid.y + u.grid.w + 4.0;\n if (u.host.w > 0.35) { hi.y = max(hi.y, bottom); }\n hi.y = min(hi.y, bottom);\n lo.y = max(lo.y, u.grid.y - u.grid.w - 4.0);\n if (u.host2.x > 0.0) { hi.y = max(hi.y, max(u.host2.x, u.host2.z) + u.host.z * 0.3); }\n let w = mix(lo - pad, hi + pad, CORNERS[vi]);\n o.pos = toClip(w);\n o.world = w;\n return o;\n}\n\n@fragment fn fsMass(i: VO) -> FO {\n let px = max(fwidth(i.world.x), fwidth(i.world.y));\n // Its slope comes from the screen: every pixel of it is in here, so the derivative is sound\n // everywhere (the module turns the uniformity check off for it).\n let ms = mass(i.world);\n let gM = vec2f(dpdx(ms.d.x), dpdy(ms.d.x));\n var o: FO;\n o.c = vec4f(0.0);\n o.v = vec4f(0.0);\n let R0 = u.host.z;\n if (ms.d.x > R0 * 0.2) { return o; }\n let h = u.heads[ms.idx];\n let R = max(h.pos.z, 1.0);\n let aa = px * 1.1 / R;\n let q = (i.world - h.pos.xy) / R;\n var hc = bean(q, i.world, h, aa, ms.d.x / R, ms.d.y / R, gM, ms.E);\n // What they had on, whoever's part of the mass it lies over. It goes under as they run\n // together.\n // (Not before the slam: until then it is a hat.)\n let worn = 1.0 - smoothstep(0.42, 0.85, u.host.w);\n if (worn > 0.0) {\n for (var n = 2u; n < 4u; n++) {\n let hh = u.heads[n];\n if (hh.more.y < 0.5) { continue; }\n let qh = (i.world - hh.pos.xy) / max(hh.pos.z, 1.0);\n if (dot(qh, qh) > 2.4) { continue; }\n let hat = hatAt(qh, hh, px * 1.1 / max(hh.pos.z, 1.0)) * worn;\n hc = hat + hc * (1.0 - hat.a);\n }\n }\n // The big one, in the middle of all of it. It opens last.\n let ce = u.host2.w;\n if (ce > 0.004 && hc.a > 0.5) {\n let c = (i.world - u.host.xy) / R0 - vec2f(0.03, 0.04);\n if (dot(c, c) < 0.36) {\n let a0 = u.heads[0];\n hc = vec4f(orb(hc.rgb, c, 0.30, ce, a0.eye.xy, a0.eye2.z, 9.3, vec3f(0.0), a0.spare.z, px * 1.1 / R0), hc.a);\n }\n }\n // It keeps to the grid (it is one room now), all but the bead.\n let dG = sdBox(i.world - u.grid.xy, u.grid.zw + vec2f(2.0), 18.0) - swell(i.world, u.misc.x) * u.misc.w;\n let clip = max(cov(dG, px * 0.75), cov(ms.d.z, px));\n o.c = hc * clip;\n let open = u.blur.z;\n if (open > 0.0) {\n let v = (h.vel.xy + (i.world - h.pos.xy) * h.vel.z) * open;\n let va = o.c.a * step(0.35, length(v) * 0.5 * u.misc.z);\n o.v = vec4f(v * va, 0.0, va);\n }\n return o;\n}\n"
|
|
export const TENDRILS = "// The whole frame in one uniform buffer. Offsets are mirrored by G in cast.js.\nstruct Head {\n pos: vec4f, // cx, cy, R, roll\n tile: vec4f, // cx, cy, half w, half h\n tileFx: vec4f, // alpha (0: no tile), corner radius, speaking ring, dim\n tilt3: vec4f, // tile lean x, y, face turn x, y\n eye: vec4f, // gaze x, y, upper lid L, R (0 open .. 1 shut)\n eye2: vec4f, // lower lid L, R, pupil dilation, eye size\n brow: vec4f, // raise L, R, angle L, R (+ furrowed: inner end down)\n brow2: vec4f, // arch L, R, weight, eye spacing\n mouth: vec4f, // open, wide, round, smile\n mouth2: vec4f, // smirk, tongue, jaw drop, -\n rim: vec4f, // rgb, strength\n look: vec4f, // glasses, gloss, the monitor's emerald in the eyes, alpha\n shape: vec4f, // rx, ry, stretch (y scale), rim angle\n vel: vec4f, // the face: x, y in px/s, growth per second, -\n tvel: vec4f, // the tile: x, y, half w, half h in px/s\n spare: vec4f, // seed, time, key light level, warmth\n flesh: vec4f, // veins under the lacquer, breath (-1..1), heartbeat (0..1), how liquid the surface is\n morph: vec4f, // -, third eye open, -, vein surge (emerald)\n fuse: vec4f, // where the tendril enters the face: x, y (in head radii), how far the walls of its tile have gone, which way the middle of the grid lies in x (-1, 0, 1)\n more: vec4f, // which way the middle of the grid lies in y (-1, 0, 1), what it wears (0 nothing, 1 a knitted hat, 2 a top-knot and a headset), how much wider its crown is than its jaw, 1 if the one mass draws it\n one: vec4f, // how far this head has run into the one mass, the calm dark wet look that comes after, terror, the drips' clock\n eyes: vec4f, // eyes pushed out through the brow (0 shut .. 1 open), brows (1 there .. 0 absorbed), how real the eyes are (bloodshot, wet), glasses knocked crooked\n pods: vec4f, // headphones: 0 above his head .. 1 on it, alpha, glasses sunk into the flesh, -\n more2: vec4f, // how unequal its two eyes are, 1 if a lens has cracked, which of the five it is, -\n}\nstruct Light { pos: vec4f, col: vec4f } // x, y, radius, intensity | rgb, -\nstruct Ring { a: vec4f, b: vec4f } // x, y, radius, width | strength, rgb\nstruct Burst { a: vec4f, b: vec4f, c: vec4f } // x, y, age, kind | half w, half h, speed, seed | count, life, size, -\nstruct Win { rect: vec4f, fx: vec4f } // cx, cy, half w, half h | alpha, corner radius, how alive, focus\nstruct Tendril { a: vec4f, b: vec4f, c: vec4f, d: vec4f } // p0, p1 | p2, p3 | grown 0..1, radius px, phase, kind (0 tendril, 1 strand, 2 sinew) | rgb, tip speed px/s\nstruct U {\n view: vec4f, // w, h, shake x, y\n misc: vec4f, // time, heads, dpr, flesh (how far the metamorphosis has gone)\n post: vec4f, // aberration, flash, grain, vignette\n pulse: vec4f, // heartbeat 0..1, breath -1..1, breath amount, seconds since the last beat\n blur: vec4f, // shake velocity x, y in px/s, seconds the shutter is open, 1 if anything blurs\n blur2: vec4f, // the screen's own breath: centre x, y, swell (px per px), -\n grade: vec4f, // crimson wash, tungsten, exposure, cold\n seam: vec4f, // how fused the two windows are, how far the walls between the four tiles have gone, 1 if the windows stack (seam is horizontal), -\n host: vec4f, // the one mass the four become: its middle x, y, a head's radius, how far it has gone\n grid: vec4f, // the four tiles as one box: cx, cy, half w, half h\n host2: vec4f, // the bead that hangs under the mass: where it hangs to (y), how far it has fallen (0 hanging .. 1 landed), where it lands (y), how open the eye in the middle of the mass is\n wins: array<Win, 2>,\n lights: array<Light, 4>,\n rings: array<Ring, 8>,\n bursts: array<Burst, 4>,\n heads: array<Head, 5>,\n tendrils: array<Tendril, 32>,\n}\n@group(0) @binding(0) var<uniform> u: U;\n\nconst CORNERS = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));\nconst MINT = vec3f(0.20, 0.95, 0.56);\nconst AMBER = vec3f(1.0, 0.56, 0.16);\nconst CRIMSON = vec3f(0.86, 0.07, 0.05);\nconst VIOLET = vec3f(0.50, 0.05, 0.44);\nconst PAGE = vec3f(0.02745);\n\nfn rot(a: f32) -> mat2x2f { let c = cos(a); let s = sin(a); return mat2x2f(c, s, -s, c); }\nfn sq(x: f32) -> f32 { return x * x; }\nfn toClip(w: vec2f) -> vec4f { return vec4f(w.x / u.view.x * 2.0 - 1.0, 1.0 - w.y / u.view.y * 2.0, 0.0, 1.0); }\nfn hash11(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }\nfn hash21(p: vec2f) -> f32 {\n var q = fract(p * vec2f(123.34, 456.21));\n q = q + dot(q, q + 45.32);\n return fract(q.x * q.y);\n}\nfn vnoise(p: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), w.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), w.x), w.y);\n}\nfn sdSegment(p: vec2f, a: vec2f, b: vec2f) -> f32 {\n let pa = p - a; let ba = b - a;\n let k = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n return length(pa - ba * k);\n}\nfn sdBox(p: vec2f, b: vec2f, r: f32) -> f32 {\n let q = abs(p) - b + vec2f(r);\n return length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - r;\n}\n// Smooth union: two shapes k px apart or less run together.\nfn smin(a: f32, b: f32, k: f32) -> f32 {\n let h = max(k - abs(a - b), 0.0) / max(k, 1e-3);\n return min(a, b) - h * h * k * 0.25;\n}\n// A living edge: how far (px) a surface swells at a point, with the breath.\nfn swell(w: vec2f, t: f32) -> f32 {\n return sin(w.y * 0.013 + t * 0.9) * sin(w.x * 0.011 - t * 0.7) * 5.0 + sin(w.y * 0.031 - t * 1.3 + w.x * 0.017) * 2.5 + u.pulse.y * 5.0 + u.pulse.x * 2.5;\n}\n// Filaments. Each is a cubic curve drawn as a tube: black lacquer under the softbox, with a\n// lit core like a fibre, and light running along it in packets.\n// kind 0 a fibre growing from its root (OpenCode) to its tip (the call). Once it is in, it\n// swallows: a swelling runs down it with every packet of light, and it is fatter\n// on the heartbeat\n// kind 1 a strand between two heads: it grows from both ends and meets in the middle, thick\n// at its roots and drawn thin where it is stretched\n// kind 2 a cord of sinew between two heads: the same, but meat, wet and striated, and it\n// never gets thin\nconst SEG = 44u;\n// Packets: what runs down a fibre toward the call. Two unrelated rates and a third that gates\n// them, so no two are the same size or the same distance apart. x is px along it.\nfn packets(x: f32, t: f32, id: f32) -> f32 {\n let a = 0.5 + 0.5 * sin(x * 0.047 - t * 6.1 + id * 1.7);\n let b = 0.5 + 0.5 * sin(x * 0.0173 - t * 3.7 + id * 4.1);\n let c = 0.5 + 0.5 * sin(x * 0.0061 + t * 0.9 + id * 2.3);\n let p = a * (0.35 + 0.65 * b);\n return sq(sq(p)) * p * smoothstep(0.25, 0.7, c + 0.25 * b);\n}\nstruct VO {\n @builtin(position) pos: vec4f,\n @location(0) c: f32, // across: -1..1 at the tube's edges (past them: padding for the antialiasing)\n @location(1) s: f32, // along: 0..1\n @location(2) nrm: vec2f,\n @location(3) tan: vec2f,\n @location(4) @interpolate(flat) idx: u32,\n @location(5) rad: f32,\n}\nstruct FO { @location(0) c: vec4f, @location(1) v: vec4f }\n\nfn radius(T: Tendril, s: f32, ii: u32) -> f32 {\n let g = T.c.x;\n if (T.c.w > 1.5) {\n let m = abs(2.0 * s - 1.0);\n return T.c.y * (0.46 + 0.54 * pow(m, 2.2)) * (0.86 + 0.14 * sin(s * 31.0 + f32(T.c.z))) * smoothstep(0.0, 0.5, g);\n }\n if (T.c.w > 0.5) {\n let m = abs(2.0 * s - 1.0);\n return T.c.y * (0.20 + 0.80 * pow(m, 1.8)) * (1.0 + 0.5 * exp(-sq((min(s, 1.0 - s) - g * 0.5) / 0.03)) * step(g, 0.98));\n }\n let root = 1.0 + 0.7 * exp(-s / 0.03);\n let taper = mix(1.0, 0.42, smoothstep(0.0, 1.0, s));\n // (Growing, its tip is swollen. Torn out and whipping back, it is only a frayed end.)\n // (A thick one's tip is hardly any thicker than it is: a swollen one that size is an arrowhead.)\n let bulb = 1.0 + mix(1.5, 0.35, smoothstep(2.0, 6.0, T.c.y)) * exp(-sq((s - g) / 0.022)) * step(g, 0.985) * step(-0.5, T.d.w);\n // Landed, it goes in: a swelling where the flesh has closed round it, then down to nothing.\n let land = mix(1.0, (1.0 + 0.45 * exp(-sq((1.0 - s - 0.05) / 0.022))) * (0.12 + 0.88 * smoothstep(0.0, 0.04, 1.0 - s)), smoothstep(0.96, 1.0, g));\n let gulp = packets(s * T.c.z, u.misc.x, f32(ii));\n let fed = smoothstep(0.9, 1.0, g) * smoothstep(1.6, 3.2, T.c.y);\n // It is not a cable: its width wanders, and it has a few nodules.\n let knot = 1.0 + 0.16 * sin(s * 23.0 + f32(ii) * 2.9) * sin(s * 7.3 + f32(ii)) + 0.30 * exp(-sq((fract(s * 3.0 + f32(ii) * 0.37) - 0.5) / 0.05));\n return T.c.y * root * taper * bulb * land * knot * (1.0 + fed * (0.55 * gulp + 0.16 * u.pulse.x));\n}\n\n@vertex fn vs(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> VO {\n let T = u.tendrils[ii];\n var o: VO;\n o.idx = ii;\n if (T.c.x <= 0.002 || T.c.y <= 0.0) {\n o.pos = vec4f(9.0, 9.0, 9.0, 1.0);\n return o;\n }\n let seg = vi / 6u;\n let cr = CORNERS[vi % 6u];\n // A fibre is only as long as it has grown; a strand is whole, and masked where it has not met.\n let reach = select(T.c.x, 1.0, T.c.w > 0.5);\n let s = (f32(seg) + cr.x) / f32(SEG) * reach;\n let k = 1.0 - s;\n let p = T.a.xy * (k * k * k) + T.a.zw * (3.0 * k * k * s) + T.b.xy * (3.0 * k * s * s) + T.b.zw * (s * s * s);\n let d = (T.a.zw - T.a.xy) * (3.0 * k * k) + (T.b.xy - T.a.zw) * (6.0 * k * s) + (T.b.zw - T.b.xy) * (3.0 * s * s);\n let tg = normalize(d + vec2f(1e-4, 0.0));\n let n = vec2f(-tg.y, tg.x);\n let r = radius(T, s, ii);\n let side = cr.y * 2.0 - 1.0;\n let pad = 1.5 / u.misc.z + abs(T.d.w) * u.blur.z * 0.25;\n o.pos = toClip(p + n * side * (r + pad));\n o.c = side * (r + pad) / max(r, 0.05);\n o.s = s;\n o.nrm = n;\n o.tan = tg;\n o.rad = r;\n return o;\n}\n\n@fragment fn fs(i: VO) -> FO {\n let T = u.tendrils[i.idx];\n let g = T.c.x;\n let t = u.misc.x;\n let ac = abs(i.c);\n let aw = fwidth(i.c) * 1.1;\n var cover = 1.0 - smoothstep(1.0 - aw, 1.0 + aw, ac);\n // Thinner than a pixel: keep the line, dimmer.\n cover *= clamp(i.rad * u.misc.z * 1.2, 0.25, 1.0);\n // A strand has no cut end: it comes up out of the lacquer it is rooted in.\n if (T.c.w > 0.5) { cover *= (1.0 - smoothstep(g * 0.5 - 0.004, g * 0.5 + 0.004, min(i.s, 1.0 - i.s))) * smoothstep(0.0, 0.16, min(i.s, 1.0 - i.s)); }\n // A fibre still growing ends in a round tip, not a cut.\n if (T.c.w < 0.5 && g < 0.985) {\n let e = (g - i.s) * T.c.z / max(i.rad, 0.5);\n if (e < 1.0) { cover *= 1.0 - smoothstep(1.0 - aw, 1.0 + aw, length(vec2f(i.c, 1.0 - e))); }\n }\n let c = clamp(i.c, -1.0, 1.0);\n let nz = sqrt(max(1.0 - c * c, 0.0));\n let N = normalize(vec3f(i.nrm * c, nz + 0.05));\n let H = normalize(vec3f(-0.50, -0.62, 1.55));\n let nh = max(dot(N, H), 0.0);\n // Lacquer.\n // (Powers by squaring: there are a lot of these pixels now the fibres are thick.)\n let nh8 = sq(sq(sq(nh)));\n let nh64 = sq(sq(sq(nh8)));\n var col = vec3f(0.010, 0.009, 0.011) + vec3f(0.07, 0.072, 0.082) * sq(clamp(0.5 + 0.5 * dot(N, vec3f(-0.42, -0.55, 0.72)), 0.0, 1.0));\n col += vec3f(0.95, 0.97, 1.0) * (nh64 * 1.6 + nh8 * 0.20) * smoothstep(0.6, 2.2, i.rad * u.misc.z);\n col += vec3f(0.42, 0.50, 0.66) * 0.22 * sq(1.0 - nz);\n // The core, and the light running down it toward the call.\n let core = exp(-sq(c / 0.5));\n let run = packets(i.s * T.c.z, t, f32(i.idx));\n let beat = u.pulse.x;\n let thick = smoothstep(1.0, 3.0, i.rad);\n // A thin one is a thread of light. A thick one is dark and wet, and only what it is\n // swallowing glows, as it goes by.\n var glow = T.d.rgb * (core * (mix(0.42, 0.03, thick) + mix(1.6, 2.3, thick) * run + mix(0.9, 0.10, thick) * beat) + mix(0.16, 0.0, thick) * nz);\n // Its growing tip is the brightest part of it.\n if (g < 0.985 && T.d.w > -0.5) {\n let tip = exp(-sq(select(i.s - g, min(i.s, 1.0 - i.s) - g * 0.5, T.c.w > 0.5) / 0.02));\n glow += mix(T.d.rgb, vec3f(1.0, 0.96, 0.9), 0.35) * tip * mix(2.0, 1.1, thick);\n }\n // Thick ones are sinew: dark red under the wet, striated along their length.\n let fibre = 0.5 + 0.5 * sin(c * 7.0 + 1.3 * sin(i.s * 31.0 + f32(i.idx) * 2.3));\n col = mix(col, col * 0.7 + vec3f(0.15, 0.012, 0.016) * (0.25 + 0.75 * fibre) * (0.3 + 0.7 * nz), thick * 0.85);\n col += vec3f(0.6, 0.04, 0.03) * 0.12 * thick * sq(1.0 - nz) * (0.5 + beat);\n col = col * mix(0.35, 1.0, thick) + glow * mix(1.3, 0.9, thick);\n // The last of it is down the hole it made.\n if (T.c.w < 0.5) { col *= mix(1.0, 0.10 + 0.90 * smoothstep(0.0, 0.045, 1.0 - i.s), smoothstep(0.96, 1.0, g)); }\n var alpha = cover * mix(0.55, 1.0, thick);\n if (T.c.w > 1.5) {\n // Sinew: fibres running its length, dark between them, wet all over.\n let fib = 0.5 + 0.5 * sin(c * 8.0 + 1.4 * sin(i.s * 27.0 + f32(i.idx) * 2.3));\n let Nf = normalize(vec3f(i.nrm * (c + 0.22 * cos(c * 8.0 + 1.4 * sin(i.s * 27.0 + f32(i.idx) * 2.3))), nz + 0.05));\n let nf = max(dot(Nf, H), 0.0);\n var m = mix(vec3f(0.035, 0.003, 0.006), vec3f(0.46, 0.05, 0.036), fib * 0.85) * (0.16 + 1.05 * pow(clamp(0.5 + 0.5 * dot(Nf, vec3f(-0.42, -0.55, 0.72)), 0.0, 1.0), 1.6));\n m += vec3f(1.0, 0.92, 0.88) * (pow(nf, 70.0) * 1.7 + pow(nf, 10.0) * 0.10);\n m += vec3f(0.75, 0.05, 0.03) * pow(1.0 - nz, 2.0) * (0.25 + 0.6 * beat);\n // Dark where it goes into each head.\n m *= 0.35 + 0.65 * smoothstep(0.0, 0.2, min(i.s, 1.0 - i.s));\n col = m * T.d.r / 0.62;\n alpha = cover;\n }\n var o: FO;\n o.c = vec4f(col * cover, alpha);\n let open = u.blur.z;\n let moving = select(smoothstep(g - 0.22, g, i.s), 0.0, T.c.w > 0.5);\n let v = i.tan * T.d.w * moving * open;\n let va = cover * step(0.5, length(v) * u.misc.z);\n o.v = vec4f(v * va, 0.0, va);\n return o;\n}\n"
|
|
export const PARTICLES = "// The whole frame in one uniform buffer. Offsets are mirrored by G in cast.js.\nstruct Head {\n pos: vec4f, // cx, cy, R, roll\n tile: vec4f, // cx, cy, half w, half h\n tileFx: vec4f, // alpha (0: no tile), corner radius, speaking ring, dim\n tilt3: vec4f, // tile lean x, y, face turn x, y\n eye: vec4f, // gaze x, y, upper lid L, R (0 open .. 1 shut)\n eye2: vec4f, // lower lid L, R, pupil dilation, eye size\n brow: vec4f, // raise L, R, angle L, R (+ furrowed: inner end down)\n brow2: vec4f, // arch L, R, weight, eye spacing\n mouth: vec4f, // open, wide, round, smile\n mouth2: vec4f, // smirk, tongue, jaw drop, -\n rim: vec4f, // rgb, strength\n look: vec4f, // glasses, gloss, the monitor's emerald in the eyes, alpha\n shape: vec4f, // rx, ry, stretch (y scale), rim angle\n vel: vec4f, // the face: x, y in px/s, growth per second, -\n tvel: vec4f, // the tile: x, y, half w, half h in px/s\n spare: vec4f, // seed, time, key light level, warmth\n flesh: vec4f, // veins under the lacquer, breath (-1..1), heartbeat (0..1), how liquid the surface is\n morph: vec4f, // -, third eye open, -, vein surge (emerald)\n fuse: vec4f, // where the tendril enters the face: x, y (in head radii), how far the walls of its tile have gone, which way the middle of the grid lies in x (-1, 0, 1)\n more: vec4f, // which way the middle of the grid lies in y (-1, 0, 1), what it wears (0 nothing, 1 a knitted hat, 2 a top-knot and a headset), how much wider its crown is than its jaw, 1 if the one mass draws it\n one: vec4f, // how far this head has run into the one mass, the calm dark wet look that comes after, terror, the drips' clock\n eyes: vec4f, // eyes pushed out through the brow (0 shut .. 1 open), brows (1 there .. 0 absorbed), how real the eyes are (bloodshot, wet), glasses knocked crooked\n pods: vec4f, // headphones: 0 above his head .. 1 on it, alpha, glasses sunk into the flesh, -\n more2: vec4f, // how unequal its two eyes are, 1 if a lens has cracked, which of the five it is, -\n}\nstruct Light { pos: vec4f, col: vec4f } // x, y, radius, intensity | rgb, -\nstruct Ring { a: vec4f, b: vec4f } // x, y, radius, width | strength, rgb\nstruct Burst { a: vec4f, b: vec4f, c: vec4f } // x, y, age, kind | half w, half h, speed, seed | count, life, size, -\nstruct Win { rect: vec4f, fx: vec4f } // cx, cy, half w, half h | alpha, corner radius, how alive, focus\nstruct Tendril { a: vec4f, b: vec4f, c: vec4f, d: vec4f } // p0, p1 | p2, p3 | grown 0..1, radius px, phase, kind (0 tendril, 1 strand, 2 sinew) | rgb, tip speed px/s\nstruct U {\n view: vec4f, // w, h, shake x, y\n misc: vec4f, // time, heads, dpr, flesh (how far the metamorphosis has gone)\n post: vec4f, // aberration, flash, grain, vignette\n pulse: vec4f, // heartbeat 0..1, breath -1..1, breath amount, seconds since the last beat\n blur: vec4f, // shake velocity x, y in px/s, seconds the shutter is open, 1 if anything blurs\n blur2: vec4f, // the screen's own breath: centre x, y, swell (px per px), -\n grade: vec4f, // crimson wash, tungsten, exposure, cold\n seam: vec4f, // how fused the two windows are, how far the walls between the four tiles have gone, 1 if the windows stack (seam is horizontal), -\n host: vec4f, // the one mass the four become: its middle x, y, a head's radius, how far it has gone\n grid: vec4f, // the four tiles as one box: cx, cy, half w, half h\n host2: vec4f, // the bead that hangs under the mass: where it hangs to (y), how far it has fallen (0 hanging .. 1 landed), where it lands (y), how open the eye in the middle of the mass is\n wins: array<Win, 2>,\n lights: array<Light, 4>,\n rings: array<Ring, 8>,\n bursts: array<Burst, 4>,\n heads: array<Head, 5>,\n tendrils: array<Tendril, 32>,\n}\n@group(0) @binding(0) var<uniform> u: U;\n\nconst CORNERS = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));\nconst MINT = vec3f(0.20, 0.95, 0.56);\nconst AMBER = vec3f(1.0, 0.56, 0.16);\nconst CRIMSON = vec3f(0.86, 0.07, 0.05);\nconst VIOLET = vec3f(0.50, 0.05, 0.44);\nconst PAGE = vec3f(0.02745);\n\nfn rot(a: f32) -> mat2x2f { let c = cos(a); let s = sin(a); return mat2x2f(c, s, -s, c); }\nfn sq(x: f32) -> f32 { return x * x; }\nfn toClip(w: vec2f) -> vec4f { return vec4f(w.x / u.view.x * 2.0 - 1.0, 1.0 - w.y / u.view.y * 2.0, 0.0, 1.0); }\nfn hash11(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }\nfn hash21(p: vec2f) -> f32 {\n var q = fract(p * vec2f(123.34, 456.21));\n q = q + dot(q, q + 45.32);\n return fract(q.x * q.y);\n}\nfn vnoise(p: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), w.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), w.x), w.y);\n}\nfn sdSegment(p: vec2f, a: vec2f, b: vec2f) -> f32 {\n let pa = p - a; let ba = b - a;\n let k = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n return length(pa - ba * k);\n}\nfn sdBox(p: vec2f, b: vec2f, r: f32) -> f32 {\n let q = abs(p) - b + vec2f(r);\n return length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - r;\n}\n// Smooth union: two shapes k px apart or less run together.\nfn smin(a: f32, b: f32, k: f32) -> f32 {\n let h = max(k - abs(a - b), 0.0) / max(k, 1e-3);\n return min(a, b) - h * h * k * 0.25;\n}\n// A living edge: how far (px) a surface swells at a point, with the breath.\nfn swell(w: vec2f, t: f32) -> f32 {\n return sin(w.y * 0.013 + t * 0.9) * sin(w.x * 0.011 - t * 0.7) * 5.0 + sin(w.y * 0.031 - t * 1.3 + w.x * 0.017) * 2.5 + u.pulse.y * 5.0 + u.pulse.x * 2.5;\n}\n// Motes. Four emitters of ninety-six: slow points of warm light adrift in front of the call\n// once it is alive. Nothing is simulated: each mote's place is a closed-form function of its\n// emitter's clock, so any frame can be drawn cold.\nconst PER = 96u;\nstruct VO {\n @builtin(position) pos: vec4f,\n @location(0) col: vec3f,\n @location(1) c: vec2f,\n}\n@vertex fn vs(@builtin(vertex_index) vi: u32, @builtin(instance_index) ii: u32) -> VO {\n var o: VO;\n o.pos = vec4f(9.0, 9.0, 9.0, 1.0);\n let b = u.bursts[ii / PER];\n let k = f32(ii % PER);\n if (k >= b.c.x || b.c.y <= 0.0) { return o; }\n let seed = b.b.w;\n let r0 = hash11(k * 1.37 + seed * 17.0);\n let r1 = hash11(k * 2.91 + seed * 5.3 + 1.0);\n let r2 = hash11(k * 0.73 + seed * 29.0 + 2.0);\n let r3 = hash11(k * 4.19 + seed * 3.1 + 3.0);\n let life = b.c.y * (0.5 + 0.5 * r1);\n let age = fract(b.a.z / life + r0) * life;\n let t = age / life;\n let p0 = b.a.xy + vec2f((r2 - 0.5) * 2.0 * b.b.x, (r3 - 0.5) * 2.0 * b.b.y);\n let pos = p0 + vec2f(sin(age * (0.7 + r1) + r0 * 6.28) * 14.0 + (r0 - 0.5) * 40.0 * t, -b.b.z * (0.4 + 0.6 * r2) * age);\n let size = b.c.z * (0.5 + 0.9 * r1);\n let c = CORNERS[vi] * 2.0 - vec2f(1.0);\n o.pos = toClip(pos + c * size);\n let warm = mix(mix(CRIMSON, AMBER, r1), MINT, step(0.9, r3));\n o.col = warm * smoothstep(0.0, 0.2, t) * smoothstep(1.0, 0.6, t) * (0.5 + 0.5 * sin(age * (3.0 + 4.0 * r2) + r0 * 6.0)) * (1.2 + 1.6 * u.pulse.x);\n o.c = c;\n return o;\n}\n@fragment fn fs(i: VO) -> @location(0) vec4f {\n let a = max(0.0, 1.0 - dot(i.c, i.c));\n return vec4f(i.col * a * a, 0.0);\n}\n"
|
|
export const BACKDROP = "// The whole frame in one uniform buffer. Offsets are mirrored by G in cast.js.\nstruct Head {\n pos: vec4f, // cx, cy, R, roll\n tile: vec4f, // cx, cy, half w, half h\n tileFx: vec4f, // alpha (0: no tile), corner radius, speaking ring, dim\n tilt3: vec4f, // tile lean x, y, face turn x, y\n eye: vec4f, // gaze x, y, upper lid L, R (0 open .. 1 shut)\n eye2: vec4f, // lower lid L, R, pupil dilation, eye size\n brow: vec4f, // raise L, R, angle L, R (+ furrowed: inner end down)\n brow2: vec4f, // arch L, R, weight, eye spacing\n mouth: vec4f, // open, wide, round, smile\n mouth2: vec4f, // smirk, tongue, jaw drop, -\n rim: vec4f, // rgb, strength\n look: vec4f, // glasses, gloss, the monitor's emerald in the eyes, alpha\n shape: vec4f, // rx, ry, stretch (y scale), rim angle\n vel: vec4f, // the face: x, y in px/s, growth per second, -\n tvel: vec4f, // the tile: x, y, half w, half h in px/s\n spare: vec4f, // seed, time, key light level, warmth\n flesh: vec4f, // veins under the lacquer, breath (-1..1), heartbeat (0..1), how liquid the surface is\n morph: vec4f, // -, third eye open, -, vein surge (emerald)\n fuse: vec4f, // where the tendril enters the face: x, y (in head radii), how far the walls of its tile have gone, which way the middle of the grid lies in x (-1, 0, 1)\n more: vec4f, // which way the middle of the grid lies in y (-1, 0, 1), what it wears (0 nothing, 1 a knitted hat, 2 a top-knot and a headset), how much wider its crown is than its jaw, 1 if the one mass draws it\n one: vec4f, // how far this head has run into the one mass, the calm dark wet look that comes after, terror, the drips' clock\n eyes: vec4f, // eyes pushed out through the brow (0 shut .. 1 open), brows (1 there .. 0 absorbed), how real the eyes are (bloodshot, wet), glasses knocked crooked\n pods: vec4f, // headphones: 0 above his head .. 1 on it, alpha, glasses sunk into the flesh, -\n more2: vec4f, // how unequal its two eyes are, 1 if a lens has cracked, which of the five it is, -\n}\nstruct Light { pos: vec4f, col: vec4f } // x, y, radius, intensity | rgb, -\nstruct Ring { a: vec4f, b: vec4f } // x, y, radius, width | strength, rgb\nstruct Burst { a: vec4f, b: vec4f, c: vec4f } // x, y, age, kind | half w, half h, speed, seed | count, life, size, -\nstruct Win { rect: vec4f, fx: vec4f } // cx, cy, half w, half h | alpha, corner radius, how alive, focus\nstruct Tendril { a: vec4f, b: vec4f, c: vec4f, d: vec4f } // p0, p1 | p2, p3 | grown 0..1, radius px, phase, kind (0 tendril, 1 strand, 2 sinew) | rgb, tip speed px/s\nstruct U {\n view: vec4f, // w, h, shake x, y\n misc: vec4f, // time, heads, dpr, flesh (how far the metamorphosis has gone)\n post: vec4f, // aberration, flash, grain, vignette\n pulse: vec4f, // heartbeat 0..1, breath -1..1, breath amount, seconds since the last beat\n blur: vec4f, // shake velocity x, y in px/s, seconds the shutter is open, 1 if anything blurs\n blur2: vec4f, // the screen's own breath: centre x, y, swell (px per px), -\n grade: vec4f, // crimson wash, tungsten, exposure, cold\n seam: vec4f, // how fused the two windows are, how far the walls between the four tiles have gone, 1 if the windows stack (seam is horizontal), -\n host: vec4f, // the one mass the four become: its middle x, y, a head's radius, how far it has gone\n grid: vec4f, // the four tiles as one box: cx, cy, half w, half h\n host2: vec4f, // the bead that hangs under the mass: where it hangs to (y), how far it has fallen (0 hanging .. 1 landed), where it lands (y), how open the eye in the middle of the mass is\n wins: array<Win, 2>,\n lights: array<Light, 4>,\n rings: array<Ring, 8>,\n bursts: array<Burst, 4>,\n heads: array<Head, 5>,\n tendrils: array<Tendril, 32>,\n}\n@group(0) @binding(0) var<uniform> u: U;\n\nconst CORNERS = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));\nconst MINT = vec3f(0.20, 0.95, 0.56);\nconst AMBER = vec3f(1.0, 0.56, 0.16);\nconst CRIMSON = vec3f(0.86, 0.07, 0.05);\nconst VIOLET = vec3f(0.50, 0.05, 0.44);\nconst PAGE = vec3f(0.02745);\n\nfn rot(a: f32) -> mat2x2f { let c = cos(a); let s = sin(a); return mat2x2f(c, s, -s, c); }\nfn sq(x: f32) -> f32 { return x * x; }\nfn toClip(w: vec2f) -> vec4f { return vec4f(w.x / u.view.x * 2.0 - 1.0, 1.0 - w.y / u.view.y * 2.0, 0.0, 1.0); }\nfn hash11(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }\nfn hash21(p: vec2f) -> f32 {\n var q = fract(p * vec2f(123.34, 456.21));\n q = q + dot(q, q + 45.32);\n return fract(q.x * q.y);\n}\nfn vnoise(p: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), w.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), w.x), w.y);\n}\nfn sdSegment(p: vec2f, a: vec2f, b: vec2f) -> f32 {\n let pa = p - a; let ba = b - a;\n let k = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n return length(pa - ba * k);\n}\nfn sdBox(p: vec2f, b: vec2f, r: f32) -> f32 {\n let q = abs(p) - b + vec2f(r);\n return length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - r;\n}\n// Smooth union: two shapes k px apart or less run together.\nfn smin(a: f32, b: f32, k: f32) -> f32 {\n let h = max(k - abs(a - b), 0.0) / max(k, 1e-3);\n return min(a, b) - h * h * k * 0.25;\n}\n// A living edge: how far (px) a surface swells at a point, with the breath.\nfn swell(w: vec2f, t: f32) -> f32 {\n return sin(w.y * 0.013 + t * 0.9) * sin(w.x * 0.011 - t * 0.7) * 5.0 + sin(w.y * 0.031 - t * 1.3 + w.x * 0.017) * 2.5 + u.pulse.y * 5.0 + u.pulse.x * 2.5;\n}\n// The notes' backdrop: what comes up out of the black round the card if you stay.\n//\n// Dark-oxblood tendrils creep in from the edges of the page toward the card, two layers of\n// them, a long way back in the dark: low, soft-edged, veiled, most there at the edge of the\n// page and all but gone by the card. Finer vessels run in the dark between them. It takes a\n// quarter of a minute to arrive. Nothing touches the card or the bean over it.\n//\n// They are shy. Where the pointer is (ambient.js keeps the places: the pointer, and where it\n// has just been), every tendril that runs through there draws its tip back out past it, toward\n// the edge it came from, thinning as it goes; let alone, it creeps back. Nothing is displaced:\n// every pixel is drawn from where it is.\n//\n// One full-screen triangle at the start of the scene pass. Everything is a function of the\n// seconds lingered, the page's clock and the shy places: a frame can be drawn on its own.\nstruct Bk {\n hole: vec4f, // the card and its bean: cx, cy, half w, half h (page px)\n st: vec4f, // seconds lingered, the page's clock, how far the hole is from the farthest corner (px), how many shy places\n shy: array<vec4f, 8>, // x, y, radius (px), how much the tissue there minds (0..1)\n}\n@group(1) @binding(0) var<uniform> b: Bk;\n@group(1) @binding(1) var vesselTex: texture_2d<f32>;\n@group(1) @binding(2) var vesselSamp: sampler;\n\nconst TAU = 6.2831853;\nconst OX_DEEP = vec3f(0.149, 0.020, 0.035); // #260509\nconst OX = vec3f(0.306, 0.043, 0.071); // #4e0b12\n// The two layers: how many tendrils, which ones, and how thick (px, half).\nconst FRONT = vec3f(18.0, 0.0, 14.0);\nconst BACK = vec3f(34.0, 2.7, 6.5);\n\n// Where a point is among a layer's n tendrils. v: from the middle of the card. dH: px from the\n// card. x: which tendril (whole part) and where across its cell (the rest): the angle, bent\n// two ways so that no tendril runs straight. (Whole turns of the angle only, so the circle\n// closes on itself.) y: how many px one cell is across there, the bends included.\nfn strand(v: vec2f, dH: f32, n: f32, seed: f32) -> vec2f {\n let ang = atan2(v.y, v.x);\n let p1 = dH * 0.0078 + ang * 3.0 + seed;\n let p2 = dH * 0.021 - ang * 4.0 + seed * 1.7;\n let sa = (n / TAU + 1.02 * cos(p1) - 0.60 * cos(p2)) / max(length(v), 1.0);\n let sd = 0.0078 * 0.34 * cos(p1) + 0.021 * 0.15 * cos(p2);\n return vec2f(ang / TAU * n + 0.34 * sin(p1) + 0.15 * sin(p2), 1.0 / max(sqrt(sa * sa + sd * sd), 1e-4));\n}\n\n// Each shy place, as the tendrils see it: which tendril of each layer runs through it, and how\n// far from the card it is. (Worked out three times a frame, here, not once a pixel.)\nstruct VO {\n @builtin(position) pos: vec4f,\n @location(0) uv: vec2f,\n @location(1) @interpolate(flat) f0: vec4f, @location(2) @interpolate(flat) f1: vec4f,\n @location(3) @interpolate(flat) k0: vec4f, @location(4) @interpolate(flat) k1: vec4f,\n @location(5) @interpolate(flat) d0: vec4f, @location(6) @interpolate(flat) d1: vec4f,\n}\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n let c = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u));\n o.pos = vec4f(c * 2.0 - vec2f(1.0), 0.0, 1.0);\n o.uv = vec2f(c.x, 1.0 - c.y);\n var f: array<f32, 8>;\n var k: array<f32, 8>;\n var d: array<f32, 8>;\n for (var n = 0; n < 8; n++) {\n let v = b.shy[n].xy - b.hole.xy;\n d[n] = sdBox(v, b.hole.zw, 60.0);\n f[n] = strand(v, d[n], FRONT.x, FRONT.y).x;\n k[n] = strand(v, d[n], BACK.x, BACK.y).x;\n }\n o.f0 = vec4f(f[0], f[1], f[2], f[3]); o.f1 = vec4f(f[4], f[5], f[6], f[7]);\n o.k0 = vec4f(k[0], k[1], k[2], k[3]); o.k1 = vec4f(k[4], k[5], k[6], k[7]);\n o.d0 = vec4f(d[0], d[1], d[2], d[3]); o.d1 = vec4f(d[4], d[5], d[6], d[7]);\n return o;\n}\nstruct FO { @location(0) c: vec4f }\n\n// One tendril's surface at a point: h its height there (0: not on it), x where across it\n// (-1..1), id which tendril, out how far outside it the point is (px), wide its half width.\n// near: 0 at its tip .. 1 some way behind it.\nstruct Tube { h: f32, x: f32, id: f32, out: f32, wide: f32, near: f32 }\n\n// A layer of tendrils round the card. v: from the middle of the card. dH: px from the card.\n// edge: px from the card to the edge of the page, this way. shied: how far the tendril here\n// has drawn back from the pointer (0..1).\n// Each tendril has a cell of the circle to itself: it sets out from the edge of the page, stops\n// short of the card (some far short, a few almost touching), and one tendril in two forks on\n// the way in.\nfn layer(v: vec2f, dH: f32, edge: f32, L: vec3f, shied: f32) -> Tube {\n let sc = strand(v, dH, L.x, L.y);\n let arc = sc.y;\n let id = floor(sc.x);\n let f = fract(sc.x) - 0.5;\n let h1 = hash11(id * 1.37 + L.y * 9.1);\n let h2 = hash11(id * 2.11 + L.y * 3.7 + 5.0);\n let h3 = hash11(id * 0.73 + L.y * 6.3 + 11.0);\n // How near the card it will get, and how far it has got: it sets out some time in the first\n // four seconds, takes eight to twelve to get there, and creeps for as long as you stay.\n let linger = b.st.x;\n let g = smoothstep(0.0, 1.0, (linger - h3 * 4.0) / (8.0 + 4.0 * h2));\n let tip = mix(edge + 24.0, 14.0 + 290.0 * h1 * h1, g) - min(12.0, 3.2 * log(1.0 + linger * 0.1) * (1.0 + h2));\n // (Shy of the pointer, its tip is back out past it: all the way to the edge, on the pointer's own line.)\n let reach = dH - max(tip, 8.0) - shied * (b.st.z + 60.0);\n var o = Tube(0.0, 0.0, id + L.y * 31.0, 1e4, 1.0, 0.0);\n if (reach <= 0.0) { return o; }\n o.near = smoothstep(0.0, 80.0, reach);\n let c0 = (h2 - 0.5) * 0.30;\n // The trunk: pointed at its tip, as wide as it gets a couple of hundred px behind it, and\n // thinner for being shy.\n let wide = min(L.z * (0.55 + 0.6 * h3) * (1.0 - exp(-reach / 150.0)) * (1.0 - 0.6 * shied) + 0.6, arc * 0.19);\n let lat = (f - c0) * arc;\n // The fork: it leaves the trunk some way behind the tip and leans into the empty side of the cell.\n let fork = reach - (50.0 + 230.0 * h3);\n let side = select(1.0, -1.0, c0 > 0.0);\n let latB = (f - c0 - side * 0.30 * smoothstep(0.0, 330.0, fork) * step(0.5, h1 + h3 * 0.6)) * arc;\n let wideB = wide * 0.6 * smoothstep(0.0, 70.0, fork);\n let dA = abs(lat) - wide;\n let dB = abs(latB) - wideB;\n if (dB < dA && wideB > 0.3) {\n o.x = latB / wideB; o.wide = wideB; o.out = dB;\n } else {\n o.x = lat / wide; o.wide = wide; o.out = dA;\n }\n o.h = sqrt(max(1.0 - o.x * o.x, 0.0));\n return o;\n}\n\n// What a tendril looks like: dull wet oxblood a long way from the light, the softbox's line\n// along it no more than a sheen, and the vein in it. tan: the direction across it.\nfn wet(T: Tube, tan: vec2f, rad: vec2f, dH: f32, t: f32, dim: f32) -> vec3f {\n // (It is not smooth: it is knotted along its length, which breaks the sheen up.)\n let knot = 0.26 * sin(dH * 0.083 + T.id * 4.1) + 0.16 * sin(dH * 0.21 + T.id * 1.3 + t * 0.4);\n let N = normalize(vec3f(tan * T.x + rad * knot * T.h, T.h * 0.9 + 0.12));\n let L = normalize(vec3f(-0.46, -0.60, 0.66));\n let H = normalize(L + vec3f(0.0, 0.0, 1.0));\n let nh = max(dot(N, H), 0.0);\n let nl = clamp(dot(N, L) * 0.5 + 0.5, 0.0, 1.0);\n var c = mix(OX_DEEP * 0.35, OX, nl * nl) * (0.5 + 0.5 * T.h);\n c += vec3f(0.46, 0.20, 0.19) * (pow(nh, 40.0) * 0.26 + pow(nh, 10.0) * 0.05);\n c += vec3f(0.30, 0.032, 0.048) * pow(1.0 - N.z, 3.0) * 0.30;\n // The vein, and the beat that runs down it toward the card: two close together, then a wait.\n // (ph: 0 at the head of a beat, rising behind it. Ahead of the head it comes up over a few px.)\n let ph = fract(dH * 0.0035 + t * 0.5 + hash11(T.id) * 0.3);\n let beat = max(exp(-ph * 9.0) + 0.6 * exp(-sq((ph - 0.2) * 14.0)), smoothstep(0.95, 1.0, ph));\n let core = exp(-sq((T.x - 0.28 * sin(dH * 0.045 + T.id)) * 2.4));\n c += vec3f(0.40, 0.036, 0.044) * core * T.h * (0.05 + 0.30 * beat);\n return c * dim;\n}\n\n@fragment fn fs(i: VO) -> FO {\n let w0 = i.uv * u.view.xy;\n let px = 1.0 / u.misc.z;\n let t = b.st.y;\n let linger = b.st.x;\n // The card and the bean are left alone.\n let v0 = w0 - b.hole.xy;\n let keep = smoothstep(4.0, 64.0, sdBox(v0, b.hole.zw, 30.0));\n if (keep <= 0.0 || linger <= 0.0) { return FO(vec4f(PAGE, 1.0)); }\n let d0 = sdBox(v0, b.hole.zw, 60.0);\n // How far out this is, from the card (0) to the edge of the page (1).\n let brim = min(min(w0.x, u.view.x - w0.x), min(w0.y, u.view.y - w0.y));\n let edge = max(d0, 0.0) + max(brim, 0.0);\n let out = clamp(d0 / max(edge, 1.0), 0.0, 1.0);\n\n // The shy places. here: the pointer is about here. shiedF, shiedB: it is on the line of the\n // tendril here (of the front layer, of the back), here or further out, so that tendril has\n // drawn its tip back through here. (Where the tendrils are when nothing is moving them: the\n // drift below sways them a little against it.)\n var here = 0.0;\n var accF = 0.0;\n var accB = 0.0;\n let places = i32(b.st.w);\n if (places > 0) {\n let sF = strand(v0, d0, FRONT.x, FRONT.y);\n let sB = strand(v0, d0, BACK.x, BACK.y);\n var pf = array<vec4f, 2>(i.f0, i.f1);\n var pk = array<vec4f, 2>(i.k0, i.k1);\n var pd = array<vec4f, 2>(i.d0, i.d1);\n for (var n = 0; n < places; n++) {\n let P = b.shy[n];\n let R2 = P.z * P.z;\n let q = w0 - P.xy;\n here += sq(sq(P.w * exp(-dot(q, q) / (R2 * 1.8))));\n // (All the way in from the pointer, and a radius or so out past it.)\n let along = P.w * exp(-sq(max(d0 - pd[n / 4][n % 4], 0.0)) / R2);\n var eF = sF.x - pf[n / 4][n % 4];\n eF -= FRONT.x * round(eF / FRONT.x);\n var eB = sB.x - pk[n / 4][n % 4];\n eB -= BACK.x * round(eB / BACK.x);\n accF += sq(sq(along * exp(-sq(eF * sF.y) / R2)));\n accB += sq(sq(along * exp(-sq(eB * sB.y) / R2)));\n }\n }\n // (Places close together run into one another: the wake of a stroke is one furrow.)\n here = min(sqrt(sqrt(here)), 1.0);\n let shiedF = min(sqrt(sqrt(accF)), 1.0);\n let shiedB = min(sqrt(sqrt(accB)), 1.0);\n\n // It is never still: a slow drift of the whole, and a quicker shiver.\n let q = w0 * 0.0042;\n let drift = vec2f(vnoise(q + vec2f(0.0, t * 0.055)), vnoise(q.yx + vec2f(5.2, -t * 0.047))) - vec2f(0.5);\n let w = w0 + drift * 96.0 + vec2f(sin(w0.y * 0.021 + t * 0.62), cos(w0.x * 0.019 - t * 0.53)) * 5.0;\n\n let v = w - b.hole.xy;\n let dH = sdBox(v, b.hole.zw, 60.0);\n let rad = v / max(length(v), 1e-3);\n let tan = vec2f(-rad.y, rad.x);\n let grown = smoothstep(0.0, 9.0, linger);\n var col = vec3f(0.0);\n\n // The dark is not empty: a breath of oxblood out toward the edges, and fine vessels in it,\n // which come in from the edge as the tendrils do.\n col += vec3f(0.020, 0.002, 0.004) * out * out * grown * (0.7 + 0.3 * sin(t * 0.9 + dH * 0.004));\n let s1 = textureSampleLevel(vesselTex, vesselSamp, w / 920.0 + vec2f(0.13, t * 0.004), 0.0).rgb;\n let s2 = textureSampleLevel(vesselTex, vesselSamp, w.yx / 1900.0 + vec2f(0.61, 0.27 - t * 0.002), 0.0).rgb;\n let wave = 0.35 + 0.65 * pow(0.5 + 0.5 * sin(dH * 0.03 + t * 1.6), 3.0);\n let fine = max(s1.r, s1.g * 0.5) + 0.5 * max(s2.r, s2.g * 0.5) + 0.12 * s1.b;\n let front = 1.0 - linger / 12.0;\n col += vec3f(0.115, 0.010, 0.015) * fine * smoothstep(front, front + 0.4, out) * wave;\n col *= 1.0 - 0.85 * here;\n\n // The tendrils: a thin layer behind, a thick one in front. Out of focus, the more so the\n // nearer the card: an edge is some px of blur, and a thread is lost in it.\n let soft = px + 1.2 + 2.6 * (1.0 - out);\n let back = layer(v, dH, edge, BACK, shiedB);\n let fore = layer(v, dH, edge, FRONT, shiedF);\n // (the light a tendril throws into the dark beside it)\n col += OX_DEEP * (0.14 * back.near * exp(-max(back.out, 0.0) / 14.0) + 0.26 * fore.near * exp(-max(fore.out, 0.0) / 24.0)) * grown;\n if (back.h > 0.0) {\n col = mix(col, wet(back, tan, rad, dH, t, 0.55), (1.0 - smoothstep(-soft, soft, back.out)) * smoothstep(0.3, 1.1, back.wide));\n }\n if (fore.h > 0.0) {\n col = mix(col, wet(fore, tan, rad, dH, t, 1.0), (1.0 - smoothstep(-soft, soft, fore.out)) * smoothstep(0.3, 1.1, fore.wide));\n }\n\n // And over all of it the dark between here and there: a veil that drifts, thin at the edge\n // of the page and whole by the card. What is left is a long way back.\n let fog = vnoise(w0 * 0.0031 + vec2f(t * 0.021, -t * 0.013)) * 0.65 + vnoise(w0 * 0.0083 - vec2f(t * 0.017, t * 0.009)) * 0.35;\n let through = pow(smoothstep(0.02, 1.0, out), 1.5) * (1.0 - 0.55 * fog);\n col = col * through + vec3f(0.012, 0.0015, 0.003) * fog * out * grown * (1.0 - 0.85 * here);\n return FO(vec4f(PAGE + col * keep, 1.0));\n}\n"
|
|
export const FLESH = "// Flesh. Baked once, at start, into a tiling texture every peeled surface reads (veins.wgsl):\n// red height: ridges of sinew running one way, bent by a slow warp, with vessels raised\n// on them and blisters pushed up through them\n// green the blisters alone\n// blue, alpha the slope of that height in x and y (a normal map), so a wet highlight can\n// break over every ridge for one texture read\n// Every noise here wraps, so the texture tiles.\nstruct VO { @builtin(position) pos: vec4f, @location(0) uv: vec2f }\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n let c = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u));\n o.pos = vec4f(c * 2.0 - vec2f(1.0), 0.0, 1.0);\n o.uv = vec2f(c.x, 1.0 - c.y);\n return o;\n}\nfn h2(p: vec2f) -> f32 {\n var q = fract(p * vec2f(0.1031, 0.1030));\n q = q + dot(q, q.yx + 33.33);\n return fract((q.x + q.y) * q.x);\n}\nfn h22(p: vec2f) -> vec2f { return vec2f(h2(p), h2(p + vec2f(17.3, 41.7))); }\nfn wrap(i: vec2f, per: vec2f) -> vec2f { return i - per * floor(i / per); }\nfn pn(p: vec2f, per: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n let a = h2(wrap(i, per));\n let b = h2(wrap(i + vec2f(1.0, 0.0), per));\n let c = h2(wrap(i + vec2f(0.0, 1.0), per));\n let d = h2(wrap(i + vec2f(1.0, 1.0), per));\n return mix(mix(a, b, w.x), mix(c, d, w.x), w.y);\n}\nfn fbm(p: vec2f, per: vec2f) -> f32 {\n return 0.5 * pn(p, per) + 0.25 * pn(p * 2.0 + vec2f(3.1, 7.3), per * 2.0) + 0.125 * pn(p * 4.0 + vec2f(9.7, 1.9), per * 4.0) + 0.0625 * pn(p * 8.0, per * 8.0);\n}\n// The nearest point of a jittered grid: its distance, and a number that is its own.\nfn cells(p: vec2f, per: vec2f) -> vec2f {\n let i = floor(p);\n let f = fract(p);\n var best = 9.0;\n var id = 0.0;\n for (var y = -1; y <= 1; y++) {\n for (var x = -1; x <= 1; x++) {\n let g = vec2f(f32(x), f32(y));\n let c = wrap(i + g, per);\n let o = g + 0.15 + 0.7 * h22(c) - f;\n let dd = dot(o, o);\n if (dd < best) { best = dd; id = h2(c + vec2f(5.5, 2.5)); }\n }\n }\n return vec2f(sqrt(best), id);\n}\nfn height(uv: vec2f) -> vec2f {\n let per = vec2f(8.0);\n let p = uv * 8.0;\n let w = vec2f(fbm(p + vec2f(1.7, 9.2), per), fbm(p + vec2f(8.3, 2.8), per)) - vec2f(0.47);\n let q = p + w * 1.7;\n // Sinew: ridged noise, four times as long as it is wide.\n let qs = q * vec2f(2.0, 0.5);\n let ps = vec2f(16.0, 4.0);\n var s = 0.0;\n var amp = 0.5;\n var f = 1.0;\n for (var o = 0; o < 4; o++) {\n let n = pn(qs * f + vec2f(f * 3.7, f * 1.3), ps * f);\n let r = 1.0 - abs(2.0 * n - 1.0);\n s += r * r * amp;\n amp *= 0.5;\n f *= 2.0;\n }\n // Vessels: thin and raised, where a slow noise crosses its middle.\n let v1 = 1.0 - smoothstep(0.0, 0.075, abs(pn(q + vec2f(31.7, 4.4), per) - 0.5));\n let v2 = (1.0 - smoothstep(0.0, 0.05, abs(pn(q * 2.0 + vec2f(5.1, 22.9), per * 2.0) - 0.5))) * 0.6;\n // Blisters: domes, a big one in some cells and small ones in a few more.\n let q2 = p + w * 0.5;\n let c1 = cells(q2, per);\n let dome = smoothstep(0.46, 0.04, c1.x) * step(0.45, c1.y);\n let c2 = cells(q2 * 2.5 + vec2f(2.2, 6.1), per * 2.5);\n let pox = smoothstep(0.36, 0.05, c2.x) * step(0.62, c2.y) * 0.55;\n let b = max(dome, pox);\n return vec2f(0.50 * s + 0.26 * max(v1, v2) + 0.50 * b, b);\n}\n@fragment fn fs(i: VO) -> @location(0) vec4f {\n let e = 1.0 / 1024.0;\n let h = height(i.uv);\n let hx = height(i.uv + vec2f(e, 0.0)).x;\n let hy = height(i.uv + vec2f(0.0, e)).x;\n let n = vec2f(h.x - hx, h.x - hy) * 26.0;\n return vec4f(clamp(h.x * 0.9, 0.0, 1.0), h.y, clamp(n * 0.5 + vec2f(0.5), vec2f(0.0), vec2f(1.0)));\n}\n// Its smaller copies, each from the one above.\n@group(0) @binding(0) var src: texture_2d<f32>;\n@group(0) @binding(1) var smp: sampler;\n@fragment fn down(i: VO) -> @location(0) vec4f { return textureSampleLevel(src, smp, i.uv, 0.0); }\n"
|
|
export const BLOOM_DOWN = "struct VO { @builtin(position) pos: vec4f, @location(0) uv: vec2f }\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n let c = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u));\n o.pos = vec4f(c * 2.0 - vec2f(1.0), 0.0, 1.0);\n o.uv = vec2f(c.x, 1.0 - c.y);\n return o;\n}\n// Keep only what is brighter than white, at a quarter of the size.\n@group(0) @binding(0) var src: texture_2d<f32>;\n@group(0) @binding(1) var samp: sampler;\n@fragment fn fs(i: VO) -> @location(0) vec4f {\n let px = 1.0 / vec2f(textureDimensions(src));\n var c = vec3f(0.0);\n for (var y = 0; y < 2; y++) {\n for (var x = 0; x < 2; x++) {\n let s = textureSampleLevel(src, samp, i.uv + (vec2f(f32(x), f32(y)) * 2.0 - vec2f(1.0)) * px, 0.0).rgb;\n c += max(s - vec3f(0.92), vec3f(0.0));\n }\n }\n return vec4f(min(c * 0.25, vec3f(6.0)), 1.0);\n}\n"
|
|
export const BLOOM_BLUR = "struct VO { @builtin(position) pos: vec4f, @location(0) uv: vec2f }\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n let c = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u));\n o.pos = vec4f(c * 2.0 - vec2f(1.0), 0.0, 1.0);\n o.uv = vec2f(c.x, 1.0 - c.y);\n return o;\n}\noverride DX: f32 = 1.0;\noverride DY: f32 = 0.0;\n@group(0) @binding(0) var src: texture_2d<f32>;\n@group(0) @binding(1) var samp: sampler;\n@fragment fn fs(i: VO) -> @location(0) vec4f {\n let step1 = vec2f(DX, DY) / vec2f(textureDimensions(src)) * 1.5;\n var c = vec3f(0.0);\n var wsum = 0.0;\n for (var k = -7; k <= 7; k++) {\n let w = exp(-f32(k * k) / 22.0);\n c += textureSampleLevel(src, samp, i.uv + step1 * f32(k), 0.0).rgb * w;\n wsum += w;\n }\n return vec4f(c / wsum, 1.0);\n}\n"
|
|
export const POST = "// The whole frame in one uniform buffer. Offsets are mirrored by G in cast.js.\nstruct Head {\n pos: vec4f, // cx, cy, R, roll\n tile: vec4f, // cx, cy, half w, half h\n tileFx: vec4f, // alpha (0: no tile), corner radius, speaking ring, dim\n tilt3: vec4f, // tile lean x, y, face turn x, y\n eye: vec4f, // gaze x, y, upper lid L, R (0 open .. 1 shut)\n eye2: vec4f, // lower lid L, R, pupil dilation, eye size\n brow: vec4f, // raise L, R, angle L, R (+ furrowed: inner end down)\n brow2: vec4f, // arch L, R, weight, eye spacing\n mouth: vec4f, // open, wide, round, smile\n mouth2: vec4f, // smirk, tongue, jaw drop, -\n rim: vec4f, // rgb, strength\n look: vec4f, // glasses, gloss, the monitor's emerald in the eyes, alpha\n shape: vec4f, // rx, ry, stretch (y scale), rim angle\n vel: vec4f, // the face: x, y in px/s, growth per second, -\n tvel: vec4f, // the tile: x, y, half w, half h in px/s\n spare: vec4f, // seed, time, key light level, warmth\n flesh: vec4f, // veins under the lacquer, breath (-1..1), heartbeat (0..1), how liquid the surface is\n morph: vec4f, // -, third eye open, -, vein surge (emerald)\n fuse: vec4f, // where the tendril enters the face: x, y (in head radii), how far the walls of its tile have gone, which way the middle of the grid lies in x (-1, 0, 1)\n more: vec4f, // which way the middle of the grid lies in y (-1, 0, 1), what it wears (0 nothing, 1 a knitted hat, 2 a top-knot and a headset), how much wider its crown is than its jaw, 1 if the one mass draws it\n one: vec4f, // how far this head has run into the one mass, the calm dark wet look that comes after, terror, the drips' clock\n eyes: vec4f, // eyes pushed out through the brow (0 shut .. 1 open), brows (1 there .. 0 absorbed), how real the eyes are (bloodshot, wet), glasses knocked crooked\n pods: vec4f, // headphones: 0 above his head .. 1 on it, alpha, glasses sunk into the flesh, -\n more2: vec4f, // how unequal its two eyes are, 1 if a lens has cracked, which of the five it is, -\n}\nstruct Light { pos: vec4f, col: vec4f } // x, y, radius, intensity | rgb, -\nstruct Ring { a: vec4f, b: vec4f } // x, y, radius, width | strength, rgb\nstruct Burst { a: vec4f, b: vec4f, c: vec4f } // x, y, age, kind | half w, half h, speed, seed | count, life, size, -\nstruct Win { rect: vec4f, fx: vec4f } // cx, cy, half w, half h | alpha, corner radius, how alive, focus\nstruct Tendril { a: vec4f, b: vec4f, c: vec4f, d: vec4f } // p0, p1 | p2, p3 | grown 0..1, radius px, phase, kind (0 tendril, 1 strand, 2 sinew) | rgb, tip speed px/s\nstruct U {\n view: vec4f, // w, h, shake x, y\n misc: vec4f, // time, heads, dpr, flesh (how far the metamorphosis has gone)\n post: vec4f, // aberration, flash, grain, vignette\n pulse: vec4f, // heartbeat 0..1, breath -1..1, breath amount, seconds since the last beat\n blur: vec4f, // shake velocity x, y in px/s, seconds the shutter is open, 1 if anything blurs\n blur2: vec4f, // the screen's own breath: centre x, y, swell (px per px), -\n grade: vec4f, // crimson wash, tungsten, exposure, cold\n seam: vec4f, // how fused the two windows are, how far the walls between the four tiles have gone, 1 if the windows stack (seam is horizontal), -\n host: vec4f, // the one mass the four become: its middle x, y, a head's radius, how far it has gone\n grid: vec4f, // the four tiles as one box: cx, cy, half w, half h\n host2: vec4f, // the bead that hangs under the mass: where it hangs to (y), how far it has fallen (0 hanging .. 1 landed), where it lands (y), how open the eye in the middle of the mass is\n wins: array<Win, 2>,\n lights: array<Light, 4>,\n rings: array<Ring, 8>,\n bursts: array<Burst, 4>,\n heads: array<Head, 5>,\n tendrils: array<Tendril, 32>,\n}\n@group(0) @binding(0) var<uniform> u: U;\n\nconst CORNERS = array<vec2f, 6>(vec2f(0, 0), vec2f(1, 0), vec2f(0, 1), vec2f(0, 1), vec2f(1, 0), vec2f(1, 1));\nconst MINT = vec3f(0.20, 0.95, 0.56);\nconst AMBER = vec3f(1.0, 0.56, 0.16);\nconst CRIMSON = vec3f(0.86, 0.07, 0.05);\nconst VIOLET = vec3f(0.50, 0.05, 0.44);\nconst PAGE = vec3f(0.02745);\n\nfn rot(a: f32) -> mat2x2f { let c = cos(a); let s = sin(a); return mat2x2f(c, s, -s, c); }\nfn sq(x: f32) -> f32 { return x * x; }\nfn toClip(w: vec2f) -> vec4f { return vec4f(w.x / u.view.x * 2.0 - 1.0, 1.0 - w.y / u.view.y * 2.0, 0.0, 1.0); }\nfn hash11(n: f32) -> f32 { return fract(sin(n * 127.1 + 311.7) * 43758.5453); }\nfn hash21(p: vec2f) -> f32 {\n var q = fract(p * vec2f(123.34, 456.21));\n q = q + dot(q, q + 45.32);\n return fract(q.x * q.y);\n}\nfn vnoise(p: vec2f) -> f32 {\n let i = floor(p);\n let f = fract(p);\n let w = f * f * (3.0 - 2.0 * f);\n return mix(mix(hash21(i), hash21(i + vec2f(1.0, 0.0)), w.x), mix(hash21(i + vec2f(0.0, 1.0)), hash21(i + vec2f(1.0, 1.0)), w.x), w.y);\n}\nfn sdSegment(p: vec2f, a: vec2f, b: vec2f) -> f32 {\n let pa = p - a; let ba = b - a;\n let k = clamp(dot(pa, ba) / max(dot(ba, ba), 1e-5), 0.0, 1.0);\n return length(pa - ba * k);\n}\nfn sdBox(p: vec2f, b: vec2f, r: f32) -> f32 {\n let q = abs(p) - b + vec2f(r);\n return length(max(q, vec2f(0.0))) + min(max(q.x, q.y), 0.0) - r;\n}\n// Smooth union: two shapes k px apart or less run together.\nfn smin(a: f32, b: f32, k: f32) -> f32 {\n let h = max(k - abs(a - b), 0.0) / max(k, 1e-3);\n return min(a, b) - h * h * k * 0.25;\n}\n// A living edge: how far (px) a surface swells at a point, with the breath.\nfn swell(w: vec2f, t: f32) -> f32 {\n return sin(w.y * 0.013 + t * 0.9) * sin(w.x * 0.011 - t * 0.7) * 5.0 + sin(w.y * 0.031 - t * 1.3 + w.x * 0.017) * 2.5 + u.pulse.y * 5.0 + u.pulse.x * 2.5;\n}\n// The lens: every shockwave bends the picture as it passes and splits its colours, the\n// shutter smears what moves, bloom is laid back on, then grain, a vignette and the grade.\n@group(1) @binding(0) var scene: texture_2d<f32>;\n@group(1) @binding(1) var bloom: texture_2d<f32>;\n@group(1) @binding(2) var motion: texture_2d<f32>;\n@group(1) @binding(3) var samp: sampler;\n// Where each of the six shutter taps sits in the spectrum, when the colours are being split.\nconst SPEC = array<f32, 6>(-0.2, 1.0, -0.6, 0.6, -1.0, 0.2);\nstruct VO { @builtin(position) pos: vec4f, @location(0) uv: vec2f }\n@vertex fn vs(@builtin(vertex_index) vi: u32) -> VO {\n var o: VO;\n let c = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u));\n o.pos = vec4f(c * 2.0 - vec2f(1.0), 0.0, 1.0);\n o.uv = vec2f(c.x, 1.0 - c.y);\n return o;\n}\n@fragment fn fs(i: VO) -> @location(0) vec4f {\n let res = u.view.xy;\n let w = i.uv * res - u.view.zw;\n var disp = vec2f(0.0);\n var split = vec2f(0.0);\n var streak = vec2f(0.0);\n var glow = vec3f(0.0);\n for (var r = 0; r < 8; r++) {\n let R = u.rings[r];\n if (R.b.x > 0.003) {\n let dv = w - R.a.xy;\n let d = length(dv);\n let x = (d - R.a.z) / max(R.a.w, 1.0);\n let e = exp(-x * x);\n let dir = dv / max(d, 1.0);\n disp -= dir * x * e * R.a.w * 0.7 * R.b.x;\n split += dir * e * R.b.x * 3.5;\n streak += dir * e * R.b.x * 8.0;\n glow += R.b.yzw * R.b.x * (e * 0.22 + exp(-x * x * 16.0) * 0.22);\n }\n }\n // The screen's own breath: the picture swells from the seam, least at the edges of the page.\n let bq = (w - u.blur2.xy) / res;\n disp += (w - u.blur2.xy) * u.blur2.w * (1.0 - smoothstep(0.25, 0.7, length(bq)));\n let uv = (w + disp) / res;\n // The colours split about the middle of whatever is happening (not the middle of the screen,\n // which splits one face and not the other), and by a pixel and a half at most: any more is a\n // rendering fault, not a lens.\n var ab = ((w - u.blur2.xy) * (u.post.x * 0.012) + split) / res;\n let abPx = length(ab * res) * u.misc.z;\n ab = ab * min(1.0, 1.5 / max(abPx, 1e-3));\n // The shutter: how far this pixel moves while it is open. Its own velocity (written by the\n // scene pass), the shake's, the push of the camera, and the streak of a ring going by.\n var v = vec2f(0.0);\n if (u.blur.w > 0.5) {\n v = (u.blur.xy + (w - u.blur2.xy) * u.blur2.z) * u.blur.z + streak;\n // (Only when the scene wrote it this frame: otherwise that target was not drawn to.)\n if (u.blur.w > 1.5) { v += textureSampleLevel(motion, samp, uv, 0.0).xy; }\n v = v * min(1.0, 64.0 / max(length(v), 1e-3));\n }\n let apart = ab * res;\n var col = vec3f(0.0);\n if (dot(v, v) * u.misc.z * u.misc.z > 0.6 || dot(apart, apart) > 16.0) {\n // Six taps along the path, jittered per pixel so the steps turn to grain. When the colours\n // are split too, each tap is also a step across the spectrum, for no more taps.\n let n = fract(52.9829189 * fract(dot(i.pos.xy, vec2f(0.06711056, 0.00583715))));\n let dv = v / res;\n var wsum = vec3f(0.0);\n let spread = smoothstep(1.0, 9.0, dot(apart, apart));\n for (var k = 0; k < 6; k++) {\n let sp = clamp(SPEC[k] + (n - 0.5) * 0.4, -1.0, 1.0);\n let c = textureSampleLevel(scene, samp, uv + dv * ((f32(k) + n) / 6.0 - 0.5) + ab * (sp / 0.6), 0.0).rgb;\n let band = max(vec3f(0.0), vec3f(1.0) - abs(vec3f(sp - 0.6, sp, sp + 0.6)) * 2.0);\n let wt = mix(vec3f(1.0), band, spread);\n col += c * wt;\n wsum += wt;\n }\n col = col / wsum;\n } else if (dot(apart, apart) > 0.0025) {\n col = vec3f(\n textureSampleLevel(scene, samp, uv + ab, 0.0).r,\n textureSampleLevel(scene, samp, uv, 0.0).g,\n textureSampleLevel(scene, samp, uv - ab, 0.0).b);\n } else {\n col = textureSampleLevel(scene, samp, uv, 0.0).rgb;\n }\n col += textureSampleLevel(bloom, samp, uv, 0.0).rgb * 0.95;\n col += glow;\n col += CRIMSON * u.grade.x * 0.014;\n col += vec3f(1.0, 0.88, 0.82) * u.post.y;\n col *= u.grade.z;\n // The grade: shadows lean a little green-teal, highlights a little warm; tungsten when the\n // room goes quiet.\n let lum = dot(col, vec3f(0.299, 0.587, 0.114));\n col = mix(col, vec3f(lum), 0.10);\n col *= mix(mix(vec3f(0.97, 1.0, 0.99), vec3f(1.04, 0.97, 0.95), u.misc.w), vec3f(1.03, 1.0, 0.95), smoothstep(0.0, 0.8, lum));\n col = mix(col, vec3f(lum) * vec3f(0.93, 0.98, 1.06), u.grade.w * 0.45);\n col = mix(col, col * vec3f(1.07, 0.98, 0.86), u.grade.y);\n let cq = i.uv - vec2f(0.5);\n col *= 1.0 - u.post.w * smoothstep(0.25, 0.95, length(cq * vec2f(1.0, 0.82)) * 1.5);\n // Grain, finer than a pixel can show standing still, and enough dither to keep the dark smooth.\n let g = hash21(i.pos.xy + vec2f(fract(u.misc.x * 7.31) * 311.0, fract(u.misc.x * 3.17) * 173.0)) - 0.5;\n // (Not in the black after Stop: that is black.)\n col += vec3f(g) * (u.post.z * (0.6 + 1.4 * sqrt(max(lum, 0.0))) + 1.0 / 255.0) * step(0.001, u.grade.z);\n return vec4f(max(col, vec3f(0.0)), 1.0);\n}\n"
|