{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ray-marched-potters-wheel-loader-that-pulls-up-a-wet-stoneware-bowl-in-a-sunlit-studio-and-stops-when-it-is-done","type":"registry:block","title":"Ray-Marched Potter's Wheel Loader That Pulls Up a Wet Stoneware Bowl in a Sunlit Studio and Stops When It Is Done","description":"Free React progress loader in one WebGL shader: a wet clay bowl rises on a spinning potter's wheel and the wheel coasts to a stop at 100%.","dependencies":[],"files":[{"path":"components/we-inc/ray-marched-potters-wheel-loader-that-pulls-up-a-wet-stoneware-bowl-in-a-sunlit-studio-and-stops-when-it-is-done.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// What the loader says while it works. `until` is the last percent that line covers.\nconst stages = [\n  { until: 12, note: \"Centring the clay\" },\n  { until: 30, note: \"Opening the ball\" },\n  { until: 58, note: \"Pulling up the walls\" },\n  { until: 84, note: \"Easing out the curve\" },\n  { until: 99, note: \"Smoothing the rim\" },\n  { until: 100, note: \"Done. The wheel is stopping\" },\n];\n// The self-running demo after the first bowl: [percent to reach, seconds to get there]. A repeated percent is a pause.\n// To show real progress, delete the demo block in the frame loop and write your own number to `s.goal`.\nconst demo: [number, number][] = [\n  [16, 2.0], [16, 0.5], [38, 2.2], [52, 1.6], [52, 0.5], [73, 2.0], [88, 1.6], [100, 1.8],\n];\nconst START = 93; // the percent it opens on: a tall wet bowl, already nearly thrown\nconst FIRST = 100; // the first run finishes the bowl so the opening seconds show it done\nconst HOLD = 3.4; // seconds the finished bowl sits on the stopped wheel before the next ball\nconst CLAY = [0.29, 0.17, 0.11]; // the dry body colour of the stoneware, linear RGB\nconst FONT = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif';\nconst SERIF = '\"Iowan Old Style\", \"Palatino Linotype\", Palatino, \"Book Antiqua\", Georgia, serif';\n\n// The bowl for a progress fraction p from 0 to 1: a ball of clay that opens, then rises and flares.\nconst shape = (p: number) => {\n  const q = Math.max(0, Math.min(1, p));\n  const open = q < 0.22 ? (q / 0.22) * (q / 0.22) * (3 - (2 * q) / 0.22) : 1;\n  const pull = Math.max(0, Math.min(1, (q - 0.16) / 0.84));\n  const ease = 1 - Math.pow(1 - pull, 1.6);\n  return {\n    H: 0.32 + (0.13 - 0.32) * open + 0.5 * ease, // height of the wall\n    rf: 0.46 - 0.14 * ease, // radius where it meets the wheel\n    rr: 0.48 + 0.34 * ease, // radius of the rim\n    w: (0.15 + (0.042 - 0.15) * ease) * open, // wall thickness\n    open,\n  };\n};\n\nconst VERT = `ATTR vec2 aPos; void main(){ gl_Position = vec4(aPos, 0.0, 1.0); }`;\nconst TONE = `\nvec3 tone(vec3 x){ x *= 0.9; vec3 a = x * (2.51 * x + 0.03); vec3 b = x * (2.43 * x + 0.59) + 0.14; return pow(clamp(a / b, 0.0, 1.0), vec3(1.0 / 2.2)); }\n`;\n\n// The photograph. A potter's wheel stands on a concrete floor in a studio; the sun comes in through a\n// window out of frame on the left. The wheel, its pan and the clay are ray marched as solids of revolution.\nconst SCENE = `\nprecision highp float;\nuniform vec2 uRes; uniform vec4 uJit; uniform vec3 uCam; uniform vec3 uTgt; uniform float uFoc; uniform vec2 uShift; uniform float uFocus;\nuniform vec4 uShape; uniform float uOpen; uniform float uSpin; uniform float uWet; uniform float uTime; uniform float uDirect; uniform vec3 uClay;\nconst float HT = 0.565;      // top of the wheel head\nconst float WZ = 2.7;        // the wall behind the wheel\nconst float WX = -5.2;       // the window in the left wall\nconst vec3 SUN = vec3(-0.70, 0.62, -0.36);\nconst vec3 SUNC = vec3(1.0, 0.85, 0.66) * 3.3;\nconst vec3 SKY = vec3(0.62, 0.72, 0.9);\nconst vec3 BC = vec3(0.0, 0.42, 0.0); // centre of the bounding sphere\n${TONE}\nfloat h31(vec3 p){ p = fract(p * 0.1031); p += dot(p, p.zyx + 31.32); return fract((p.x + p.y) * p.z); }\nfloat h21(vec2 p){ vec3 q = fract(vec3(p.xyx) * 0.1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }\nfloat n2(vec2 x){ vec2 i = floor(x); vec2 f = fract(x); f = f * f * (3.0 - 2.0 * f);\n  return mix(mix(h21(i), h21(i + vec2(1.0, 0.0)), f.x), mix(h21(i + vec2(0.0, 1.0)), h21(i + vec2(1.0, 1.0)), f.x), f.y); }\nfloat fbm(vec2 p){ return 0.5 * n2(p) + 0.25 * n2(p * 2.03 + 7.1) + 0.125 * n2(p * 4.01 + 3.3) + 0.0625 * n2(p * 8.1 + 1.7); }\nfloat rcyl(vec2 q, float r, float h, float rr){ vec2 d = vec2(q.x - r + rr, abs(q.y) - h + rr); return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)) - rr; }\nfloat seg(vec2 p, vec2 a, vec2 b){ vec2 pa = p - a, ba = b - a; float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); return length(pa - ba * h); }\nfloat smax(float a, float b, float k){ float h = clamp(0.5 - 0.5 * (b - a) / k, 0.0, 1.0); return mix(b, a, h) + k * h * (1.0 - h); }\nfloat smin(float a, float b, float k){ float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0); return mix(b, a, h) - k * h * (1.0 - h); }\n\n// ---- the clay ------------------------------------------------------------------------------------\n// outer radius at height y: a squat dome while it is a ball, a flaring bowl once it is opened\nfloat clayR(float y){\n  float H = uShape.x; float t = clamp(y / H, 0.0, 1.0);\n  float dome = uShape.y * sqrt(max(1.0 - t * t, 0.0) + 0.0004) * (1.0 + 0.08 * t);\n  float bowl = uShape.y + (uShape.z - uShape.y) * pow(sin(t * 1.5708), 0.72) + 0.03 * sin(t * 3.14159) * uOpen;\n  // throwing lines: the rings the fingers leave as they climb\n  float rings = sin(y * 92.0 + 1.7 * sin(y * 23.0)) * (0.6 + 0.4 * sin(y * 31.0 + 2.0));\n  return mix(dome, bowl, uOpen) + 0.0022 * rings * uOpen * smoothstep(0.03, 0.12, y) * smoothstep(H, H - 0.08, y);\n}\nfloat clayD(vec3 q){\n  float rho = length(q.xz); float y = q.y - HT; float H = uShape.x; float w = uShape.w;\n  float R = clayR(y);\n  float d = max((rho - R) * mix(0.32, 0.62, uOpen), max(-y, y - H));\n  if (uOpen > 0.02) {\n    float b = mix(H + 0.06, 0.075, uOpen);\n    float Ri = R - w + 0.003 * sin(y * 88.0 + 1.3);\n    float cav = smax((rho - Ri) * 0.62, b - y, 0.05);\n    d = max(d, -cav);\n    // a rounded rim, a little proud of the wall\n    float br = min(w * 0.5, 0.026);\n    vec2 rc = vec2(clayR(H) - w * 0.5, H - br * 0.6);\n    d = smin(d, length(vec2(rho, y) - rc) - br, 0.012);\n  }\n  // a skirt of slurry where the clay meets the wheel\n  d = smin(d, rcyl(vec2(rho, y - 0.004), uShape.y + 0.05, 0.006, 0.005), 0.03);\n  return d;\n}\n\n// ---- the wheel -----------------------------------------------------------------------------------\nfloat headD(vec3 q){ float rho = length(q.xz); return rcyl(vec2(rho, q.y - 0.53), 0.8, 0.035, 0.012); }\nfloat panD(vec3 q){\n  vec2 r = vec2(length(q.xz), q.y);\n  float d = min(seg(r, vec2(0.25, 0.44), vec2(1.2, 0.44)), seg(r, vec2(1.2, 0.44), vec2(1.36, 0.67))) - 0.016;\n  return min(d, length(r - vec2(1.365, 0.675)) - 0.026);\n}\nfloat bodyD(vec3 q){\n  vec2 r = vec2(length(q.xz), q.y);\n  float d = rcyl(r - vec2(0.0, 0.215), 1.0, 0.205, 0.07);\n  return min(d, rcyl(r - vec2(0.0, 0.47), 0.16, 0.06, 0.01));\n}\nvec2 objMap(vec3 q){\n  vec2 m = vec2(bodyD(q), 1.0);\n  float p = panD(q); if (p < m.x) m = vec2(p, 2.0);\n  float h = headD(q); if (h < m.x) m = vec2(h, 3.0);\n  float c = clayD(q); if (c < m.x) m = vec2(c, 4.0);\n  return m;\n}\nfloat sceneD(vec3 q){ return min(min(bodyD(q), panD(q)), min(headD(q), clayD(q))); }\n\n// ---- the window the sun comes through --------------------------------------------------------\nfloat pane(vec2 w, float soft){\n  float inside = smoothstep(-soft, soft, w.x - 0.25) * smoothstep(-soft, soft, 6.6 - w.x) * smoothstep(-soft, soft, w.y + 9.0) * smoothstep(-soft, soft, 3.4 - w.y);\n  vec2 c = vec2((w.x - 0.25) / 1.45, (w.y + 9.0) / 1.7);\n  vec2 e = (0.5 - abs(fract(c) - 0.5)) * vec2(1.45, 1.7);\n  return inside * smoothstep(0.045 - soft, 0.045 + soft, e.x) * smoothstep(0.045 - soft, 0.045 + soft, e.y);\n}\nfloat sunMask(vec3 p){ float t = (WX - p.x) / SUN.x; vec3 h = p + SUN * t; return pane(h.yz, 0.015 + t * 0.011); }\n\nvec3 env(vec3 rd){\n  vec3 c = mix(vec3(0.93, 0.82, 0.68), vec3(0.8, 0.84, 0.92), smoothstep(-0.1, 0.9, rd.y)) * 0.95;\n  if (rd.y < -0.02) c = vec3(0.62, 0.55, 0.48) * 1.0;\n  if (rd.x < -0.05) {\n    float t = WX / rd.x; vec2 w = vec2(1.0 + rd.y * t, rd.z * t);\n    c = mix(c, vec3(3.4, 3.6, 3.9), pane(w, 0.06));\n  }\n  // a big skylight overhead: the long soft highlight on wet clay and on the metal\n  c += vec3(2.6, 2.6, 2.5) * smoothstep(0.78, 0.9, rd.y) * smoothstep(0.45, 0.0, abs(rd.x + 0.1));\n  return c;\n}\n\nfloat shadow(vec3 ro, vec3 rd){\n  vec3 oc = ro - BC; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + 2.2;\n  if (h < 0.0) return 1.0;\n  h = sqrt(h); float tEnd = -b + h; float t = max(0.004, -b - h);\n  float res = 1.0;\n  for (int i = 0; i < 52; i++) {\n    if (t > tEnd) break;\n    float d = sceneD(ro + rd * t);\n    res = min(res, 8.0 * d / t);\n    if (res < 0.004) break;\n    t += clamp(d, 0.006, 0.14);\n  }\n  return clamp(res, 0.0, 1.0);\n}\nfloat objAO(vec3 p, vec3 n){\n  float o = 0.0; float w = 1.0;\n  for (int i = 1; i <= 5; i++) { float h = 0.03 * float(i * i); float d = sceneD(p + n * h); o += w * max(h - d, 0.0); w *= 0.62; }\n  return clamp(1.0 - 1.8 * o, 0.0, 1.0);\n}\n\n// ---- the room ----------------------------------------------------------------------------------\nvec3 floorC(vec3 p, vec3 rd){\n  vec3 n = vec3(0.0, 1.0, 0.0);\n  // sealed concrete, trowel clouds, a joint line, and clay dust that collects round the wheel\n  float m = fbm(p.xz * 0.9); float f = n2(p.xz * 40.0); float sp = h21(floor(p.xz * 140.0));\n  vec3 alb = vec3(0.47, 0.44, 0.41) * (0.82 + 0.3 * m + 0.05 * f) * (1.0 - 0.18 * step(0.985, sp));\n  float joint = smoothstep(0.012, 0.0, abs(fract((p.z + 1.6) / 3.2) - 0.5) * 3.2 - 1.588);\n  alb *= 1.0 - 0.35 * joint;\n  float r = length(p.xz);\n  float dust = smoothstep(2.3, 1.0, r) * (0.5 + 0.5 * fbm(p.xz * 3.0 + 4.0));\n  alb = mix(alb, uClay * 1.15 + 0.1, 0.35 * dust);\n  float sh = shadow(p + n * 0.002, SUN) * sunMask(p);\n  float ao = objAO(p, n);\n  vec3 col = alb * (SUNC * SUN.y * sh + SKY * 0.42 * ao + vec3(0.9, 0.7, 0.5) * 0.1 * ao);\n  vec3 rr = reflect(rd, normalize(n + vec3(f - 0.5, 0.0, m - 0.5) * 0.06));\n  float F = 0.04 + 0.96 * pow(1.0 - max(dot(-rd, n), 0.0), 5.0);\n  col += F * 0.35 * env(rr) * ao * (1.0 - 0.6 * dust);\n  return col;\n}\nvec3 wallC(vec3 p, vec3 rd){\n  vec3 n = vec3(0.0, 0.0, -1.0);\n  float m = fbm(p.xy * 1.4); float f = n2(p.xy * 55.0);\n  vec3 alb = vec3(0.9, 0.85, 0.77) * (0.88 + 0.14 * m + 0.04 * f);\n  float sh = shadow(p + n * 0.002, SUN) * sunMask(p);\n  return alb * (SUNC * max(dot(n, SUN), 0.0) * sh + SKY * 0.4 + vec3(1.0, 0.8, 0.6) * 0.2 + vec3(0.7, 0.6, 0.5) * 0.25 * smoothstep(1.2, 0.0, p.y));\n}\nvec3 room(vec3 ro, vec3 rd){\n  float t = 1e9; float kind = 0.0;\n  if (rd.y < 0.0) { float tf = -ro.y / rd.y; if (ro.z + rd.z * tf < WZ) { t = tf; kind = 1.0; } }\n  if (kind < 0.5 && rd.z > 0.0) { t = (WZ - ro.z) / rd.z; kind = 2.0; }\n  if (kind < 0.5) return env(rd);\n  vec3 p = ro + rd * t;\n  return kind < 1.5 ? floorC(p, rd) : wallC(p, rd);\n}\n\n// ---- materials ------------------------------------------------------------------------------------\nvec3 light(vec3 p, vec3 n, vec3 rd, vec3 alb, float gloss, float spec, float refl, float sh, float ao){\n  float dl = max(dot(n, SUN), 0.0);\n  vec3 col = alb * (SUNC * dl * sh + SKY * 0.45 * (0.55 + 0.45 * n.y) * ao + vec3(0.8, 0.6, 0.45) * 0.22 * max(-n.y, 0.0) * ao);\n  vec3 hv = normalize(SUN - rd);\n  col += SUNC * sh * spec * pow(max(dot(n, hv), 0.0), gloss) * (gloss + 8.0) / 60.0;\n  float F = 0.04 + 0.96 * pow(1.0 - max(dot(-rd, n), 0.0), 5.0);\n  col += F * refl * env(reflect(rd, n)) * ao;\n  return col;\n}\nvec3 shade(vec3 p, vec3 n, vec3 rd, float id){\n  float sh = shadow(p + n * 0.004, SUN) * sunMask(p);\n  float ao = objAO(p, n);\n  float rho = length(p.xz);\n  float a = atan(p.z, p.x);\n  if (id < 1.5) {\n    // the body: enamelled steel in a deep green-grey, a little worn and splashed\n    float m = fbm(vec2(a * 3.0, p.y * 6.0));\n    vec3 alb = vec3(0.075, 0.09, 0.085) * (0.85 + 0.3 * m);\n    alb = mix(alb, uClay * 0.9, 0.5 * smoothstep(0.72, 0.85, fbm(vec2(a * 9.0, p.y * 14.0) + 3.0)));\n    return light(p, n, rd, alb, 60.0, 0.5, 0.55, sh, ao);\n  }\n  if (id < 2.5) {\n    // the splash pan: off-white moulded plastic, slurry in the bottom and flung up the sides\n    float m = fbm(vec2(a * 5.0, rho * 8.0));\n    vec3 alb = vec3(0.5, 0.52, 0.5) * (0.92 + 0.1 * m);\n    float slip = smoothstep(0.5, 0.8, fbm(vec2(a * 6.0, rho * 4.0 + p.y * 9.0)) + 0.3 * smoothstep(0.5, 0.44, p.y) * smoothstep(1.25, 0.95, rho));\n    alb = mix(alb, uClay * 1.2 + 0.04, slip * 0.7);\n    return light(p, n, rd, alb, mix(30.0, 160.0, slip), mix(0.15, 0.9, slip), mix(0.25, 0.8, slip), sh, ao);\n  }\n  float as = a + uSpin;\n  if (id < 3.5) {\n    // the wheel head: cast aluminium, fine lathe rings, and smears of clay that turn with it\n    float ring = n2(vec2(rho * 520.0, 1.0)); float cent = smoothstep(0.004, 0.0, abs(fract(rho / 0.16) - 0.5) * 0.16 - 0.076);\n    vec3 F0 = vec3(0.86, 0.85, 0.83) * (0.86 + 0.14 * ring) * (1.0 - 0.4 * cent);\n    float smear = smoothstep(0.55, 0.8, fbm(vec2(as * 2.2, rho * 6.0))) * smoothstep(0.3, 0.5, rho);\n    smear = max(smear, step(0.78, rho) * 0.6 * smoothstep(0.4, 0.7, fbm(vec2(as * 7.0, 2.0))));\n    vec3 r = reflect(rd, normalize(n + vec3(ring - 0.5) * 0.03));\n    vec3 hv = normalize(SUN - rd);\n    vec3 metal = F0 * (0.75 * env(r) * ao + SUNC * sh * 0.6 * pow(max(dot(n, hv), 0.0), 50.0));\n    vec3 clay = light(p, n, rd, uClay * 0.7, 120.0, 0.8, 0.7, sh, ao);\n    return mix(metal, clay, smear);\n  }\n  // the clay: wet stoneware. Slip streaks run round the wall and turn with the wheel; the wet sheen\n  // breaks into bands where the fingers have just passed, and dulls once the wheel stops.\n  float y = p.y - HT;\n  float st = fbm(vec2(as * 2.5, y * 34.0)); float fine = n2(vec2(as * 30.0, y * 260.0));\n  vec3 alb = uClay * (0.78 + 0.34 * st + 0.08 * fine);\n  alb *= mix(1.25, 0.72, uWet); // wet clay is darker\n  float wetBand = mix(0.55, 1.0, smoothstep(0.3, 0.7, n2(vec2(as * 1.5, y * 22.0))));\n  float wet = uWet * wetBand;\n  vec3 nb = normalize(n + vec3(cos(a), 0.0, sin(a)) * (fine - 0.5) * 0.12 * uOpen);\n  return light(p, nb, rd, alb, mix(10.0, 260.0, wet), mix(0.05, 1.8, wet), mix(0.03, 1.0, wet), sh, ao);\n}\n\nvec3 nObj(vec3 q){ vec2 e = vec2(0.0007, 0.0); return normalize(vec3(objMap(q + e.xyy).x - objMap(q - e.xyy).x, objMap(q + e.yxy).x - objMap(q - e.yxy).x, objMap(q + e.yyx).x - objMap(q - e.yyx).x)); }\n\nvec3 render(vec3 ro, vec3 rd){\n  vec3 oc = ro - BC; float b = dot(oc, rd); float h = b * b - dot(oc, oc) + 2.2;\n  if (h < 0.0) return room(ro, rd);\n  h = sqrt(h); float t = max(0.0, -b - h); float tEnd = -b + h;\n  vec2 hit = vec2(0.0);\n  for (int i = 0; i < 140; i++) {\n    vec2 m = objMap(ro + rd * t);\n    if (m.x < 0.0005 * (1.0 + t * 0.1)) { hit = vec2(t, m.y); break; }\n    t += m.x * 0.8; if (t > tEnd) break;\n  }\n  if (hit.y < 0.5) return room(ro, rd);\n  vec3 p = ro + rd * hit.x;\n  return shade(p, nObj(p), rd, hit.y);\n}\n\nvoid main(){\n  vec2 fc = gl_FragCoord.xy + uJit.xy;\n  vec2 uv = (fc - 0.5 * uRes) / uRes.y - uShift;\n  vec3 fw = normalize(uTgt - uCam); vec3 rt = normalize(cross(vec3(0.0, 1.0, 0.0), fw)); vec3 up = cross(fw, rt);\n  vec3 rd = normalize(fw * uFoc + rt * uv.x + up * uv.y);\n  vec3 ro = uCam;\n  vec3 fp = ro + rd * (uFocus / dot(rd, fw));\n  ro += rt * uJit.z + up * uJit.w; rd = normalize(fp - ro);\n  vec3 col = min(render(ro, rd), vec3(30.0));\n  if (uDirect > 0.5) col = tone(col);\n  outC = vec4(col, 1.0);\n}\n`;\n\n// Developing the frame: a little bloom off the wet highlights, filmic curve, warm vignette, grain.\nconst POST = `\nprecision highp float;\nuniform sampler2D uAcc; uniform vec2 uRes; uniform float uGrain; uniform vec2 uCentre;\n${TONE}\nfloat h21(vec2 p){ vec3 q = fract(vec3(p.xyx) * 0.1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }\nvoid main(){\n  vec2 uv = gl_FragCoord.xy / uRes;\n  vec3 c = texture2D(uAcc, uv).rgb;\n  vec2 px = 1.0 / uRes;\n  vec3 nb = texture2D(uAcc, uv + vec2(px.x, 0.0)).rgb + texture2D(uAcc, uv - vec2(px.x, 0.0)).rgb + texture2D(uAcc, uv + vec2(0.0, px.y)).rgb + texture2D(uAcc, uv - vec2(0.0, px.y)).rgb;\n  c = max(c + (c - nb * 0.25) * 0.25, 0.0);\n  vec3 b = vec3(0.0);\n  for (int i = 0; i < 16; i++) {\n    float a = float(i) * 2.39996; float r = sqrt((float(i) + 0.5) / 16.0);\n    vec3 s = texture2D(uAcc, uv + vec2(cos(a), sin(a)) * r * 0.012 * vec2(uRes.y / uRes.x, 1.0)).rgb;\n    b += min(max(s - 3.0, 0.0), vec3(8.0)) * (1.0 - 0.6 * r);\n  }\n  c += b * 0.035;\n  vec2 q = (uv - uCentre) * vec2(uRes.x / uRes.y, 1.0);\n  c *= mix(vec3(1.0), vec3(0.78, 0.7, 0.62), smoothstep(0.45, 1.25, length(q)));\n  c = tone(c);\n  float g = h21(gl_FragCoord.xy + uGrain * 91.7) - 0.5;\n  c += g * 0.022;\n  outC = vec4(c, 1.0);\n}\n`;\n\n// No WebGL: the same studio as a still made of gradients and clipped shapes.\nfunction Still({ pct }: { pct: number }) {\n  const sh = shape(pct / 100);\n  const h = 40 + sh.H * 150;\n  return (\n    <div aria-hidden=\"true\" className=\"absolute inset-0 overflow-hidden\" style={{ background: \"linear-gradient(180deg, #e8ddcc 0%, #e0d3bf 52%, #8f8378 52.2%, #a2968a 100%)\" }}>\n      <div className=\"absolute left-0 top-0 h-[52%] w-full\" style={{ background: \"repeating-linear-gradient(112deg, rgba(255,240,214,0) 0 90px, rgba(255,244,222,0.5) 90px 260px, rgba(255,240,214,0) 260px 300px)\" }} />\n      <div className=\"absolute left-1/2 top-[56%] h-[300px] w-[340px] -translate-x-1/2 -translate-y-1/2 lg:left-[68%]\">\n        <div className=\"absolute bottom-0 left-[6%] h-[48%] w-[88%] rounded-[22px]\" style={{ background: \"linear-gradient(90deg,#1c2321,#33403b 45%,#151a19)\" }} />\n        <div className=\"absolute left-0 top-[34%] h-[26%] w-full rounded-[50%]\" style={{ background: \"radial-gradient(ellipse at 50% 40%, #a07a62 0 38%, #d4d0c6 39% 100%)\" }} />\n        <div className=\"absolute left-[24%] top-[38%] h-[14%] w-[52%] rounded-[50%]\" style={{ background: \"linear-gradient(180deg,#e2e0dc,#9c9a96)\" }} />\n        <div className=\"absolute left-1/2 -translate-x-1/2\" style={{ bottom: \"56%\", height: h, width: 150 + sh.rr * 60, background: \"linear-gradient(90deg,#5a3423,#9a6648 40%,#6e4029)\", clipPath: \"polygon(4% 0, 96% 0, 74% 100%, 26% 100%)\", borderRadius: \"0 0 40% 40%\" }} />\n      </div>\n    </div>\n  );\n}\n\nexport default function PottersWheelBowlLoader() {\n  const stage = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [pct, setPct] = useState(START);\n  const [done, setDone] = useState(false);\n  const [shown, setShown] = useState<\"wait\" | \"gl\" | \"still\">(\"wait\");\n  const api = useRef<{ press: () => void } | null>(null);\n\n  useEffect(() => {\n    const box = stage.current, cv = canvas.current;\n    if (!box || !cv) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const opts = { antialias: false, alpha: false, powerPreference: \"high-performance\" as const };\n    const gl2 = cv.getContext(\"webgl2\", opts) as WebGL2RenderingContext | null;\n    const gl = (gl2 ?? cv.getContext(\"webgl\", opts)) as WebGLRenderingContext | null;\n    const canAcc = !!gl2 && (!!gl2.getExtension(\"EXT_color_buffer_float\") || !!gl2.getExtension(\"EXT_color_buffer_half_float\"));\n    const info = gl ? gl.getExtension(\"WEBGL_debug_renderer_info\") : null;\n    const software = /swiftshader|llvmpipe|software|basic render/i.test(gl && info ? String(gl.getParameter(info.UNMASKED_RENDERER_WEBGL)) : \"\");\n\n    let scene: WebGLProgram | null = null, post: WebGLProgram | null = null;\n    if (gl) {\n      const head = gl2 ? \"#version 300 es\\n#define ATTR in\\n\" : \"#define ATTR attribute\\n\";\n      const fhead = gl2 ? \"#version 300 es\\n#define texture2D texture\\nprecision highp float;\\nout vec4 outC;\\n\" : \"#define outC gl_FragColor\\n\";\n      const compile = (type: number, src: string) => {\n        const sh = gl.createShader(type);\n        if (!sh) return null;\n        gl.shaderSource(sh, src); gl.compileShader(sh);\n        if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) { console.warn(gl.getShaderInfoLog(sh)); return null; }\n        return sh;\n      };\n      const link = (frag: string) => {\n        const v = compile(gl.VERTEX_SHADER, head + VERT), f = compile(gl.FRAGMENT_SHADER, fhead + frag);\n        const p = gl.createProgram();\n        if (!v || !f || !p) return null;\n        gl.attachShader(p, v); gl.attachShader(p, f); gl.bindAttribLocation(p, 0, \"aPos\"); gl.linkProgram(p);\n        return gl.getProgramParameter(p, gl.LINK_STATUS) ? p : null;\n      };\n      scene = link(SCENE); post = canAcc ? link(POST) : null;\n    }\n    const live = !!gl && !!scene && (!canAcc || !!post);\n    if (!live) setShown(\"still\");\n\n    const su: Record<string, WebGLUniformLocation | null> = {}, pu: Record<string, WebGLUniformLocation | null> = {};\n    let acc: WebGLTexture | null = null, fbo: WebGLFramebuffer | null = null;\n    if (live && gl && scene) {\n      for (const n of [\"uRes\", \"uJit\", \"uCam\", \"uTgt\", \"uFoc\", \"uShift\", \"uFocus\", \"uShape\", \"uOpen\", \"uSpin\", \"uWet\", \"uTime\", \"uDirect\", \"uClay\"]) su[n] = gl.getUniformLocation(scene, n);\n      if (post) for (const n of [\"uAcc\", \"uRes\", \"uGrain\", \"uCentre\"]) pu[n] = gl.getUniformLocation(post, n);\n      const quad = gl.createBuffer();\n      gl.bindBuffer(gl.ARRAY_BUFFER, quad);\n      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);\n      gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);\n      if (canAcc) { acc = gl.createTexture(); fbo = gl.createFramebuffer(); }\n    }\n\n    let W = 0, H = 0, scale = 1, cssW = 1, cssH = 1;\n    const s = {\n      goal: reduce ? 100 : START, seg: -1, segT: 0, from: START, running: !reduce,\n      p: reduce ? 1 : START / 100,\n      // phase 0 throwing, 1 done (the wheel coasts to a stop and the bowl rests), 2 a new ball is centred\n      phase: 0, hold: 0, omega: reduce ? 0 : 9.5, spin: 0.6, wet: reduce ? 0.7 : 1, reset: 0,\n      sx: 0, sy: 0, px: 0, py: 0,\n      count: 0, fresh: true, frame: 0, slow: 0, fps: 0, fpsN: 0, fpsT: 0,\n      visible: true, raf: 0, last: 0, t: 0, pct: START, first: true, done: false,\n    };\n    (box as HTMLDivElement & { __fps?: () => number }).__fps = () => s.fps;\n    const size = () => {\n      const r = box.getBoundingClientRect();\n      cssW = Math.max(1, r.width); cssH = Math.max(1, r.height);\n      if (!live || !gl) return;\n      const dpr = Math.min(software ? 0.55 : 1.25, window.devicePixelRatio || 1) * scale;\n      const k = Math.min(1, Math.sqrt(1.0e6 / (cssW * cssH * dpr * dpr)));\n      const w = Math.max(2, Math.round(cssW * dpr * k)), h = Math.max(2, Math.round(cssH * dpr * k));\n      if (w === W && h === H) return;\n      W = w; H = h; cv.width = W; cv.height = H;\n      if (gl2 && acc && fbo) {\n        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, acc);\n        gl2.texImage2D(gl.TEXTURE_2D, 0, gl2.RGBA16F, W, H, 0, gl.RGBA, gl2.HALF_FLOAT, null);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n        gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);\n        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, acc, 0);\n        gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n      }\n      s.count = 0; s.fresh = true;\n    };\n    const halton = (i: number, b: number) => { let f = 1, r = 0; while (i > 0) { f /= b; r += f * (i % b); i = Math.floor(i / b); } return r; };\n\n    // A longish lens looking down into the bowl, the wheel to the right and the figures beside it.\n    const camera = () => {\n      const aspect = cssW / cssH, wide = cssW >= 1024, roomy = cssW >= 640;\n      const el = 0.5 - s.sy * 0.05, az = -0.2 + s.sx * 0.1, dist = 9.2;\n      const tgt = [0, 0.62, 0];\n      const cam = [tgt[0] + dist * Math.sin(az) * Math.cos(el), tgt[1] + dist * Math.sin(el), tgt[2] - dist * Math.cos(az) * Math.cos(el)];\n      const foc = wide ? 2.6 : roomy ? 2.4 : Math.min(2.3, 1.12 + aspect * 0.62);\n      const shift = wide ? [0.19 * aspect, -0.02] : roomy ? [0.2 * aspect, 0.02] : [0.0, 0.17];\n      return { cam, tgt, foc, shift };\n    };\n\n    const draw = (alpha: number, sample: number) => {\n      if (!live || !gl || !scene) return;\n      const c = camera();\n      const jx = sample ? halton(sample, 2) - 0.5 : 0, jy = sample ? halton(sample, 3) - 0.5 : 0;\n      const la = halton(sample, 5) * Math.PI * 2, lr = sample ? Math.sqrt(halton(sample, 7)) * 0.07 : 0;\n      const sh = shape(s.p);\n      gl.useProgram(scene);\n      gl.bindFramebuffer(gl.FRAMEBUFFER, canAcc ? fbo : null);\n      gl.viewport(0, 0, W, H);\n      if (canAcc && alpha < 1) { gl.enable(gl.BLEND); gl.blendColor(0, 0, 0, alpha); gl.blendFunc(gl.CONSTANT_ALPHA, gl.ONE_MINUS_CONSTANT_ALPHA); } else gl.disable(gl.BLEND);\n      gl.uniform2f(su.uRes, W, H);\n      gl.uniform4f(su.uJit, canAcc ? jx : 0, canAcc ? jy : 0, canAcc ? Math.cos(la) * lr : 0, canAcc ? Math.sin(la) * lr : 0);\n      gl.uniform3f(su.uCam, c.cam[0], c.cam[1], c.cam[2]); gl.uniform3f(su.uTgt, c.tgt[0], c.tgt[1], c.tgt[2]);\n      gl.uniform1f(su.uFoc, c.foc); gl.uniform2f(su.uShift, c.shift[0], c.shift[1]);\n      gl.uniform1f(su.uFocus, Math.hypot(c.cam[0], c.cam[1] - 0.8, c.cam[2]) - 0.1);\n      gl.uniform4f(su.uShape, sh.H, sh.rf, sh.rr, sh.w); gl.uniform1f(su.uOpen, sh.open);\n      // while spinning, each accumulated sample sees the wheel at a slightly different angle: that is the motion blur\n      gl.uniform1f(su.uSpin, s.spin + (sample ? (halton(sample, 11) - 0.5) * s.omega * 0.03 : 0));\n      gl.uniform1f(su.uWet, s.wet); gl.uniform1f(su.uTime, s.t);\n      gl.uniform1f(su.uDirect, canAcc ? 0 : 1);\n      gl.uniform3f(su.uClay, CLAY[0], CLAY[1], CLAY[2]);\n      gl.drawArrays(gl.TRIANGLES, 0, 3);\n      if (canAcc && post) {\n        gl.bindFramebuffer(gl.FRAMEBUFFER, null);\n        gl.disable(gl.BLEND);\n        gl.useProgram(post);\n        gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, acc);\n        gl.uniform1i(pu.uAcc, 1); gl.uniform2f(pu.uRes, W, H);\n        gl.uniform1f(pu.uGrain, reduce ? 1 : s.frame % 64);\n        gl.uniform2f(pu.uCentre, 0.5 + c.shift[0] * (H / W), 0.5 + c.shift[1]);\n        gl.drawArrays(gl.TRIANGLES, 0, 3);\n      }\n    };\n\n    // the one button: finish the bowl now, or once it is done, wedge a new ball and throw again\n    const press = () => {\n      if (reduce) {\n        s.goal = s.goal >= 100 ? 0 : Math.min(100, Math.round(s.goal / 20) * 20 + 20);\n        s.p = s.goal / 100; s.count = 0; s.fresh = true; wake();\n        return;\n      }\n      if (s.phase === 0) { s.seg = -2; s.goal = 100; }\n      else if (s.phase === 1) { s.hold = HOLD; }\n      wake();\n    };\n    api.current = { press };\n\n    const frame = (now: number) => {\n      s.raf = 0;\n      if (!s.visible) return;\n      const dtRaw = s.last ? (now - s.last) / 1000 : 0.016;\n      const dt = Math.min(0.033, dtRaw);\n      s.last = now; s.frame++; s.t += dt;\n      s.fpsN++; s.fpsT += dtRaw; if (s.fpsT > 1) { s.fps = s.fpsN / s.fpsT; s.fpsN = 0; s.fpsT = 0; }\n\n      // ---- the demo: walk the script. Replace this block with your own `s.goal = percent`.\n      if (s.running && s.phase === 0 && s.seg > -2) {\n        s.segT += dt;\n        let [to, secs] = s.seg < 0 ? [FIRST, 0.6] : demo[s.seg];\n        while (s.seg >= 0 && s.segT >= secs && s.seg < demo.length - 1) {\n          s.segT -= secs; s.from = to; s.seg++;\n          [to, secs] = demo[s.seg];\n        }\n        const k = Math.min(1, s.segT / secs), e = k * k * (3 - 2 * k);\n        s.goal = s.from + (to - s.from) * e;\n      }\n\n      let moving = false;\n      if (!reduce) {\n        // the clay follows the number with a lag: hands can only pull a wall up so fast\n        if (s.phase === 0) {\n          s.p += Math.max(-0.5 * dt, Math.min(0.3 * dt, (s.goal / 100 - s.p) * (1 - Math.exp(-dt * 3.4))));\n          s.omega += (9.5 - s.omega) * (1 - Math.exp(-dt * 3));\n          s.wet += (1 - s.wet) * (1 - Math.exp(-dt * 2));\n          if (s.goal >= 100 && s.p > 0.996) { s.p = 1; s.phase = 1; s.hold = 0; }\n        } else if (s.phase === 1) {\n          // the foot comes off the pedal: the wheel coasts, drags to a stop and rocks back a hair\n          s.hold += dt;\n          s.omega -= (1.4 + 0.5 * s.omega) * dt * 2.1;\n          if (s.omega < 0) s.omega *= 0.8;\n          if (s.omega < -0.25) s.omega = -0.25;\n          s.wet += (0.5 - s.wet) * (1 - Math.exp(-dt * 0.9));\n          if (s.hold > HOLD) { s.phase = 2; s.reset = 0; }\n        } else {\n          // the bowl is cut off and a fresh ball slapped down: the shape runs back to a centred mound\n          s.reset = Math.min(1, s.reset + dt / 1.1);\n          const k = s.reset, e = k * k * (3 - 2 * k);\n          s.p = 1 - e;\n          s.omega += (9.5 - s.omega) * (1 - Math.exp(-dt * 2.5));\n          s.wet += (1 - s.wet) * (1 - Math.exp(-dt * 3));\n          if (s.reset >= 1) { s.phase = 0; s.p = 0; s.goal = 0; s.from = 0; s.seg = 0; s.segT = 0; }\n        }\n        s.spin += s.omega * dt;\n        s.sx += (s.px - s.sx) * (1 - Math.exp(-dt * 2.5)); s.sy += (s.py - s.sy) * (1 - Math.exp(-dt * 2.5));\n        moving = true;\n      } else {\n        s.p = s.goal / 100; s.omega = 0;\n      }\n\n      const pctNow = s.phase === 1 ? 100 : s.phase === 2 ? 0 : Math.round(Math.min(100, s.p * 100 + 0.0001));\n      if (pctNow !== s.pct) { s.pct = pctNow; setPct(pctNow); }\n      const isDone = s.phase === 1 || (reduce && s.goal >= 100);\n      if (isDone !== s.done) { s.done = isDone; setDone(isDone); }\n\n      if (live) {\n        if (s.fresh || !canAcc) { draw(1, 0); s.fresh = false; s.count = 1; }\n        else if (moving && (Math.abs(s.omega) > 0.02 || s.phase !== 1)) draw(0.4, 1 + (s.frame % 32));\n        else if (s.count < 48) { s.count++; draw(1 / s.count, s.count); }\n        if (s.first) { s.first = false; setShown(\"gl\"); }\n        if (!reduce && !software && dtRaw > 0.026) s.slow++; else s.slow = Math.max(0, s.slow - 2);\n        if (s.slow > 40 && scale > 0.45) { scale *= 0.82; s.slow = 0; size(); }\n      }\n      if (moving || (live && s.count < 48)) s.raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!s.raf && s.visible) { s.last = 0; s.raf = requestAnimationFrame(frame); } };\n\n    size();\n    const ro = new ResizeObserver(() => { size(); wake(); });\n    ro.observe(box);\n    const io = new IntersectionObserver(([e]) => { s.visible = e.isIntersecting && !document.hidden; if (s.visible) wake(); }, { threshold: 0.05 });\n    io.observe(box);\n    const vis = () => { s.visible = !document.hidden; if (s.visible) wake(); };\n    document.addEventListener(\"visibilitychange\", vis);\n    // the pointer walks the camera a little round the wheel\n    const move = (e: PointerEvent) => {\n      const r = box.getBoundingClientRect();\n      s.px = ((e.clientX - r.left) / r.width) * 2 - 1; s.py = ((e.clientY - r.top) / r.height) * 2 - 1;\n      if (reduce) { s.count = 0; s.fresh = true; }\n      wake();\n    };\n    const leave = () => { s.px = 0; s.py = 0; };\n    box.addEventListener(\"pointermove\", move);\n    box.addEventListener(\"pointerleave\", leave);\n    const lost = (e: Event) => { e.preventDefault(); setShown(\"still\"); };\n    cv.addEventListener(\"webglcontextlost\", lost);\n    wake();\n\n    return () => {\n      cancelAnimationFrame(s.raf); ro.disconnect(); io.disconnect();\n      document.removeEventListener(\"visibilitychange\", vis);\n      box.removeEventListener(\"pointermove\", move); box.removeEventListener(\"pointerleave\", leave);\n      cv.removeEventListener(\"webglcontextlost\", lost);\n      api.current = null;\n    };\n  }, []);\n\n  const at = Math.max(0, stages.findIndex((st) => pct <= st.until));\n\n  return (\n    <section className=\"relative isolate overflow-hidden bg-[#e4d8c6] text-[#2a1d15]\" style={{ fontFamily: FONT }}>\n      <style>{`\n        @keyframes ray-marched-potters-wheel-loader-rise { from { opacity: 0; transform: translateY(0.4em); filter: blur(4px); } to { opacity: 1; transform: none; filter: blur(0); } }\n        .ray-marched-potters-wheel-loader-note { animation: ray-marched-potters-wheel-loader-rise 560ms cubic-bezier(0.2, 0.9, 0.2, 1) both; }\n        @media (prefers-reduced-motion: reduce) { .ray-marched-potters-wheel-loader-note { animation: none; } }\n      `}</style>\n      <div ref={stage} className=\"relative mx-auto h-[720px] w-full max-w-[1600px] lg:h-[760px]\" style={{ background: \"linear-gradient(180deg, #ebe0cf 0%, #e1d4c0 50%, #9a8e82 50%, #8c8177 100%)\" }}>\n        <canvas ref={canvas} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full transition-opacity duration-700 motion-reduce:transition-none ${shown === \"gl\" ? \"opacity-100\" : \"opacity-0\"}`} />\n        {shown === \"still\" && <Still pct={pct} />}\n\n        <div className=\"pointer-events-none absolute inset-0 flex flex-col justify-between px-6 pb-7 pt-7 sm:px-10 lg:px-16 lg:pb-14 lg:pt-14\">\n          <p className=\"text-[11px] font-medium uppercase tracking-[0.32em] text-[#2a1d15]/65\">Wrenfold Pottery <span className=\"mx-2 text-[#2a1d15]/30\">/</span> building the shop</p>\n          <div className=\"max-w-[560px]\">\n            <div\n              role=\"progressbar\"\n              aria-label=\"Building the shop\"\n              aria-valuemin={0}\n              aria-valuemax={100}\n              aria-valuenow={pct}\n              aria-valuetext={`${pct} percent. ${stages[at].note}`}\n              className=\"flex items-start font-semibold leading-[0.8] tracking-[-0.065em] text-[#2a1d15]\"\n              style={{ fontVariantNumeric: \"tabular-nums\", fontSize: \"clamp(112px, 17vw, 248px)\" }}\n            >\n              <span>{pct}</span>\n              <span className=\"ml-[0.06em] mt-[0.04em] text-[0.34em] tracking-normal text-[#9a4e2c]\">%</span>\n            </div>\n            <div className=\"mt-5 flex items-baseline gap-3 text-[11px] font-medium uppercase tracking-[0.3em] text-[#2a1d15]/60 lg:mt-7\">\n              <span className=\"tabular-nums text-[#8f4427]\">{String(at + 1).padStart(2, \"0\")}</span>\n              <span className=\"h-px w-8 self-center bg-[#2a1d15]/25\" />\n              <span className=\"tabular-nums\">{String(stages.length).padStart(2, \"0\")}</span>\n            </div>\n            <p aria-live=\"polite\" className=\"mt-2 h-[1.3em] text-[22px] italic leading-snug text-[#2a1d15] lg:text-[28px]\" style={{ fontFamily: SERIF }}>\n              <span key={at} className=\"ray-marched-potters-wheel-loader-note block\">{stages[at].note}</span>\n            </p>\n            <button\n              type=\"button\"\n              onClick={() => api.current?.press()}\n              className=\"pointer-events-auto mt-6 inline-flex h-11 items-center gap-2.5 rounded-full bg-[#2a1d15] pl-4 pr-5 text-[13px] font-medium tracking-[-0.01em] text-[#f5ebde] shadow-[0_8px_20px_-8px_rgba(60,30,10,0.6)] outline-none transition-colors duration-200 hover:bg-[#45301f] focus-visible:ring-2 focus-visible:ring-[#9a4e2c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#e4d8c6] lg:mt-8\"\n            >\n              <svg aria-hidden=\"true\" viewBox=\"0 0 20 20\" className=\"h-4 w-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><ellipse cx=\"10\" cy=\"13\" rx=\"7\" ry=\"2.2\" /><path d=\"M5 12.6c-.6-3 .2-6 1.6-8h6.8c1.4 2 2.2 5 1.6 8\" /></svg>\n              {done ? \"Throw another bowl\" : \"Finish the bowl\"}\n            </button>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
