@arraypress/effects-astro 0.0.0-stage → 0.1.0
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.
- package/AGENTS.md +85 -0
- package/COMPONENTS.md +1264 -0
- package/LICENSE +139 -0
- package/README.md +197 -2
- package/package.json +60 -4
- package/src/components/AsciiRain.astro +36 -0
- package/src/components/BorderSweep.astro +39 -0
- package/src/components/Caustics.astro +39 -0
- package/src/components/ColorPanels.astro +62 -0
- package/src/components/Cursor.astro +97 -0
- package/src/components/DotGrid.astro +34 -0
- package/src/components/DotSurface.astro +35 -0
- package/src/components/EffectCanvas.astro +152 -0
- package/src/components/FitText.astro +35 -0
- package/src/components/FlutedGlass.astro +36 -0
- package/src/components/Glass.astro +69 -0
- package/src/components/GlassGlyph.astro +38 -0
- package/src/components/GlowField.astro +177 -0
- package/src/components/Grain.astro +98 -0
- package/src/components/HaloRing.astro +38 -0
- package/src/components/HighlightSweep.astro +74 -0
- package/src/components/ImageRipple.astro +56 -0
- package/src/components/Ink.astro +37 -0
- package/src/components/InkField.astro +45 -0
- package/src/components/IsoCity.astro +54 -0
- package/src/components/LightField.astro +40 -0
- package/src/components/LiquidMetal.astro +41 -0
- package/src/components/Magnetic.astro +52 -0
- package/src/components/Marquee.astro +216 -0
- package/src/components/MosaicReveal.astro +196 -0
- package/src/components/NebulaLogo.astro +38 -0
- package/src/components/NeonSwarm.astro +38 -0
- package/src/components/Ocean.astro +40 -0
- package/src/components/OutlineWordmark.astro +222 -0
- package/src/components/PaperBackground.astro +40 -0
- package/src/components/PaperShader.astro +55 -0
- package/src/components/Parallax.astro +49 -0
- package/src/components/ParticleLogo.astro +37 -0
- package/src/components/PixelGlitchText.astro +70 -0
- package/src/components/PointCloud.astro +37 -0
- package/src/components/ProductStack.astro +298 -0
- package/src/components/PulseMark.astro +189 -0
- package/src/components/RadiantGlass.astro +38 -0
- package/src/components/RainOnGlass.astro +71 -0
- package/src/components/Reveal.astro +115 -0
- package/src/components/ScrambleText.astro +52 -0
- package/src/components/ScrollReveal.astro +38 -0
- package/src/components/ShaderBackground.astro +55 -0
- package/src/components/SignalLines.astro +41 -0
- package/src/components/SilkRibbon.astro +37 -0
- package/src/components/SpotlightText.astro +131 -0
- package/src/components/Tilt.astro +79 -0
- package/src/components/Topography.astro +38 -0
- package/src/components/Typewriter.astro +66 -0
- package/src/components/VariableType.astro +59 -0
- package/src/components/VoxelLogo.astro +46 -0
- package/src/components/WaveBars.astro +41 -0
- package/src/components/WorldRoutes.astro +41 -0
- package/src/components/style.js +19 -0
- package/src/index.d.ts +143 -0
- package/src/index.js +105 -0
- package/src/runtime/ascii-rain.d.ts +53 -0
- package/src/runtime/ascii-rain.js +355 -0
- package/src/runtime/audio-meter.d.ts +65 -0
- package/src/runtime/audio-meter.js +282 -0
- package/src/runtime/audio.d.ts +26 -0
- package/src/runtime/audio.js +453 -0
- package/src/runtime/blur.d.ts +2 -0
- package/src/runtime/blur.js +56 -0
- package/src/runtime/canvas2d.d.ts +23 -0
- package/src/runtime/canvas2d.js +105 -0
- package/src/runtime/caustics.d.ts +40 -0
- package/src/runtime/caustics.js +286 -0
- package/src/runtime/color.d.ts +33 -0
- package/src/runtime/color.js +213 -0
- package/src/runtime/curl.d.ts +5 -0
- package/src/runtime/curl.js +81 -0
- package/src/runtime/cursor.d.ts +9 -0
- package/src/runtime/cursor.js +80 -0
- package/src/runtime/device.d.ts +14 -0
- package/src/runtime/device.js +73 -0
- package/src/runtime/dot-grid.d.ts +27 -0
- package/src/runtime/dot-grid.js +245 -0
- package/src/runtime/dot-surface.d.ts +46 -0
- package/src/runtime/dot-surface.js +429 -0
- package/src/runtime/feedback.d.ts +18 -0
- package/src/runtime/feedback.js +131 -0
- package/src/runtime/fit-text.d.ts +5 -0
- package/src/runtime/fit-text.js +60 -0
- package/src/runtime/fluid.d.ts +55 -0
- package/src/runtime/fluid.js +504 -0
- package/src/runtime/fluted-glass.d.ts +27 -0
- package/src/runtime/fluted-glass.js +157 -0
- package/src/runtime/gl.d.ts +19 -0
- package/src/runtime/gl.js +104 -0
- package/src/runtime/glass-glyph.d.ts +49 -0
- package/src/runtime/glass-glyph.js +355 -0
- package/src/runtime/glass-sheen.d.ts +2 -0
- package/src/runtime/glass-sheen.js +30 -0
- package/src/runtime/glsl.d.ts +17 -0
- package/src/runtime/glsl.js +78 -0
- package/src/runtime/glyphs.d.ts +22 -0
- package/src/runtime/glyphs.js +107 -0
- package/src/runtime/halo-ring.d.ts +47 -0
- package/src/runtime/halo-ring.js +334 -0
- package/src/runtime/height-field.d.ts +50 -0
- package/src/runtime/height-field.js +176 -0
- package/src/runtime/image-ripple.d.ts +25 -0
- package/src/runtime/image-ripple.js +353 -0
- package/src/runtime/image.d.ts +11 -0
- package/src/runtime/image.js +81 -0
- package/src/runtime/in-view.d.ts +6 -0
- package/src/runtime/in-view.js +36 -0
- package/src/runtime/ink-field/shaders.js +258 -0
- package/src/runtime/ink-field/sim.js +582 -0
- package/src/runtime/ink-field.d.ts +39 -0
- package/src/runtime/ink-field.js +311 -0
- package/src/runtime/ink.d.ts +31 -0
- package/src/runtime/ink.js +109 -0
- package/src/runtime/instancing.d.ts +12 -0
- package/src/runtime/instancing.js +37 -0
- package/src/runtime/iso-camera.d.ts +35 -0
- package/src/runtime/iso-camera.js +85 -0
- package/src/runtime/iso-city/figures.d.ts +30 -0
- package/src/runtime/iso-city/figures.js +136 -0
- package/src/runtime/iso-city/look.d.ts +34 -0
- package/src/runtime/iso-city/look.js +105 -0
- package/src/runtime/iso-city/plan.d.ts +59 -0
- package/src/runtime/iso-city/plan.js +463 -0
- package/src/runtime/iso-city/roads.d.ts +64 -0
- package/src/runtime/iso-city/roads.js +320 -0
- package/src/runtime/iso-city/scene.d.ts +27 -0
- package/src/runtime/iso-city/scene.js +432 -0
- package/src/runtime/iso-city/shaders.d.ts +6 -0
- package/src/runtime/iso-city/shaders.js +233 -0
- package/src/runtime/iso-city/shadows.d.ts +13 -0
- package/src/runtime/iso-city/shadows.js +148 -0
- package/src/runtime/iso-city/traffic.d.ts +80 -0
- package/src/runtime/iso-city/traffic.js +457 -0
- package/src/runtime/iso-city.d.ts +37 -0
- package/src/runtime/iso-city.js +458 -0
- package/src/runtime/lens-map.d.ts +11 -0
- package/src/runtime/lens-map.js +146 -0
- package/src/runtime/light-field.d.ts +29 -0
- package/src/runtime/light-field.js +292 -0
- package/src/runtime/liquid-glass.d.ts +48 -0
- package/src/runtime/liquid-glass.js +423 -0
- package/src/runtime/liquid-metal/beads.js +217 -0
- package/src/runtime/liquid-metal/field.js +88 -0
- package/src/runtime/liquid-metal/look.js +64 -0
- package/src/runtime/liquid-metal/shaders.js +255 -0
- package/src/runtime/liquid-metal/wave.js +53 -0
- package/src/runtime/liquid-metal.d.ts +46 -0
- package/src/runtime/liquid-metal.js +366 -0
- package/src/runtime/loop.d.ts +7 -0
- package/src/runtime/loop.js +112 -0
- package/src/runtime/magnetic.d.ts +9 -0
- package/src/runtime/magnetic.js +46 -0
- package/src/runtime/marquee.d.ts +2 -0
- package/src/runtime/marquee.js +27 -0
- package/src/runtime/mesh.d.ts +30 -0
- package/src/runtime/mesh.js +217 -0
- package/src/runtime/mosaic-reveal.d.ts +34 -0
- package/src/runtime/mosaic-reveal.js +504 -0
- package/src/runtime/motion.d.ts +2 -0
- package/src/runtime/motion.js +21 -0
- package/src/runtime/mount.d.ts +13 -0
- package/src/runtime/mount.js +120 -0
- package/src/runtime/nebula-logo.d.ts +31 -0
- package/src/runtime/nebula-logo.js +282 -0
- package/src/runtime/neon-swarm.d.ts +31 -0
- package/src/runtime/neon-swarm.js +258 -0
- package/src/runtime/ocean/presets.d.ts +54 -0
- package/src/runtime/ocean/presets.js +184 -0
- package/src/runtime/ocean/shader.d.ts +14 -0
- package/src/runtime/ocean/shader.js +389 -0
- package/src/runtime/ocean/view.d.ts +24 -0
- package/src/runtime/ocean/view.js +98 -0
- package/src/runtime/ocean/waves.d.ts +29 -0
- package/src/runtime/ocean/waves.js +119 -0
- package/src/runtime/ocean.d.ts +31 -0
- package/src/runtime/ocean.js +173 -0
- package/src/runtime/palettes.d.ts +37 -0
- package/src/runtime/palettes.js +75 -0
- package/src/runtime/paper-look.d.ts +42 -0
- package/src/runtime/paper-look.js +91 -0
- package/src/runtime/paper-looks.d.ts +17 -0
- package/src/runtime/paper-looks.js +21 -0
- package/src/runtime/paper.d.ts +37 -0
- package/src/runtime/paper.js +285 -0
- package/src/runtime/particle-logo.d.ts +31 -0
- package/src/runtime/particle-logo.js +196 -0
- package/src/runtime/ping-pong.d.ts +43 -0
- package/src/runtime/ping-pong.js +175 -0
- package/src/runtime/pixel-glitch.d.ts +17 -0
- package/src/runtime/pixel-glitch.js +287 -0
- package/src/runtime/point-cloud.d.ts +33 -0
- package/src/runtime/point-cloud.js +287 -0
- package/src/runtime/pointer.d.ts +27 -0
- package/src/runtime/pointer.js +128 -0
- package/src/runtime/points.d.ts +25 -0
- package/src/runtime/points.js +130 -0
- package/src/runtime/pools.d.ts +2 -0
- package/src/runtime/pools.js +25 -0
- package/src/runtime/product-stack.d.ts +24 -0
- package/src/runtime/product-stack.js +210 -0
- package/src/runtime/radiant-glass.d.ts +29 -0
- package/src/runtime/radiant-glass.js +282 -0
- package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
- package/src/runtime/rain-on-glass/backdrop.js +185 -0
- package/src/runtime/rain-on-glass/shader.d.ts +2 -0
- package/src/runtime/rain-on-glass/shader.js +168 -0
- package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
- package/src/runtime/rain-on-glass/wipe.js +65 -0
- package/src/runtime/rain-on-glass.d.ts +27 -0
- package/src/runtime/rain-on-glass.js +210 -0
- package/src/runtime/ramp.d.ts +2 -0
- package/src/runtime/ramp.js +30 -0
- package/src/runtime/random.d.ts +2 -0
- package/src/runtime/random.js +22 -0
- package/src/runtime/scroll-reveal.d.ts +22 -0
- package/src/runtime/scroll-reveal.js +73 -0
- package/src/runtime/shader-background.d.ts +42 -0
- package/src/runtime/shader-background.js +261 -0
- package/src/runtime/shader-backgrounds/band-lens.js +72 -0
- package/src/runtime/shader-backgrounds/common.js +53 -0
- package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
- package/src/runtime/shader-backgrounds/grid.js +33 -0
- package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
- package/src/runtime/shader-backgrounds/silk.js +57 -0
- package/src/runtime/shader-backgrounds/waves.js +31 -0
- package/src/runtime/shape.d.ts +42 -0
- package/src/runtime/shape.js +313 -0
- package/src/runtime/silk-ribbon.d.ts +23 -0
- package/src/runtime/silk-ribbon.js +206 -0
- package/src/runtime/slideshow.d.ts +27 -0
- package/src/runtime/slideshow.js +234 -0
- package/src/runtime/spotlight.d.ts +9 -0
- package/src/runtime/spotlight.js +97 -0
- package/src/runtime/stack-poses.d.ts +53 -0
- package/src/runtime/stack-poses.js +273 -0
- package/src/runtime/stage.d.ts +47 -0
- package/src/runtime/stage.js +187 -0
- package/src/runtime/swarm.d.ts +49 -0
- package/src/runtime/swarm.js +199 -0
- package/src/runtime/text-motion.d.ts +41 -0
- package/src/runtime/text-motion.js +165 -0
- package/src/runtime/text.d.ts +11 -0
- package/src/runtime/text.js +90 -0
- package/src/runtime/tilt.d.ts +19 -0
- package/src/runtime/tilt.js +116 -0
- package/src/runtime/topography.d.ts +71 -0
- package/src/runtime/topography.js +650 -0
- package/src/runtime/trackers.d.ts +21 -0
- package/src/runtime/trackers.js +76 -0
- package/src/runtime/variable-type.d.ts +43 -0
- package/src/runtime/variable-type.js +358 -0
- package/src/runtime/voxel-logo.d.ts +31 -0
- package/src/runtime/voxel-logo.js +237 -0
- package/src/runtime/waves.d.ts +70 -0
- package/src/runtime/waves.js +799 -0
- package/src/runtime/world-labels.d.ts +29 -0
- package/src/runtime/world-labels.js +59 -0
- package/src/runtime/world-land.d.ts +8 -0
- package/src/runtime/world-land.js +105 -0
- package/src/runtime/world-map.d.ts +69 -0
- package/src/runtime/world-map.js +308 -0
- package/src/runtime/world-plan.d.ts +101 -0
- package/src/runtime/world-plan.js +333 -0
- package/src/runtime/world-routes.d.ts +75 -0
- package/src/runtime/world-routes.js +673 -0
- package/src/styles/border-sweep.css +82 -0
- package/src/styles/glass.css +104 -0
- package/src/styles/motion.css +218 -0
- package/src/styles/reveal.css +51 -0
- package/src/vendor/paper/LICENSE +201 -0
- package/src/vendor/paper/NOTICE +5 -0
- package/src/vendor/paper/README.md +8 -0
- package/src/vendor/paper/get-shader-color-from-string.js +100 -0
- package/src/vendor/paper/get-shader-noise-texture.js +17 -0
- package/src/vendor/paper/presets.js +3678 -0
- package/src/vendor/paper/shader-sizing.js +37 -0
- package/src/vendor/paper/shader-utils.js +130 -0
- package/src/vendor/paper/shaders/color-panels.js +223 -0
- package/src/vendor/paper/shaders/dithering.js +270 -0
- package/src/vendor/paper/shaders/dot-grid.js +109 -0
- package/src/vendor/paper/shaders/dot-orbit.js +122 -0
- package/src/vendor/paper/shaders/fluted-glass.js +360 -0
- package/src/vendor/paper/shaders/gem-smoke.js +572 -0
- package/src/vendor/paper/shaders/god-rays.js +132 -0
- package/src/vendor/paper/shaders/grain-gradient.js +300 -0
- package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
- package/src/vendor/paper/shaders/halftone-dots.js +320 -0
- package/src/vendor/paper/shaders/heatmap.js +383 -0
- package/src/vendor/paper/shaders/image-dithering.js +198 -0
- package/src/vendor/paper/shaders/lens-distortion.js +275 -0
- package/src/vendor/paper/shaders/liquid-metal.js +632 -0
- package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/metaballs.js +110 -0
- package/src/vendor/paper/shaders/neuro-noise.js +76 -0
- package/src/vendor/paper/shaders/paper-texture.js +526 -0
- package/src/vendor/paper/shaders/perlin-noise.js +166 -0
- package/src/vendor/paper/shaders/pulsing-border.js +238 -0
- package/src/vendor/paper/shaders/simplex-noise.js +91 -0
- package/src/vendor/paper/shaders/smoke-ring.js +132 -0
- package/src/vendor/paper/shaders/spiral.js +82 -0
- package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
- package/src/vendor/paper/shaders/swirl.js +103 -0
- package/src/vendor/paper/shaders/voronoi.js +138 -0
- package/src/vendor/paper/shaders/warp.js +129 -0
- package/src/vendor/paper/shaders/water.js +121 -0
- package/src/vendor/paper/shaders/waves.js +65 -0
- package/src/vendor/paper/vertex-shader.js +159 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/light-field
|
|
3
|
+
*
|
|
4
|
+
* Liquid light: a field of light warped through itself (domain-warped
|
|
5
|
+
* noise) in a palette's three colours, with thin bright caustic bands
|
|
6
|
+
* glinting where it folds, and its colours split slightly at the edges as
|
|
7
|
+
* light through a prism splits them. The pointer is a lens: the light
|
|
8
|
+
* bends around it and brightens under it, and holding the button swells it.
|
|
9
|
+
*
|
|
10
|
+
* Under the light runs a real fluid (./fluid.js): the pointer stirs it, a
|
|
11
|
+
* click drops a bloom of ink, and the fluid's flow pushes the light along
|
|
12
|
+
* with it. Without WebGL 2 the light runs alone.
|
|
13
|
+
*
|
|
14
|
+
* A quiet area can be set where the light dims (behind a headline, say),
|
|
15
|
+
* so the colour frames the words instead of running under them.
|
|
16
|
+
*
|
|
17
|
+
* The colours change by setting the element's `data-colors` attribute to
|
|
18
|
+
* JSON `{ "colors": [three hex], "glint": "hex" }` (see `setColors` in the
|
|
19
|
+
* package index); the light eases to them in about a second.
|
|
20
|
+
*
|
|
21
|
+
* Drawn at half the pixel ratio by default and scaled up: the field is
|
|
22
|
+
* soft, so the saving costs nothing visible. On phones and tablets the
|
|
23
|
+
* prism split is dropped (one sample a pixel rather than three).
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { createStage } from './stage.js';
|
|
27
|
+
import { parseColor } from './color.js';
|
|
28
|
+
import { GLSL_NOISE, GLSL_PALETTE, GLSL_QUIET, paletteUniform, quietUniform } from './glsl.js';
|
|
29
|
+
import { canHover, isMobileGpu } from './device.js';
|
|
30
|
+
import { watchColors } from './mount.js';
|
|
31
|
+
import { PALETTES, findPalette, pickColors } from './palettes.js';
|
|
32
|
+
import { pointerIn } from './pointer.js';
|
|
33
|
+
import { createFluid, stir } from './fluid.js';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {object} LightFieldConfig
|
|
37
|
+
* @property {string[]} [colors] The light's three colours, as CSS hex (default the palette's, or Lumetri's).
|
|
38
|
+
* @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
|
|
39
|
+
* @property {string} [glint] The caustic bands' colour (default the palette's, or white-gold).
|
|
40
|
+
* @property {number} [speed=1] How fast the light moves.
|
|
41
|
+
* @property {number} [lens=1] How strongly the pointer bends the light; 0 for not at all.
|
|
42
|
+
* @property {boolean} [prism=true] Split the colours at the edges (always off on phones).
|
|
43
|
+
* @property {boolean | { trail?: number, drops?: boolean, force?: number, fade?: number, diffusion?: number, radius?: number, curl?: number, ignore?: string }} [fluid=true]
|
|
44
|
+
* The fluid under the light: false for none, or its settings (see `stir`
|
|
45
|
+
* and `createFluid`; `fade` is how fast the ink fades, per second).
|
|
46
|
+
* @property {{ x?: number, y?: number, radius?: number, depth?: number } | null} [quiet=null]
|
|
47
|
+
* An area where the light dims: centre x/y (0–1, from the top left),
|
|
48
|
+
* radius (a share of the height) and depth (0 none, 1 black).
|
|
49
|
+
* @property {number} [vignette=0.45] How much the corners darken, 0–1.
|
|
50
|
+
* @property {number} [grain=0.035] Film grain, so dark ramps do not band.
|
|
51
|
+
* @property {number} [scale=0.5] Share of the pixel ratio drawn at.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The light's fragment shader.
|
|
56
|
+
*
|
|
57
|
+
* @param {boolean} prism Whether to sample three times and split the colours.
|
|
58
|
+
* @returns {string} GLSL.
|
|
59
|
+
*/
|
|
60
|
+
const fragment = (prism) => `
|
|
61
|
+
precision highp float;
|
|
62
|
+
#define PRISM ${prism ? 1 : 0}
|
|
63
|
+
uniform vec2 uRes;
|
|
64
|
+
uniform float uTime;
|
|
65
|
+
uniform vec2 uMouse;
|
|
66
|
+
uniform float uPress;
|
|
67
|
+
uniform float uActive;
|
|
68
|
+
uniform float uLens;
|
|
69
|
+
uniform vec3 uGlint;
|
|
70
|
+
// The fluid: the ink it carries and its velocity; uFluid 0 without one.
|
|
71
|
+
uniform sampler2D uDye;
|
|
72
|
+
uniform sampler2D uVel;
|
|
73
|
+
uniform float uFluid;
|
|
74
|
+
uniform float uVignette;
|
|
75
|
+
uniform float uGrain;
|
|
76
|
+
|
|
77
|
+
${GLSL_NOISE}
|
|
78
|
+
// The palette in Oklab (uPal), so it loops without muddy midpoints.
|
|
79
|
+
${GLSL_PALETTE}
|
|
80
|
+
${GLSL_QUIET}
|
|
81
|
+
// The light at one point, pushed by the fluid's flow; its warp field out through r.
|
|
82
|
+
float light(vec2 uv, float t, vec2 m, vec2 flow, out vec2 r) {
|
|
83
|
+
vec2 q = vec2(fbm(uv * 1.3 + vec2(0.0, t)), fbm(uv * 1.3 + vec2(5.2, -t)));
|
|
84
|
+
r = vec2(fbm(uv * 1.5 + 2.2 * q + vec2(1.7, 9.2) + 0.7 * t), fbm(uv * 1.5 + 2.2 * q + vec2(8.3, 2.8) - 0.5 * t));
|
|
85
|
+
// The pointer as a lens: d / (|d| + 0.2), a soft push that cannot pinch to a point.
|
|
86
|
+
vec2 d = uv - m;
|
|
87
|
+
float lens = exp(-dot(d, d) * 6.0) * (0.12 + 0.3 * uActive + 0.35 * uPress) * uLens;
|
|
88
|
+
r += lens * d / (length(d) + 0.2);
|
|
89
|
+
r += flow;
|
|
90
|
+
return fbm(uv * 1.7 + 2.6 * r);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
void main() {
|
|
94
|
+
vec2 uv = (gl_FragCoord.xy - 0.5 * uRes) / uRes.y;
|
|
95
|
+
vec2 m = (uMouse - 0.5 * uRes) / uRes.y;
|
|
96
|
+
float t = uTime * 0.05;
|
|
97
|
+
|
|
98
|
+
// The fluid's velocity as a push on the light, eased so a hard flick
|
|
99
|
+
// bends it a long way without tearing it.
|
|
100
|
+
vec2 screen = gl_FragCoord.xy / uRes;
|
|
101
|
+
vec2 vel = texture2D(uVel, screen).xy * 0.0009 * uFluid;
|
|
102
|
+
vec2 flow = vel / (1.0 + length(vel));
|
|
103
|
+
|
|
104
|
+
vec2 r;
|
|
105
|
+
float f = light(uv, t, m, flow, r);
|
|
106
|
+
vec3 col;
|
|
107
|
+
#if PRISM
|
|
108
|
+
// Three samples a hair apart along the flow: red, green and blue part at the edges.
|
|
109
|
+
vec2 split = 0.012 * normalize(r - 0.5 + 1e-4);
|
|
110
|
+
vec2 rr, rb;
|
|
111
|
+
float fr = light(uv + split, t, m, flow, rr);
|
|
112
|
+
float fb = light(uv - split, t, m, flow, rb);
|
|
113
|
+
col.r = pal(fr + 0.35 * length(rr) + t * 0.3).r;
|
|
114
|
+
col.g = pal(f + 0.35 * length(r) + t * 0.3).g;
|
|
115
|
+
col.b = pal(fb + 0.35 * length(rb) + t * 0.3).b;
|
|
116
|
+
#else
|
|
117
|
+
col = pal(f + 0.35 * length(r) + t * 0.3);
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
// Light where the field is dense, deep where it thins.
|
|
121
|
+
col *= 0.18 + 1.25 * f * f;
|
|
122
|
+
|
|
123
|
+
// Caustics: thin bright bands where the field crosses its contours.
|
|
124
|
+
float bands = pow(abs(sin(f * 16.0 - t * 4.0)), 22.0);
|
|
125
|
+
col += bands * mix(pal(f + 0.5), uGlint, 0.6) * 0.5 * smoothstep(0.35, 0.75, f);
|
|
126
|
+
|
|
127
|
+
// The pointer brightens the light under it.
|
|
128
|
+
vec2 d = uv - m;
|
|
129
|
+
col += exp(-dot(d, d) * 9.0) * pal(t + 0.2) * (0.06 + 0.2 * uActive) * uLens;
|
|
130
|
+
|
|
131
|
+
// The quiet area dims; ink is dimmed less (it is the visitor's own, and it does not stay).
|
|
132
|
+
float open = quietOpen(uv);
|
|
133
|
+
col *= mix(1.0 - uQuiet.w, 1.0, open);
|
|
134
|
+
|
|
135
|
+
// The ink: its colour at full strength, covering as much as there is of
|
|
136
|
+
// it, lit by the field beneath so it takes the light's folds.
|
|
137
|
+
vec3 dye = texture2D(uDye, screen).rgb * uFluid;
|
|
138
|
+
float ink = max(dye.r, max(dye.g, dye.b));
|
|
139
|
+
vec3 hue = dye / max(ink, 1e-4);
|
|
140
|
+
float cover = 1.0 - exp(-ink * 2.5);
|
|
141
|
+
col = mix(col, hue * (0.7 + 0.8 * f) * mix(1.0 - uQuiet.w * 0.62, 1.0, open), cover * 0.9);
|
|
142
|
+
|
|
143
|
+
col *= 1.0 - uVignette * dot(uv * 0.55, uv * 0.55);
|
|
144
|
+
col += (hash(gl_FragCoord.xy + fract(uTime)) - 0.5) * uGrain;
|
|
145
|
+
gl_FragColor = vec4(max(col, 0.0), 1.0);
|
|
146
|
+
}
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
/** The glint when none is given: a warm white, as sunlight through water. */
|
|
150
|
+
const GLINT = '#fff3c4';
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The palette and glint as the shader takes them: three Oklab colours, then
|
|
154
|
+
* the glint in sRGB.
|
|
155
|
+
*
|
|
156
|
+
* @param {string[]} colors Three hex colours.
|
|
157
|
+
* @param {string} glint A hex colour.
|
|
158
|
+
* @returns {Float32Array} Twelve channels.
|
|
159
|
+
*/
|
|
160
|
+
function channels(colors, glint) {
|
|
161
|
+
return new Float32Array([...paletteUniform(colors), ...parseColor(glint)]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Starts a light field on an element: an opaque canvas inside it, filling it.
|
|
166
|
+
*
|
|
167
|
+
* @param {HTMLElement} el The element (its first canvas is drawn into).
|
|
168
|
+
* @param {LightFieldConfig} config The settings.
|
|
169
|
+
* @returns {() => void} Stops it.
|
|
170
|
+
*/
|
|
171
|
+
export function lightField(el, config) {
|
|
172
|
+
const settings = config.fluid === false ? null : config.fluid === true || config.fluid == null ? {} : config.fluid;
|
|
173
|
+
const colors = pickColors(config, [...PALETTES.Lumetri.colors]);
|
|
174
|
+
let glint = config.glint ?? findPalette(config.palette)?.glint ?? GLINT;
|
|
175
|
+
const colours = channels(colors, glint);
|
|
176
|
+
/** @type {Float32Array} */
|
|
177
|
+
let target = colours.slice();
|
|
178
|
+
const mouse = { x: 0, y: 0, set: false };
|
|
179
|
+
let press = 0;
|
|
180
|
+
let pressTarget = 0;
|
|
181
|
+
let active = 0;
|
|
182
|
+
const start = performance.now() - 40_000;
|
|
183
|
+
/** @type {import('./fluid.js').Fluid | null} */
|
|
184
|
+
let fluid = null;
|
|
185
|
+
/** @type {ReturnType<typeof stir> | null} */
|
|
186
|
+
let stirrer = null;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Where the lens rests without a pointer: above the middle, drifting.
|
|
190
|
+
*
|
|
191
|
+
* @param {HTMLCanvasElement} canvas The canvas.
|
|
192
|
+
* @param {number} now The time, ms.
|
|
193
|
+
* @returns {{ x: number, y: number }} Canvas pixels, y up.
|
|
194
|
+
*/
|
|
195
|
+
const rest = (canvas, now) => ({
|
|
196
|
+
x: canvas.width * (0.5 + 0.28 * Math.sin(now * 0.00013)),
|
|
197
|
+
y: canvas.height * (0.62 + 0.12 * Math.sin(now * 0.00021 + 1.1)),
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const { stage, stop } = createStage(el, {
|
|
201
|
+
fragment: fragment(config.prism !== false && !isMobileGpu()),
|
|
202
|
+
alpha: false,
|
|
203
|
+
scale: config.scale ?? 0.5,
|
|
204
|
+
setup({ gl, uniform, still, program }) {
|
|
205
|
+
if (settings && !still && typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
206
|
+
fluid = createFluid(gl, { inkFade: settings.fade, diffusion: settings.diffusion, curl: settings.curl });
|
|
207
|
+
}
|
|
208
|
+
stirrer = fluid
|
|
209
|
+
? stir(fluid, el, {
|
|
210
|
+
colors: colors.map(parseColor),
|
|
211
|
+
trail: settings?.trail,
|
|
212
|
+
drops: settings?.drops,
|
|
213
|
+
force: settings?.force,
|
|
214
|
+
radius: settings?.radius,
|
|
215
|
+
ignore: settings?.ignore,
|
|
216
|
+
})
|
|
217
|
+
: null;
|
|
218
|
+
// Making the fluid used its own programs: back to the light's.
|
|
219
|
+
gl.useProgram(program);
|
|
220
|
+
gl.uniform1i(uniform('uDye'), 3);
|
|
221
|
+
gl.uniform1i(uniform('uVel'), 4);
|
|
222
|
+
gl.uniform1f(uniform('uFluid'), fluid ? 1 : 0);
|
|
223
|
+
gl.uniform1f(uniform('uLens'), config.lens ?? 1);
|
|
224
|
+
gl.uniform1f(uniform('uVignette'), config.vignette ?? 0.45);
|
|
225
|
+
gl.uniform1f(uniform('uGrain'), config.grain ?? 0.035);
|
|
226
|
+
|
|
227
|
+
if (!((config.lens ?? 1) > 0 && canHover() && !still)) return () => stirrer?.destroy();
|
|
228
|
+
/** Holding the button down swells the lens. */
|
|
229
|
+
const down = () => {
|
|
230
|
+
pressTarget = 1;
|
|
231
|
+
};
|
|
232
|
+
/** Letting go lets it settle. */
|
|
233
|
+
const up = () => {
|
|
234
|
+
pressTarget = 0;
|
|
235
|
+
};
|
|
236
|
+
document.addEventListener('pointerdown', down);
|
|
237
|
+
document.addEventListener('pointerup', up);
|
|
238
|
+
return () => {
|
|
239
|
+
stirrer?.destroy();
|
|
240
|
+
document.removeEventListener('pointerdown', down);
|
|
241
|
+
document.removeEventListener('pointerup', up);
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
resize({ gl, uniform, canvas }) {
|
|
245
|
+
fluid?.resize(canvas.width / canvas.height);
|
|
246
|
+
gl.uniform4f(uniform('uQuiet'), ...quietUniform(config.quiet, canvas.width / canvas.height));
|
|
247
|
+
},
|
|
248
|
+
update(_stage, _now, dt) {
|
|
249
|
+
if (!fluid) return;
|
|
250
|
+
stirrer?.update(dt);
|
|
251
|
+
if (dt > 0) fluid.step(dt);
|
|
252
|
+
fluid.bind(3, 4);
|
|
253
|
+
},
|
|
254
|
+
uniforms({ gl, uniform, canvas, still }, now, dt) {
|
|
255
|
+
const p = (config.lens ?? 1) > 0 && canHover() && !still ? pointerIn(el) : null;
|
|
256
|
+
const goal = p?.inside ? { x: p.x * canvas.width, y: p.y * canvas.height } : rest(canvas, now);
|
|
257
|
+
if (!mouse.set) Object.assign(mouse, goal, { set: true });
|
|
258
|
+
mouse.x += (goal.x - mouse.x) * 0.06;
|
|
259
|
+
mouse.y += (goal.y - mouse.y) * 0.06;
|
|
260
|
+
press += (pressTarget - press) * 0.08;
|
|
261
|
+
active += ((p?.inside ? 1 : 0) - active) * 0.05;
|
|
262
|
+
// By the clock, not the frame: about a second to new colours however fast the screen draws.
|
|
263
|
+
const ease = 1 - Math.exp(-(dt * 1000) / 350);
|
|
264
|
+
for (let i = 0; i < colours.length; i++) colours[i] += (target[i] - colours[i]) * ease;
|
|
265
|
+
gl.uniform1f(uniform('uTime'), ((now - start) / 1000) * (config.speed ?? 1));
|
|
266
|
+
gl.uniform2f(uniform('uMouse'), mouse.x, mouse.y);
|
|
267
|
+
gl.uniform1f(uniform('uPress'), press);
|
|
268
|
+
gl.uniform1f(uniform('uActive'), active);
|
|
269
|
+
gl.uniform3fv(uniform('uPal'), colours.subarray(0, 9));
|
|
270
|
+
gl.uniform3fv(uniform('uGlint'), colours.subarray(9, 12));
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
if (!stage) return stop;
|
|
274
|
+
|
|
275
|
+
// New colours: the light heads for them. Those set before it started are
|
|
276
|
+
// its colours from the first frame.
|
|
277
|
+
let started = false;
|
|
278
|
+
const unwatch = watchColors(el, (next) => {
|
|
279
|
+
glint = next.glint ?? glint;
|
|
280
|
+
target = channels(next.colors, glint);
|
|
281
|
+
stirrer?.setColors(next.colors.map(parseColor));
|
|
282
|
+
if (!started || stage.still) colours.set(target);
|
|
283
|
+
if (stage.still && started) stage.redraw();
|
|
284
|
+
});
|
|
285
|
+
started = true;
|
|
286
|
+
if (stage.still) stage.redraw();
|
|
287
|
+
|
|
288
|
+
return () => {
|
|
289
|
+
stop();
|
|
290
|
+
unwatch();
|
|
291
|
+
};
|
|
292
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface LiquidGlassOptions {
|
|
2
|
+
/** How hard the glass bends what is behind it, 0–2; `true` is 1, `false` or 0 is off. Default 1 (CSS `--glass-refract`). */
|
|
3
|
+
refract?: boolean | number;
|
|
4
|
+
/** How much the rim splits what it bends into red, green and blue, 0–1; 0 is one pass, cheaper. Default 0.35 (CSS `--glass-dispersion`). */
|
|
5
|
+
dispersion?: number;
|
|
6
|
+
/** How wide the bending rim is, px. Default 28 (CSS `--glass-bezel`). */
|
|
7
|
+
bezel?: number;
|
|
8
|
+
/** How bright the highlight along the rim is, 0–1. Default 0.7 (CSS `--glass-specular`). */
|
|
9
|
+
specular?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A lens's settings, all worked out. */
|
|
13
|
+
export interface LensSettings {
|
|
14
|
+
refract: number;
|
|
15
|
+
dispersion: number;
|
|
16
|
+
bezel: number;
|
|
17
|
+
specular: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** One step of a lens filter: a bend of the backdrop (`feDisplacementMap`'s scale, for one colour channel or all), or the rim's highlight laid over it. */
|
|
21
|
+
export type LensStep = { kind: 'bend'; scale: number; channel?: 'R' | 'G' | 'B' } | { kind: 'shine'; amount: number };
|
|
22
|
+
|
|
23
|
+
/** The settings a lens takes when neither its options nor its CSS give one. */
|
|
24
|
+
export const LENS_DEFAULTS: Readonly<LensSettings>;
|
|
25
|
+
|
|
26
|
+
/** Whether this browser draws SVG filters in `backdrop-filter` (Chromium). Elsewhere the panels keep glass.css's frost. */
|
|
27
|
+
export function lensSupported(): boolean;
|
|
28
|
+
|
|
29
|
+
/** Reads a setting's value: a number, `true` (1), `false` or `none` (0); undefined when there is none. */
|
|
30
|
+
export function lensValue(value: unknown): number | undefined;
|
|
31
|
+
|
|
32
|
+
/** A lens's settings: each from `options`, else the custom property `read` returns (`--glass-refract`…), else the default (`unset` for the strength), clamped to its range. */
|
|
33
|
+
export function lensSettings(options: LiquidGlassOptions, read: (property: string) => string, unset?: number): LensSettings;
|
|
34
|
+
|
|
35
|
+
/** The steps of a lens's filter: one bend, or three (R, G, B) with dispersion, then the highlight. */
|
|
36
|
+
export function lensSteps(settings: LensSettings): LensStep[];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Bends what is behind one `.glass` panel as a thick lens, through
|
|
40
|
+
* `backdrop-filter: url()` (Chromium; elsewhere it does nothing and the
|
|
41
|
+
* frost stays). Settings left out are read from the panel's custom
|
|
42
|
+
* properties. The filter is remade when the panel's size or radius
|
|
43
|
+
* changes. Returns a function that stops it.
|
|
44
|
+
*/
|
|
45
|
+
export function liquidGlass(el: HTMLElement, options?: LiquidGlassOptions): () => void;
|
|
46
|
+
|
|
47
|
+
/** Bends what is behind every `.glass` panel on the page, now and later, whose `--glass-refract` is above 0. Safe to call more than once. */
|
|
48
|
+
export function glassLens(): void;
|