@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,261 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-background
3
+ *
4
+ * Six animated backgrounds for a hero or a section, each one shader
5
+ * tinted from the colour tokens it sits under: mesh-gradient, grain-gradient,
6
+ * silk, band-lens, grid and waves. The shaders are in ./shader-backgrounds, one a
7
+ * file.
8
+ *
9
+ * Colours: up to four. Those not given come from the live `--color-accent`
10
+ * where the shader background sits (a section can set its own): the accent itself, the accent 55% of the way to
11
+ * `--color-bg` (a pale tint on a light page, a deep shade on a dark one),
12
+ * the accent's hue turned 30° towards yellow and lifted, and its hue
13
+ * turned 45° away from yellow (turned in Oklab, towards the lightness where
14
+ * each new hue is most vivid; yellows only glow when light). They
15
+ * are read when the effect starts, so a theme's accent tints every
16
+ * shader background with no settings, and again when `setColors` gives new ones.
17
+ *
18
+ * Each draws light whose alpha follows its brightness, so the page shows
19
+ * through where it is dark. With `interactive`, it leans towards the
20
+ * pointer.
21
+ *
22
+ * `static` draws one frame, at `frame` seconds, and never runs the loop:
23
+ * for a shader background that is wallpaper rather than a feature (a fixed,
24
+ * full-page one is always in view, so it would otherwise never pause).
25
+ * With prefers-reduced-motion, one frame at 0. Without WebGL, soft
26
+ * gradients in the same colours stand in.
27
+ *
28
+ * Ported from @arraypress/effect-canvas-astro, which this replaces; its
29
+ * fainter and plainer shaders were left behind (`<GlowField>` and `<Grain>`
30
+ * do the plain glows and grain in CSS).
31
+ */
32
+
33
+ import { createStage } from './stage.js';
34
+ import { parseColor, mixOklab, toOklab, turnHue } from './color.js';
35
+ import { canHover, prefersReducedMotion } from './device.js';
36
+ import { pointerIn } from './pointer.js';
37
+ import { watchColors } from './mount.js';
38
+ import { WAVES } from './shader-backgrounds/waves.js';
39
+ import { GRID } from './shader-backgrounds/grid.js';
40
+ import { MESH_GRADIENT } from './shader-backgrounds/mesh-gradient.js';
41
+ import { GRAIN_GRADIENT } from './shader-backgrounds/grain-gradient.js';
42
+ import { BAND_LENS } from './shader-backgrounds/band-lens.js';
43
+ import { SILK } from './shader-backgrounds/silk.js';
44
+ import { pickColors } from './palettes.js';
45
+
46
+ /** @typedef {import('./color.js').Rgb} Rgb */
47
+
48
+ /**
49
+ * @typedef {'mesh-gradient' | 'grain-gradient' | 'silk' | 'band-lens' | 'grid' | 'waves'} ShaderBackgroundName
50
+ */
51
+
52
+ /**
53
+ * @typedef {object} ShaderBackgroundConfig
54
+ * @property {ShaderBackgroundName} effect Which shader background.
55
+ * @property {string[]} [colors] Up to four colours (hex or `rgb()`); those missing or unreadable come from `--color-accent`.
56
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`. Its three colours and its glint as the fourth.
57
+ * @property {number} [speed=1] How fast it moves, 0–4.
58
+ * @property {number} [intensity=1] How strong it is (brightness and contrast, not opacity), 0–2.
59
+ * @property {boolean} [static=false] One frame, never the loop: for a shader background that is wallpaper.
60
+ * @property {number} [frame=12] With `static`, the moment drawn, in seconds.
61
+ * @property {boolean} [interactive=false] Lean towards the pointer (on devices that hover).
62
+ */
63
+
64
+ /** Every shader background's fragment shader, by name. */
65
+ export const SHADER_BACKGROUNDS = {
66
+ 'mesh-gradient': MESH_GRADIENT,
67
+ 'grain-gradient': GRAIN_GRADIENT,
68
+ silk: SILK,
69
+ 'band-lens': BAND_LENS,
70
+ grid: GRID,
71
+ waves: WAVES,
72
+ };
73
+
74
+ /** The accent when the page sets none: a bright green. */
75
+ const ACCENT = /** @type {Rgb} */ ([0, 0.89, 0.45]);
76
+ /** The page background when the page sets none. */
77
+ const PAGE = /** @type {Rgb} */ ([0, 0, 0]);
78
+ /** Yellow's hue in Oklab, degrees. */
79
+ const YELLOW = 110;
80
+ /** How far the third colour turns from the accent's hue, towards yellow, degrees. */
81
+ const TOWARD = 30;
82
+ /** How far the fourth turns, away from yellow, degrees. */
83
+ const AWAY = 45;
84
+ /** How far the smoothed pointer closes on the real one each frame. */
85
+ const EASE = 0.06;
86
+
87
+ /**
88
+ * Reads a colour as the shader backgrounds take it: hex (`#rgb`, `#rrggbb`) or
89
+ * `rgb()` / `rgba()` with whole-number channels.
90
+ *
91
+ * @param {string} value The colour, as CSS writes it.
92
+ * @returns {Rgb | null} Its channels, 0–1; null for anything else.
93
+ */
94
+ export function readColor(value) {
95
+ const s = String(value ?? '').trim();
96
+ if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(s)) return parseColor(s);
97
+ const rgb = s.match(/^rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)/i);
98
+ return rgb ? [Number(rgb[1]) / 255, Number(rgb[2]) / 255, Number(rgb[3]) / 255] : null;
99
+ }
100
+
101
+ /**
102
+ * The four colours a shader background is drawn in: those given, in order (any
103
+ * that cannot be read are skipped), and the rest from the accent.
104
+ *
105
+ * @param {object} from Where they come from.
106
+ * @param {string} [from.accent] The page's `--color-accent` (default a bright green).
107
+ * @param {string} [from.background] The page's `--color-bg` (default black).
108
+ * @param {string[]} [from.colors] Colours given, hex or `rgb()`.
109
+ * @returns {[Rgb, Rgb, Rgb, Rgb]} The four colours.
110
+ */
111
+ export function shaderBackgroundPalette({ accent, background, colors = [] }) {
112
+ const a = readColor(accent ?? '') ?? ACCENT;
113
+ const bg = readColor(background ?? '') ?? PAGE;
114
+ const [, la, lb] = toOklab(a);
115
+ const hue = (Math.atan2(lb, la) * 180) / Math.PI;
116
+ /**
117
+ * How far a hue sits from yellow, round the circle.
118
+ *
119
+ * @param {number} h The hue, degrees.
120
+ * @returns {number} Degrees, 0–180.
121
+ */
122
+ const fromYellow = (h) => Math.abs(((((h - YELLOW + 180) % 360) + 360) % 360) - 180);
123
+ // A hue nearer yellow only glows when light (dim, it is olive), so the
124
+ // third turns a little that way and is lifted, and the fourth turns
125
+ // further the other way and can sit deep.
126
+ const side = fromYellow(hue + AWAY) >= fromYellow(hue - AWAY) ? 1 : -1;
127
+ /** @type {[Rgb, Rgb, Rgb, Rgb]} */
128
+ const derived = [a, mixOklab(a, bg, 0.55), turnHue(a, -side * TOWARD, 0.06), turnHue(a, side * AWAY)];
129
+ const given = colors.map(readColor).filter((c) => c !== null);
130
+ return /** @type {[Rgb, Rgb, Rgb, Rgb]} */ (derived.map((d, i) => given[i] ?? d));
131
+ }
132
+
133
+ /**
134
+ * A number setting, clamped to its range.
135
+ *
136
+ * @param {unknown} value The setting.
137
+ * @param {number} fallback Its default, for a missing or non-numeric one.
138
+ * @param {number} min The lowest it may be.
139
+ * @param {number} max The highest it may be.
140
+ * @returns {number} The setting.
141
+ */
142
+ function clamp(value, fallback, min, max) {
143
+ const n = Number(value ?? fallback);
144
+ return Number.isFinite(n) ? Math.min(max, Math.max(min, n)) : fallback;
145
+ }
146
+
147
+ /**
148
+ * The settings that steer the shader, read and clamped.
149
+ *
150
+ * @param {Partial<ShaderBackgroundConfig>} config The config.
151
+ * @returns {{ speed: number, intensity: number, frame: number }} Speed (0–4),
152
+ * intensity (0–2) and the still frame, in seconds.
153
+ */
154
+ export function shaderBackgroundSettings(config) {
155
+ return {
156
+ speed: clamp(config.speed, 1, 0, 4),
157
+ intensity: clamp(config.intensity, 1, 0, 2),
158
+ frame: clamp(config.frame, 12, -Infinity, Infinity),
159
+ };
160
+ }
161
+
162
+ /**
163
+ * The stand-in without WebGL: two soft pools of the first and third
164
+ * colours.
165
+ *
166
+ * @param {Rgb[]} palette The shader background's colours.
167
+ * @returns {string} A CSS `background`.
168
+ */
169
+ export function shaderBackgroundFallback(palette) {
170
+ /**
171
+ * A colour as CSS, at an alpha.
172
+ *
173
+ * @param {Rgb} c The colour.
174
+ * @param {number} alpha Its alpha.
175
+ * @returns {string} `rgba(…)`.
176
+ */
177
+ const css = (c, alpha) => `rgba(${c.map((v) => Math.round(v * 255)).join(',')},${alpha})`;
178
+ return [
179
+ `radial-gradient(ellipse 55% 70% at 75% 25%, ${css(palette[0], 0.14)}, transparent 65%)`,
180
+ `radial-gradient(ellipse 60% 70% at 20% 75%, ${css(palette[2], 0.1)}, transparent 65%)`,
181
+ ].join(',');
182
+ }
183
+
184
+ /**
185
+ * The palette now: the accent and background tokens as the element sees
186
+ * them (so a section can set its own), under the colours given.
187
+ *
188
+ * @param {HTMLElement} el The shader background's element.
189
+ * @param {string[] | undefined} colors Colours given.
190
+ * @returns {[Rgb, Rgb, Rgb, Rgb]} The four colours.
191
+ */
192
+ function livePalette(el, colors) {
193
+ const styles = getComputedStyle(el);
194
+ return shaderBackgroundPalette({
195
+ accent: styles.getPropertyValue('--color-accent'),
196
+ background: styles.getPropertyValue('--color-bg'),
197
+ colors,
198
+ });
199
+ }
200
+
201
+ /**
202
+ * Starts a shader background on an element: a canvas inside it, filling it.
203
+ *
204
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
205
+ * @param {ShaderBackgroundConfig} config The settings.
206
+ * @returns {() => void} Stops it.
207
+ */
208
+ export function shaderBackground(el, config) {
209
+ const fragment = SHADER_BACKGROUNDS[config.effect];
210
+ if (!fragment) {
211
+ console.warn('[effects-astro]', `No shader background "${config.effect}"`);
212
+ return () => {};
213
+ }
214
+ const { speed, intensity, frame } = shaderBackgroundSettings(config);
215
+ const reduced = prefersReducedMotion();
216
+ let palette = livePalette(el, pickColors(config, [], (p) => [...p.colors, p.glint]));
217
+ const start = performance.now();
218
+ const mouse = { x: 0.5, y: 0.5, on: 0 };
219
+
220
+ /**
221
+ * The shader's clock at a moment.
222
+ *
223
+ * @param {number} now The time, ms.
224
+ * @returns {number} Seconds since the start, times the speed.
225
+ */
226
+ const clock = (now) => ((now - start) / 1000) * speed;
227
+
228
+
229
+ const { stage, stop } = createStage(el, {
230
+ fragment,
231
+ still: config.static === true,
232
+ uniforms({ gl, uniform, still }, now) {
233
+ if (!still && config.interactive && canHover()) {
234
+ const p = pointerIn(el);
235
+ mouse.x += ((p.inside ? p.x : 0.5) - mouse.x) * EASE;
236
+ mouse.y += ((p.inside ? p.y : 0.5) - mouse.y) * EASE;
237
+ mouse.on += ((p.inside ? 1 : 0) - mouse.on) * EASE;
238
+ }
239
+ gl.uniform1f(uniform('uTime'), reduced ? 0 : still ? frame : clock(now));
240
+ gl.uniform1f(uniform('uClock'), reduced || still ? 0 : (now - start) / 1000);
241
+ gl.uniform2f(uniform('uMouse'), still ? 0.5 : mouse.x, still ? 0.5 : mouse.y);
242
+ gl.uniform1f(uniform('uPointer'), still ? 0 : mouse.on);
243
+ gl.uniform1f(uniform('uIntensity'), intensity);
244
+ palette.forEach((c, i) => gl.uniform3fv(uniform(`uColor${i + 1}`), c));
245
+ },
246
+ });
247
+ if (!stage) {
248
+ el.style.background = shaderBackgroundFallback(palette);
249
+ return stop;
250
+ }
251
+
252
+
253
+ const unwatch = watchColors(el, (next) => {
254
+ palette = livePalette(el, next.colors);
255
+ if (stage.still) stage.redraw();
256
+ });
257
+ return () => {
258
+ stop();
259
+ unwatch();
260
+ };
261
+ }
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/band-lens
3
+ *
4
+ * Band lens: a flowing two-colour field seen through a grid of lens cells about a
5
+ * hundred times wider than they are tall, which smears it into tall,
6
+ * uneven streaks with bright refracted edges. Plumb, never rotated:
7
+ * light falling, not a swipe.
8
+ */
9
+
10
+ import { SHADER_BACKGROUND_GLSL } from './common.js';
11
+
12
+ /** The band lens shader background's fragment shader. */
13
+ export const BAND_LENS = `${SHADER_BACKGROUND_GLSL}
14
+ /* One cell of the lens grid. Tiling with fract() puts every fragment in
15
+ its own cell, then the sphere equation gives the warp for that cell. */
16
+ vec2 bandLens(vec2 p, float spacingX, float spacingY, float radiusSq){
17
+ vec2 c;
18
+ c.x = fract(p.x/spacingX + .5)*spacingX - spacingX*.5;
19
+ c.y = fract(p.y/spacingY + .5)*spacingY - spacingY*.5;
20
+ float sp = radiusSq - c.x*c.x - c.y*c.y;
21
+ float amount = smoothstep(-.1, .05, sp);
22
+ float lens = sqrt(max(sp, -sp*.1)/.3);
23
+ float warp = mix(1., lens, amount);
24
+ vec2 out_ = p;
25
+ out_.x += c.x*warp - c.x;
26
+ out_.y *= warp; /* the vertical smear */
27
+ return out_;
28
+ }
29
+
30
+ /* Smooth flowing scalar in 0-1, from three interfering directional waves.
31
+ Cheaper and far smoother than fbm, which is what keeps the streaks clean
32
+ instead of grainy. */
33
+ float flowField(vec2 uv, float t){
34
+ vec2 d1 = vec2(cos(1.31), sin(1.31));
35
+ vec2 d2 = vec2(cos(4.02), sin(4.02));
36
+ /* Time terms are negated relative to the obvious reading: the field
37
+ drifts right-to-left. Flip the signs on the two t terms to reverse
38
+ it — that is the only thing controlling travel direction. */
39
+ float a = dot(uv,d1) + sin(dot(uv,d2)*2.1 - t)*.30 - t*.20;
40
+ float b = dot(uv,d2.yx) + cos(dot(uv,d1.yx)*1.9 + t*.80)*.25;
41
+ float v = sin(a*1.5)*.5 + .5;
42
+ v += cos(b*1.2)*1.3;
43
+ v += sin(dot(uv,d1+d2)*2.4 - t*3.5)*1.2;
44
+ return smoothstep(0., 4.12, v);
45
+ }
46
+
47
+ void main(){
48
+ vec2 r = uRes;
49
+ /* Aspect-correct, origin-centred — matches the reference's framing. */
50
+ vec2 p = (gl_FragCoord.xy*2. - r)/r.y;
51
+ float t = uTime*.30;
52
+
53
+ /* Deliberately NOT rotated. The beams are plumb — the reference sets
54
+ no rotation uniform, and tilting them reads as a swipe rather than
55
+ as light falling. The irregularity comes from the flow field, not
56
+ from any angle. */
57
+ float scale = 3.7;
58
+ vec2 warped = bandLens(p*scale, 1.0, 0.01, 0.41*0.41);
59
+ float g = flowField(warped/scale, t*.8);
60
+
61
+ /* Two-stop ramp: accent into the page tone. A third colour would mud
62
+ the streaks — the reference ships two for the same reason. */
63
+ vec3 col = mix(uColor2, uColor1, g);
64
+
65
+ /* ALPHA carries the streaks, never a darkened colour (see the note on
66
+ mesh-gradient). Squared so dim areas fall to fully transparent and
67
+ the page black shows through between beams. */
68
+ float a = g*g*uIntensity;
69
+
70
+ gl_FragColor = premultiply(vec4(col, clamp(a, 0., 1.)));
71
+ }
72
+ `;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/common
3
+ *
4
+ * What every shader background shader starts with: its uniforms, the noise they
5
+ * share, a rotation, a vortex, and `premultiply`.
6
+ *
7
+ * The noise is the shader backgrounds' own (`hash`, value noise `vnoise`, and a
8
+ * five-octave `fbm` without rotation between octaves), not glsl.js's: the
9
+ * two give different fields, and every shader background was tuned against this one.
10
+ *
11
+ * Uniforms (set by shader-background.js):
12
+ *
13
+ * - `uRes`: the canvas size in pixels.
14
+ * - `uTime`: seconds since it started, times `speed`.
15
+ * - `uClock`: seconds since it started, whatever the `speed` (0 when
16
+ * still), for what keeps real time, such as grain.
17
+ * - `uColor1`…`uColor4`: the colours, 0–1. Only mesh-gradient,
18
+ * grain-gradient and silk read the fourth.
19
+ * - `uIntensity`: the strength, 0–2.
20
+ * - `uMouse`: the smoothed pointer, 0–1 from the bottom left (the middle when idle).
21
+ * - `uPointer`: how present the pointer is, eased 0–1 (0 when it is away,
22
+ * still, or not `interactive`).
23
+ *
24
+ * Each shader works out a straight colour and an alpha that follows its
25
+ * brightness, so dark pixels let the page through, and hands them to
26
+ * `premultiply` for the stage's premultiplied canvas.
27
+ */
28
+
29
+ /** GLSL: the shader backgrounds' precision, uniforms, noise, rotation, vortex and `premultiply`. */
30
+ export const SHADER_BACKGROUND_GLSL = `
31
+ precision highp float;
32
+ uniform vec2 uRes;
33
+ uniform float uTime;
34
+ uniform float uClock;
35
+ uniform vec3 uColor1;
36
+ uniform vec3 uColor2;
37
+ uniform vec3 uColor3;
38
+ uniform vec3 uColor4;
39
+ uniform float uIntensity;
40
+ uniform vec2 uMouse;
41
+ uniform float uPointer;
42
+ float hash(vec2 p){p=fract(p*vec2(123.34,456.21));p+=dot(p,p+45.32);return fract(p.x*p.y);}
43
+ float vnoise(vec2 p){vec2 i=floor(p);vec2 f=fract(p);f=f*f*(3.-2.*f);
44
+ float a=hash(i),b=hash(i+vec2(1.,0.)),c=hash(i+vec2(0.,1.)),d=hash(i+vec2(1.,1.));
45
+ return mix(mix(a,b,f.x),mix(c,d,f.x),f.y);}
46
+ float fbm(vec2 p){float v=0.;float a=.5;for(int i=0;i<5;i++){v+=a*vnoise(p);p*=2.03;a*=.5;}return v;}
47
+ /* Rotates p about the origin by a radians. */
48
+ vec2 rot(vec2 p,float a){float s=sin(a),c=cos(a);return mat2(c,-s,s,c)*p;}
49
+ /* A vortex: turns hardest at the centre, falling to nothing by the edge, so it reads as a swirl rather than a spin. */
50
+ vec2 swirl(vec2 p,float amt){float r=length(p);return rot(p,amt*(1.-smoothstep(0.,.9,r)));}
51
+ /* A straight colour and alpha as the premultiplied canvas takes them (each clamped to 0-1 first, as a straight canvas would). */
52
+ vec4 premultiply(vec4 c){c=clamp(c,0.,1.);return vec4(c.rgb*c.a,c.a);}
53
+ `;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/grain-gradient
3
+ *
4
+ * Grain gradient: the grainy-gradient poster look. Three large, soft
5
+ * lights sweep slow loops round the copy through deep shadow, stretched
6
+ * along their paths, folded by a broad warp, merging and parting: one in
7
+ * the accent, one in the fourth colour and one drifting between the two,
8
+ * with the lifted third glinting where they gather. Colour runs from the
9
+ * deep second colour up through the lights' own, blended in Oklab.
10
+ *
11
+ * The grain is dither, not static: each pixel's place on that ramp is
12
+ * jittered by fine triangular noise, a new frame twelve times a second
13
+ * whatever the `speed`, so the lights' edges dissolve into specks of
14
+ * colour, heaviest in the shadows as film grain is. The middle stays
15
+ * darker and calmer for the copy. With `interactive`, the pointer pushes
16
+ * the field aside and lights it where it rests. `intensity` sets how much
17
+ * light there is.
18
+ *
19
+ * Dithering the ramp position is Paper's grain-gradient technique
20
+ * (paper-design/shaders, Apache-2.0); the field and ramp are this
21
+ * package's own. The grain hash is Dave Hoskins' "Hash without Sine" (MIT).
22
+ */
23
+
24
+ import { SHADER_BACKGROUND_GLSL } from './common.js';
25
+ import { GLSL_OKLAB } from '../color.js';
26
+
27
+ /** The grain gradient shader background's fragment shader. */
28
+ export const GRAIN_GRADIENT = `${SHADER_BACKGROUND_GLSL}
29
+ ${GLSL_OKLAB}
30
+ /* A hash fine enough for per-pixel grain (Dave Hoskins' Hash without Sine): the shared one streaks at pixel scale. */
31
+ float grain(vec2 p){vec3 p3=fract(p.xyx*.1031);p3+=dot(p3,p3.yzx+33.33);return fract((p3.x+p3.y)*p3.z);}
32
+ /* One light: a soft glow on a slow loop round the middle, stretched along
33
+ its path so it sweeps; k sets its size. */
34
+ float light(vec2 q,float th,float k,float w){vec2 c=vec2(.64,.4)*(1.+.18*sin(th*1.7+w))*vec2(cos(th),sin(th));vec2 v=rot(q-c,-th)*vec2(1.,2.2);return exp(-dot(v,v)*k);}
35
+ void main(){
36
+ vec2 uv=gl_FragCoord.xy/uRes;
37
+ float ar=uRes.x/uRes.y;
38
+ vec2 at=(uv-.5)*vec2(ar,1.);
39
+ float t=uTime*.12+8.;
40
+
41
+ /* The pointer: a soft lens that pushes the field away from it. */
42
+ vec2 d=at-(uMouse-.5)*vec2(ar,1.);
43
+ float near=exp(-dot(d,d)*5.)*uPointer;
44
+ vec2 p=at-d*.35*near;
45
+
46
+ /* One broad warp, so the lights fold and morph as they sweep. */
47
+ vec2 w=vec2(vnoise(p*1.6+vec2(t*.5,-t*.3)),vnoise(p*1.6+vec2(5.3-t*.4,1.7+t*.25)))-.5;
48
+ vec2 q=p+w*.55;
49
+
50
+ /* Three lights looping round the copy: two opposite each other, so
51
+ the frame stays balanced, and one the other way that meets, merges
52
+ with and parts from each. One in the accent, one in the fourth
53
+ colour, and one drifting between the two; where they gather, the
54
+ lifted third glints. Colours are blended in Oklab. */
55
+ float th=t*.8;
56
+ float l1=light(q,th,3.6,0.);
57
+ float l2=light(q,th+3.14+.7*sin(t*.37),4.2,2.);
58
+ float l3=light(q,2.-t*.6,5.,4.);
59
+ float s=l1+l2+l3;
60
+ float u=.5+.5*sin(t*.45);
61
+ float w1=l1*l1+l3*l3*(1.-u),w4=l2*l2+l3*l3*u;
62
+ vec3 body=(toOklab(uColor1)*w1+toOklab(uColor4)*w4)/max(w1+w4,1e-4);
63
+ /* Calmer in the middle, for the copy; brighter towards the pointer. */
64
+ float mid=exp(-dot(at*vec2(.8,1.4),at*vec2(.8,1.4))*4.);
65
+ s*=1.-.62*mid;
66
+ s+=.3*near;
67
+ s*=.75+.25*uIntensity;
68
+
69
+ /* Dither: triangular noise, a new frame twelve times a second whatever
70
+ the speed, moves each pixel along the ramp; wider in the shadows, as
71
+ film grain is, and a little calmer behind the copy. */
72
+ float frame=floor(uClock*12.);
73
+ vec2 px=gl_FragCoord.xy+fract(frame*.618)*vec2(173.,311.);
74
+ float g=grain(px)+grain(px+vec2(41.,289.))-1.;
75
+ float sd=s+g*(.09+.28*(1.-clamp(s,0.,1.)))*(1.-.35*mid);
76
+
77
+ /* The ramp: the deep colour, then the lights' own, then the glint. */
78
+ vec3 lab=mix(toOklab(uColor2),body,smoothstep(.2,.8,sd));
79
+ vec3 col=fromOklab(mix(lab,toOklab(uColor3),smoothstep(.9,1.7,sd)*.85));
80
+ /* A light film grain over the colour. */
81
+ col*=1.+g*.06;
82
+
83
+ /* Alpha follows the light, so the shadows let the page through. */
84
+ float a=smoothstep(.18,.6,sd)*min(uIntensity,1.);
85
+ gl_FragColor = premultiply(vec4(col,a));
86
+ }
87
+ `;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/grid
3
+ *
4
+ * Grid: a perspective floor grid scrolling towards a glowing horizon: retro,
5
+ * synthwave.
6
+ */
7
+
8
+ import { SHADER_BACKGROUND_GLSL } from './common.js';
9
+
10
+ /** The grid shader background's fragment shader. */
11
+ export const GRID = `${SHADER_BACKGROUND_GLSL}
12
+ void main(){
13
+ vec2 uv=gl_FragCoord.xy/uRes;
14
+ float ar=uRes.x/uRes.y;
15
+ float horizon=.62;
16
+ vec3 col=vec3(0.);
17
+ if(uv.y<horizon){
18
+ float z=(horizon-uv.y)+.015;
19
+ float pz=1./z;
20
+ vec2 g=vec2((uv.x-.5)*ar*pz*.9,pz*.5+uTime*1.1);
21
+ float dx=abs(fract(g.x+.5)-.5);
22
+ float dy=abs(fract(g.y+.5)-.5);
23
+ float fog=smoothstep(.0,.45,z);
24
+ float line=(.022/(dx+.018)+.022/(dy+.018))*.5;
25
+ col+=uColor1*line*fog*.85;
26
+ }
27
+ col+=uColor2*exp(-abs(uv.y-horizon)*22.)*.55;
28
+ col+=uColor3*exp(-abs(uv.y-horizon)*5.)*.10;
29
+ col*=uIntensity;
30
+ float a=clamp(max(max(col.r,col.g),col.b)*1.35,0.,1.);
31
+ gl_FragColor = premultiply(vec4(col,a));
32
+ }
33
+ `;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/mesh-gradient
3
+ *
4
+ * Mesh gradient: four colour spots on their own orbits, warped by noise and pulled
5
+ * through a slow vortex, blended by inverse distance so no spot has an
6
+ * edge, and finished with fine grain (which also stops the big ramps
7
+ * banding). Coverage rides in the alpha and the colour keeps its chroma,
8
+ * so it is a pastel tint on a light page and a deep pool on a dark one.
9
+ */
10
+
11
+ import { SHADER_BACKGROUND_GLSL } from './common.js';
12
+
13
+ /** The mesh gradient shader background's fragment shader. */
14
+ export const MESH_GRADIENT = `${SHADER_BACKGROUND_GLSL}
15
+ void main(){
16
+ vec2 uv=gl_FragCoord.xy/uRes;
17
+ float ar=uRes.x/uRes.y;
18
+ vec2 p=(uv-.5)*vec2(ar,1.);
19
+ float t=uTime*.12;
20
+
21
+ /* Organic distortion — warp the sampling point by two decorrelated
22
+ fbm fields so the spots deform instead of sliding rigidly. */
23
+ vec2 w=vec2(fbm(p*1.3+vec2(t,-t*.7)),fbm(p*1.3+vec2(-t*.6,t*.9)+4.2));
24
+ p+=(w-.5)*.6;
25
+
26
+ /* Slow vortex, oscillating so it never settles. */
27
+ p=swirl(p,.85*sin(t*.35));
28
+ p+=(uMouse-.5)*vec2(ar,1.)*.10;
29
+
30
+ /* Four spots, each on its own orbit. */
31
+ vec2 s1=vec2(sin(t*.90)*.44,cos(t*.70)*.32);
32
+ vec2 s2=vec2(cos(t*.60+2.)*.48,sin(t*.80+1.)*.36);
33
+ vec2 s3=vec2(sin(t*.50+4.)*.42,cos(t*.90+3.)*.40);
34
+ vec2 s4=vec2(cos(t*.75+5.)*.38,sin(t*.55+2.5)*.30);
35
+
36
+ /* Inverse-distance weighting: every pixel is a blend of ALL four,
37
+ weighted by proximity. The +.05 floor stops the weight blowing up
38
+ at a spot centre (which would punch a hard dot). */
39
+ float w1=1./(dot(p-s1,p-s1)+.05);
40
+ float w2=1./(dot(p-s2,p-s2)+.05);
41
+ float w3=1./(dot(p-s3,p-s3)+.05);
42
+ float w4=1./(dot(p-s4,p-s4)+.05);
43
+ float sum=w1+w2+w3+w4;
44
+ vec3 col=(uColor1*w1+uColor2*w2+uColor3*w3+uColor4*w4)/sum;
45
+
46
+ /* COVERAGE — the load-bearing term. The weights above are normalised,
47
+ so the hue blend alone returns a fully-saturated colour at EVERY
48
+ pixel; left there it floods the page and swallows any text on top.
49
+ This density field breaks it into soft pools with the page showing
50
+ through between them, which is what a gradient mesh on a real site
51
+ actually looks like. */
52
+ float cover=smoothstep(.30,.78,fbm(p*1.15+vec2(t*.5,-t*.35)+2.7));
53
+
54
+ /* Radial falloff so the wash melts out rather than ending flat. */
55
+ float vig=1.-smoothstep(.15,.95,length((uv-.5)*vec2(ar,1.)));
56
+
57
+ /* Fine grain — dithers the gradient (big smooth ramps band badly on
58
+ 8-bit displays) and adds the paper texture. */
59
+ float g=hash(uv*uRes*.65+fract(uTime*.35)*vec2(19.,37.));
60
+
61
+ /* The mask drives ALPHA ONLY; the colour keeps full chroma.
62
+ This is the whole trick, and getting it wrong is why washes look
63
+ dirty: the browser composites this canvas over the page as
64
+ col*a + page*(1-a). Multiplying the COLOUR by the mask (the
65
+ obvious move) darkens it toward black while alpha drops too, so
66
+ over a light page you composite a dark colour at partial alpha —
67
+ i.e. grey mud. Keep the colour saturated, mask the alpha, and the
68
+ same shader gives a pastel tint on white and a deep pool on black
69
+ with no per-mode branching. */
70
+ float mask=cover*vig*(1.+(g-.5)*.4);
71
+ float a=clamp(mask*uIntensity,0.,1.);
72
+ gl_FragColor = premultiply(vec4(clamp(col,0.,1.),a));
73
+ }
74
+ `;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/silk
3
+ *
4
+ * Silk: flowing folds like a sheet of silk: fbm warped by fbm warped by fbm
5
+ * (after Inigo Quilez's domain warping), where the warp fields themselves
6
+ * flow, so the folds travel across the frame rather than churning in
7
+ * place, with a sheen on the crests and a calmer middle for a headline.
8
+ */
9
+
10
+ import { SHADER_BACKGROUND_GLSL } from './common.js';
11
+
12
+ /** The silk shader background's fragment shader. */
13
+ export const SILK = `${SHADER_BACKGROUND_GLSL}
14
+ /* Three octaves, not fbm's five: silk is BROAD soft folds. The extra
15
+ octaves are what turned the first draft into marbled smoke. */
16
+ float fbm3(vec2 p){float v=0.;float a=.5;for(int i=0;i<3;i++){v+=a*vnoise(p);p*=2.03;a*=.5;}return v;}
17
+ void main(){
18
+ vec2 uv=gl_FragCoord.xy/uRes;
19
+ float ar=uRes.x/uRes.y;
20
+ vec2 p=(uv-.5)*vec2(ar,1.)*.95;
21
+ float t=uTime*.05;
22
+
23
+ /* Slow drift of the whole sheet, plus a gentle cursor pull. */
24
+ p=rot(p,t*.30);
25
+ p+=(uMouse-.5)*vec2(ar,1.)*.20;
26
+
27
+ /* Two warp fields that flow at different rates and in different
28
+ directions — the folds move because THESE move. */
29
+ vec2 q=vec2(fbm3(p+vec2(t*.90,t*.30)),
30
+ fbm3(p+vec2(5.2,1.3)-vec2(t*.60,t*.80)));
31
+ vec2 r=vec2(fbm3(p+2.1*q+vec2(1.7,9.2)+vec2(t*.45,-t*.25)),
32
+ fbm3(p+2.1*q+vec2(8.3,2.8)-vec2(t*.30,t*.50)));
33
+ float f=fbm3(p+2.3*r);
34
+
35
+ /* Colour: depth (c4 -> c2) by the folded field, cooler body (c3) where
36
+ the first warp is strong, accent (c1) on the high ridges. */
37
+ /* fbm3 lives in ~.25-.65, so every threshold is centred there. */
38
+ vec3 col=mix(uColor4,uColor2,smoothstep(.25,.55,f));
39
+ col=mix(col,uColor3,smoothstep(.20,.55,dot(q,q)));
40
+ col=mix(col,uColor1,smoothstep(.40,.64,r.y));
41
+
42
+ /* Sheen: a soft, wide highlight along the fold crests. */
43
+ float sheen=pow(clamp(1.-abs(f-.52)*3.,0.,1.),2.);
44
+ col+=uColor1*sheen*.25;
45
+
46
+ /* Coverage: a sheet, not pools — the troughs keep a FLOOR of the deep
47
+ colour (c4) rather than going see-through, which is what made the
48
+ first drafts read as faint smudges on the page. Radial falloff melts
49
+ the outer edge; a copy-safe dip keeps the centre (where hero text
50
+ sits) calmer; grain dithers the ramps. */
51
+ float vig=1.-smoothstep(.45,1.35,length((uv-.5)*vec2(ar,1.)));
52
+ float copy=mix(.7,1.,smoothstep(.05,.5,length((uv-vec2(.5,.52))*vec2(ar*.55,1.))));
53
+ float g=hash(uv*uRes*.65+fract(uTime*.35)*vec2(19.,37.));
54
+ float mask=clamp(.42+smoothstep(.28,.6,f)*.58+sheen*.3,0.,1.)*vig*copy*(1.+(g-.5)*.3);
55
+ gl_FragColor = premultiply(vec4(clamp(col,0.,1.),clamp(mask*uIntensity,0.,1.)));
56
+ }
57
+ `;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/shader-backgrounds/waves
3
+ *
4
+ * Waves: three glowing waveform lines across the middle: a signal, on brand for
5
+ * audio shops.
6
+ */
7
+
8
+ import { SHADER_BACKGROUND_GLSL } from './common.js';
9
+
10
+ /** The waves shader background's fragment shader. */
11
+ export const WAVES = `${SHADER_BACKGROUND_GLSL}
12
+ void main(){
13
+ vec2 uv=gl_FragCoord.xy/uRes;
14
+ float ar=uRes.x/uRes.y;
15
+ float t=uTime;
16
+ vec3 col=vec3(0.);
17
+ for(int i=0;i<3;i++){
18
+ float fi=float(i);
19
+ float yy=.5+(fi-1.)*.15+(uMouse.y-.5)*.05;
20
+ float w=sin(uv.x*(4.5+fi*1.4)*ar*.6+t*(.45+fi*.2)+fi*2.1)
21
+ *sin(uv.x*1.6*ar-t*.3+fi*.7);
22
+ float amp=.09+.045*fi;
23
+ float d=abs(uv.y-yy-w*amp);
24
+ vec3 c=i==0?uColor1:(i==1?uColor2:uColor3);
25
+ col+=c*(.005/(d+.004))*.55;
26
+ }
27
+ col*=uIntensity;
28
+ float a=clamp(max(max(col.r,col.g),col.b)*1.2,0.,1.);
29
+ gl_FragColor = premultiply(vec4(col,a));
30
+ }
31
+ `;