@arraypress/effects-astro 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (314) hide show
  1. package/AGENTS.md +85 -0
  2. package/COMPONENTS.md +1264 -0
  3. package/LICENSE +139 -0
  4. package/README.md +197 -2
  5. package/package.json +60 -4
  6. package/src/components/AsciiRain.astro +36 -0
  7. package/src/components/BorderSweep.astro +39 -0
  8. package/src/components/Caustics.astro +39 -0
  9. package/src/components/ColorPanels.astro +62 -0
  10. package/src/components/Cursor.astro +97 -0
  11. package/src/components/DotGrid.astro +34 -0
  12. package/src/components/DotSurface.astro +35 -0
  13. package/src/components/EffectCanvas.astro +152 -0
  14. package/src/components/FitText.astro +35 -0
  15. package/src/components/FlutedGlass.astro +36 -0
  16. package/src/components/Glass.astro +69 -0
  17. package/src/components/GlassGlyph.astro +38 -0
  18. package/src/components/GlowField.astro +177 -0
  19. package/src/components/Grain.astro +98 -0
  20. package/src/components/HaloRing.astro +38 -0
  21. package/src/components/HighlightSweep.astro +74 -0
  22. package/src/components/ImageRipple.astro +56 -0
  23. package/src/components/Ink.astro +37 -0
  24. package/src/components/InkField.astro +45 -0
  25. package/src/components/IsoCity.astro +54 -0
  26. package/src/components/LightField.astro +40 -0
  27. package/src/components/LiquidMetal.astro +41 -0
  28. package/src/components/Magnetic.astro +52 -0
  29. package/src/components/Marquee.astro +216 -0
  30. package/src/components/MosaicReveal.astro +196 -0
  31. package/src/components/NebulaLogo.astro +38 -0
  32. package/src/components/NeonSwarm.astro +38 -0
  33. package/src/components/Ocean.astro +40 -0
  34. package/src/components/OutlineWordmark.astro +222 -0
  35. package/src/components/PaperBackground.astro +40 -0
  36. package/src/components/PaperShader.astro +55 -0
  37. package/src/components/Parallax.astro +49 -0
  38. package/src/components/ParticleLogo.astro +37 -0
  39. package/src/components/PixelGlitchText.astro +70 -0
  40. package/src/components/PointCloud.astro +37 -0
  41. package/src/components/ProductStack.astro +298 -0
  42. package/src/components/PulseMark.astro +189 -0
  43. package/src/components/RadiantGlass.astro +38 -0
  44. package/src/components/RainOnGlass.astro +71 -0
  45. package/src/components/Reveal.astro +115 -0
  46. package/src/components/ScrambleText.astro +52 -0
  47. package/src/components/ScrollReveal.astro +38 -0
  48. package/src/components/ShaderBackground.astro +55 -0
  49. package/src/components/SignalLines.astro +41 -0
  50. package/src/components/SilkRibbon.astro +37 -0
  51. package/src/components/SpotlightText.astro +131 -0
  52. package/src/components/Tilt.astro +79 -0
  53. package/src/components/Topography.astro +38 -0
  54. package/src/components/Typewriter.astro +66 -0
  55. package/src/components/VariableType.astro +59 -0
  56. package/src/components/VoxelLogo.astro +46 -0
  57. package/src/components/WaveBars.astro +41 -0
  58. package/src/components/WorldRoutes.astro +41 -0
  59. package/src/components/style.js +19 -0
  60. package/src/index.d.ts +143 -0
  61. package/src/index.js +105 -0
  62. package/src/runtime/ascii-rain.d.ts +53 -0
  63. package/src/runtime/ascii-rain.js +355 -0
  64. package/src/runtime/audio-meter.d.ts +65 -0
  65. package/src/runtime/audio-meter.js +282 -0
  66. package/src/runtime/audio.d.ts +26 -0
  67. package/src/runtime/audio.js +453 -0
  68. package/src/runtime/blur.d.ts +2 -0
  69. package/src/runtime/blur.js +56 -0
  70. package/src/runtime/canvas2d.d.ts +23 -0
  71. package/src/runtime/canvas2d.js +105 -0
  72. package/src/runtime/caustics.d.ts +40 -0
  73. package/src/runtime/caustics.js +286 -0
  74. package/src/runtime/color.d.ts +33 -0
  75. package/src/runtime/color.js +213 -0
  76. package/src/runtime/curl.d.ts +5 -0
  77. package/src/runtime/curl.js +81 -0
  78. package/src/runtime/cursor.d.ts +9 -0
  79. package/src/runtime/cursor.js +80 -0
  80. package/src/runtime/device.d.ts +14 -0
  81. package/src/runtime/device.js +73 -0
  82. package/src/runtime/dot-grid.d.ts +27 -0
  83. package/src/runtime/dot-grid.js +245 -0
  84. package/src/runtime/dot-surface.d.ts +46 -0
  85. package/src/runtime/dot-surface.js +429 -0
  86. package/src/runtime/feedback.d.ts +18 -0
  87. package/src/runtime/feedback.js +131 -0
  88. package/src/runtime/fit-text.d.ts +5 -0
  89. package/src/runtime/fit-text.js +60 -0
  90. package/src/runtime/fluid.d.ts +55 -0
  91. package/src/runtime/fluid.js +504 -0
  92. package/src/runtime/fluted-glass.d.ts +27 -0
  93. package/src/runtime/fluted-glass.js +157 -0
  94. package/src/runtime/gl.d.ts +19 -0
  95. package/src/runtime/gl.js +104 -0
  96. package/src/runtime/glass-glyph.d.ts +49 -0
  97. package/src/runtime/glass-glyph.js +355 -0
  98. package/src/runtime/glass-sheen.d.ts +2 -0
  99. package/src/runtime/glass-sheen.js +30 -0
  100. package/src/runtime/glsl.d.ts +17 -0
  101. package/src/runtime/glsl.js +78 -0
  102. package/src/runtime/glyphs.d.ts +22 -0
  103. package/src/runtime/glyphs.js +107 -0
  104. package/src/runtime/halo-ring.d.ts +47 -0
  105. package/src/runtime/halo-ring.js +334 -0
  106. package/src/runtime/height-field.d.ts +50 -0
  107. package/src/runtime/height-field.js +176 -0
  108. package/src/runtime/image-ripple.d.ts +25 -0
  109. package/src/runtime/image-ripple.js +353 -0
  110. package/src/runtime/image.d.ts +11 -0
  111. package/src/runtime/image.js +81 -0
  112. package/src/runtime/in-view.d.ts +6 -0
  113. package/src/runtime/in-view.js +36 -0
  114. package/src/runtime/ink-field/shaders.js +258 -0
  115. package/src/runtime/ink-field/sim.js +582 -0
  116. package/src/runtime/ink-field.d.ts +39 -0
  117. package/src/runtime/ink-field.js +311 -0
  118. package/src/runtime/ink.d.ts +31 -0
  119. package/src/runtime/ink.js +109 -0
  120. package/src/runtime/instancing.d.ts +12 -0
  121. package/src/runtime/instancing.js +37 -0
  122. package/src/runtime/iso-camera.d.ts +35 -0
  123. package/src/runtime/iso-camera.js +85 -0
  124. package/src/runtime/iso-city/figures.d.ts +30 -0
  125. package/src/runtime/iso-city/figures.js +136 -0
  126. package/src/runtime/iso-city/look.d.ts +34 -0
  127. package/src/runtime/iso-city/look.js +105 -0
  128. package/src/runtime/iso-city/plan.d.ts +59 -0
  129. package/src/runtime/iso-city/plan.js +463 -0
  130. package/src/runtime/iso-city/roads.d.ts +64 -0
  131. package/src/runtime/iso-city/roads.js +320 -0
  132. package/src/runtime/iso-city/scene.d.ts +27 -0
  133. package/src/runtime/iso-city/scene.js +432 -0
  134. package/src/runtime/iso-city/shaders.d.ts +6 -0
  135. package/src/runtime/iso-city/shaders.js +233 -0
  136. package/src/runtime/iso-city/shadows.d.ts +13 -0
  137. package/src/runtime/iso-city/shadows.js +148 -0
  138. package/src/runtime/iso-city/traffic.d.ts +80 -0
  139. package/src/runtime/iso-city/traffic.js +457 -0
  140. package/src/runtime/iso-city.d.ts +37 -0
  141. package/src/runtime/iso-city.js +458 -0
  142. package/src/runtime/lens-map.d.ts +11 -0
  143. package/src/runtime/lens-map.js +146 -0
  144. package/src/runtime/light-field.d.ts +29 -0
  145. package/src/runtime/light-field.js +292 -0
  146. package/src/runtime/liquid-glass.d.ts +48 -0
  147. package/src/runtime/liquid-glass.js +423 -0
  148. package/src/runtime/liquid-metal/beads.js +217 -0
  149. package/src/runtime/liquid-metal/field.js +88 -0
  150. package/src/runtime/liquid-metal/look.js +64 -0
  151. package/src/runtime/liquid-metal/shaders.js +255 -0
  152. package/src/runtime/liquid-metal/wave.js +53 -0
  153. package/src/runtime/liquid-metal.d.ts +46 -0
  154. package/src/runtime/liquid-metal.js +366 -0
  155. package/src/runtime/loop.d.ts +7 -0
  156. package/src/runtime/loop.js +112 -0
  157. package/src/runtime/magnetic.d.ts +9 -0
  158. package/src/runtime/magnetic.js +46 -0
  159. package/src/runtime/marquee.d.ts +2 -0
  160. package/src/runtime/marquee.js +27 -0
  161. package/src/runtime/mesh.d.ts +30 -0
  162. package/src/runtime/mesh.js +217 -0
  163. package/src/runtime/mosaic-reveal.d.ts +34 -0
  164. package/src/runtime/mosaic-reveal.js +504 -0
  165. package/src/runtime/motion.d.ts +2 -0
  166. package/src/runtime/motion.js +21 -0
  167. package/src/runtime/mount.d.ts +13 -0
  168. package/src/runtime/mount.js +120 -0
  169. package/src/runtime/nebula-logo.d.ts +31 -0
  170. package/src/runtime/nebula-logo.js +282 -0
  171. package/src/runtime/neon-swarm.d.ts +31 -0
  172. package/src/runtime/neon-swarm.js +258 -0
  173. package/src/runtime/ocean/presets.d.ts +54 -0
  174. package/src/runtime/ocean/presets.js +184 -0
  175. package/src/runtime/ocean/shader.d.ts +14 -0
  176. package/src/runtime/ocean/shader.js +389 -0
  177. package/src/runtime/ocean/view.d.ts +24 -0
  178. package/src/runtime/ocean/view.js +98 -0
  179. package/src/runtime/ocean/waves.d.ts +29 -0
  180. package/src/runtime/ocean/waves.js +119 -0
  181. package/src/runtime/ocean.d.ts +31 -0
  182. package/src/runtime/ocean.js +173 -0
  183. package/src/runtime/palettes.d.ts +37 -0
  184. package/src/runtime/palettes.js +75 -0
  185. package/src/runtime/paper-look.d.ts +42 -0
  186. package/src/runtime/paper-look.js +91 -0
  187. package/src/runtime/paper-looks.d.ts +17 -0
  188. package/src/runtime/paper-looks.js +21 -0
  189. package/src/runtime/paper.d.ts +37 -0
  190. package/src/runtime/paper.js +303 -0
  191. package/src/runtime/particle-logo.d.ts +31 -0
  192. package/src/runtime/particle-logo.js +196 -0
  193. package/src/runtime/ping-pong.d.ts +43 -0
  194. package/src/runtime/ping-pong.js +175 -0
  195. package/src/runtime/pixel-glitch.d.ts +17 -0
  196. package/src/runtime/pixel-glitch.js +287 -0
  197. package/src/runtime/point-cloud.d.ts +33 -0
  198. package/src/runtime/point-cloud.js +287 -0
  199. package/src/runtime/pointer.d.ts +27 -0
  200. package/src/runtime/pointer.js +128 -0
  201. package/src/runtime/points.d.ts +25 -0
  202. package/src/runtime/points.js +130 -0
  203. package/src/runtime/pools.d.ts +2 -0
  204. package/src/runtime/pools.js +25 -0
  205. package/src/runtime/product-stack.d.ts +24 -0
  206. package/src/runtime/product-stack.js +210 -0
  207. package/src/runtime/radiant-glass.d.ts +29 -0
  208. package/src/runtime/radiant-glass.js +282 -0
  209. package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
  210. package/src/runtime/rain-on-glass/backdrop.js +185 -0
  211. package/src/runtime/rain-on-glass/shader.d.ts +2 -0
  212. package/src/runtime/rain-on-glass/shader.js +168 -0
  213. package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
  214. package/src/runtime/rain-on-glass/wipe.js +65 -0
  215. package/src/runtime/rain-on-glass.d.ts +27 -0
  216. package/src/runtime/rain-on-glass.js +210 -0
  217. package/src/runtime/ramp.d.ts +2 -0
  218. package/src/runtime/ramp.js +30 -0
  219. package/src/runtime/random.d.ts +2 -0
  220. package/src/runtime/random.js +22 -0
  221. package/src/runtime/scroll-reveal.d.ts +22 -0
  222. package/src/runtime/scroll-reveal.js +73 -0
  223. package/src/runtime/shader-background.d.ts +42 -0
  224. package/src/runtime/shader-background.js +261 -0
  225. package/src/runtime/shader-backgrounds/band-lens.js +72 -0
  226. package/src/runtime/shader-backgrounds/common.js +53 -0
  227. package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
  228. package/src/runtime/shader-backgrounds/grid.js +33 -0
  229. package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
  230. package/src/runtime/shader-backgrounds/silk.js +57 -0
  231. package/src/runtime/shader-backgrounds/waves.js +31 -0
  232. package/src/runtime/shape.d.ts +42 -0
  233. package/src/runtime/shape.js +313 -0
  234. package/src/runtime/silk-ribbon.d.ts +23 -0
  235. package/src/runtime/silk-ribbon.js +206 -0
  236. package/src/runtime/slideshow.d.ts +27 -0
  237. package/src/runtime/slideshow.js +234 -0
  238. package/src/runtime/spotlight.d.ts +9 -0
  239. package/src/runtime/spotlight.js +97 -0
  240. package/src/runtime/stack-poses.d.ts +53 -0
  241. package/src/runtime/stack-poses.js +273 -0
  242. package/src/runtime/stage.d.ts +47 -0
  243. package/src/runtime/stage.js +187 -0
  244. package/src/runtime/swarm.d.ts +49 -0
  245. package/src/runtime/swarm.js +199 -0
  246. package/src/runtime/text-motion.d.ts +41 -0
  247. package/src/runtime/text-motion.js +165 -0
  248. package/src/runtime/text.d.ts +11 -0
  249. package/src/runtime/text.js +90 -0
  250. package/src/runtime/tilt.d.ts +19 -0
  251. package/src/runtime/tilt.js +116 -0
  252. package/src/runtime/topography.d.ts +71 -0
  253. package/src/runtime/topography.js +650 -0
  254. package/src/runtime/trackers.d.ts +21 -0
  255. package/src/runtime/trackers.js +76 -0
  256. package/src/runtime/variable-type.d.ts +43 -0
  257. package/src/runtime/variable-type.js +358 -0
  258. package/src/runtime/voxel-logo.d.ts +31 -0
  259. package/src/runtime/voxel-logo.js +237 -0
  260. package/src/runtime/waves.d.ts +70 -0
  261. package/src/runtime/waves.js +799 -0
  262. package/src/runtime/world-labels.d.ts +29 -0
  263. package/src/runtime/world-labels.js +59 -0
  264. package/src/runtime/world-land.d.ts +8 -0
  265. package/src/runtime/world-land.js +105 -0
  266. package/src/runtime/world-map.d.ts +69 -0
  267. package/src/runtime/world-map.js +308 -0
  268. package/src/runtime/world-plan.d.ts +101 -0
  269. package/src/runtime/world-plan.js +333 -0
  270. package/src/runtime/world-routes.d.ts +75 -0
  271. package/src/runtime/world-routes.js +673 -0
  272. package/src/styles/border-sweep.css +82 -0
  273. package/src/styles/glass.css +104 -0
  274. package/src/styles/motion.css +218 -0
  275. package/src/styles/reveal.css +51 -0
  276. package/src/vendor/paper/LICENSE +201 -0
  277. package/src/vendor/paper/NOTICE +5 -0
  278. package/src/vendor/paper/README.md +8 -0
  279. package/src/vendor/paper/get-shader-color-from-string.js +100 -0
  280. package/src/vendor/paper/get-shader-noise-texture.js +17 -0
  281. package/src/vendor/paper/presets.js +3678 -0
  282. package/src/vendor/paper/shader-sizing.js +37 -0
  283. package/src/vendor/paper/shader-utils.js +130 -0
  284. package/src/vendor/paper/shaders/color-panels.js +223 -0
  285. package/src/vendor/paper/shaders/dithering.js +270 -0
  286. package/src/vendor/paper/shaders/dot-grid.js +109 -0
  287. package/src/vendor/paper/shaders/dot-orbit.js +122 -0
  288. package/src/vendor/paper/shaders/fluted-glass.js +360 -0
  289. package/src/vendor/paper/shaders/gem-smoke.js +572 -0
  290. package/src/vendor/paper/shaders/god-rays.js +132 -0
  291. package/src/vendor/paper/shaders/grain-gradient.js +300 -0
  292. package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
  293. package/src/vendor/paper/shaders/halftone-dots.js +320 -0
  294. package/src/vendor/paper/shaders/heatmap.js +383 -0
  295. package/src/vendor/paper/shaders/image-dithering.js +198 -0
  296. package/src/vendor/paper/shaders/lens-distortion.js +275 -0
  297. package/src/vendor/paper/shaders/liquid-metal.js +632 -0
  298. package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
  299. package/src/vendor/paper/shaders/metaballs.js +110 -0
  300. package/src/vendor/paper/shaders/neuro-noise.js +76 -0
  301. package/src/vendor/paper/shaders/paper-texture.js +526 -0
  302. package/src/vendor/paper/shaders/perlin-noise.js +166 -0
  303. package/src/vendor/paper/shaders/pulsing-border.js +238 -0
  304. package/src/vendor/paper/shaders/simplex-noise.js +91 -0
  305. package/src/vendor/paper/shaders/smoke-ring.js +132 -0
  306. package/src/vendor/paper/shaders/spiral.js +82 -0
  307. package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
  308. package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
  309. package/src/vendor/paper/shaders/swirl.js +103 -0
  310. package/src/vendor/paper/shaders/voronoi.js +138 -0
  311. package/src/vendor/paper/shaders/warp.js +129 -0
  312. package/src/vendor/paper/shaders/water.js +121 -0
  313. package/src/vendor/paper/shaders/waves.js +65 -0
  314. package/src/vendor/paper/vertex-shader.js +159 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/liquid-metal/field
3
+ *
4
+ * The logo's distance field on the GPU, on texture unit 1. It arrives as
5
+ * bytes (src/runtime/shape.js), whose steps the rounded edge's slope
6
+ * would show as stripes, so it is blurred on the GPU into a float target
7
+ * (src/runtime/ping-pong.js), where the steps become smooth ramps. Where
8
+ * the GPU cannot filter a float target, the bytes are used as they are.
9
+ *
10
+ * Uploading uses unit 0 for the blur and leaves its framebuffer bound:
11
+ * whoever draws next restores theirs.
12
+ */
13
+
14
+ import { createProgram, bindTriangle, VERTEX } from '../gl.js';
15
+ import { createPingPong } from '../ping-pong.js';
16
+ import { SMOOTH } from './shaders.js';
17
+
18
+ /**
19
+ * @typedef {object} Field
20
+ * @property {(bytes: Uint8Array, width: number, height: number) => void} upload
21
+ * Takes a new field (one byte a pixel, rows from the top) and binds it to unit 1.
22
+ * @property {() => void} dispose Frees its textures, targets, program and buffer.
23
+ */
24
+
25
+ /**
26
+ * Sets up the field, empty (all outside) until the first upload.
27
+ *
28
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
29
+ * @returns {Field} The field.
30
+ */
31
+ export function createField(gl) {
32
+ const bytes = gl.createTexture();
33
+ gl.activeTexture(gl.TEXTURE1);
34
+ gl.bindTexture(gl.TEXTURE_2D, bytes);
35
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
36
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
37
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
38
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
39
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, 1, 1, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, new Uint8Array([0]));
40
+
41
+ const blur = createProgram(gl, VERTEX, SMOOTH);
42
+ const smooth = blur && createPingPong(gl, 1, 1);
43
+ const targets = smooth?.linear ? smooth : null;
44
+ const triangle = bindTriangle(gl);
45
+
46
+ /**
47
+ * One blur pass into the write target.
48
+ *
49
+ * @param {WebGLTexture} source What is blurred.
50
+ * @param {number} x The step across, a share of the width.
51
+ * @param {number} y The step down, a share of the height.
52
+ */
53
+ const pass = (source, x, y) => {
54
+ if (!blur || !targets) return;
55
+ const { width, height } = targets.size();
56
+ gl.bindFramebuffer(gl.FRAMEBUFFER, targets.write.fbo);
57
+ gl.viewport(0, 0, width, height);
58
+ gl.activeTexture(gl.TEXTURE0);
59
+ gl.bindTexture(gl.TEXTURE_2D, source);
60
+ gl.uniform2f(blur.uniform('uStep'), x, y);
61
+ gl.drawArrays(gl.TRIANGLES, 0, 3);
62
+ targets.swap();
63
+ };
64
+
65
+ return {
66
+ upload(field, width, height) {
67
+ gl.activeTexture(gl.TEXTURE1);
68
+ gl.bindTexture(gl.TEXTURE_2D, bytes);
69
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
70
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width, height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, field);
71
+ if (!blur || !targets || !targets.resize(width, height)) return;
72
+ gl.useProgram(blur.program);
73
+ bindTriangle(gl, triangle);
74
+ gl.disable(gl.BLEND);
75
+ gl.uniform1i(blur.uniform('uSource'), 0);
76
+ pass(/** @type {WebGLTexture} */ (bytes), 1 / width, 0);
77
+ pass(targets.read.texture, 0, 1 / height);
78
+ gl.activeTexture(gl.TEXTURE1);
79
+ gl.bindTexture(gl.TEXTURE_2D, targets.read.texture);
80
+ },
81
+ dispose() {
82
+ gl.deleteTexture(bytes);
83
+ smooth?.dispose();
84
+ if (blur) gl.deleteProgram(blur.program);
85
+ gl.deleteBuffer(triangle);
86
+ },
87
+ };
88
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/liquid-metal/look
3
+ *
4
+ * The liquid metal's colours: the metal's own (its reflectance face on,
5
+ * by name or as a CSS colour) and the studio's, which a palette tints.
6
+ */
7
+
8
+ import { parseColor, toOklab, fromOklab } from '../color.js';
9
+
10
+ /**
11
+ * @typedef {import('../color.js').Rgb} Rgb
12
+ */
13
+
14
+ /** The metals by name: each one's colour face on, sRGB. Black chrome is a dark mirror that only lights at its edges and glints. */
15
+ export const METALS = Object.freeze({
16
+ chrome: '#e6e8eb',
17
+ gold: '#ffd98f',
18
+ 'rose-gold': '#f4c2ad',
19
+ copper: '#f2a882',
20
+ 'black-chrome': '#58595d',
21
+ });
22
+
23
+ /** The studio's colours with no palette: a cool sky, a white horizon, a warm floor. */
24
+ const STUDIO = ['#dde5ef', '#ffffff', '#ebe7e2'];
25
+ /** How light a palette colour is made before it tints the studio (Oklab L), and how much of its colour it keeps. */
26
+ const STUDIO_LIGHTNESS = 0.9;
27
+ const STUDIO_CHROMA = 0.75;
28
+
29
+ /**
30
+ * The metal's colour, face on. A tint that is neither a metal's name nor a
31
+ * hex colour is warned about, and chrome used.
32
+ *
33
+ * @param {string | undefined} tint A metal's name (METALS, any case) or a CSS hex colour; none for chrome.
34
+ * @returns {Rgb} Its colour, sRGB 0–1.
35
+ */
36
+ export function metalColor(tint) {
37
+ if (!tint) return parseColor(METALS.chrome);
38
+ const name = /** @type {keyof typeof METALS | undefined} */ (Object.keys(METALS).find((k) => k === tint.toLowerCase().replace(/\s+/g, '-')));
39
+ try {
40
+ return parseColor(name ? METALS[name] : tint);
41
+ } catch {
42
+ console.warn('[effects-astro]', `No metal "${tint}"`);
43
+ return parseColor(METALS.chrome);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * The studio's three tints (the sky, the horizon, the floor) from a
49
+ * palette: each colour made light and a little softer in Oklab, so it
50
+ * colours the light without dimming the room. Without colours, the
51
+ * neutral studio. Fewer than three colours repeat.
52
+ *
53
+ * @param {string[] | undefined} colors CSS hex colours.
54
+ * @returns {[Rgb, Rgb, Rgb]} The sky's, the horizon's and the floor's tint, sRGB 0–1.
55
+ */
56
+ export function studioTints(colors) {
57
+ if (!colors?.length) return /** @type {[Rgb, Rgb, Rgb]} */ (STUDIO.map(parseColor));
58
+ return /** @type {[Rgb, Rgb, Rgb]} */ (
59
+ [0, 1, 2].map((i) => {
60
+ const [, a, b] = toOklab(parseColor(colors[i % colors.length]));
61
+ return fromOklab([STUDIO_LIGHTNESS, a * STUDIO_CHROMA, b * STUDIO_CHROMA]);
62
+ })
63
+ );
64
+ }
@@ -0,0 +1,255 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/liquid-metal/shaders
3
+ *
4
+ * The liquid metal's GLSL (ES 1.00): the step of its wave simulation, and
5
+ * the render that draws the logo as polished chrome in a studio.
6
+ *
7
+ * Both work in the logo's box (the area round it the simulation covers):
8
+ * `uv` 0–1 across it with y up, and distances in box heights. The shape is
9
+ * a distance field (src/runtime/shape.js) packed in a byte texture: 0.5 at
10
+ * the edge, rising inside. The simulation's state is a float texture: r
11
+ * the surface's height off its rest, g its vertical speed.
12
+ */
13
+
14
+ import { GLSL_OKLAB } from '../color.js';
15
+ import { GLSL_HEIGHT_FIELD } from '../height-field.js';
16
+
17
+ /** The most droplets the render draws. */
18
+ export const MAX_BEADS = 24;
19
+
20
+ /** The distance field, read in box heights: positive inside, negative outside. */
21
+ const FIELD = `
22
+ uniform sampler2D uSdf;
23
+ uniform float uSpread;
24
+ float field(vec2 uv) { return (texture2D(uSdf, vec2(uv.x, 1.0 - uv.y)).r - 0.5) * 2.0 * uSpread; }
25
+ `;
26
+
27
+ /**
28
+ * One pass of a gaussian blur (`uStep` one texel along it), into a float
29
+ * target: run across then down over the byte field, it smooths the bytes'
30
+ * steps into ramps, which the bevel's slope would otherwise show as
31
+ * stripes.
32
+ */
33
+ export const SMOOTH = `
34
+ precision highp float;
35
+ varying vec2 vUv;
36
+ uniform sampler2D uSource;
37
+ uniform vec2 uStep;
38
+ void main() {
39
+ float sum = 0.0;
40
+ float total = 0.0;
41
+ for (int i = -8; i <= 8; i++) {
42
+ float w = exp(-float(i * i) / 18.0);
43
+ sum += texture2D(uSource, vUv + uStep * float(i)).r * w;
44
+ total += w;
45
+ }
46
+ gl_FragColor = vec4(sum / total, 0.0, 0.0, 1.0);
47
+ }
48
+ `;
49
+
50
+ /**
51
+ * One step of the wave (on src/runtime/height-field.js): a damped wave
52
+ * equation on the height, with a spring pulling every cell back to its
53
+ * rest (the surface tension that reforms the logo) and a little viscosity
54
+ * smoothing the speed, so small ripples die first. Waves run only through
55
+ * the metal (and just past its edge, where a swell pushes the outline
56
+ * out); elsewhere they are damped away.
57
+ */
58
+ export const STEP = `
59
+ precision highp float;
60
+ varying vec2 vUv;
61
+ uniform float uBevel;
62
+ uniform float uBulge;
63
+ ${GLSL_HEIGHT_FIELD}
64
+ ${FIELD}
65
+ void main() {
66
+ vec4 s = waveState(vUv);
67
+ float h = s.x;
68
+ // Metal is where the shape is, or where a swell has pushed its edge out to.
69
+ float metal = smoothstep(-uBevel * 1.5, 0.0, field(vUv) + max(h, 0.0) * uBulge);
70
+ float v = s.y + waveForce(s) - wavePushes(vUv);
71
+ v *= mix(0.55, uMotion.z, metal);
72
+ h = (h + v) * mix(0.8, 1.0, metal);
73
+ gl_FragColor = wavePack(h, v);
74
+ }
75
+ `;
76
+
77
+ /**
78
+ * The render. The logo is a slab of metal seen from in front, a little in
79
+ * perspective (`uLens`), so its flat face reflects a sweep of the studio:
80
+ * sky above the horizon, floor below, with the horizon's bright line across
81
+ * it. Its edges round over in a quarter circle (`uBevel` wide), so they
82
+ * catch the softboxes round the room and darken where they turn away. The
83
+ * waves tilt the surface and push the outline in or out; droplets are
84
+ * spheres, drawn on top while they fly and melting into the edge as they
85
+ * crawl back. Output is premultiplied: transparent round the logo, with a
86
+ * soft shadow under it.
87
+ */
88
+ export const RENDER = `
89
+ precision highp float;
90
+ uniform vec2 uRes;
91
+ uniform vec4 uBox;
92
+ uniform float uAspect;
93
+ uniform vec2 uSdfTexel;
94
+ uniform sampler2D uState;
95
+ uniform vec2 uStateTexel;
96
+ uniform float uWaves;
97
+ uniform float uBevel;
98
+ uniform float uBulge;
99
+ uniform float uWave;
100
+ uniform vec2 uCentre;
101
+ uniform float uLens;
102
+ uniform float uSpin;
103
+ uniform float uPx;
104
+ uniform float uShadow;
105
+ uniform vec3 uMetal;
106
+ uniform vec3 uSky;
107
+ uniform vec3 uBand;
108
+ uniform vec3 uFloor;
109
+ uniform vec4 uBeads[${MAX_BEADS}];
110
+ uniform int uBeadCount;
111
+ ${FIELD}
112
+ ${GLSL_OKLAB}
113
+
114
+ // A softbox: a bright panel with soft edges. at: azimuth, elevation, half
115
+ // width (radians), half height (elevation).
116
+ float softbox(float az, float el, vec4 at) {
117
+ float da = abs(mod(az - at.x + 3.14159265, 6.2831853) - 3.14159265) / at.z;
118
+ float de = abs(el - at.y) / at.w;
119
+ float edge = pow(pow(da, 6.0) + pow(de, 6.0), 1.0 / 6.0);
120
+ return smoothstep(1.0, 0.7, edge);
121
+ }
122
+
123
+ // The studio, in linear light, by the direction a reflection leaves in (y up,
124
+ // z towards the viewer): sky, a bright horizon, a dark floor, softboxes
125
+ // round the walls and a light overhead. The room turns slowly (uSpin), so
126
+ // the reflections glide.
127
+ vec3 studio(vec3 r) {
128
+ float el = r.y;
129
+ float az = atan(r.x, r.z) - uSpin;
130
+ // The room is lit in front of the logo and dim behind it.
131
+ float front = smoothstep(-0.8, 0.5, r.z);
132
+ vec3 sky = oklabToLinear(uSky) * (0.05 + 0.75 * exp(-max(el, 0.0) * 4.0));
133
+ vec3 ground = oklabToLinear(uFloor) * (0.008 + 0.16 * smoothstep(-0.03, -0.55, el));
134
+ // A pool of light on the floor, a band across the lower face.
135
+ ground += oklabToLinear(uFloor) * exp(-pow((el + 0.21) / 0.07, 2.0)) * 0.22;
136
+ vec3 col = mix(ground, sky, smoothstep(-0.006, 0.006, el)) * mix(0.25, 1.0, front);
137
+ col += oklabToLinear(uBand) * (exp(-abs(el - 0.004) / 0.008) * 2.2 + exp(-abs(el) / 0.07) * 0.25) * mix(0.08, 1.0, front);
138
+ col += vec3(4.5) * softbox(az, el, vec4(-0.95, 0.4, 0.42, 0.18));
139
+ col += vec3(6.0) * softbox(az, el, vec4(1.3, 0.16, 0.12, 0.4));
140
+ col += vec3(2.5) * softbox(az, el, vec4(2.7, 0.25, 0.35, 0.1));
141
+ col += vec3(2.2) * smoothstep(0.8, 0.96, el);
142
+ return col;
143
+ }
144
+
145
+ // The key light: a small hard lamp, for the sharp glints on curves.
146
+ float key(vec3 r) {
147
+ float a = 0.75 + uSpin;
148
+ vec3 l = normalize(vec3(sin(a) * 0.8, 0.6, cos(a) * 0.8));
149
+ return pow(max(dot(r, l), 0.0), 1800.0) * 60.0;
150
+ }
151
+
152
+ // The metal at a point with a normal: the studio reflected, by Fresnel's
153
+ // law (the metal's colour face on, white at grazing angles), plus a faint
154
+ // film's colour where it turns away.
155
+ vec3 metal(vec3 n, vec2 p) {
156
+ vec3 eye = normalize(vec3((p - uCentre) * uLens, -1.0));
157
+ vec3 r = reflect(eye, n);
158
+ float facing = clamp(dot(n, -eye), 0.0, 1.0);
159
+ vec3 f0 = oklabToLinear(uMetal);
160
+ vec3 fresnel = f0 + (1.0 - f0) * pow(1.0 - facing, 5.0);
161
+ vec3 col = (studio(r) + key(r)) * fresnel;
162
+ float graze = pow(1.0 - facing, 3.0);
163
+ col *= mix(vec3(1.0), 0.8 + 0.2 * cos(6.2831853 * (vec3(0.0, 0.33, 0.67) + graze * 1.3 + 0.15)), graze * 0.5);
164
+ return col;
165
+ }
166
+
167
+ // Linear light to the screen: a filmic curve (Narkowicz's ACES fit), then sRGB.
168
+ vec3 toScreen(vec3 c) {
169
+ c *= 0.9;
170
+ c = clamp((c * (2.51 * c + 0.03)) / (c * (2.43 * c + 0.59) + 0.14), 0.0, 1.0);
171
+ return oklabToSrgb(c);
172
+ }
173
+
174
+ // The bevel's profile: a quarter circle from the edge (0) to the flat top
175
+ // (1); returns its height and its slope. The slope is capped just short of
176
+ // upright, so the outermost pixel does not flicker between reflections.
177
+ vec2 profile(float x) {
178
+ x = clamp(x, 0.0, 1.0);
179
+ float s = sqrt(max(2.0 * x - x * x, 0.012));
180
+ return vec2(s, (1.0 - x) / s);
181
+ }
182
+
183
+ void main() {
184
+ vec2 uv = (gl_FragCoord.xy / uRes - uBox.xy) / uBox.zw;
185
+ if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) { gl_FragColor = vec4(0.0); return; }
186
+ vec2 p = uv * vec2(uAspect, 1.0);
187
+ float d = field(uv);
188
+ if (d < -uSpread * 0.97 && uBeadCount == 0) { gl_FragColor = vec4(0.0); return; }
189
+
190
+ // The rest shape's slope. A distance field's gradient is a unit vector,
191
+ // so only its direction is read: the bytes' steps do not ripple the chrome.
192
+ vec2 e = uSdfTexel * 2.0;
193
+ vec2 g = vec2(field(uv + vec2(e.x, 0.0)) - field(uv - vec2(e.x, 0.0)), field(uv + vec2(0.0, e.y)) - field(uv - vec2(0.0, e.y)));
194
+ vec2 inward = g / max(length(g), 1e-6);
195
+
196
+ // The waves: height off the rest, and its slope per box height.
197
+ float h = 0.0;
198
+ vec2 gh = vec2(0.0);
199
+ if (uWaves > 0.5) {
200
+ vec2 s = uStateTexel;
201
+ h = texture2D(uState, uv).r;
202
+ gh = vec2(texture2D(uState, uv + vec2(s.x, 0.0)).r - texture2D(uState, uv - vec2(s.x, 0.0)).r, texture2D(uState, uv + vec2(0.0, s.y)).r - texture2D(uState, uv - vec2(0.0, s.y)).r) / (2.0 * s * vec2(uAspect, 1.0));
203
+ }
204
+
205
+ // The outline, moved by the waves: a swell pushes it out, a dent pulls it in (and parts it).
206
+ float de = d + h * uBulge;
207
+ vec2 gde = inward + gh * uBulge;
208
+ float bevel = uBevel;
209
+ float shadow = uShadow * pow(clamp((field(uv + vec2(0.0, 0.014)) + h * uBulge + 0.05) / 0.06, 0.0, 1.0), 2.0) * 0.6;
210
+
211
+ // Droplets: those crawling back melt into the edge (a smooth union, so a
212
+ // neck of metal reaches out to them); those in the air sit on top.
213
+ vec3 drop = vec3(0.0, 0.0, 1.0);
214
+ float dropCover = 0.0;
215
+ float dropTop = -1.0;
216
+ float shade = 0.0;
217
+ for (int i = 0; i < ${MAX_BEADS}; i++) {
218
+ if (i >= uBeadCount) break;
219
+ vec4 b = uBeads[i];
220
+ vec2 off = p - b.xy;
221
+ float len = length(off);
222
+ if (b.w < 0.0) {
223
+ float db = b.z - len;
224
+ float k = b.z * 1.4;
225
+ float m = clamp(0.5 + 0.5 * (db - de) / k, 0.0, 1.0);
226
+ de = mix(de, db, m) + k * m * (1.0 - m);
227
+ gde = mix(gde, -off / max(len, 1e-5), m);
228
+ bevel = mix(bevel, b.z, m);
229
+ } else {
230
+ // Its shadow, cast down and wider the higher it flies.
231
+ vec2 under = off + vec2(0.0, b.w * 0.5 + b.z * 0.4);
232
+ shade = max(shade, exp(-dot(under, under) / (b.z * b.z * (1.2 + b.w * 60.0))) * 0.55);
233
+ float cover = smoothstep(b.z + uPx, b.z - uPx, len);
234
+ if (cover > 0.0 && b.w > dropTop) {
235
+ vec2 q = off / b.z;
236
+ drop = vec3(q, sqrt(max(1.0 - dot(q, q), 0.0)) + 0.05);
237
+ dropCover = cover;
238
+ dropTop = b.w;
239
+ }
240
+ }
241
+ }
242
+
243
+ // Premultiplied: the metal, a droplet over it, and the shadows under both.
244
+ vec4 out_ = vec4(0.0);
245
+ float cover = smoothstep(-uPx, uPx, de);
246
+ if (cover > 0.0) {
247
+ vec2 slope = profile(de / bevel);
248
+ vec3 n = normalize(vec3(-(gde * slope.y + gh * uWave * bevel), 1.0));
249
+ out_ = vec4(toScreen(metal(n, p) * (1.0 - shade)), 1.0) * cover;
250
+ }
251
+ if (dropCover > 0.0) out_ = vec4(toScreen(metal(normalize(drop), p)), 1.0) * dropCover + out_ * (1.0 - dropCover);
252
+ out_.a += max(shadow, shade) * (1.0 - out_.a);
253
+ gl_FragColor = out_;
254
+ }
255
+ `;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/liquid-metal/wave
3
+ *
4
+ * The liquid metal's surface: a height field (src/runtime/height-field.js)
5
+ * over the logo's box, stepped by shaders.js's STEP, which keeps the waves
6
+ * in the metal and adds a spring back to rest.
7
+ *
8
+ * Reads the distance field from texture unit 1, where the effect keeps it;
9
+ * uses unit 0 for its own state. Each step leaves its program, framebuffer
10
+ * and viewport bound: whoever draws next restores theirs.
11
+ */
12
+
13
+ import { createHeightField } from '../height-field.js';
14
+ import { STEP } from './shaders.js';
15
+
16
+ /**
17
+ * The shape the waves run through, in box heights.
18
+ *
19
+ * @typedef {object} WaveShape
20
+ * @property {number} spread The distance field's reach.
21
+ * @property {number} bevel The width of the rounded edge.
22
+ * @property {number} bulge How far the outline moves per unit of height.
23
+ */
24
+
25
+ /**
26
+ * @typedef {import('../height-field.js').HeightField & { shape: (shape: WaveShape) => void }} Wave
27
+ * The height field, and `shape`, which sets the shape the waves run through.
28
+ */
29
+
30
+ /**
31
+ * Sets up the wave simulation.
32
+ *
33
+ * @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
34
+ * @returns {Wave | null} The wave, or null where the GPU cannot draw into
35
+ * float textures or the step does not compile.
36
+ */
37
+ export function createWave(gl) {
38
+ const field = createHeightField(gl, STEP);
39
+ if (!field) return null;
40
+ const { uniform } = field;
41
+ gl.useProgram(field.program);
42
+ gl.uniform1i(uniform('uSdf'), 1);
43
+
44
+ return {
45
+ ...field,
46
+ shape({ spread, bevel, bulge }) {
47
+ gl.useProgram(field.program);
48
+ gl.uniform1f(uniform('uSpread'), spread);
49
+ gl.uniform1f(uniform('uBevel'), bevel);
50
+ gl.uniform1f(uniform('uBulge'), bulge);
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,46 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ /** A metal by name. */
4
+ export type MetalName = 'chrome' | 'gold' | 'rose-gold' | 'copper' | 'black-chrome';
5
+
6
+ export interface LiquidMetalConfig {
7
+ /** A word to make of metal. */
8
+ text?: string;
9
+ /** Its CSS font, without the size. Default: the page's, bold. */
10
+ font?: string;
11
+ /** An image (an SVG logo) to make of metal instead. */
12
+ src?: string;
13
+ /** Where the logo sits, each 0–1 from the top left. Default the right half. */
14
+ area?: { x: number; y: number; width: number; height: number };
15
+ /** How much of its area the logo fills: 1 fits it, less shrinks it about the area's middle. Default 1. */
16
+ size?: number;
17
+ /** The metal: a name, or a CSS hex colour (its colour face on). Default `chrome`. */
18
+ tint?: MetalName | (string & {});
19
+ /** The studio's colours, reflected in the metal: the sky, the horizon, the floor. Default a neutral studio. */
20
+ colors?: string[];
21
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`: it tints the studio. */
22
+ palette?: PaletteName | (string & {});
23
+ /** How wide its rounded edges are. Default 1. */
24
+ bevel?: number;
25
+ /** How thick the metal is: more settles sooner, with smaller ripples. Default 1. */
26
+ viscosity?: number;
27
+ /** How hard it pulls back into shape: more reforms sooner, with a quicker wobble. Default 1. */
28
+ tension?: number;
29
+ /** How hard the pointer pushes into it. Default 1. */
30
+ ripple?: number;
31
+ /** Whether it reacts to the pointer at all. Default true. */
32
+ interactive?: boolean;
33
+ /** The soft shadow under it; 0 for none. Default 1. */
34
+ shadow?: number;
35
+ }
36
+
37
+ /** The logo's box (its area scaled by `size`, grown by a margin, kept on the canvas) in canvas pixels, and the logo's area as a share of the box. */
38
+ export function logoBox(
39
+ area: { x: number; y: number; width: number; height: number },
40
+ size: number,
41
+ width: number,
42
+ height: number,
43
+ ): { left: number; top: number; width: number; height: number; shape: { x: number; y: number; width: number; height: number } };
44
+
45
+ /** Starts liquid metal in `el`'s canvas. Returns a function that stops it. */
46
+ export function liquidMetal(el: HTMLElement, config: LiquidMetalConfig): () => void;