Sharper first view and smoke loader sign-off
The loader now measures throughput from whole tile batches, not just the two probe tiles, and after a session settles inside its deadline it tops up in the background: the needed level if the budget cut it short, then one level above it on capable devices with a fast connection (drawn downscaled), within time and memory caps and never under Save-Data. The chop in the album end card and the page footer is replaced by the LUCIO loader in smoke from lucioIP, falling back to the SVG loader without WebGL. sync-brand.sh now copies lucio-loaders.js and defaults to ../lucioIP. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e48a1eacf4
commit
4cdbd66fcf
10 files changed
+990
-41
No files matched your search
@@ -194,7 +194,7 @@ This type-checks with `tsc --noEmit` (strict) and bundles with esbuild. Fonts ar
|
||||
|
||||
### Brand
|
||||
|
||||
`scripts/sync-brand.sh` copies the tokens, `lucio-morph.js`, the favicon and the chop from `../LUCIO_ip` (or `$LUCIO_IP_DIR`) into `web/brand/`, stripping comments. The copies are committed; rebuild the front-end afterwards.
|
||||
`scripts/sync-brand.sh` copies the tokens, `lucio-morph.js`, `lucio-loaders.js`, the favicon and the chop from `../lucioIP` (or `$LUCIO_IP_DIR`) into `web/brand/`, stripping comments. The copies are committed; rebuild the front-end afterwards.
|
||||
|
||||
## Output layout
|
||||
|
||||
|
||||
+4
-3
@@ -97,18 +97,19 @@ Served by the daemon in serve mode, and in export mode on `server.listen` (nothi
|
||||
4. Final level: highest level up to the needed one whose visible-tile bytes ÷ throughput ≤ (budget − elapsed) × 0.8. If it is 2+ levels above the probe, fetch one intermediate level first.
|
||||
5. Fetch only visible tiles, centre outwards, `concurrency` at a time; each tile fades in over the lower layer as it decodes.
|
||||
6. Deadline `budget_ms` (3000): abort unfinished upgrades and keep what is on screen.
|
||||
7. Top-up (album viewer, un-zoomed, only when steps 3–5 finished inside the deadline; never with Save-Data or on 2g/3g): each level batch also measures throughput (bytes ÷ wall time). If the final level stopped short of the needed one, fetch the needed level when its bytes ÷ throughput ≤ 6 s. Then, on a capable device (≥ 4 cores, `deviceMemory` ≥ 4 GB where reported) with throughput ≥ 1.5 MB/s, fetch one level above the needed one when it fits in 4 s and its decoded visible pixels stay under 35 % of the tile cache; it is drawn downscaled with high-quality smoothing. These fetches run at prefetch priority, show no loader and stop when the photo is left or zoomed.
|
||||
|
||||
Moving to another photo aborts that photo's requests. Prefetch the next photo's seed and probe level and, for multi-slide photos, the next slide's tiles. Decoded tiles live in an LRU cache capped at about 250 MB on desktop and 120 MB on phones. Decode with `createImageBitmap` (in a worker where supported). The canvas is always viewport-sized. Pixel density capped at `max_dpr` (2).
|
||||
|
||||
## Screens
|
||||
|
||||
Album index: full-width strips, 8 px apart on phones, 16 px on desktop. Header with the Lucio wordmark (Guoliang → Lucio morph on hover, the only animation on this screen); footer with the chop. Closed strip 32:6 showing the `collapsed_focus_y` band of the 32:9 cover, height `min(100vw*6/32, 28vh)`; open 32:9, height `min(100vw*9/32, 62vh)`; the cover is drawn cover-fit, never stretched (under the height caps a very wide screen crops top and bottom). Desktop: hover opens. Touch: the strip nearest the vertical centre opens while scrolling; tap enters. On open the height animates 240 ms, then the title fades in (light-on): mono date line, then the title in Bricolage Grotesque, bottom-left. Covers use the tile loader; closed strips load only the visible band; only strips near the viewport load.
|
||||
Album index: full-width strips, 8 px apart on phones, 16 px on desktop. Header with the Lucio wordmark (Guoliang → Lucio morph on hover, the only animation on this screen); footer with the LUCIO loader in smoke (bottom-right; the plain SVG loader without WebGL; the chop until the script runs). Closed strip 32:6 showing the `collapsed_focus_y` band of the 32:9 cover, height `min(100vw*6/32, 28vh)`; open 32:9, height `min(100vw*9/32, 62vh)`; the cover is drawn cover-fit, never stretched (under the height caps a very wide screen crops top and bottom). Desktop: hover opens. Touch: the strip nearest the vertical centre opens while scrolling; tap enters. On open the height animates 240 ms, then the title fades in (light-on): mono date line, then the title in Bricolage Grotesque, bottom-left. Covers use the tile loader; closed strips load only the visible band; only strips near the viewport load.
|
||||
|
||||
Album viewer: one photo at a time, contained in the viewport (fills height or width, never stretched), centred on graphite. Swipe right-to-left, ←/→, click-and-drag; one pointer-events handler for mouse and touch with flick velocity and rubber-band ends; Home/End; Esc returns to the index. `slides: N`: the photo is scaled so a 1/N-wide section fits the viewport; moving between its slides is a continuous pan. `/a/<slug>/#7` opens photo 7. End card: chop, "— Lucio", the next album's strip. Reduced motion: crossfades.
|
||||
Album viewer: one photo at a time, contained in the viewport (fills height or width, never stretched), centred on graphite. Swipe right-to-left, ←/→, click-and-drag; one pointer-events handler for mouse and touch with flick velocity and rubber-band ends; Home/End; Esc returns to the index. `slides: N`: the photo is scaled so a 1/N-wide section fits the viewport; moving between its slides is a continuous pan. `/a/<slug>/#7` opens photo 7. End card: the LUCIO loader in smoke, "— Lucio", the next album's strip. Reduced motion: crossfades.
|
||||
|
||||
Captions: hidden by default; shown while the pointer is in the bottom 20% of the photo; click or tap pins/unpins; `i` toggles. A tap is < 10 px movement and < 300 ms. Panel: mono line `03 / 12 · Z8 · 24-70 f/2.8 · 35mm · f/8 · 1/250 · ISO 64` (EXIF only when `show_exif`), then the caption in IBM Plex Sans over a graphite fade. Captions are real DOM text.
|
||||
|
||||
Lucio brand (source of truth: ../LUCIO_ip): graphite #111114 ground, paper #F3F1EC text, beam #FFF3CF only on focus and a thin progress line, steel for secondary text, cinnabar only in the chop. Bricolage Grotesque display, IBM Plex Sans body, IBM Plex Mono eyebrows (uppercase, +0.08em). Fonts self-hosted woff2, nothing from Google. If a photo has nothing sharp after 400 ms, the L→U→C→I→O loader (LucioMorph.loader) appears on the right edge, vertically centred, inset ≥ 32 px. One animated element per screen. Motion: 120 ms hover, 240 ms reveals, 900 ms light-on with cubic-bezier(0.16, 1, 0.3, 1). Brand files are copied from LUCIO_ip by `scripts/sync-brand.sh`.
|
||||
Lucio brand (source of truth: ../lucioIP): graphite #111114 ground, paper #F3F1EC text, beam #FFF3CF only on focus and a thin progress line, steel for secondary text, cinnabar only in the chop. Bricolage Grotesque display, IBM Plex Sans body, IBM Plex Mono eyebrows (uppercase, +0.08em). Fonts self-hosted woff2, nothing from Google. If a photo has nothing sharp after 400 ms, the L→U→C→I→O loader (LucioMorph.loader) appears on the right edge, vertically centred, inset ≥ 32 px. One animated element per screen. Motion: 120 ms hover, 240 ms reveals, 900 ms light-on with cubic-bezier(0.16, 1, 0.3, 1). Brand files are copied from lucioIP by `scripts/sync-brand.sh`.
|
||||
|
||||
## Discouraging saves
|
||||
|
||||
|
||||
+279
-1
@@ -1 +1,279 @@
|
||||
"use strict";(()=>{(function(n){let t={from:"Guoliang",to:"Lucio",letters:[{ch:"G",kind:"keep",shared:"M8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50",fullA:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",fullB:"M8.50 0.00L8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50L80.00 91.50",out:[{d:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00",P:79.21,j:"end"},{d:"M58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",P:73.21,j:"start"}],in:[{d:"M8.50 22.00L8.50 0.00",P:22,j:"start"},{d:"M58.00 91.50L80.00 91.50",P:22,j:"start"}],x0:0,x1:0,dot:null},{ch:"u",kind:"keep",shared:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullA:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullB:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",out:[],in:[],x0:88.8,x1:88,dot:null},{ch:"o",kind:"keep",shared:"M38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullB:"M60.00 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50L60.00 91.50",out:[{d:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50",P:60.41,j:"both"}],in:[{d:"M38.00 46.50L60.00 46.50",P:22,j:"start"},{d:"M38.00 91.50L60.00 91.50",P:22,j:"start"}],x0:159,x1:158.2,dot:null},{ch:"l",kind:"fade",d:"M8.50 0.00L8.50 100.00",x0:230.8,x1:230.8,dot:null},{ch:"i",kind:"keep",shared:"M8.50 38.00L8.50 100.00",fullA:"M8.50 38.00L8.50 100.00",fullB:"M8.50 38.00L8.50 100.00",out:[],in:[],x0:262.8,x1:227.9,dot:[0,14,17]},{ch:"a",kind:"fade",d:"M38.00 91.50L51.50 91.50L51.50 78.00L51.50 60.00L51.50 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",x0:291.6,x1:291.6,dot:null},{ch:"n",kind:"fade",d:"M51.50 100.00L51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00L8.50 100.00",x0:362.7,x1:362.7,dot:null},{ch:"g",kind:"keep",shared:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M0.00 127.50L38.00 127.50A13.50 13.50 0 0 0 51.50 114.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00",fullB:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",out:[{d:"M51.50 60.00L51.50 114.00A13.50 13.50 0 0 1 38.00 127.50L0.00 127.50",P:113.21,j:"start"}],in:[],x0:432.9,x1:256.7,dot:null}],pad:17,vbw:526.9,vbh:170,stroke:17,raysT:"translate(0.000 22.727) scale(0.7727)"},e="M47.6 70.7L71.9 61.1L71.1 58.2L45.2 62.0ZM44.9 61.5L61.2 40.9L59.1 38.8L38.5 55.1ZM38.0 54.8L41.8 28.9L38.9 28.1L29.3 52.4Z",i="http://www.w3.org/2000/svg",s=(u,y)=>{let d=document.createElementNS(i,u);for(let v in y)d.setAttribute(v,y[v]);return d},r=()=>n.matchMedia&&n.matchMedia("(prefers-reduced-motion: reduce)").matches,o=u=>Math.max(0,Math.min(1,u)),a=u=>u*u*(3-2*u),h=.5;function l(u,y){let d=0,v=0,f=null,M=0;function A(L){let x=(L-M)/y;M=L,d=d<v?Math.min(v,d+x):Math.max(v,d-x),u(d),f=d===v?null:requestAnimationFrame(A)}function p(L){if(v=L,r()){d=L,u(d);return}f===null&&(M=performance.now(),f=requestAnimationFrame(A))}return{play:()=>p(1),reverse:()=>p(0),toggle:()=>p(v?0:1),set:L=>{cancelAnimationFrame(f),f=null,v=d=L,u(d)},stop:()=>{cancelAnimationFrame(f),f=null},get t(){return d}}}function c(u,y,d,v){let f=o(v)*y;if(u.style.visibility=f<.05?"hidden":"visible",d==="both"){let M=f/2;u.setAttribute("stroke-dasharray",M.toFixed(2)+" "+Math.max(0,y-2*M).toFixed(2)+" "+M.toFixed(2)),u.setAttribute("stroke-dashoffset","0")}else d==="end"?(u.setAttribute("stroke-dasharray",f.toFixed(2)+" "+(2*y+20).toFixed(2)),u.setAttribute("stroke-dashoffset",(-(y-f)).toFixed(2))):(u.setAttribute("stroke-dasharray",f.toFixed(2)+" "+(2*y+20).toFixed(2)),u.setAttribute("stroke-dashoffset","0"))}function g(u,y={}){let d=Object.assign({trigger:"hover",color:"currentColor",rays:"#FFF3CF",duration:450,autoDelay:1800},y),v=s("svg",{viewBox:"0 0 "+t.vbw+" "+t.vbh,role:"img","aria-label":"Guoliang Chen, Lucio"});v.style.display="block",v.style.width="100%",v.style.height="auto";let f=sLine truncated
|
||||
"use strict";(()=>{(function(n){let e={from:"Guoliang",to:"Lucio",letters:[{ch:"G",kind:"keep",shared:"M8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50",fullA:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",fullB:"M8.50 0.00L8.50 22.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L58.00 91.50L80.00 91.50",out:[{d:"M80.00 8.50L58.00 8.50L22.00 8.50A13.50 13.50 0 0 0 8.50 22.00",P:79.21,j:"end"},{d:"M58.00 91.50A13.50 13.50 0 0 0 71.50 78.00L71.50 56.00L41.50 56.00",P:73.21,j:"start"}],in:[{d:"M8.50 22.00L8.50 0.00",P:22,j:"start"},{d:"M58.00 91.50L80.00 91.50",P:22,j:"start"}],x0:0,x1:0,dot:null},{ch:"u",kind:"keep",shared:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullA:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",fullB:"M8.50 38.00L8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00L51.50 38.00",out:[],in:[],x0:88.8,x1:88,dot:null},{ch:"o",kind:"keep",shared:"M38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullB:"M60.00 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50L60.00 91.50",out:[{d:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50",P:60.41,j:"both"}],in:[{d:"M38.00 46.50L60.00 46.50",P:22,j:"start"},{d:"M38.00 91.50L60.00 91.50",P:22,j:"start"}],x0:159,x1:158.2,dot:null},{ch:"l",kind:"fade",d:"M8.50 0.00L8.50 100.00",x0:230.8,x1:230.8,dot:null},{ch:"i",kind:"keep",shared:"M8.50 38.00L8.50 100.00",fullA:"M8.50 38.00L8.50 100.00",fullB:"M8.50 38.00L8.50 100.00",out:[],in:[],x0:262.8,x1:227.9,dot:[0,14,17]},{ch:"a",kind:"fade",d:"M38.00 91.50L51.50 91.50L51.50 78.00L51.50 60.00L51.50 46.50L38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",x0:291.6,x1:291.6,dot:null},{ch:"n",kind:"fade",d:"M51.50 100.00L51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00L8.50 100.00",x0:362.7,x1:362.7,dot:null},{ch:"g",kind:"keep",shared:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",fullA:"M0.00 127.50L38.00 127.50A13.50 13.50 0 0 0 51.50 114.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00",fullB:"M38.00 91.50A13.50 13.50 0 0 0 51.50 78.00L51.50 60.00A13.50 13.50 0 0 0 38.00 46.50L22.00 46.50A13.50 13.50 0 0 0 8.50 60.00L8.50 78.00A13.50 13.50 0 0 0 22.00 91.50L38.00 91.50",out:[{d:"M51.50 60.00L51.50 114.00A13.50 13.50 0 0 1 38.00 127.50L0.00 127.50",P:113.21,j:"start"}],in:[],x0:432.9,x1:256.7,dot:null}],pad:17,vbw:526.9,vbh:170,stroke:17,raysT:"translate(0.000 22.727) scale(0.7727)"},t="M47.6 70.7L71.9 61.1L71.1 58.2L45.2 62.0ZM44.9 61.5L61.2 40.9L59.1 38.8L38.5 55.1ZM38.0 54.8L41.8 28.9L38.9 28.1L29.3 52.4Z",i="http://www.w3.org/2000/svg",s=(v,E)=>{let p=document.createElementNS(i,v);for(let y in E)p.setAttribute(y,E[y]);return p},r=()=>n.matchMedia&&n.matchMedia("(prefers-reduced-motion: reduce)").matches,o=v=>Math.max(0,Math.min(1,v)),a=v=>v*v*(3-2*v),l=.5;function h(v,E){let p=0,y=0,x=null,M=0;function F(T){let A=(T-M)/E;M=T,p=p<y?Math.min(y,p+A):Math.max(y,p-A),v(p),x=p===y?null:requestAnimationFrame(F)}function w(T){if(y=T,r()){p=T,v(p);return}x===null&&(M=performance.now(),x=requestAnimationFrame(F))}return{play:()=>w(1),reverse:()=>w(0),toggle:()=>w(y?0:1),set:T=>{cancelAnimationFrame(x),x=null,y=p=T,v(p)},stop:()=>{cancelAnimationFrame(x),x=null},get t(){return p}}}function c(v,E,p,y){let x=o(y)*E;if(v.style.visibility=x<.05?"hidden":"visible",p==="both"){let M=x/2;v.setAttribute("stroke-dasharray",M.toFixed(2)+" "+Math.max(0,E-2*M).toFixed(2)+" "+M.toFixed(2)),v.setAttribute("stroke-dashoffset","0")}else p==="end"?(v.setAttribute("stroke-dasharray",x.toFixed(2)+" "+(2*E+20).toFixed(2)),v.setAttribute("stroke-dashoffset",(-(E-x)).toFixed(2))):(v.setAttribute("stroke-dasharray",x.toFixed(2)+" "+(2*E+20).toFixed(2)),v.setAttribute("stroke-dashoffset","0"))}function f(v,E={}){let p=Object.assign({trigger:"hover",color:"currentColor",rays:"#FFF3CF",duration:450,autoDelay:1800},E),y=s("svg",{viewBox:"0 0 "+e.vbw+" "+e.vbh,role:"img","aria-label":"Guoliang Chen, Lucio"});y.style.display="block",y.style.width="100%",y.style.height="auto";let x=sLine truncated
|
||||
precision highp float;
|
||||
uniform vec2 uRes;
|
||||
uniform float uPx, uTime, uDark;
|
||||
uniform vec3 uColor;
|
||||
#define PI 3.14159265
|
||||
#define HPI 1.5707963
|
||||
const float HB = ${49.8.toFixed(4)}, CR = ${16.2.toFixed(4)}, HW = ${10.2.toFixed(4)}, H = ${s.toFixed(4)};
|
||||
const float SL = ${r.toFixed(4)}, CL = ${o.toFixed(4)}, PER = ${a.toFixed(4)}, Q = ${l.toFixed(4)};
|
||||
const vec2 L2 = vec2(0.6608, 0.7506); // the brand's one light: from the upper right
|
||||
float sdRB(vec2 p) { vec2 q = abs(p) - vec2(H); return length(max(q, 0.)) + min(max(q.x, q.y), 0.) - CR; }
|
||||
// arc length of the nearest centreline point, CCW, 0 at the bottom-right corner's 45-degree point
|
||||
float pathS(vec2 p) {
|
||||
if (abs(p.x) <= H && abs(p.y) <= H) { if (abs(p.x) > abs(p.y)) p.x = sign(p.x) * (H + 1e-3); else p.y = sign(p.y) * (H + 1e-3); }
|
||||
float s;
|
||||
if (p.x > H && p.y > H) s = SL + atan(p.y - H, p.x - H) * CR;
|
||||
else if (p.x < -H && p.y > H) s = 2. * SL + CL + (atan(p.y - H, p.x + H) - HPI) * CR;
|
||||
else if (p.x < -H && p.y < -H) s = 3. * SL + 2. * CL + atan(-(p.y + H), -(p.x + H)) * CR;
|
||||
else if (p.x > H && p.y < -H) s = 4. * SL + 3. * CL + (atan(p.y + H, p.x - H) + HPI) * CR;
|
||||
else if (p.x > H) s = p.y + H;
|
||||
else if (p.y > H) s = SL + CL + (H - p.x);
|
||||
else if (p.x < -H) s = 2. * SL + 2. * CL + (H - p.y);
|
||||
else s = 3. * SL + 3. * CL + (p.x + H);
|
||||
return mod(s + CL * 0.5, PER);
|
||||
}
|
||||
float hash11(float n) { return fract(sin(n * 127.1 + 11.7) * 43758.5453); }
|
||||
float hash12(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
|
||||
vec2 hash22(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973)); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.xx + p3.yz) * p3.zy); }
|
||||
// simplex noise 3D (Ashima Arts / Stefan Gustavson, MIT)
|
||||
vec3 mod289(vec3 x) { return x - floor(x * (1. / 289.)) * 289.; }
|
||||
vec4 mod289(vec4 x) { return x - floor(x * (1. / 289.)) * 289.; }
|
||||
vec4 permute(vec4 x) { return mod289(((x * 34.) + 1.) * x); }
|
||||
vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
|
||||
float snoise(vec3 v) {
|
||||
const vec2 C = vec2(1. / 6., 1. / 3.); const vec4 D = vec4(0., .5, 1., 2.);
|
||||
vec3 i = floor(v + dot(v, C.yyy)); vec3 x0 = v - i + dot(i, C.xxx);
|
||||
vec3 g = step(x0.yzx, x0.xyz); vec3 l = 1. - g; vec3 i1 = min(g.xyz, l.zxy); vec3 i2 = max(g.xyz, l.zxy);
|
||||
vec3 x1 = x0 - i1 + C.xxx; vec3 x2 = x0 - i2 + C.yyy; vec3 x3 = x0 - D.yyy;
|
||||
i = mod289(i);
|
||||
vec4 p = permute(permute(permute(i.z + vec4(0., i1.z, i2.z, 1.)) + i.y + vec4(0., i1.y, i2.y, 1.)) + i.x + vec4(0., i1.x, i2.x, 1.));
|
||||
float n_ = 0.142857142857; vec3 ns = n_ * D.wyz - D.xzx;
|
||||
vec4 j = p - 49. * floor(p * ns.z * ns.z);
|
||||
vec4 x_ = floor(j * ns.z); vec4 y_ = floor(j - 7. * x_);
|
||||
vec4 x = x_ * ns.x + ns.yyyy; vec4 y = y_ * ns.x + ns.yyyy; vec4 h = 1. - abs(x) - abs(y);
|
||||
vec4 b0 = vec4(x.xy, y.xy); vec4 b1 = vec4(x.zw, y.zw);
|
||||
vec4 s0 = floor(b0) * 2. + 1.; vec4 s1 = floor(b1) * 2. + 1.; vec4 sh = -step(h, vec4(0.));
|
||||
vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
|
||||
vec3 p0 = vec3(a0.xy, h.x); vec3 p1 = vec3(a0.zw, h.y); vec3 p2 = vec3(a1.xy, h.z); vec3 p3 = vec3(a1.zw, h.w);
|
||||
vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
|
||||
p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;
|
||||
vec4 m = max(.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.); m = m * m;
|
||||
return 42. * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
|
||||
}
|
||||
// premultiplied "over": c with coverage a goes on top of dst
|
||||
void over(inout vec4 dst, vec3 c, float a) { a = clamp(a, 0., 1.); dst = vec4(c * a, a) + dst * (1. - a); }
|
||||
vec2 frag() { return (gl_FragCoord.xy - 0.5 * uRes) * uPx; }
|
||||
`,L=`
|
||||
uniform float uHead, uLen, uSurge, uMid, uFlowA, uFlowB, uFlowW;
|
||||
uniform sampler2D uWet; // how recently each stretch of pipe was under water, 1 = now
|
||||
const float RI = 0.84; // bore radius / outer radius: the rest is glass wall
|
||||
const float MEN = 0.55; // meniscus depth, fraction of bore radius
|
||||
// x: coverage, y: distance behind the head along the pipe, z: distance inside the nearest meniscus
|
||||
vec3 slug(float s, float vi) {
|
||||
float rel = mod(uHead - s + 24., PER) - 24.;
|
||||
float gap = PER - uLen, full = 1. - smoothstep(0.3, 1.5, gap); // O: the two ends meet and the ring closes
|
||||
float c = sqrt(max(0., 1. - vi * vi));
|
||||
float m = MEN * HW * RI * smoothstep(0., 30., gap);
|
||||
float front = m * c * (1. - 0.4 * uSurge); // concave: the water climbs the wall ahead of the centre
|
||||
float back = uLen + m * (1. - c) * (1. + 0.4 * uSurge);
|
||||
float dIn = mix(min(rel - front, back - rel), 60., full);
|
||||
return vec3(clamp(dIn / uPx + 0.5, 0., 1.), rel, dIn);
|
||||
}
|
||||
// noise laid on a circle, so the texture wraps the loop without a seam
|
||||
float ringNoise(float s, float vi, float freq, float z) {
|
||||
float a = 6.2831853 * s / PER, R = PER / 6.2831853 * freq;
|
||||
return snoise(vec3(R * cos(a) + uTime * 0.3, R * sin(a) - uTime * 0.2, vi * 1.25 + z));
|
||||
}
|
||||
float flowTex(float s, float vi, float z) {
|
||||
return 0.5 + 0.5 * (0.6 * ringNoise(s, vi, 0.06, z) + 0.28 * ringNoise(s, vi * 1.8, 0.13, z + 3.1) + 0.12 * ringNoise(s, vi * 3.6, 0.27, z + 7.7));
|
||||
}
|
||||
void main() {
|
||||
vec2 p = frag();
|
||||
vec4 o = vec4(0.);
|
||||
// contact shadow thrown down-left, and the light the water focuses into it
|
||||
vec2 so = -L2 * 5.5;
|
||||
vec2 ps = p - so;
|
||||
float dsh = sdRB(ps);
|
||||
float sr = abs(dsh) / HW; // glass passes most light: the shadow is darkest under the walls
|
||||
o.a = (1. - smoothstep(-4., 10., abs(dsh) - HW)) * mix(0.05, 0.2, uDark) + exp(-pow((sr - 0.95) / 0.35, 2.)) * mix(0.08, 0.06, uDark);
|
||||
{
|
||||
vec3 Ws = slug(pathS(ps), clamp(dsh / (HW * RI), -1., 1.));
|
||||
float cz = exp(-pow((dsh / HW + 0.2) / 0.3, 2.)) * Ws.x;
|
||||
o.rgb += mix(uColor, vec3(1.), 0.25) * cz * mix(0.45, 0.12, uDark);
|
||||
}
|
||||
float dc = sdRB(p);
|
||||
float v = dc / HW;
|
||||
float tube = clamp((HW - abs(dc)) / uPx + 0.5, 0., 1.);
|
||||
if (tube <= 0.) { gl_FragColor = o; return; }
|
||||
vec2 n2 = normalize(p - clamp(p, -H, H) + 1e-4);
|
||||
vec2 t2 = vec2(-n2.y, n2.x);
|
||||
float s = pathS(p);
|
||||
float vc = clamp(v, -1., 1.);
|
||||
vec3 N = vec3(n2 * vc, sqrt(max(0., 1. - vc * vc)));
|
||||
vec3 Ld = normalize(vec3(L2 * 0.78, 0.62));
|
||||
vec3 Hh = normalize(Ld + vec3(0., 0., 1.));
|
||||
vec3 gTint = mix(vec3(0.42, 0.50, 0.53), vec3(0.78, 0.88, 0.92), uDark);
|
||||
vec3 hiC = vec3(1.0, 0.985, 0.95);
|
||||
// glass: the walls are thicker to the eye near the silhouette
|
||||
float gl = 2. * (sqrt(max(0., 1. - vc * vc)) - sqrt(max(0., RI * RI - vc * vc)));
|
||||
float gA = 1. - exp(-gl * 0.42);
|
||||
over(o, gTint, gA * 0.3 * tube);
|
||||
float vi = clamp(v / RI, -1., 1.);
|
||||
float bore = clamp((RI * HW - abs(dc)) / uPx + 0.5, 0., 1.);
|
||||
vec3 W = slug(s, vi);
|
||||
float cov = W.x * bore;
|
||||
vec2 hl = vec2(dot(L2, -t2), dot(L2, n2)); // light direction in the slug's local frame
|
||||
vec3 wetC = mix(uColor, vec3(1.), 0.35);
|
||||
// where the water has just left: a film on the walls and beads that drain away
|
||||
float wet = texture2D(uWet, vec2(s / PER, 0.5)).r * (1. - W.x);
|
||||
if (wet > 0.01 && bore > 0.) {
|
||||
over(o, wetC, wet * 0.22 * smoothstep(0.5, 0.95, abs(vi)) * bore);
|
||||
float cs = PER / 110.;
|
||||
float gx = floor(s / cs), gy = floor((vi + 1.) * 2.);
|
||||
for (int a = -1; a <= 1; a++) for (int b = -1; b <= 1; b++) {
|
||||
vec2 cell = vec2(gx + float(a), gy + float(b));
|
||||
if (cell.y < 0. || cell.y > 3.) continue;
|
||||
vec2 hc = vec2(mod(cell.x, 110.), cell.y);
|
||||
vec2 h = hash22(hc);
|
||||
float h3 = hash12(hc.yx + 17.);
|
||||
float pres = smoothstep(h3, h3 + 0.3, wet * 1.2) * step(0.45, hash12(hc + 3.7));
|
||||
if (pres <= 0.01) continue;
|
||||
vec2 c = vec2((cell.x + h.x) * cs, clamp(-1. + (cell.y + h.y) * 0.5, -0.88, 0.88));
|
||||
float r = mix(0.35, 1.3, h.x * h.y) * sqrt(pres);
|
||||
vec2 dl = vec2(s - c.x, (vi - c.y) * RI * HW);
|
||||
float d = length(dl) - r;
|
||||
float fill = clamp(-d / uPx + 0.5, 0., 1.) * bore;
|
||||
over(o, wetC * 0.75, fill * 0.45);
|
||||
over(o, uColor * 0.4, exp(-pow(d / 0.25, 2.)) * 0.35 * bore);
|
||||
over(o, hiC, exp(-pow(length(dl - vec2(-hl.x, hl.y) * r * 0.45) / (0.28 * r + 0.08), 2.)) * 0.85 * bore);
|
||||
}
|
||||
}
|
||||
if (cov > 0.) {
|
||||
float th = sqrt(max(0., 1. - vi * vi));
|
||||
float kv = 1. + 0.4 * (1. - 2. * vi * vi); // the centre runs ahead of the walls
|
||||
float tex = mix(flowTex(s - kv * uFlowA, vi, 0.), flowTex(s - kv * uFlowB, vi, 7.3), uFlowW);
|
||||
float side = dot(n2 * vi, L2);
|
||||
vec3 wc = mix(mix(uColor, vec3(1.), 0.55), uColor, smoothstep(0.05, 0.9, th)); // Beer-Lambert: thicker is deeper
|
||||
wc *= 1. - 0.55 * smoothstep(0.62, 1.0, abs(vi)); // total internal reflection at the wall
|
||||
wc += mix(uColor, vec3(1.), 0.65) * exp(-pow((side + 0.42) / 0.17, 2.)) * 0.42; // caustic on the far wall
|
||||
wc *= 0.8 + 0.4 * tex;
|
||||
float spA = smoothstep(0.62, 0.9, ringNoise(s - kv * uFlowA, vi * 4., 0.45, 11.));
|
||||
float spB = smoothstep(0.62, 0.9, ringNoise(s - kv * uFlowB, vi * 4., 0.45, 19.));
|
||||
wc += 0.25 * mix(spA, spB, uFlowW);
|
||||
wc *= 1. - 0.6 * exp(-pow(W.z / 1.1, 2.)); // meniscus: dark refracted band
|
||||
wc += 0.5 * exp(-pow((W.z - 2.1) / 0.7, 2.)) * mix(uColor, vec3(1.), 0.75); // and its bright inner lip
|
||||
over(o, wc, (0.58 + 0.34 * th + 0.2 * exp(-pow(W.z / 1.5, 2.))) * cov);
|
||||
// entrained bubbles ride the flow; they only move when the water does
|
||||
float full = 1. - smoothstep(0.3, 1.5, PER - uLen);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
float fi = float(i);
|
||||
float bv = (hash11(fi + 1.3) * 2. - 1.) * 0.62;
|
||||
float br = mix(0.5, 1.9, hash11(fi + 7.9) * hash11(fi + 3.1));
|
||||
float bk = 1. + 0.35 * (1. - 2. * bv * bv) + 0.2 * (hash11(fi + 4.4) - 0.5);
|
||||
float bs = mod(hash11(fi + 9.2) * PER + bk * uMid, PER);
|
||||
float bx = mod(uHead - bs + 24., PER) - 24.;
|
||||
float fade = mix(smoothstep(4., 9., bx) * smoothstep(uLen, uLen - 9., bx), 1., full);
|
||||
vec2 dl = vec2(W.y - bx, (vi - bv) * RI * HW);
|
||||
dl.x -= PER * floor(dl.x / PER + 0.5);
|
||||
float d = length(dl) - br;
|
||||
if (d < 1.2 && fade > 0.) {
|
||||
float f = fade * cov;
|
||||
over(o, mix(wc, vec3(1.), 0.5), clamp(-d / uPx + 0.5, 0., 1.) * 0.3 * f);
|
||||
over(o, wc * 0.3, exp(-pow(d / 0.28, 2.)) * 0.6 * f);
|
||||
over(o, hiC, exp(-pow(length(dl - hl * br * 0.42) / (0.22 * br + 0.12), 2.)) * 0.9 * f);
|
||||
}
|
||||
}
|
||||
}
|
||||
// front wall, reflections
|
||||
over(o, gTint, gA * 0.3 * tube);
|
||||
float ndh = max(dot(N, Hh), 0.);
|
||||
float spec = pow(ndh, 110.) * 0.95 + pow(ndh, 14.) * 0.09;
|
||||
spec += pow(max(dot(vec3(-N.xy, N.z), Hh), 0.), 70.) * 0.28; // the back inner surface
|
||||
float fres = pow(1. - N.z, 3.) * mix(0.12, 0.3, uDark);
|
||||
float wl = exp(-pow((abs(v) - RI) * HW / 0.3, 2.)) * 0.2; // bore wall seen edge-on
|
||||
over(o, hiC, (spec + fres + wl) * tube);
|
||||
over(o, gTint * 0.55, exp(-pow((abs(v) - 1.) * HW / 0.45, 2.)) * mix(0.45, 0.1, uDark) * tube);
|
||||
gl_FragColor = o;
|
||||
}`,v=`
|
||||
uniform vec4 uPuff[${c}]; // one puff per stretch of the frame: centre xy, radius, weight
|
||||
const float W0 = ${f.toFixed(4)};
|
||||
float fbm(vec3 p) { float f = 0., a = 0.55; for (int i = 0; i < 4; i++) { f += a * snoise(p); p = p * 2.03 + vec3(1.7, 9.2, 3.1); a *= 0.42; } return f; }
|
||||
vec2 warpAt(vec2 p) { vec3 np = vec3(p * 0.022, uTime * 0.12); return vec2(snoise(np), snoise(np + vec3(19.1, 7.3, 3.7))); }
|
||||
// x: density, y: mean growth of the puffs here (released smoke has grown)
|
||||
vec2 puffs(vec2 p, vec2 warp) {
|
||||
float D = 0., G = 0.;
|
||||
for (int i = 0; i < ${c}; i++) {
|
||||
vec4 f = uPuff[i];
|
||||
float grow = f.z - W0;
|
||||
vec2 q = p - warp * (1.5 + 0.6 * grow) - f.xy; // turbulence displaces older smoke further (kept below folding)
|
||||
float g = f.w * exp(-dot(q, q) / (f.z * f.z));
|
||||
D += g; G += g * grow;
|
||||
}
|
||||
return vec2(D, G / max(D, 1e-5));
|
||||
}
|
||||
void main() {
|
||||
vec2 p = frag();
|
||||
vec2 wp = warpAt(p);
|
||||
vec2 P = puffs(p, wp);
|
||||
float ext = min(0.5 * uRes.x * uPx - abs(p.x), 0.5 * uRes.y * uPx - abs(p.y));
|
||||
P.x *= smoothstep(0., 16., ext);
|
||||
if (P.x < 0.004) { gl_FragColor = vec4(0.); return; }
|
||||
// billows: domain-warped noise evolving in place, eaten away as the smoke ages
|
||||
vec2 pw = p - wp * (1.5 + 0.6 * P.y);
|
||||
vec3 dp = vec3(pw * 0.035, uTime * 0.16);
|
||||
vec2 q = vec2(snoise(dp), snoise(dp + vec3(5.2, 1.3, 2.8)));
|
||||
float n = fbm(vec3(pw * 0.045 + 1.1 * q, uTime * 0.2 + 3.));
|
||||
float bil = smoothstep(-0.7, 0.55, n + 0.1 - 0.04 * P.y);
|
||||
float d = P.x * (0.5 + 0.75 * bil);
|
||||
// light from the upper right: shade by how much smoke lies toward it
|
||||
vec2 pl = p + L2 * 7.;
|
||||
float dl = puffs(pl, warpAt(pl)).x;
|
||||
float lit = clamp(mix(0.55, 0.85, uDark) - (dl - P.x) * mix(1.3, 0.9, uDark), 0., 1.) * (0.88 + 0.16 * bil);
|
||||
float a = 1. - exp(-d * 1.9);
|
||||
vec3 shade = uColor * mix(vec3(0.62, 0.64, 0.70), vec3(0.50, 0.53, 0.60), uDark);
|
||||
vec3 c = mix(shade, uColor, clamp(lit, 0., 1.));
|
||||
c += uColor * 0.18 * (1. - a) * lit; // thin wisps let light through
|
||||
gl_FragColor = vec4(min(c, vec3(1.)) * a, a);
|
||||
}`,E=`
|
||||
uniform float uSegA, uLen, uMix, uMove, uHum, uTR;
|
||||
uniform vec3 uColA, uColB;
|
||||
uniform vec2 uPts[${h}];
|
||||
vec3 emit(float s) {
|
||||
float x = mod(s - uSegA, PER); // distance ahead of the tail
|
||||
float din = x <= uLen ? min(x, uLen - x) : -min(x - uLen, PER - x);
|
||||
din = mix(din, 1e3, step(PER - 0.5, uLen));
|
||||
float on = smoothstep(-0.6, 0.6, din);
|
||||
float strike = uMove * exp(-max(uLen - x, 0.) / 18.) * on; // the end being struck stutters while it runs
|
||||
float fl = mix(1., 0.15 + 0.85 * step(0.3, hash12(vec2(floor(x / 6.), floor(uTime * 30.)))), strike);
|
||||
float after = uMove * exp(-mod(uSegA - s, PER) / 10.) * (1. - on) * 0.6; // the tail lets go with an afterglow
|
||||
vec3 col = mix(uColB, uColA, uMix);
|
||||
return (col * (on * fl * (1. + 0.6 * strike) + after) + vec3(0.35) * strike * fl) * uHum;
|
||||
}
|
||||
void main() {
|
||||
vec2 p = frag();
|
||||
float dc = sdRB(p), d = abs(dc), s = pathS(p);
|
||||
vec3 e = emit(s);
|
||||
// light spilling onto the wall: integrated over the whole tube so every lit stretch contributes
|
||||
vec3 g = vec3(0.);
|
||||
for (int i = 0; i < ${h}; i++) {
|
||||
vec2 dv = p - uPts[i];
|
||||
float r2 = dot(dv, dv);
|
||||
g += emit((float(i) + 0.5) * (PER / ${h}.)) * (exp(-r2 / 60.) + 0.35 * exp(-r2 / 420.));
|
||||
}
|
||||
g *= (PER / ${h}.) / 40.;
|
||||
float vt = clamp(dc / uTR, -1., 1.);
|
||||
float tm = clamp((uTR - d) / uPx + 0.5, 0., 1.);
|
||||
float I = max(max(e.r, e.g), e.b);
|
||||
float core = exp(-vt * vt * 3.2);
|
||||
vec3 tubeL = e * (0.4 + 0.85 * core) + vec3(1.) * I * pow(core, 4.) * 0.55; // white-hot centre, saturated rim
|
||||
vec3 nearL = e * exp(-max(d - uTR * 0.8, 0.) / 1.2) * 0.6;
|
||||
vec3 L = g + nearL * (1. - tm) + tubeL * tm;
|
||||
vec3 mapped = 1. - exp(-L * 1.25);
|
||||
// the glass itself, visible where it is dark
|
||||
vec2 n2 = normalize(p - clamp(p, -H, H) + 1e-4);
|
||||
vec3 N = vec3(n2 * vt, sqrt(max(0., 1. - vt * vt)));
|
||||
vec3 Hh = normalize(normalize(vec3(L2 * 0.78, 0.62)) + vec3(0., 0., 1.));
|
||||
vec3 gTint = mix(vec3(0.22, 0.24, 0.27), vec3(0.62, 0.66, 0.72), uDark);
|
||||
vec4 o = vec4(0.);
|
||||
over(o, gTint, tm * (0.14 + 0.35 * pow(1. - N.z, 2.)) * (1. - clamp(I, 0., 1.) * 0.6));
|
||||
if (uDark > 0.5) o.rgb += mapped;
|
||||
else { // on paper light can't add; lay the hue down instead, keeping it saturated
|
||||
vec3 Lc = g + nearL * (1. - tm) + e * (0.4 + 0.85 * core) * tm;
|
||||
float m = max(max(Lc.r, Lc.g), Lc.b);
|
||||
over(o, Lc / max(m, 1e-3), (1. - exp(-m * 1.4)) * mix(0.85, 1., tm));
|
||||
over(o, vec3(1.), pow(core, 4.) * min(I, 1.) * 0.6 * tm);
|
||||
}
|
||||
over(o, vec3(1.), pow(max(dot(N, Hh), 0.), 60.) * 0.5 * tm);
|
||||
gl_FragColor = o;
|
||||
}`,p={water:L,smoke:v,neon:E},y={water:1.3,smoke:1.9,neon:1.8},x={water:{color:"#2FA8FF"},smoke:{color:"#F5F5F2"},neon:{colors:["#FF2E88","#2EF0FF","#FFB020","#7CFF4F","#9B5CFF"],tube:.58}},M={sequence:"LUCIO",hold:.7,morph:.45,speed:1,size:96},F=m=>{let S=m.replace("#",""),z=S.length===3?S.split("").map(d=>d+d).join(""):S;return[0,2,4].map(d=>parseInt(z.slice(d,d+2),16)/255)},w=()=>n.matchMedia&&n.matchMedia("(prefers-reduced-motion: reduce)").matches,T=m=>m<.5?4*m*m*m:1-Math.pow(-2*m+2,3)/2,A=m=>m-Math.floor(m),P=m=>A(Math.sin(m*127.1+11.7)*43758.5453),N=(m,S,z)=>{let d=Math.min(1,Math.max(0,(z-m)/(S-m)));return d*d*(3-2*d)};function C(m){for(let S=m;S&&S.nodeType===1;S=S.parentElement){let z=getComputedStyle(S).backgroundColor.match(/[\d.]+/g);if(z&&(z.length<4||+z[3]>.5))return(.2126*z[0]+.7152*z[1]+.0722*z[2])/255<.5}return!!(n.matchMedia&&n.matchMedia("(prefers-color-scheme: dark)").matches)}let R={C:[0,.75],L:[.25,.75],U:[.25,1],I:[.75,1],O:[.75,1.75]};function _(m){let S=()=>{let X=(m.sequence||"LUCIO").toUpperCase().split("").filter(U=>R[U]);return X.length?X:["O"]},z=(X,U)=>{let[q,I]=R[U];for(let j=-1;j<6;j++)if(q+j>=X[0]-1e-6&&I+j>=X[1]-1e-6)return[q+j,I+j];return[q,I]},d={i:0,j:0,seg:R[S()[0]].slice(),u:1,f:1,moving:!1,travel:0,vHead:0},H=d.seg,D=d.seg,u=0;return d.step=X=>{let U=d.seg.slice();if(u+=X,!d.moving&&u>=m.hold){let q=S();d.j=(d.i+1)%q.length,H=d.seg.slice(),D=z(d.seg,q[d.j]),d.moving=!0,u-=m.hold}if(d.moving){let q=w()?0:m.morph;d.f=q>0?Math.min(1,u/q):1,d.u=T(d.f),d.seg=[H[0]+(D[0]-H[0])*d.u,H[1]+(D[1]-H[1])*d.u],d.f>=1&&(d.moving=!1,d.i=d.j,u=0)}else d.f=1,d.u=1;if(d.travel+=(d.seg[0]-U[0]+(d.seg[1]-U[1]))/2*a,d.vHead=X>0?(d.seg[1]-U[1])*a/X:0,!d.moving){let q=Math.floor(d.seg[0]);d.seg[0]-=q,d.seg[1]-=q}},d.units=()=>({a:a*(d.seg[0]+.25),len:Math.min(a,(d.seg[1]-d.seg[0])*a)}),d.reset=()=>{d.i=d.j=0,d.seg=R[S()[0]].slice(),d.moving=!1,u=0},d}let O=new Set,$=0,Q=0;function pe(m){let S=Q?Math.min(.1,(m-Q)/1e3):0;Q=m;for(let z of O)z.frame(S);$=O.size?requestAnimationFrame(pe):0,$||(Q=0)}function oe(m,S,z){let d=Object.assign({},M,x[m],z||{}),H=document.createElement("div");H.className="lucio-fx lucio-fx-"+m,H.setAttribute("role","img"),H.setAttribute("aria-label","Loading"),H.style.cssText="position:relative;display:inline-block;vertical-align:middle;flex:none";let D=document.createElement("canvas");D.style.cssText="position:absolute;pointer-events:none",H.appendChild(D),S.appendChild(H);let u=D.getContext("webgl",{premultipliedAlpha:!0,alpha:!0,antialias:!1});if(!u)return console.warn("LucioLoaders: WebGL unavailable"),null;let X=(k,K)=>{let W=u.createShader(k);if(u.shaderSource(W,K),u.compileShader(W),!u.getShaderParameter(W,u.COMPILE_STATUS))throw new Error(m+": "+u.getShaderInfoLog(W));return W},U=u.createProgram();if(u.attachShader(U,X(u.VERTEX_SHADER,"attribute vec2 a; void main(){ gl_Position = vec4(a, 0., 1.); }")),u.attachShader(U,X(u.FRAGMENT_SHADER,g+p[m])),u.linkProgram(U),!u.getProgramParameter(U,u.LINK_STATUS))throw new Error(m+": "+u.getProgramInfoLog(U));u.useProgram(U),u.bindBuffer(u.ARRAY_BUFFER,u.createBuffer()),u.bufferData(u.ARRAY_BUFFER,new Float32Array([-1,-1,3,-1,-1,3]),u.STATIC_DRAW),u.enableVertexAttribArray(0),u.vertexAttribPointer(0,2,u.FLOAT,!1,0,0);let q={},I=k=>k in q?q[k]:q[k]=u.getUniformLocation(U,k);if(m==="neon"){let k=[];for(let K=0;K<h;K++)k.push(...b((K+.5)*a/h));u.uniform2fv(I("uPts[0]"),new Float32Array(k))}let j=64,mt=new Float32Array(j).fill(-1e3),ft=new Uint8Array(j);m==="water"&&(u.bindTexture(u.TEXTURE_2D,u.createTexture()),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.LINEAR),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.REPEAT),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.uniform1i(I("uWet"),0));let vt=new Float32Array(c*4),ae=new Float32Array(c),ye=new Float32Array(c),Y=_(d),gt=(k,K,W)=>{if(W>=a-.5)return 1e3;let G=((k-K)%a+a)%a;return G<=W?Math.min(G,W-G):-Math.min(G-W,a-G)},ie=0,Ge=d.theme==="light"?!1:d.theme==="dark"?!0:C(S),Zt=0,bt=!0,xe=n.IntersectionObserver?new IntersectionObserver(k=>{bt=k[0].isIntersecting}):null;xe&&xe.observe(H);function yt(k){d.size=k;let K=Math.min(n.devicePixelRatio||1,2),W=k*y[m];H.style.width=H.style.height=k+"px",D.style.width=D.style.height=W+"px",D.style.left=D.style.top=-(W-k)/2+"px",D.width=D.height=Math.round(W*K),u.viewport(0,0,D.width,D.height),u.uniform2f(I("uRes"),D.width,D.height),u.uniform1f(I("uPx"),120/(k*D.width/W))}yt(d.size);function xt(k){if((d.theme==="auto"||!d.theme)&&++Zt%30===0&&(Ge=C(S)),!bt)return;k*=d.speed,ie+=k*(w()?.35:1),Y.step(k);let{a:K,len:W}=Y.units();if(u.uniform1f(I("uTime"),ie),u.uniform1f(I("uDark"),Ge?1:0),m==="water"){let le=A(Y.travel/70),B=A(Y.travel/70+.5);u.uniform3fv(I("uColor"),F(d.color)),u.uniform1f(I("uHead"),K+W),u.uniform1f(I("uLen"),W),u.uniform1f(I("uSurge"),Math.min(1,Math.max(0,Y.vHead/700))),u.uniform1f(I("uMid"),Y.travel),u.uniform1f(I("uFlowA"),le*70),u.uni
Line truncated
|
||||
@@ -16,6 +16,5 @@
|
||||
<noscript><p>This album needs JavaScript to draw its photos.</p></noscript>
|
||||
<p><a href="/">All albums</a></p>
|
||||
</div>
|
||||
<template id="chop-template"><span class="chop">{{.Assets.Chop}}</span></template>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,10 +3,10 @@ set -euo pipefail
|
||||
|
||||
scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
repo_dir="$(dirname "$scripts_dir")"
|
||||
brand_dir="${LUCIO_IP_DIR:-$repo_dir/../LUCIO_ip}"
|
||||
brand_dir="${LUCIO_IP_DIR:-$repo_dir/../lucioIP}"
|
||||
out_dir="$repo_dir/web/brand"
|
||||
|
||||
for required in tokens/tokens.css motion/lucio-morph.js logo/favicon.svg logo/lucio-chop-chen.svg; do
|
||||
for required in tokens/tokens.css motion/lucio-morph.js motion/lucio-loaders.js logo/favicon.svg logo/lucio-chop-chen.svg; do
|
||||
if [ ! -f "$brand_dir/$required" ]; then
|
||||
echo "sync-brand: $brand_dir/$required not found (set LUCIO_IP_DIR)" >&2
|
||||
exit 1
|
||||
@@ -33,7 +33,8 @@ strip_svg() {
|
||||
} > "$out_dir/tokens.css"
|
||||
|
||||
strip_js < "$brand_dir/motion/lucio-morph.js" > "$out_dir/lucio-morph.js"
|
||||
strip_js < "$brand_dir/motion/lucio-loaders.js" > "$out_dir/lucio-loaders.js"
|
||||
strip_svg < "$brand_dir/logo/favicon.svg" > "$out_dir/favicon.svg"
|
||||
strip_svg < "$brand_dir/logo/lucio-chop-chen.svg" > "$out_dir/lucio-chop-chen.svg"
|
||||
|
||||
echo "sync-brand: copied tokens.css, lucio-morph.js, favicon.svg, lucio-chop-chen.svg from $brand_dir into $out_dir"
|
||||
echo "sync-brand: copied tokens.css, lucio-morph.js, lucio-loaders.js, favicon.svg, lucio-chop-chen.svg from $brand_dir into $out_dir"
|
||||
@@ -0,0 +1,468 @@
|
||||
(function (global) {
|
||||
const HB = 49.8, CR = 16.2, HW = 10.2, H = HB - CR, SL = 2 * H, CL = Math.PI / 2 * CR, PER = 4 * (SL + CL), Q = PER / 4;
|
||||
const NPTS = 96, NPUFF = 64, W0 = HW * 0.85;
|
||||
function pathP(s) {
|
||||
s = (((s - CL / 2) % PER) + PER) % PER;
|
||||
const arc = (cx, cy, a) => [cx + CR * Math.cos(a), cy + CR * Math.sin(a)];
|
||||
if (s < SL) return [HB, -H + s]; s -= SL;
|
||||
if (s < CL) return arc(H, H, s / CR); s -= CL;
|
||||
if (s < SL) return [H - s, HB]; s -= SL;
|
||||
if (s < CL) return arc(-H, H, Math.PI / 2 + s / CR); s -= CL;
|
||||
if (s < SL) return [-HB, H - s]; s -= SL;
|
||||
if (s < CL) return arc(-H, -H, Math.PI + s / CR); s -= CL;
|
||||
if (s < SL) return [-H + s, -HB]; s -= SL;
|
||||
return arc(H, -H, -Math.PI / 2 + s / CR);
|
||||
}
|
||||
const PRELUDE = `
|
||||
precision highp float;
|
||||
uniform vec2 uRes;
|
||||
uniform float uPx, uTime, uDark;
|
||||
uniform vec3 uColor;
|
||||
#define PI 3.14159265
|
||||
#define HPI 1.5707963
|
||||
const float HB = ${HB.toFixed(4)}, CR = ${CR.toFixed(4)}, HW = ${HW.toFixed(4)}, H = ${H.toFixed(4)};
|
||||
const float SL = ${SL.toFixed(4)}, CL = ${CL.toFixed(4)}, PER = ${PER.toFixed(4)}, Q = ${Q.toFixed(4)};
|
||||
const vec2 L2 = vec2(0.6608, 0.7506); // the brand's one light: from the upper right
|
||||
float sdRB(vec2 p) { vec2 q = abs(p) - vec2(H); return length(max(q, 0.)) + min(max(q.x, q.y), 0.) - CR; }
|
||||
// arc length of the nearest centreline point, CCW, 0 at the bottom-right corner's 45-degree point
|
||||
float pathS(vec2 p) {
|
||||
if (abs(p.x) <= H && abs(p.y) <= H) { if (abs(p.x) > abs(p.y)) p.x = sign(p.x) * (H + 1e-3); else p.y = sign(p.y) * (H + 1e-3); }
|
||||
float s;
|
||||
if (p.x > H && p.y > H) s = SL + atan(p.y - H, p.x - H) * CR;
|
||||
else if (p.x < -H && p.y > H) s = 2. * SL + CL + (atan(p.y - H, p.x + H) - HPI) * CR;
|
||||
else if (p.x < -H && p.y < -H) s = 3. * SL + 2. * CL + atan(-(p.y + H), -(p.x + H)) * CR;
|
||||
else if (p.x > H && p.y < -H) s = 4. * SL + 3. * CL + (atan(p.y + H, p.x - H) + HPI) * CR;
|
||||
else if (p.x > H) s = p.y + H;
|
||||
else if (p.y > H) s = SL + CL + (H - p.x);
|
||||
else if (p.x < -H) s = 2. * SL + 2. * CL + (H - p.y);
|
||||
else s = 3. * SL + 3. * CL + (p.x + H);
|
||||
return mod(s + CL * 0.5, PER);
|
||||
}
|
||||
float hash11(float n) { return fract(sin(n * 127.1 + 11.7) * 43758.5453); }
|
||||
float hash12(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * .1031); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.x + p3.y) * p3.z); }
|
||||
vec2 hash22(vec2 p) { vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973)); p3 += dot(p3, p3.yzx + 33.33); return fract((p3.xx + p3.yz) * p3.zy); }
|
||||
// simplex noise 3D (Ashima Arts / Stefan Gustavson, MIT)
|
||||
vec3 mod289(vec3 x) { return x - floor(x * (1. / 289.)) * 289.; }
|
||||
vec4 mod289(vec4 x) { return x - floor(x * (1. / 289.)) * 289.; }
|
||||
vec4 permute(vec4 x) { return mod289(((x * 34.) + 1.) * x); }
|
||||
vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
|
||||
float snoise(vec3 v) {
|
||||
const vec2 C = vec2(1. / 6., 1. / 3.); const vec4 D = vec4(0., .5, 1., 2.);
|
||||
vec3 i = floor(v + dot(v, C.yyy)); vec3 x0 = v - i + dot(i, C.xxx);
|
||||
vec3 g = step(x0.yzx, x0.xyz); vec3 l = 1. - g; vec3 i1 = min(g.xyz, l.zxy); vec3 i2 = max(g.xyz, l.zxy);
|
||||
vec3 x1 = x0 - i1 + C.xxx; vec3 x2 = x0 - i2 + C.yyy; vec3 x3 = x0 - D.yyy;
|
||||
i = mod289(i);
|
||||
vec4 p = permute(permute(permute(i.z + vec4(0., i1.z, i2.z, 1.)) + i.y + vec4(0., i1.y, i2.y, 1.)) + i.x + vec4(0., i1.x, i2.x, 1.));
|
||||
float n_ = 0.142857142857; vec3 ns = n_ * D.wyz - D.xzx;
|
||||
vec4 j = p - 49. * floor(p * ns.z * ns.z);
|
||||
vec4 x_ = floor(j * ns.z); vec4 y_ = floor(j - 7. * x_);
|
||||
vec4 x = x_ * ns.x + ns.yyyy; vec4 y = y_ * ns.x + ns.yyyy; vec4 h = 1. - abs(x) - abs(y);
|
||||
vec4 b0 = vec4(x.xy, y.xy); vec4 b1 = vec4(x.zw, y.zw);
|
||||
vec4 s0 = floor(b0) * 2. + 1.; vec4 s1 = floor(b1) * 2. + 1.; vec4 sh = -step(h, vec4(0.));
|
||||
vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy; vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
|
||||
vec3 p0 = vec3(a0.xy, h.x); vec3 p1 = vec3(a0.zw, h.y); vec3 p2 = vec3(a1.xy, h.z); vec3 p3 = vec3(a1.zw, h.w);
|
||||
vec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));
|
||||
p0 *= norm.x; p1 *= norm.y; p2 *= norm.z; p3 *= norm.w;
|
||||
vec4 m = max(.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.); m = m * m;
|
||||
return 42. * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
|
||||
}
|
||||
// premultiplied "over": c with coverage a goes on top of dst
|
||||
void over(inout vec4 dst, vec3 c, float a) { a = clamp(a, 0., 1.); dst = vec4(c * a, a) + dst * (1. - a); }
|
||||
vec2 frag() { return (gl_FragCoord.xy - 0.5 * uRes) * uPx; }
|
||||
`;
|
||||
const WATER = `
|
||||
uniform float uHead, uLen, uSurge, uMid, uFlowA, uFlowB, uFlowW;
|
||||
uniform sampler2D uWet; // how recently each stretch of pipe was under water, 1 = now
|
||||
const float RI = 0.84; // bore radius / outer radius: the rest is glass wall
|
||||
const float MEN = 0.55; // meniscus depth, fraction of bore radius
|
||||
// x: coverage, y: distance behind the head along the pipe, z: distance inside the nearest meniscus
|
||||
vec3 slug(float s, float vi) {
|
||||
float rel = mod(uHead - s + 24., PER) - 24.;
|
||||
float gap = PER - uLen, full = 1. - smoothstep(0.3, 1.5, gap); // O: the two ends meet and the ring closes
|
||||
float c = sqrt(max(0., 1. - vi * vi));
|
||||
float m = MEN * HW * RI * smoothstep(0., 30., gap);
|
||||
float front = m * c * (1. - 0.4 * uSurge); // concave: the water climbs the wall ahead of the centre
|
||||
float back = uLen + m * (1. - c) * (1. + 0.4 * uSurge);
|
||||
float dIn = mix(min(rel - front, back - rel), 60., full);
|
||||
return vec3(clamp(dIn / uPx + 0.5, 0., 1.), rel, dIn);
|
||||
}
|
||||
// noise laid on a circle, so the texture wraps the loop without a seam
|
||||
float ringNoise(float s, float vi, float freq, float z) {
|
||||
float a = 6.2831853 * s / PER, R = PER / 6.2831853 * freq;
|
||||
return snoise(vec3(R * cos(a) + uTime * 0.3, R * sin(a) - uTime * 0.2, vi * 1.25 + z));
|
||||
}
|
||||
float flowTex(float s, float vi, float z) {
|
||||
return 0.5 + 0.5 * (0.6 * ringNoise(s, vi, 0.06, z) + 0.28 * ringNoise(s, vi * 1.8, 0.13, z + 3.1) + 0.12 * ringNoise(s, vi * 3.6, 0.27, z + 7.7));
|
||||
}
|
||||
void main() {
|
||||
vec2 p = frag();
|
||||
vec4 o = vec4(0.);
|
||||
// contact shadow thrown down-left, and the light the water focuses into it
|
||||
vec2 so = -L2 * 5.5;
|
||||
vec2 ps = p - so;
|
||||
float dsh = sdRB(ps);
|
||||
float sr = abs(dsh) / HW; // glass passes most light: the shadow is darkest under the walls
|
||||
o.a = (1. - smoothstep(-4., 10., abs(dsh) - HW)) * mix(0.05, 0.2, uDark) + exp(-pow((sr - 0.95) / 0.35, 2.)) * mix(0.08, 0.06, uDark);
|
||||
{
|
||||
vec3 Ws = slug(pathS(ps), clamp(dsh / (HW * RI), -1., 1.));
|
||||
float cz = exp(-pow((dsh / HW + 0.2) / 0.3, 2.)) * Ws.x;
|
||||
o.rgb += mix(uColor, vec3(1.), 0.25) * cz * mix(0.45, 0.12, uDark);
|
||||
}
|
||||
float dc = sdRB(p);
|
||||
float v = dc / HW;
|
||||
float tube = clamp((HW - abs(dc)) / uPx + 0.5, 0., 1.);
|
||||
if (tube <= 0.) { gl_FragColor = o; return; }
|
||||
vec2 n2 = normalize(p - clamp(p, -H, H) + 1e-4);
|
||||
vec2 t2 = vec2(-n2.y, n2.x);
|
||||
float s = pathS(p);
|
||||
float vc = clamp(v, -1., 1.);
|
||||
vec3 N = vec3(n2 * vc, sqrt(max(0., 1. - vc * vc)));
|
||||
vec3 Ld = normalize(vec3(L2 * 0.78, 0.62));
|
||||
vec3 Hh = normalize(Ld + vec3(0., 0., 1.));
|
||||
vec3 gTint = mix(vec3(0.42, 0.50, 0.53), vec3(0.78, 0.88, 0.92), uDark);
|
||||
vec3 hiC = vec3(1.0, 0.985, 0.95);
|
||||
// glass: the walls are thicker to the eye near the silhouette
|
||||
float gl = 2. * (sqrt(max(0., 1. - vc * vc)) - sqrt(max(0., RI * RI - vc * vc)));
|
||||
float gA = 1. - exp(-gl * 0.42);
|
||||
over(o, gTint, gA * 0.3 * tube);
|
||||
float vi = clamp(v / RI, -1., 1.);
|
||||
float bore = clamp((RI * HW - abs(dc)) / uPx + 0.5, 0., 1.);
|
||||
vec3 W = slug(s, vi);
|
||||
float cov = W.x * bore;
|
||||
vec2 hl = vec2(dot(L2, -t2), dot(L2, n2)); // light direction in the slug's local frame
|
||||
vec3 wetC = mix(uColor, vec3(1.), 0.35);
|
||||
// where the water has just left: a film on the walls and beads that drain away
|
||||
float wet = texture2D(uWet, vec2(s / PER, 0.5)).r * (1. - W.x);
|
||||
if (wet > 0.01 && bore > 0.) {
|
||||
over(o, wetC, wet * 0.22 * smoothstep(0.5, 0.95, abs(vi)) * bore);
|
||||
float cs = PER / 110.;
|
||||
float gx = floor(s / cs), gy = floor((vi + 1.) * 2.);
|
||||
for (int a = -1; a <= 1; a++) for (int b = -1; b <= 1; b++) {
|
||||
vec2 cell = vec2(gx + float(a), gy + float(b));
|
||||
if (cell.y < 0. || cell.y > 3.) continue;
|
||||
vec2 hc = vec2(mod(cell.x, 110.), cell.y);
|
||||
vec2 h = hash22(hc);
|
||||
float h3 = hash12(hc.yx + 17.);
|
||||
float pres = smoothstep(h3, h3 + 0.3, wet * 1.2) * step(0.45, hash12(hc + 3.7));
|
||||
if (pres <= 0.01) continue;
|
||||
vec2 c = vec2((cell.x + h.x) * cs, clamp(-1. + (cell.y + h.y) * 0.5, -0.88, 0.88));
|
||||
float r = mix(0.35, 1.3, h.x * h.y) * sqrt(pres);
|
||||
vec2 dl = vec2(s - c.x, (vi - c.y) * RI * HW);
|
||||
float d = length(dl) - r;
|
||||
float fill = clamp(-d / uPx + 0.5, 0., 1.) * bore;
|
||||
over(o, wetC * 0.75, fill * 0.45);
|
||||
over(o, uColor * 0.4, exp(-pow(d / 0.25, 2.)) * 0.35 * bore);
|
||||
over(o, hiC, exp(-pow(length(dl - vec2(-hl.x, hl.y) * r * 0.45) / (0.28 * r + 0.08), 2.)) * 0.85 * bore);
|
||||
}
|
||||
}
|
||||
if (cov > 0.) {
|
||||
float th = sqrt(max(0., 1. - vi * vi));
|
||||
float kv = 1. + 0.4 * (1. - 2. * vi * vi); // the centre runs ahead of the walls
|
||||
float tex = mix(flowTex(s - kv * uFlowA, vi, 0.), flowTex(s - kv * uFlowB, vi, 7.3), uFlowW);
|
||||
float side = dot(n2 * vi, L2);
|
||||
vec3 wc = mix(mix(uColor, vec3(1.), 0.55), uColor, smoothstep(0.05, 0.9, th)); // Beer-Lambert: thicker is deeper
|
||||
wc *= 1. - 0.55 * smoothstep(0.62, 1.0, abs(vi)); // total internal reflection at the wall
|
||||
wc += mix(uColor, vec3(1.), 0.65) * exp(-pow((side + 0.42) / 0.17, 2.)) * 0.42; // caustic on the far wall
|
||||
wc *= 0.8 + 0.4 * tex;
|
||||
float spA = smoothstep(0.62, 0.9, ringNoise(s - kv * uFlowA, vi * 4., 0.45, 11.));
|
||||
float spB = smoothstep(0.62, 0.9, ringNoise(s - kv * uFlowB, vi * 4., 0.45, 19.));
|
||||
wc += 0.25 * mix(spA, spB, uFlowW);
|
||||
wc *= 1. - 0.6 * exp(-pow(W.z / 1.1, 2.)); // meniscus: dark refracted band
|
||||
wc += 0.5 * exp(-pow((W.z - 2.1) / 0.7, 2.)) * mix(uColor, vec3(1.), 0.75); // and its bright inner lip
|
||||
over(o, wc, (0.58 + 0.34 * th + 0.2 * exp(-pow(W.z / 1.5, 2.))) * cov);
|
||||
// entrained bubbles ride the flow; they only move when the water does
|
||||
float full = 1. - smoothstep(0.3, 1.5, PER - uLen);
|
||||
for (int i = 0; i < 12; i++) {
|
||||
float fi = float(i);
|
||||
float bv = (hash11(fi + 1.3) * 2. - 1.) * 0.62;
|
||||
float br = mix(0.5, 1.9, hash11(fi + 7.9) * hash11(fi + 3.1));
|
||||
float bk = 1. + 0.35 * (1. - 2. * bv * bv) + 0.2 * (hash11(fi + 4.4) - 0.5);
|
||||
float bs = mod(hash11(fi + 9.2) * PER + bk * uMid, PER);
|
||||
float bx = mod(uHead - bs + 24., PER) - 24.;
|
||||
float fade = mix(smoothstep(4., 9., bx) * smoothstep(uLen, uLen - 9., bx), 1., full);
|
||||
vec2 dl = vec2(W.y - bx, (vi - bv) * RI * HW);
|
||||
dl.x -= PER * floor(dl.x / PER + 0.5);
|
||||
float d = length(dl) - br;
|
||||
if (d < 1.2 && fade > 0.) {
|
||||
float f = fade * cov;
|
||||
over(o, mix(wc, vec3(1.), 0.5), clamp(-d / uPx + 0.5, 0., 1.) * 0.3 * f);
|
||||
over(o, wc * 0.3, exp(-pow(d / 0.28, 2.)) * 0.6 * f);
|
||||
over(o, hiC, exp(-pow(length(dl - hl * br * 0.42) / (0.22 * br + 0.12), 2.)) * 0.9 * f);
|
||||
}
|
||||
}
|
||||
}
|
||||
// front wall, reflections
|
||||
over(o, gTint, gA * 0.3 * tube);
|
||||
float ndh = max(dot(N, Hh), 0.);
|
||||
float spec = pow(ndh, 110.) * 0.95 + pow(ndh, 14.) * 0.09;
|
||||
spec += pow(max(dot(vec3(-N.xy, N.z), Hh), 0.), 70.) * 0.28; // the back inner surface
|
||||
float fres = pow(1. - N.z, 3.) * mix(0.12, 0.3, uDark);
|
||||
float wl = exp(-pow((abs(v) - RI) * HW / 0.3, 2.)) * 0.2; // bore wall seen edge-on
|
||||
over(o, hiC, (spec + fres + wl) * tube);
|
||||
over(o, gTint * 0.55, exp(-pow((abs(v) - 1.) * HW / 0.45, 2.)) * mix(0.45, 0.1, uDark) * tube);
|
||||
gl_FragColor = o;
|
||||
}`;
|
||||
const SMOKE = `
|
||||
uniform vec4 uPuff[${NPUFF}]; // one puff per stretch of the frame: centre xy, radius, weight
|
||||
const float W0 = ${W0.toFixed(4)};
|
||||
float fbm(vec3 p) { float f = 0., a = 0.55; for (int i = 0; i < 4; i++) { f += a * snoise(p); p = p * 2.03 + vec3(1.7, 9.2, 3.1); a *= 0.42; } return f; }
|
||||
vec2 warpAt(vec2 p) { vec3 np = vec3(p * 0.022, uTime * 0.12); return vec2(snoise(np), snoise(np + vec3(19.1, 7.3, 3.7))); }
|
||||
// x: density, y: mean growth of the puffs here (released smoke has grown)
|
||||
vec2 puffs(vec2 p, vec2 warp) {
|
||||
float D = 0., G = 0.;
|
||||
for (int i = 0; i < ${NPUFF}; i++) {
|
||||
vec4 f = uPuff[i];
|
||||
float grow = f.z - W0;
|
||||
vec2 q = p - warp * (1.5 + 0.6 * grow) - f.xy; // turbulence displaces older smoke further (kept below folding)
|
||||
float g = f.w * exp(-dot(q, q) / (f.z * f.z));
|
||||
D += g; G += g * grow;
|
||||
}
|
||||
return vec2(D, G / max(D, 1e-5));
|
||||
}
|
||||
void main() {
|
||||
vec2 p = frag();
|
||||
vec2 wp = warpAt(p);
|
||||
vec2 P = puffs(p, wp);
|
||||
float ext = min(0.5 * uRes.x * uPx - abs(p.x), 0.5 * uRes.y * uPx - abs(p.y));
|
||||
P.x *= smoothstep(0., 16., ext);
|
||||
if (P.x < 0.004) { gl_FragColor = vec4(0.); return; }
|
||||
// billows: domain-warped noise evolving in place, eaten away as the smoke ages
|
||||
vec2 pw = p - wp * (1.5 + 0.6 * P.y);
|
||||
vec3 dp = vec3(pw * 0.035, uTime * 0.16);
|
||||
vec2 q = vec2(snoise(dp), snoise(dp + vec3(5.2, 1.3, 2.8)));
|
||||
float n = fbm(vec3(pw * 0.045 + 1.1 * q, uTime * 0.2 + 3.));
|
||||
float bil = smoothstep(-0.7, 0.55, n + 0.1 - 0.04 * P.y);
|
||||
float d = P.x * (0.5 + 0.75 * bil);
|
||||
// light from the upper right: shade by how much smoke lies toward it
|
||||
vec2 pl = p + L2 * 7.;
|
||||
float dl = puffs(pl, warpAt(pl)).x;
|
||||
float lit = clamp(mix(0.55, 0.85, uDark) - (dl - P.x) * mix(1.3, 0.9, uDark), 0., 1.) * (0.88 + 0.16 * bil);
|
||||
float a = 1. - exp(-d * 1.9);
|
||||
vec3 shade = uColor * mix(vec3(0.62, 0.64, 0.70), vec3(0.50, 0.53, 0.60), uDark);
|
||||
vec3 c = mix(shade, uColor, clamp(lit, 0., 1.));
|
||||
c += uColor * 0.18 * (1. - a) * lit; // thin wisps let light through
|
||||
gl_FragColor = vec4(min(c, vec3(1.)) * a, a);
|
||||
}`;
|
||||
const NEON = `
|
||||
uniform float uSegA, uLen, uMix, uMove, uHum, uTR;
|
||||
uniform vec3 uColA, uColB;
|
||||
uniform vec2 uPts[${NPTS}];
|
||||
vec3 emit(float s) {
|
||||
float x = mod(s - uSegA, PER); // distance ahead of the tail
|
||||
float din = x <= uLen ? min(x, uLen - x) : -min(x - uLen, PER - x);
|
||||
din = mix(din, 1e3, step(PER - 0.5, uLen));
|
||||
float on = smoothstep(-0.6, 0.6, din);
|
||||
float strike = uMove * exp(-max(uLen - x, 0.) / 18.) * on; // the end being struck stutters while it runs
|
||||
float fl = mix(1., 0.15 + 0.85 * step(0.3, hash12(vec2(floor(x / 6.), floor(uTime * 30.)))), strike);
|
||||
float after = uMove * exp(-mod(uSegA - s, PER) / 10.) * (1. - on) * 0.6; // the tail lets go with an afterglow
|
||||
vec3 col = mix(uColB, uColA, uMix);
|
||||
return (col * (on * fl * (1. + 0.6 * strike) + after) + vec3(0.35) * strike * fl) * uHum;
|
||||
}
|
||||
void main() {
|
||||
vec2 p = frag();
|
||||
float dc = sdRB(p), d = abs(dc), s = pathS(p);
|
||||
vec3 e = emit(s);
|
||||
// light spilling onto the wall: integrated over the whole tube so every lit stretch contributes
|
||||
vec3 g = vec3(0.);
|
||||
for (int i = 0; i < ${NPTS}; i++) {
|
||||
vec2 dv = p - uPts[i];
|
||||
float r2 = dot(dv, dv);
|
||||
g += emit((float(i) + 0.5) * (PER / ${NPTS}.)) * (exp(-r2 / 60.) + 0.35 * exp(-r2 / 420.));
|
||||
}
|
||||
g *= (PER / ${NPTS}.) / 40.;
|
||||
float vt = clamp(dc / uTR, -1., 1.);
|
||||
float tm = clamp((uTR - d) / uPx + 0.5, 0., 1.);
|
||||
float I = max(max(e.r, e.g), e.b);
|
||||
float core = exp(-vt * vt * 3.2);
|
||||
vec3 tubeL = e * (0.4 + 0.85 * core) + vec3(1.) * I * pow(core, 4.) * 0.55; // white-hot centre, saturated rim
|
||||
vec3 nearL = e * exp(-max(d - uTR * 0.8, 0.) / 1.2) * 0.6;
|
||||
vec3 L = g + nearL * (1. - tm) + tubeL * tm;
|
||||
vec3 mapped = 1. - exp(-L * 1.25);
|
||||
// the glass itself, visible where it is dark
|
||||
vec2 n2 = normalize(p - clamp(p, -H, H) + 1e-4);
|
||||
vec3 N = vec3(n2 * vt, sqrt(max(0., 1. - vt * vt)));
|
||||
vec3 Hh = normalize(normalize(vec3(L2 * 0.78, 0.62)) + vec3(0., 0., 1.));
|
||||
vec3 gTint = mix(vec3(0.22, 0.24, 0.27), vec3(0.62, 0.66, 0.72), uDark);
|
||||
vec4 o = vec4(0.);
|
||||
over(o, gTint, tm * (0.14 + 0.35 * pow(1. - N.z, 2.)) * (1. - clamp(I, 0., 1.) * 0.6));
|
||||
if (uDark > 0.5) o.rgb += mapped;
|
||||
else { // on paper light can't add; lay the hue down instead, keeping it saturated
|
||||
vec3 Lc = g + nearL * (1. - tm) + e * (0.4 + 0.85 * core) * tm;
|
||||
float m = max(max(Lc.r, Lc.g), Lc.b);
|
||||
over(o, Lc / max(m, 1e-3), (1. - exp(-m * 1.4)) * mix(0.85, 1., tm));
|
||||
over(o, vec3(1.), pow(core, 4.) * min(I, 1.) * 0.6 * tm);
|
||||
}
|
||||
over(o, vec3(1.), pow(max(dot(N, Hh), 0.), 60.) * 0.5 * tm);
|
||||
gl_FragColor = o;
|
||||
}`;
|
||||
const SRC = { water: WATER, smoke: SMOKE, neon: NEON };
|
||||
const PAD = { water: 1.3, smoke: 1.9, neon: 1.8 };
|
||||
const DEFAULTS = {
|
||||
water: { color: "#2FA8FF" },
|
||||
smoke: { color: "#F5F5F2" },
|
||||
neon: { colors: ["#FF2E88", "#2EF0FF", "#FFB020", "#7CFF4F", "#9B5CFF"], tube: 0.58 },
|
||||
};
|
||||
const COMMON = { sequence: "LUCIO", hold: 0.7, morph: 0.45, speed: 1, size: 96 };
|
||||
const rgb = hex => { const h = hex.replace("#", ""), f = h.length === 3 ? h.split("").map(c => c + c).join("") : h; return [0, 2, 4].map(i => parseInt(f.slice(i, i + 2), 16) / 255); };
|
||||
const reduced = () => global.matchMedia && global.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
||||
const ease = f => f < 0.5 ? 4 * f * f * f : 1 - Math.pow(-2 * f + 2, 3) / 2;
|
||||
const fract = x => x - Math.floor(x);
|
||||
const hash = n => fract(Math.sin(n * 127.1 + 11.7) * 43758.5453);
|
||||
const smooth = (a, b, x) => { const k = Math.min(1, Math.max(0, (x - a) / (b - a))); return k * k * (3 - 2 * k); };
|
||||
function bgIsDark(el) {
|
||||
for (let n = el; n && n.nodeType === 1; n = n.parentElement) {
|
||||
const m = getComputedStyle(n).backgroundColor.match(/[\d.]+/g);
|
||||
if (m && (m.length < 4 || +m[3] > 0.5)) return (0.2126 * m[0] + 0.7152 * m[1] + 0.0722 * m[2]) / 255 < 0.5;
|
||||
}
|
||||
return !!(global.matchMedia && global.matchMedia("(prefers-color-scheme: dark)").matches);
|
||||
}
|
||||
const LET = { C: [0, .75], L: [.25, .75], U: [.25, 1], I: [.75, 1], O: [.75, 1.75] };
|
||||
function speller(o) {
|
||||
const seq = () => { const s = (o.sequence || "LUCIO").toUpperCase().split("").filter(c => LET[c]); return s.length ? s : ["O"]; };
|
||||
const target = (cur, ch) => { const [s2, e2] = LET[ch]; for (let q = -1; q < 6; q++) { if (s2 + q >= cur[0] - 1e-6 && e2 + q >= cur[1] - 1e-6) return [s2 + q, e2 + q]; } return [s2, e2]; };
|
||||
const st = { i: 0, j: 0, seg: LET[seq()[0]].slice(), u: 1, f: 1, moving: false, travel: 0, vHead: 0 };
|
||||
let from = st.seg, to = st.seg, timer = 0;
|
||||
st.step = dt => {
|
||||
const before = st.seg.slice();
|
||||
timer += dt;
|
||||
if (!st.moving && timer >= o.hold) {
|
||||
const s = seq(); st.j = (st.i + 1) % s.length; from = st.seg.slice(); to = target(st.seg, s[st.j]);
|
||||
st.moving = true; timer -= o.hold;
|
||||
}
|
||||
if (st.moving) {
|
||||
const dur = reduced() ? 0 : o.morph;
|
||||
st.f = dur > 0 ? Math.min(1, timer / dur) : 1; st.u = ease(st.f);
|
||||
st.seg = [from[0] + (to[0] - from[0]) * st.u, from[1] + (to[1] - from[1]) * st.u];
|
||||
if (st.f >= 1) { st.moving = false; st.i = st.j; timer = 0; }
|
||||
} else { st.f = 1; st.u = 1; }
|
||||
st.travel += ((st.seg[0] - before[0]) + (st.seg[1] - before[1])) / 2 * PER;
|
||||
st.vHead = dt > 0 ? (st.seg[1] - before[1]) * PER / dt : 0;
|
||||
if (!st.moving) { const n = Math.floor(st.seg[0]); st.seg[0] -= n; st.seg[1] -= n; }
|
||||
};
|
||||
st.units = () => ({ a: PER * (st.seg[0] + 0.25), len: Math.min(PER, (st.seg[1] - st.seg[0]) * PER) });
|
||||
st.reset = () => { st.i = st.j = 0; st.seg = LET[seq()[0]].slice(); st.moving = false; timer = 0; };
|
||||
return st;
|
||||
}
|
||||
const live = new Set();
|
||||
let raf = 0, last = 0;
|
||||
function loop(now) {
|
||||
const dt = last ? Math.min(0.1, (now - last) / 1000) : 0; last = now;
|
||||
for (const inst of live) inst.frame(dt);
|
||||
raf = live.size ? requestAnimationFrame(loop) : 0;
|
||||
if (!raf) last = 0;
|
||||
}
|
||||
function create(kind, container, opts) {
|
||||
const o = Object.assign({}, COMMON, DEFAULTS[kind], opts || {});
|
||||
const wrap = document.createElement("div");
|
||||
wrap.className = "lucio-fx lucio-fx-" + kind;
|
||||
wrap.setAttribute("role", "img"); wrap.setAttribute("aria-label", "Loading");
|
||||
wrap.style.cssText = "position:relative;display:inline-block;vertical-align:middle;flex:none";
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.style.cssText = "position:absolute;pointer-events:none";
|
||||
wrap.appendChild(canvas); container.appendChild(wrap);
|
||||
const gl = canvas.getContext("webgl", { premultipliedAlpha: true, alpha: true, antialias: false });
|
||||
if (!gl) { console.warn("LucioLoaders: WebGL unavailable"); return null; }
|
||||
const sh = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(kind + ": " + gl.getShaderInfoLog(s)); return s; };
|
||||
const prog = gl.createProgram();
|
||||
gl.attachShader(prog, sh(gl.VERTEX_SHADER, "attribute vec2 a; void main(){ gl_Position = vec4(a, 0., 1.); }"));
|
||||
gl.attachShader(prog, sh(gl.FRAGMENT_SHADER, PRELUDE + SRC[kind]));
|
||||
gl.linkProgram(prog);
|
||||
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) throw new Error(kind + ": " + gl.getProgramInfoLog(prog));
|
||||
gl.useProgram(prog);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
|
||||
gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
||||
const U = {}; const u = n => n in U ? U[n] : (U[n] = gl.getUniformLocation(prog, n));
|
||||
if (kind === "neon") { const pts = []; for (let i = 0; i < NPTS; i++) pts.push(...pathP((i + 0.5) * PER / NPTS)); gl.uniform2fv(u("uPts[0]"), new Float32Array(pts)); }
|
||||
const BINS = 64, wetAt = new Float32Array(BINS).fill(-1e3), wetTex = new Uint8Array(BINS);
|
||||
if (kind === "water") {
|
||||
gl.bindTexture(gl.TEXTURE_2D, gl.createTexture());
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.uniform1i(u("uWet"), 0);
|
||||
}
|
||||
const puff = new Float32Array(NPUFF * 4), pDen = new Float32Array(NPUFF), pAge = new Float32Array(NPUFF);
|
||||
const sp = speller(o);
|
||||
const inside = (s, a, len) => { if (len >= PER - 0.5) return 1e3; const x = ((s - a) % PER + PER) % PER; return x <= len ? Math.min(x, len - x) : -Math.min(x - len, PER - x); };
|
||||
let t = 0, dark = o.theme === "light" ? false : o.theme === "dark" ? true : bgIsDark(container), frames = 0, visible = true;
|
||||
const io = global.IntersectionObserver ? new IntersectionObserver(es => { visible = es[0].isIntersecting; }) : null;
|
||||
if (io) io.observe(wrap);
|
||||
function setSize(px) {
|
||||
o.size = px;
|
||||
const dpr = Math.min(global.devicePixelRatio || 1, 2), c = px * PAD[kind];
|
||||
wrap.style.width = wrap.style.height = px + "px";
|
||||
canvas.style.width = canvas.style.height = c + "px";
|
||||
canvas.style.left = canvas.style.top = (-(c - px) / 2) + "px";
|
||||
canvas.width = canvas.height = Math.round(c * dpr);
|
||||
gl.viewport(0, 0, canvas.width, canvas.height);
|
||||
gl.uniform2f(u("uRes"), canvas.width, canvas.height);
|
||||
gl.uniform1f(u("uPx"), 120 / (px * canvas.width / c));
|
||||
}
|
||||
setSize(o.size);
|
||||
function frame(dt) {
|
||||
if (o.theme === "auto" || !o.theme) { if (++frames % 30 === 0) dark = bgIsDark(container); }
|
||||
if (!visible) return;
|
||||
dt *= o.speed;
|
||||
t += dt * (reduced() ? 0.35 : 1);
|
||||
sp.step(dt);
|
||||
const { a, len } = sp.units();
|
||||
gl.uniform1f(u("uTime"), t);
|
||||
gl.uniform1f(u("uDark"), dark ? 1 : 0);
|
||||
if (kind === "water") {
|
||||
const Df = 70, pa = fract(sp.travel / Df), pb = fract(sp.travel / Df + 0.5);
|
||||
gl.uniform3fv(u("uColor"), rgb(o.color));
|
||||
gl.uniform1f(u("uHead"), a + len); gl.uniform1f(u("uLen"), len);
|
||||
gl.uniform1f(u("uSurge"), Math.min(1, Math.max(0, sp.vHead / 700)));
|
||||
gl.uniform1f(u("uMid"), sp.travel);
|
||||
gl.uniform1f(u("uFlowA"), pa * Df); gl.uniform1f(u("uFlowB"), pb * Df);
|
||||
gl.uniform1f(u("uFlowW"), 1 - Math.abs(2 * pb - 1));
|
||||
for (let i = 0; i < BINS; i++) {
|
||||
if (inside((i + 0.5) * PER / BINS, a, len) > -2) wetAt[i] = t;
|
||||
wetTex[i] = Math.round(255 * Math.exp(-(t - wetAt[i]) / 1.1));
|
||||
}
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, BINS, 1, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, wetTex);
|
||||
} else if (kind === "smoke") {
|
||||
gl.uniform3fv(u("uColor"), rgb(o.color));
|
||||
const kIn = 1 - Math.exp(-dt * 20), kOut = Math.exp(-dt * 4.2);
|
||||
for (let i = 0; i < NPUFF; i++) {
|
||||
const s = (i + 0.5) * PER / NPUFF, cover = smooth(-6, 6, inside(s, a, len));
|
||||
if (cover >= pDen[i]) { pDen[i] += (cover - pDen[i]) * kIn; pAge[i] *= Math.exp(-dt * 8); }
|
||||
else { pDen[i] = Math.max(cover, pDen[i] * kOut); pAge[i] += dt; }
|
||||
const w = W0 + 10 * pAge[i], [x, y] = pathP(s);
|
||||
puff.set([x, y + 9 * pAge[i], w, pDen[i] * (W0 * 1.6 / (w + 0.6 * W0)) * (PER / NPUFF) / (1.7725 * w)], i * 4);
|
||||
}
|
||||
gl.uniform4fv(u("uPuff[0]"), puff);
|
||||
} else {
|
||||
const pal = o.colors.map(rgb), n = pal.length;
|
||||
gl.uniform1f(u("uTR"), HW * o.tube);
|
||||
gl.uniform1f(u("uHum"), 0.975 + 0.025 * Math.sin(t * 46) * Math.sin(t * 7.3) + (hash(Math.floor(t * 9)) > 0.985 ? -0.2 : 0));
|
||||
gl.uniform1f(u("uSegA"), a); gl.uniform1f(u("uLen"), len);
|
||||
gl.uniform3fv(u("uColB"), pal[sp.i % n]); gl.uniform3fv(u("uColA"), pal[(sp.moving ? sp.j : sp.i) % n]);
|
||||
gl.uniform1f(u("uMix"), sp.moving ? smooth(0.05, 0.35, sp.f) : 1);
|
||||
gl.uniform1f(u("uMove"), sp.moving ? Math.sin(Math.PI * sp.f) : 0);
|
||||
}
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||
}
|
||||
const inst = { frame };
|
||||
live.add(inst);
|
||||
if (!raf) raf = requestAnimationFrame(loop);
|
||||
return {
|
||||
el: wrap, canvas,
|
||||
tick: frame,
|
||||
setColor(c) { o.color = c; if (kind === "neon") o.colors = [c]; },
|
||||
setColors(cs) { o.colors = cs.slice(); },
|
||||
setTiming({ hold, morph }) { if (hold != null) o.hold = hold; if (morph != null) o.morph = morph; },
|
||||
setSequence(seq) { o.sequence = seq; sp.reset(); },
|
||||
setSpeed(s) { o.speed = s; },
|
||||
setSize,
|
||||
setTheme(th) { o.theme = th; dark = th === "light" ? false : th === "dark" ? true : bgIsDark(container); },
|
||||
stop() { live.delete(inst); if (io) io.disconnect(); wrap.remove(); const ext = gl.getExtension("WEBGL_lose_context"); if (ext) ext.loseContext(); },
|
||||
};
|
||||
}
|
||||
global.LucioLoaders = {
|
||||
water: (el, opts) => create("water", el, opts),
|
||||
smoke: (el, opts) => create("smoke", el, opts),
|
||||
neon: (el, opts) => create("neon", el, opts),
|
||||
geometry: { HB, CR, HW, PER, pathP, LET },
|
||||
};
|
||||
})(window);
|
||||
+25
-1
@@ -1,4 +1,4 @@
|
||||
import { mountWordmark } from "./brand";
|
||||
import { mountSignoffMark, mountWordmark } from "./brand";
|
||||
import { TileCache, cacheBudget } from "./cache";
|
||||
import { entropyScore, startEntropy } from "./entropy";
|
||||
import { guardLink, takeNav, type GuardOptions } from "./gate";
|
||||
@@ -79,8 +79,32 @@ function showLoadError(): void {
|
||||
document.querySelector<HTMLElement>(".load-error")?.removeAttribute("hidden");
|
||||
}
|
||||
|
||||
function mountFooterMarks(): void {
|
||||
const holders = Array.from(document.querySelectorAll<HTMLElement>(".site-footer .chop"));
|
||||
if (holders.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (typeof IntersectionObserver !== "function") {
|
||||
holders.forEach(mountSignoffMark);
|
||||
return;
|
||||
}
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
for (const entry of entries) {
|
||||
if (entry.isIntersecting) {
|
||||
observer.unobserve(entry.target);
|
||||
mountSignoffMark(entry.target as HTMLElement);
|
||||
}
|
||||
}
|
||||
},
|
||||
{ rootMargin: "200px" },
|
||||
);
|
||||
holders.forEach((holder) => observer.observe(holder));
|
||||
}
|
||||
|
||||
function boot(): void {
|
||||
startEntropy();
|
||||
mountFooterMarks();
|
||||
const settings = readSettings(document.body);
|
||||
if (settings.page === "album") {
|
||||
const stage = document.getElementById("stage");
|
||||
|
||||
+67
-7
@@ -1,4 +1,5 @@
|
||||
import "../brand/lucio-morph.js";
|
||||
import "../brand/lucio-loaders.js";
|
||||
|
||||
export interface MorphHandle {
|
||||
play(): void;
|
||||
@@ -25,7 +26,7 @@ export interface WordmarkOptions {
|
||||
export interface LoaderOptions {
|
||||
size?: number;
|
||||
color?: string;
|
||||
track?: string;
|
||||
track?: string | null;
|
||||
rays?: string;
|
||||
hold?: number;
|
||||
morph?: number;
|
||||
@@ -36,11 +37,28 @@ interface LucioMorphApi {
|
||||
loader(container: Element, options?: LoaderOptions): LoaderHandle;
|
||||
}
|
||||
|
||||
interface SmokeOptions {
|
||||
size?: number;
|
||||
color?: string;
|
||||
theme?: "dark" | "light" | "auto";
|
||||
}
|
||||
|
||||
interface SmokeHandle {
|
||||
el: HTMLElement;
|
||||
setSize(px: number): void;
|
||||
stop(): void;
|
||||
}
|
||||
|
||||
interface LucioLoadersApi {
|
||||
smoke(container: Element, options?: SmokeOptions): SmokeHandle | null;
|
||||
}
|
||||
|
||||
export const palette = {
|
||||
graphite: "#111114",
|
||||
graphite3: "#26262D",
|
||||
paper: "#F3F1EC",
|
||||
beam: "#FFF3CF",
|
||||
smoke: "#F5F5F2",
|
||||
};
|
||||
|
||||
export function lucioMorph(): LucioMorphApi | null {
|
||||
@@ -67,11 +85,53 @@ export function mountWordmark(link: HTMLElement, animated: boolean): MorphHandle
|
||||
return handle;
|
||||
}
|
||||
|
||||
export function cloneChop(): HTMLElement | null {
|
||||
const template = document.getElementById("chop-template");
|
||||
if (!(template instanceof HTMLTemplateElement)) {
|
||||
return null;
|
||||
const fallbackMarkSize = 44;
|
||||
|
||||
function markSize(holder: HTMLElement): number {
|
||||
return Math.round(holder.getBoundingClientRect().width) || fallbackMarkSize;
|
||||
}
|
||||
|
||||
// The sign-off mark: the LUCIO loader in smoke, or the plain SVG loader where WebGL is unavailable.
|
||||
// Replaces whatever the holder contains (the server-rendered chop) once it can draw.
|
||||
export function mountSignoffMark(holder: HTMLElement): void {
|
||||
if (holder.dataset.mounted === "1") {
|
||||
return;
|
||||
}
|
||||
const node = template.content.firstElementChild;
|
||||
return node ? (node.cloneNode(true) as HTMLElement) : null;
|
||||
const size = markSize(holder);
|
||||
const loaders = (window as unknown as { LucioLoaders?: LucioLoadersApi }).LucioLoaders;
|
||||
const fallback = Array.from(holder.childNodes);
|
||||
holder.replaceChildren();
|
||||
let smoke: SmokeHandle | null = null;
|
||||
try {
|
||||
smoke = loaders ? loaders.smoke(holder, { size, theme: "dark", color: palette.smoke }) : null;
|
||||
} catch {
|
||||
smoke = null;
|
||||
}
|
||||
if (smoke) {
|
||||
smoke.el.removeAttribute("role");
|
||||
smoke.el.removeAttribute("aria-label");
|
||||
const handle = smoke;
|
||||
if (typeof ResizeObserver === "function") {
|
||||
let last = size;
|
||||
new ResizeObserver(() => {
|
||||
const next = markSize(holder);
|
||||
if (next !== last) {
|
||||
last = next;
|
||||
handle.setSize(next);
|
||||
}
|
||||
}).observe(holder);
|
||||
}
|
||||
} else {
|
||||
holder.replaceChildren();
|
||||
const api = lucioMorph();
|
||||
if (api) {
|
||||
const svg = api.loader(holder, { size, color: palette.paper, track: null, rays: palette.beam }).svg;
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.style.width = "100%";
|
||||
svg.style.height = "auto";
|
||||
} else {
|
||||
holder.append(...fallback);
|
||||
}
|
||||
}
|
||||
holder.dataset.mounted = "1";
|
||||
}
|
||||
+123
-14
@@ -65,6 +65,46 @@ function until<T>(promise: Promise<T>, signal: AbortSignal, fallback: T): Promis
|
||||
|
||||
const probeStep = 3;
|
||||
const seedUpscale = 4;
|
||||
const fillBudgetMs = 6000;
|
||||
const enhanceBudgetMs = 4000;
|
||||
const goodThroughput = 1500;
|
||||
const enhanceMemoryShare = 0.35;
|
||||
|
||||
interface Outcome {
|
||||
needed: number;
|
||||
final: number;
|
||||
throughput: number;
|
||||
}
|
||||
|
||||
interface NetworkHints {
|
||||
saveData?: boolean;
|
||||
effectiveType?: string;
|
||||
}
|
||||
|
||||
type HintedNavigator = Navigator & { connection?: NetworkHints; deviceMemory?: number };
|
||||
|
||||
function saveData(): boolean {
|
||||
const connection = (navigator as HintedNavigator).connection;
|
||||
return !!connection && (connection.saveData === true || /2g|3g/.test(connection.effectiveType ?? ""));
|
||||
}
|
||||
|
||||
function capableDevice(): boolean {
|
||||
const nav = navigator as HintedNavigator;
|
||||
if ((nav.hardwareConcurrency ?? 4) < 4) {
|
||||
return false;
|
||||
}
|
||||
return typeof nav.deviceMemory !== "number" || nav.deviceMemory >= 4;
|
||||
}
|
||||
|
||||
function batchRate(results: PromiseSettledResult<TileResult>[], ms: number): number {
|
||||
let bytes = 0;
|
||||
for (const result of results) {
|
||||
if (result.status === "fulfilled") {
|
||||
bytes += result.value.bytes;
|
||||
}
|
||||
}
|
||||
return bytes > 0 && ms > 0 ? bytes / ms : 0;
|
||||
}
|
||||
|
||||
export interface DrawTarget {
|
||||
g: CanvasRenderingContext2D;
|
||||
@@ -95,6 +135,8 @@ export class PhotoLoader {
|
||||
private settling = false;
|
||||
private session: AbortController | null = null;
|
||||
private prefetchController: AbortController | null = null;
|
||||
private enhancer: AbortController | null = null;
|
||||
private enhanceLevel = -1;
|
||||
finalLevel = -1;
|
||||
private targetLevel = -1;
|
||||
readonly status: LoadStatus = { active: false, started: 0, planned: 0, done: 0, sharp: false };
|
||||
@@ -342,7 +384,7 @@ export class PhotoLoader {
|
||||
);
|
||||
}
|
||||
|
||||
start(view: View, dpr: number, onSettled: () => void): void {
|
||||
start(view: View, dpr: number, onSettled: () => void, enhance = false): void {
|
||||
this.stopSession();
|
||||
const controller = new AbortController();
|
||||
this.session = controller;
|
||||
@@ -353,8 +395,9 @@ export class PhotoLoader {
|
||||
this.status.done = 0;
|
||||
this.status.sharp = false;
|
||||
this.notify();
|
||||
void this.run(view, dpr, controller).then(() => {
|
||||
if (this.session === controller) {
|
||||
void this.run(view, dpr, controller).then((outcome) => {
|
||||
const current = this.session === controller;
|
||||
if (current) {
|
||||
this.session = null;
|
||||
this.status.active = false;
|
||||
this.notify();
|
||||
@@ -362,10 +405,13 @@ export class PhotoLoader {
|
||||
if (!controller.signal.aborted || controller.signal.reason === "deadline") {
|
||||
onSettled();
|
||||
}
|
||||
if (enhance && current && outcome && !controller.signal.aborted) {
|
||||
void this.enhance(view, outcome);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async run(view: View, dpr: number, controller: AbortController): Promise<void> {
|
||||
private async run(view: View, dpr: number, controller: AbortController): Promise<Outcome | null> {
|
||||
const signal = controller.signal;
|
||||
const started = performance.now();
|
||||
const budget = this.env.settings.budgetMs;
|
||||
@@ -373,14 +419,14 @@ export class PhotoLoader {
|
||||
try {
|
||||
const ready = await until(this.ensurePool(), signal, false);
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (ready && !this.open()) {
|
||||
this.settling = true;
|
||||
await this.env.keys.settle(this.pyramid.hash, signal);
|
||||
this.settling = false;
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!ready || !this.open()) {
|
||||
@@ -389,11 +435,11 @@ export class PhotoLoader {
|
||||
ids.map((id) => () => this.fetchJumble(id, PRIORITY_CURRENT, signal)),
|
||||
controller,
|
||||
);
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
await this.ensureSeed();
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
const needed = neededLevel(this.pyramid, view.displayWidth, dpr);
|
||||
const probe = Math.max(0, needed - probeStep);
|
||||
@@ -416,7 +462,7 @@ export class PhotoLoader {
|
||||
}
|
||||
}
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
this.finalLevel = Math.max(this.finalLevel, probe);
|
||||
const throughput = currentThroughput();
|
||||
@@ -438,20 +484,80 @@ export class PhotoLoader {
|
||||
this.finalLevel = final;
|
||||
this.targetLevel = final;
|
||||
this.env.requestDraw();
|
||||
let measured = 0;
|
||||
for (const level of plan) {
|
||||
await this.track(
|
||||
this.uncached(level, view).map((tile) => () => this.fetchTile(tile, PRIORITY_CURRENT, signal)),
|
||||
const tiles = this.uncached(level, view);
|
||||
const at = performance.now();
|
||||
const results = await this.track(
|
||||
tiles.map((tile) => () => this.fetchTile(tile, PRIORITY_CURRENT, signal)),
|
||||
controller,
|
||||
);
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
const rate = tiles.length >= 2 ? batchRate(results, performance.now() - at) : 0;
|
||||
if (rate > 0) {
|
||||
measured = recordThroughput(rate);
|
||||
}
|
||||
}
|
||||
return { needed, final, throughput: measured || currentThroughput() };
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
private async enhance(view: View, outcome: Outcome): Promise<void> {
|
||||
if (!this.opened || saveData()) {
|
||||
return;
|
||||
}
|
||||
const levels = this.pyramid.levels;
|
||||
const { needed } = outcome;
|
||||
const top = capableDevice() ? Math.min(levels.length - 1, needed + 1) : needed;
|
||||
if (outcome.final >= top) {
|
||||
return;
|
||||
}
|
||||
this.enhancer?.abort();
|
||||
const controller = new AbortController();
|
||||
this.enhancer = controller;
|
||||
const signal = controller.signal;
|
||||
const memory = this.env.cache.budget * enhanceMemoryShare;
|
||||
let throughput = outcome.throughput;
|
||||
let spent = 0;
|
||||
for (let level = Math.max(outcome.final + 1, needed); level <= top; level++) {
|
||||
const extra = level > needed;
|
||||
if (extra) {
|
||||
const info = levels[level];
|
||||
const decoded = info.width * (view.u1 - view.u0) * info.height * (view.v1 - view.v0) * 4;
|
||||
if (throughput < goodThroughput || decoded > memory) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
spent += this.uncachedBytes(level, view) / throughput;
|
||||
if (spent > (extra ? enhanceBudgetMs : fillBudgetMs)) {
|
||||
break;
|
||||
}
|
||||
if (extra) {
|
||||
this.enhanceLevel = Math.max(this.enhanceLevel, level);
|
||||
}
|
||||
const tiles = this.uncached(level, view);
|
||||
const at = performance.now();
|
||||
const results = await Promise.allSettled(tiles.map((tile) => this.fetchTile(tile, PRIORITY_PREFETCH, signal)));
|
||||
if (signal.aborted) {
|
||||
return;
|
||||
}
|
||||
const rate = tiles.length >= 2 ? batchRate(results, performance.now() - at) : 0;
|
||||
if (rate > 0) {
|
||||
throughput = recordThroughput(rate);
|
||||
}
|
||||
if (!extra) {
|
||||
this.finalLevel = Math.max(this.finalLevel, level);
|
||||
}
|
||||
}
|
||||
if (this.enhancer === controller) {
|
||||
this.enhancer = null;
|
||||
}
|
||||
}
|
||||
|
||||
prefetchProbe(view: View, dpr: number): void {
|
||||
const controller = this.resetPrefetch();
|
||||
const signal = controller.signal;
|
||||
@@ -490,6 +596,8 @@ export class PhotoLoader {
|
||||
}
|
||||
|
||||
stopSession(): void {
|
||||
this.enhancer?.abort();
|
||||
this.enhancer = null;
|
||||
if (this.session) {
|
||||
this.session.abort("superseded");
|
||||
this.session = null;
|
||||
@@ -558,9 +666,10 @@ export class PhotoLoader {
|
||||
const levels = this.pyramid.levels;
|
||||
const ids = this.ids;
|
||||
const needed = neededLevel(this.pyramid, target.displayWidth, target.dpr);
|
||||
const topLevel = Math.max(needed, Math.min(this.enhanceLevel, needed + 1));
|
||||
|
||||
let base = -1;
|
||||
for (let l = needed; ids && l >= 0 && base < 0; l--) {
|
||||
for (let l = topLevel; ids && l >= 0 && base < 0; l--) {
|
||||
const range = tileRange(levels[l], view);
|
||||
if (!range) {
|
||||
continue;
|
||||
@@ -611,7 +720,7 @@ export class PhotoLoader {
|
||||
return animating;
|
||||
}
|
||||
|
||||
for (let l = Math.max(0, base); l <= needed; l++) {
|
||||
for (let l = Math.max(0, base); l <= topLevel; l++) {
|
||||
const level = levels[l];
|
||||
const range = tileRange(level, view);
|
||||
if (!range) {
|
||||
|
||||
+19
-10
@@ -1,4 +1,4 @@
|
||||
import { cloneChop, mountWordmark } from "./brand";
|
||||
import { mountSignoffMark, mountWordmark } from "./brand";
|
||||
import { CaptionPanel, setLang } from "./caption";
|
||||
import type { View } from "./geometry";
|
||||
import { guardLink, type GuardOptions } from "./gate";
|
||||
@@ -110,6 +110,7 @@ export class Viewer {
|
||||
private readonly indicator: BusyIndicator;
|
||||
private readonly progress: ProgressLine;
|
||||
private readonly homeMark: HTMLElement | null;
|
||||
private readonly signoffMark: HTMLElement;
|
||||
private nextStrip: Strip | null = null;
|
||||
private nextSlug = "";
|
||||
private idleTimer = 0;
|
||||
@@ -184,6 +185,9 @@ export class Viewer {
|
||||
throw new Error("canvas 2d unavailable");
|
||||
}
|
||||
this.g = g;
|
||||
this.signoffMark = document.createElement("span");
|
||||
this.signoffMark.className = "chop";
|
||||
this.signoffMark.setAttribute("aria-hidden", "true");
|
||||
this.endCard = this.buildEndCard();
|
||||
this.nextLink = this.endCard.querySelector("a.next-album") as HTMLAnchorElement;
|
||||
this.nextFrame = this.endCard.querySelector(".next-strip") as HTMLElement;
|
||||
@@ -234,10 +238,7 @@ export class Viewer {
|
||||
next.appendChild(frame);
|
||||
const signoff = document.createElement("div");
|
||||
signoff.className = "signoff";
|
||||
const chop = cloneChop();
|
||||
if (chop) {
|
||||
signoff.appendChild(chop);
|
||||
}
|
||||
signoff.appendChild(this.signoffMark);
|
||||
const signature = document.createElement("p");
|
||||
signature.className = "signature";
|
||||
signature.textContent = "— Lucio";
|
||||
@@ -882,6 +883,9 @@ export class Viewer {
|
||||
if (stop.photo >= 0) {
|
||||
this.startSession();
|
||||
}
|
||||
if (stop.photo < 0 || stop.photo === this.manifest.photos.length - 1) {
|
||||
mountSignoffMark(this.signoffMark);
|
||||
}
|
||||
this.syncNextStrip();
|
||||
this.updateCaption();
|
||||
}
|
||||
@@ -984,11 +988,16 @@ export class Viewer {
|
||||
}
|
||||
const index = this.current;
|
||||
const loader = this.loader(stop.photo);
|
||||
loader.start(this.viewAt(stop), this.dpr, () => {
|
||||
if (this.current === index) {
|
||||
this.prefetchAround(index);
|
||||
}
|
||||
});
|
||||
loader.start(
|
||||
this.viewAt(stop),
|
||||
this.dpr,
|
||||
() => {
|
||||
if (this.current === index) {
|
||||
this.prefetchAround(index);
|
||||
}
|
||||
},
|
||||
true,
|
||||
);
|
||||
this.indicator.watch(loader);
|
||||
this.progress.watch(loader);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user