@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,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/glass-glyph
|
|
3
|
+
*
|
|
4
|
+
* A character or a logo as a thick slab of dark, smoked glass, lit from
|
|
5
|
+
* behind by one coloured light: four beams turning out from a point like a
|
|
6
|
+
* pinwheel, sharp on one side and fading on the other. Outside the glass the
|
|
7
|
+
* light is only a dim trace on a near-black ground; the slab catches it,
|
|
8
|
+
* carries it through its body and glows with it along its bevels, so the
|
|
9
|
+
* glass is the lit thing. The light stays put; the slab turns slowly on its
|
|
10
|
+
* own and leans a little away from the pointer, so its side walls show and
|
|
11
|
+
* the highlights slide along its bevels.
|
|
12
|
+
*
|
|
13
|
+
* Through the glass the beams are softened, shifted and split into colour,
|
|
14
|
+
* hardest across the bevels, and muted by the smoke; a bright rim runs round
|
|
15
|
+
* the outer edge and a fainter crease where the bevel meets the face, both
|
|
16
|
+
* brightest where they face the light or the beams, and the bevels mirror
|
|
17
|
+
* the light back.
|
|
18
|
+
*
|
|
19
|
+
* The lens model (edge-weighted refraction, rim, glint and fresnel) is
|
|
20
|
+
* adapted from shaders.com's Glass component (MIT, © 2026 Shader Effects
|
|
21
|
+
* Inc.; see LICENSE).
|
|
22
|
+
*
|
|
23
|
+
* Opaque: the effect is the whole background of what it fills. Without
|
|
24
|
+
* WebGL it removes its canvas and the element's background shows. With
|
|
25
|
+
* reduced motion it is one still frame, the slab turned a little.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { createStage } from './stage.js';
|
|
29
|
+
import { drawShape, distanceField, blurField } from './shape.js';
|
|
30
|
+
import { parseColor, toOklab, fromOklab } from './color.js';
|
|
31
|
+
import { canHover } from './device.js';
|
|
32
|
+
import { pointerIn } from './pointer.js';
|
|
33
|
+
import { watchColors } from './mount.js';
|
|
34
|
+
import { pickColors } from './palettes.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} GlassGlyphConfig
|
|
38
|
+
* @property {string} [text] The character or word to make of glass.
|
|
39
|
+
* @property {string} [font] Its CSS font, without the size (default: the page's, bold).
|
|
40
|
+
* @property {string} [src] An image (an SVG logo) to make of glass instead.
|
|
41
|
+
* @property {{ x: number, y: number, width: number, height: number }} [area]
|
|
42
|
+
* Where the shape sits, each 0–1 from the top left (default: the right half).
|
|
43
|
+
* @property {{ x: number, y: number }} [light] Where the beams of light cross, each 0–1 from the top left (default: two fifths of the way into the shape's area, a little below its middle).
|
|
44
|
+
* @property {string[]} [colors] The light's colour, then the glass's tint (default acid green, white).
|
|
45
|
+
* @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`. Its first colour lights the glass; its glint is the highlight.
|
|
46
|
+
* @property {string} [background='#050505'] The ground.
|
|
47
|
+
* @property {number} [refraction=1] How hard the glass bends what is behind it, most of all across its bevels, 0–2.
|
|
48
|
+
* @property {number} [thickness=0.035] How wide the bevel round the edge is, a share of the height, 0.01–0.1.
|
|
49
|
+
* @property {number} [zoom=1.04] How much the glass magnifies the light behind it, 1–1.3.
|
|
50
|
+
* @property {number} [aberration=0.6] How far the colours part where it bends, 0–2; 0 for none.
|
|
51
|
+
* @property {number} [frost=0] Frosted glass: how much more the light through it is blurred, 0–1.
|
|
52
|
+
* @property {number} [tint=0.1] How much the glass takes the tint colour, 0–1.
|
|
53
|
+
* @property {number} [highlight=0.8] The lit rims and the glints, 0–2.
|
|
54
|
+
* @property {number} [fresnel=0.5] How much the bevels mirror the light, 0–1.
|
|
55
|
+
* @property {number} [lightAngle=135] Where the light on the rims comes from, degrees, 0–360 (0 right, 90 top).
|
|
56
|
+
* @property {number} [glow=1] How strong the coloured light is, 0–2.
|
|
57
|
+
* @property {number} [ambient=0.1] How much of the light shows outside the glass, 0–1: 0 is a black ground, 1 the full beams.
|
|
58
|
+
* @property {boolean} [halftone=false] Dither the light outside the glass into dots where it fades.
|
|
59
|
+
* @property {number} [sway=1] How far the slab turns on its own and away from the pointer, 0–2; 0 holds it still.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
const FRAG = `
|
|
63
|
+
precision highp float;
|
|
64
|
+
uniform vec2 uRes;
|
|
65
|
+
uniform sampler2D uSdf;
|
|
66
|
+
uniform vec2 uSdfTexel;
|
|
67
|
+
uniform float uSpread;
|
|
68
|
+
uniform vec2 uCross;
|
|
69
|
+
uniform vec2 uTilt;
|
|
70
|
+
uniform vec3 uGlow;
|
|
71
|
+
uniform vec3 uGlass;
|
|
72
|
+
uniform vec3 uTint;
|
|
73
|
+
uniform vec3 uGround;
|
|
74
|
+
uniform float uRefraction;
|
|
75
|
+
uniform float uBevel;
|
|
76
|
+
uniform float uZoom;
|
|
77
|
+
uniform float uAberration;
|
|
78
|
+
uniform float uFrost;
|
|
79
|
+
uniform float uTintAmount;
|
|
80
|
+
uniform float uHighlight;
|
|
81
|
+
uniform float uFresnel;
|
|
82
|
+
uniform vec2 uLightDir;
|
|
83
|
+
uniform float uGlowAmount;
|
|
84
|
+
uniform float uAmbient;
|
|
85
|
+
uniform float uHalftone;
|
|
86
|
+
|
|
87
|
+
const float TAU = 6.2831853;
|
|
88
|
+
// How deep the slab is, in heights: how far its back face slides as it turns.
|
|
89
|
+
const float SLAB = 0.15;
|
|
90
|
+
const vec3 LUMA = vec3(0.299, 0.587, 0.114);
|
|
91
|
+
|
|
92
|
+
// The distance field: 0.5 at the shape's edge, more inside.
|
|
93
|
+
float field(vec2 uv) { return texture2D(uSdf, vec2(uv.x, 1.0 - uv.y)).r; }
|
|
94
|
+
// How far inside the edge, in heights; negative outside.
|
|
95
|
+
float depthAt(vec2 uv) { return (field(uv) - 0.5) * 2.0 * uSpread; }
|
|
96
|
+
|
|
97
|
+
// One beam of the pinwheel: sharp along its axis at angle 'axis', fading
|
|
98
|
+
// counter-clockwise over about 'width' radians. 'edge' softens the sharp
|
|
99
|
+
// side, in heights.
|
|
100
|
+
float beam(float angle, float r, float axis, float width, float edge) {
|
|
101
|
+
float s = mod(angle - axis + 3.14159265, TAU) - 3.14159265;
|
|
102
|
+
float e = edge / max(r, 1e-3);
|
|
103
|
+
return smoothstep(-e, e, s) * exp(-max(s, 0.0) / width);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The light behind the glass, 0 dark to about 1: four beams turning out from
|
|
107
|
+
// where they cross. 'soft' (0 sharp, 1 through thick glass) blurs their edges.
|
|
108
|
+
float light(vec2 uv, float soft) {
|
|
109
|
+
vec2 d = (uv - uCross) * vec2(uRes.x / uRes.y, 1.0);
|
|
110
|
+
float r = length(d);
|
|
111
|
+
float a = atan(d.y, d.x);
|
|
112
|
+
float edge = mix(1.5 / uRes.y, 0.05, soft);
|
|
113
|
+
float spread = 1.0 + soft * 0.6;
|
|
114
|
+
// Right and up are the main beams; down and left are their echoes.
|
|
115
|
+
float b = beam(a, r, 0.0, 0.24 * spread, edge) * 1.0
|
|
116
|
+
+ beam(a, r, 1.5708, 0.22 * spread, edge) * 0.85
|
|
117
|
+
+ beam(a, r, -1.5708, 0.18 * spread, edge) * 0.24
|
|
118
|
+
+ beam(a, r, 3.14159, 0.16 * spread, edge) * 0.18;
|
|
119
|
+
// Brighter away from the crossing, and a haze round it.
|
|
120
|
+
b *= smoothstep(0.0, 0.6, r) * 0.8 + 0.2;
|
|
121
|
+
b += exp(-r * r * 12.0) * 0.06;
|
|
122
|
+
return b * uGlowAmount;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// The light as the smoked glass shows it: its colour, muted, going pale where it is brightest.
|
|
126
|
+
vec3 lit(vec2 uv, float soft) {
|
|
127
|
+
float b = light(uv, soft);
|
|
128
|
+
return uGlass * b + vec3(pow(clamp(b, 0.0, 1.0), 3.0) * 0.15);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// The ground outside the glass: near black, the light only a dim trace of
|
|
132
|
+
// itself ('uAmbient'), dithered into dots with 'uHalftone'.
|
|
133
|
+
vec3 ground(vec2 uv) {
|
|
134
|
+
float b = light(uv, 0.0);
|
|
135
|
+
// Dots on a fine grid, as big as the light is bright, mixed in where it fades.
|
|
136
|
+
vec2 cell = fract(uv * uRes / (4.0 * max(uRes.y / 760.0, 1.0))) - 0.5;
|
|
137
|
+
float spot = smoothstep(0.08, -0.08, length(cell) - sqrt(clamp(b, 0.0, 1.0)) * 0.62);
|
|
138
|
+
float fade = smoothstep(0.02, 0.2, b) * (1.0 - smoothstep(0.35, 0.8, b));
|
|
139
|
+
b = mix(b, spot * min(b * 1.6, 1.0), fade * uHalftone * 0.5);
|
|
140
|
+
return uGround + uGlow * b * uAmbient;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void main() {
|
|
144
|
+
vec2 uv = gl_FragCoord.xy / uRes;
|
|
145
|
+
float aspect = uRes.x / uRes.y;
|
|
146
|
+
float pxH = 1.0 / uRes.y;
|
|
147
|
+
vec2 toUv = vec2(1.0 / aspect, 1.0);
|
|
148
|
+
float d = depthAt(uv);
|
|
149
|
+
// The light the slab gathers and carries through its body, broad and soft.
|
|
150
|
+
float carry = light(uv, 1.0);
|
|
151
|
+
|
|
152
|
+
// Outside: the dark ground, and a faint haze where the lit glass glows into it.
|
|
153
|
+
vec3 back = ground(uv) + uGlass * carry * exp(min(d, 0.0) / 0.01) * 0.08;
|
|
154
|
+
|
|
155
|
+
// The back face: the shape slid against the turn, a slab's depth behind.
|
|
156
|
+
// Between it and the front are the side walls.
|
|
157
|
+
vec2 slide = -uTilt * SLAB * toUv;
|
|
158
|
+
float dBack = depthAt(uv - slide);
|
|
159
|
+
float wall = max(max(dBack, depthAt(uv - slide * 0.5)), d);
|
|
160
|
+
if (wall < -pxH * 2.0) { gl_FragColor = vec4(back, 1.0); return; }
|
|
161
|
+
|
|
162
|
+
float soft = clamp(0.4 + uFrost, 0.0, 1.0);
|
|
163
|
+
vec3 rimTone = mix(vec3(1.0), uGlass, 0.3);
|
|
164
|
+
vec3 L = normalize(vec3(uLightDir, 0.9));
|
|
165
|
+
// The smoked glass itself: near black, warmed by the light it carries.
|
|
166
|
+
vec3 smoke = uGround + uGlass * (0.01 + carry * 0.04);
|
|
167
|
+
|
|
168
|
+
// The side walls: glass seen edge on, carrying the light and lit where
|
|
169
|
+
// they face it, with the back face's edge as a fainter line.
|
|
170
|
+
float wallCover = clamp(wall / (pxH * 1.2), 0.0, 1.0);
|
|
171
|
+
float wallLit = clamp(dot(normalize(uTilt + 1e-5), uLightDir) * 0.5 + 0.5, 0.0, 1.0);
|
|
172
|
+
vec3 side = smoke + lit(uv + slide * 2.0, soft) * 0.5 + uGlass * carry * 0.2;
|
|
173
|
+
side += rimTone * (0.05 + 0.18 * wallLit) * uHighlight;
|
|
174
|
+
float backLine = clamp(1.0 - abs(dBack - pxH) / (pxH * 1.3), 0.0, 1.0);
|
|
175
|
+
side += rimTone * backLine * (0.25 + carry) * 0.5 * uHighlight;
|
|
176
|
+
vec3 col = mix(back, side, wallCover);
|
|
177
|
+
|
|
178
|
+
// The front face.
|
|
179
|
+
vec2 t = uSdfTexel * 3.0;
|
|
180
|
+
vec2 grad = vec2(field(uv + vec2(t.x, 0.0)) - field(uv - vec2(t.x, 0.0)), field(uv + vec2(0.0, t.y)) - field(uv - vec2(0.0, t.y)));
|
|
181
|
+
vec2 inward = grad / max(length(grad), 1e-5);
|
|
182
|
+
// The bevel: steepest at the lip, a steady slope across, and flat past the crease.
|
|
183
|
+
float s = clamp(d / max(uBevel, 0.002), 0.0, 1.0);
|
|
184
|
+
float crease = 1.0 - smoothstep(1.0 - (pxH * 2.0) / max(uBevel, 0.002), 1.0, s);
|
|
185
|
+
float slope = (0.9 + 1.6 * pow(1.0 - s, 4.0)) * crease;
|
|
186
|
+
vec3 n = normalize(vec3(-inward * slope + uTilt, 1.0));
|
|
187
|
+
|
|
188
|
+
// Through the glass: the light at full strength, refracted by the surface,
|
|
189
|
+
// magnified about the crossing, softened, and split into colour.
|
|
190
|
+
vec3 r = refract(vec3(0.0, 0.0, -1.0), n, 0.67);
|
|
191
|
+
vec2 offset = r.xy / max(-r.z, 0.2) * 0.12 * uRefraction * toUv;
|
|
192
|
+
vec2 lens = uCross + (uv - uCross) / uZoom + offset;
|
|
193
|
+
vec2 split = offset * uAberration * 0.18;
|
|
194
|
+
float thick = mix(soft, 1.0, (1.0 - s) * 0.2);
|
|
195
|
+
vec3 through = vec3(lit(lens + split, thick).r, lit(lens, thick).g, lit(lens - split, thick).b) * 1.35;
|
|
196
|
+
// Tinted, keeping its brightness.
|
|
197
|
+
vec3 tinted = mix(through, uTint * dot(through, LUMA) / max(dot(uTint, LUMA), 1e-3), uTintAmount);
|
|
198
|
+
|
|
199
|
+
// The bevels catch the light: they mirror it from along the reflected ray,
|
|
200
|
+
// and the light trapped in the slab glows out of them.
|
|
201
|
+
float edge = 1.0 - s;
|
|
202
|
+
float fres = pow(1.0 - n.z, 1.5) * uFresnel * 2.2;
|
|
203
|
+
vec3 m = reflect(vec3(0.0, 0.0, -1.0), n);
|
|
204
|
+
vec3 mirrored = lit(uv + m.xy * 0.45 * toUv, 0.4) * 1.3 + uGlass * carry * 0.3 + vec3(0.02);
|
|
205
|
+
vec3 face = smoke + tinted * (1.0 - fres * 0.35) + mirrored * fres + uGlass * carry * edge * edge * 0.12;
|
|
206
|
+
|
|
207
|
+
// The rim at the lip, the crease where the bevel meets the face, and the
|
|
208
|
+
// glints on the slope; brightest where they face the light or the beams.
|
|
209
|
+
float facing = clamp(dot(-inward, uLightDir) * 0.5 + 0.5, 0.0, 1.0);
|
|
210
|
+
float rim = clamp(1.0 - abs(d - pxH * 1.2) / (pxH * 1.4), 0.0, 1.0);
|
|
211
|
+
float seam = clamp(1.0 - abs(d - uBevel) / (pxH * 1.4), 0.0, 1.0);
|
|
212
|
+
vec3 h = normalize(L + vec3(0.0, 0.0, 1.0));
|
|
213
|
+
float glint = pow(max(dot(n, h), 0.0), 70.0) * (1.0 - s * 0.6);
|
|
214
|
+
float catchLight = 0.5 + min(carry, 1.0) * 0.9;
|
|
215
|
+
face += rimTone * uHighlight * catchLight * (rim * (0.7 + 0.9 * facing) + seam * (0.12 + 0.4 * facing) + glint * 1.4);
|
|
216
|
+
|
|
217
|
+
float inside = clamp(d / (pxH * 1.5), 0.0, 1.0);
|
|
218
|
+
gl_FragColor = vec4(mix(col, face, smoothstep(0.0, 1.0, inside)), 1.0);
|
|
219
|
+
}
|
|
220
|
+
`;
|
|
221
|
+
|
|
222
|
+
/** The default light and tint: acid green, and clear glass. */
|
|
223
|
+
const COLORS = ['#c6ff00', '#ffffff'];
|
|
224
|
+
|
|
225
|
+
/** Where the shape sits by default: the right half. */
|
|
226
|
+
const AREA = { x: 0.45, y: 0.05, width: 0.55, height: 0.9 };
|
|
227
|
+
|
|
228
|
+
/** How far the slab turns on its own, and how much further the pointer can turn it. */
|
|
229
|
+
const SWAY = 0.07;
|
|
230
|
+
const LEAN = 0.16;
|
|
231
|
+
|
|
232
|
+
/** How far the light shifts with the pointer: a touch of parallax, no more. */
|
|
233
|
+
const PARALLAX = 0.012;
|
|
234
|
+
|
|
235
|
+
/** How much of the light's colour the smoked glass keeps. */
|
|
236
|
+
const SMOKE = 0.8;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The light's colour and the colour it takes in the smoked glass: the same
|
|
240
|
+
* lightness, its chroma muted in Oklab.
|
|
241
|
+
*
|
|
242
|
+
* @param {string} color The light's colour.
|
|
243
|
+
* @returns {{ glow: import('./color.js').Rgb, glass: import('./color.js').Rgb }} Both, as RGB 0–1.
|
|
244
|
+
*/
|
|
245
|
+
function lightColors(color) {
|
|
246
|
+
const glow = parseColor(color);
|
|
247
|
+
const [L, a, b] = toOklab(glow);
|
|
248
|
+
return { glow, glass: fromOklab([L, a * SMOKE, b * SMOKE]) };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Starts glass on an element: an opaque canvas inside it, filling it.
|
|
253
|
+
*
|
|
254
|
+
* @param {HTMLElement} el The element (its first canvas is drawn into).
|
|
255
|
+
* @param {GlassGlyphConfig} config The settings.
|
|
256
|
+
* @returns {() => void} Stops it.
|
|
257
|
+
*/
|
|
258
|
+
export function glassGlyph(el, config) {
|
|
259
|
+
let colors = pickColors(config, COLORS, (p) => [p.colors[0], p.glint]);
|
|
260
|
+
let lit = lightColors(colors[0]);
|
|
261
|
+
const start = performance.now();
|
|
262
|
+
const area = config.area ?? AREA;
|
|
263
|
+
// The light's crossing, 0–1 with y up as the shader has it.
|
|
264
|
+
const cross = { x: config.light?.x ?? area.x + area.width * 0.42, y: 1 - (config.light?.y ?? area.y + area.height * 0.6) };
|
|
265
|
+
const sway = config.sway ?? 1;
|
|
266
|
+
const tilt = { x: 0, y: 0 };
|
|
267
|
+
const shift = { x: 0, y: 0 };
|
|
268
|
+
/** Bumped on each resize, so a slow shape drawn for an old size is dropped. */
|
|
269
|
+
let generation = 0;
|
|
270
|
+
|
|
271
|
+
const { stage, stop } = createStage(el, {
|
|
272
|
+
fragment: FRAG,
|
|
273
|
+
alpha: false,
|
|
274
|
+
setup({ gl, uniform }) {
|
|
275
|
+
gl.uniform1i(uniform('uSdf'), 0);
|
|
276
|
+
gl.uniform1f(uniform('uRefraction'), config.refraction ?? 1);
|
|
277
|
+
gl.uniform1f(uniform('uBevel'), config.thickness ?? 0.035);
|
|
278
|
+
gl.uniform1f(uniform('uZoom'), config.zoom ?? 1.04);
|
|
279
|
+
gl.uniform1f(uniform('uAberration'), config.aberration ?? 0.6);
|
|
280
|
+
gl.uniform1f(uniform('uFrost'), config.frost ?? 0);
|
|
281
|
+
gl.uniform1f(uniform('uTintAmount'), config.tint ?? 0.1);
|
|
282
|
+
gl.uniform1f(uniform('uHighlight'), config.highlight ?? 0.8);
|
|
283
|
+
gl.uniform1f(uniform('uFresnel'), config.fresnel ?? 0.5);
|
|
284
|
+
gl.uniform1f(uniform('uGlowAmount'), config.glow ?? 1);
|
|
285
|
+
gl.uniform1f(uniform('uAmbient'), config.ambient ?? 0.1);
|
|
286
|
+
gl.uniform1f(uniform('uHalftone'), config.halftone ? 1 : 0);
|
|
287
|
+
const angle = ((config.lightAngle ?? 135) * Math.PI) / 180;
|
|
288
|
+
gl.uniform2f(uniform('uLightDir'), Math.cos(angle), Math.sin(angle));
|
|
289
|
+
gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#050505'));
|
|
290
|
+
const texture = gl.createTexture();
|
|
291
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
292
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
293
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
294
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
295
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
296
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
297
|
+
// Empty until the shape is drawn: all outside.
|
|
298
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, 1, 1, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, new Uint8Array([0]));
|
|
299
|
+
},
|
|
300
|
+
resize({ gl, uniform, canvas }) {
|
|
301
|
+
// The field at up to 640 px across: it is smooth, so the GPU's filtering does the rest.
|
|
302
|
+
const width = Math.min(640, canvas.width);
|
|
303
|
+
const height = Math.max(1, Math.round((width * canvas.height) / canvas.width));
|
|
304
|
+
const mine = ++generation;
|
|
305
|
+
drawShape({ text: config.text, font: config.font, src: config.src, area, padding: 0.06 }, width, height)
|
|
306
|
+
.then((mask) => {
|
|
307
|
+
if (mine !== generation) return;
|
|
308
|
+
// Reaching well past the bevel, blurred a little so the edges' slope is smooth.
|
|
309
|
+
const spread = Math.round(width / 12);
|
|
310
|
+
const sdf = blurField(distanceField(mask, spread), width, height, width / 200);
|
|
311
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
312
|
+
gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
|
|
313
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width, height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, sdf);
|
|
314
|
+
gl.useProgram(stage?.program ?? null);
|
|
315
|
+
gl.uniform2f(uniform('uSdfTexel'), 1 / width, 1 / height);
|
|
316
|
+
// The field's reach, in heights of the canvas.
|
|
317
|
+
gl.uniform1f(uniform('uSpread'), spread / height);
|
|
318
|
+
if (stage?.still) stage.redraw();
|
|
319
|
+
})
|
|
320
|
+
.catch((error) => console.warn('[effects-astro]', error));
|
|
321
|
+
},
|
|
322
|
+
uniforms({ gl, uniform, still }, now) {
|
|
323
|
+
const p = !still && canHover() ? pointerIn(el) : null;
|
|
324
|
+
// A still frame is held at a moment where the slab is turned a little, so its walls show.
|
|
325
|
+
const t = still ? 7 : (now - start) / 1000;
|
|
326
|
+
// The slab turns slowly on its own, and leans away from the pointer, showing the wall on its side.
|
|
327
|
+
const lean = p?.inside ? { x: (0.5 - p.x) * 2, y: (0.5 - p.y) * 2 } : { x: 0, y: 0 };
|
|
328
|
+
const goal = {
|
|
329
|
+
x: (Math.sin(t * 0.31) * 0.7 + Math.sin(t * 0.13 + 2) * 0.3) * SWAY + lean.x * LEAN,
|
|
330
|
+
y: (Math.sin(t * 0.23 + 1.3) * 0.7 + Math.sin(t * 0.11) * 0.3) * SWAY * 0.7 + lean.y * LEAN * 0.6,
|
|
331
|
+
};
|
|
332
|
+
const ease = still ? 1 : 0.04;
|
|
333
|
+
tilt.x += (goal.x * sway - tilt.x) * ease;
|
|
334
|
+
tilt.y += (goal.y * sway - tilt.y) * ease;
|
|
335
|
+
shift.x += (-lean.x * PARALLAX - shift.x) * ease;
|
|
336
|
+
shift.y += (-lean.y * PARALLAX - shift.y) * ease;
|
|
337
|
+
gl.uniform2f(uniform('uTilt'), tilt.x, tilt.y);
|
|
338
|
+
gl.uniform2f(uniform('uCross'), cross.x + shift.x, cross.y + shift.y);
|
|
339
|
+
gl.uniform3fv(uniform('uGlow'), lit.glow);
|
|
340
|
+
gl.uniform3fv(uniform('uGlass'), lit.glass);
|
|
341
|
+
gl.uniform3fv(uniform('uTint'), parseColor(colors[1] ?? colors[0]));
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
if (!stage) return stop;
|
|
345
|
+
|
|
346
|
+
const unwatch = watchColors(el, (next) => {
|
|
347
|
+
colors = next.colors;
|
|
348
|
+
lit = lightColors(colors[0]);
|
|
349
|
+
if (stage.still) stage.redraw();
|
|
350
|
+
});
|
|
351
|
+
return () => {
|
|
352
|
+
stop();
|
|
353
|
+
unwatch();
|
|
354
|
+
};
|
|
355
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/glass-sheen
|
|
3
|
+
*
|
|
4
|
+
* The sheen on every `.glass` panel (glass.css): a soft light where the
|
|
5
|
+
* pointer is, from two custom properties kept up to date here. One
|
|
6
|
+
* document listener for every panel on the page.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
let installed = false;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Moves the sheen to the pointer: its place within whichever panel it is
|
|
13
|
+
* over, as percentages.
|
|
14
|
+
*
|
|
15
|
+
* @param {PointerEvent} event The pointer's move.
|
|
16
|
+
*/
|
|
17
|
+
function follow(event) {
|
|
18
|
+
const panel = /** @type {Element | null} */ (event.target)?.closest?.('.glass');
|
|
19
|
+
if (!(panel instanceof HTMLElement)) return;
|
|
20
|
+
const box = panel.getBoundingClientRect();
|
|
21
|
+
panel.style.setProperty('--glass-x', `${((event.clientX - box.left) / box.width) * 100}%`);
|
|
22
|
+
panel.style.setProperty('--glass-y', `${((event.clientY - box.top) / box.height) * 100}%`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Starts the sheen for every `.glass` panel on the page, now and later; once is enough. */
|
|
26
|
+
export function glassSheen() {
|
|
27
|
+
if (installed || typeof document === 'undefined') return;
|
|
28
|
+
installed = true;
|
|
29
|
+
document.addEventListener('pointermove', follow, { passive: true });
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** GLSL: `hash`, `noise` and `fbm` over vec2, each 0–1. */
|
|
2
|
+
export const GLSL_NOISE: string;
|
|
3
|
+
|
|
4
|
+
/** GLSL: `uniform vec3 uPal[3]` and `vec3 pal(float t)`, a palette looped in Oklab. Includes GLSL_OKLAB. */
|
|
5
|
+
export const GLSL_PALETTE: string;
|
|
6
|
+
|
|
7
|
+
/** GLSL: `uniform vec4 uQuiet` and `float quietOpen(vec2 uv)`, 0 at a quiet area's centre, 1 outside it. */
|
|
8
|
+
export const GLSL_QUIET: string;
|
|
9
|
+
|
|
10
|
+
/** Three hex colours in Oklab, nine channels, for `uPal`. */
|
|
11
|
+
export function paletteUniform(colors: string[]): Float32Array;
|
|
12
|
+
|
|
13
|
+
/** A quiet area for `uQuiet`: centre (centred uv), radius, depth; zeros for none. */
|
|
14
|
+
export function quietUniform(
|
|
15
|
+
quiet: { x?: number; y?: number; radius?: number; depth?: number } | null | undefined,
|
|
16
|
+
aspect: number,
|
|
17
|
+
): [number, number, number, number];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/glsl
|
|
3
|
+
*
|
|
4
|
+
* Shader pieces more than one effect uses, with the JavaScript that feeds
|
|
5
|
+
* their uniforms: value noise, a three-colour palette looped in Oklab, and
|
|
6
|
+
* a quiet area where an effect dims behind copy.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { GLSL_OKLAB, parseColor, toOklab } from './color.js';
|
|
10
|
+
|
|
11
|
+
/** GLSL: `hash(vec2)`, smooth value `noise(vec2)` and five-octave `fbm(vec2)`, each 0–1. */
|
|
12
|
+
export const GLSL_NOISE = `
|
|
13
|
+
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
|
|
14
|
+
float noise(vec2 p) {
|
|
15
|
+
vec2 i = floor(p), f = fract(p);
|
|
16
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
17
|
+
return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x), mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
|
|
18
|
+
}
|
|
19
|
+
float fbm(vec2 p) {
|
|
20
|
+
float v = 0.0, a = 0.5;
|
|
21
|
+
mat2 m = mat2(1.6, 1.2, -1.2, 1.6);
|
|
22
|
+
for (int i = 0; i < 5; i++) { v += a * noise(p); p = m * p; a *= 0.5; }
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* GLSL: `uniform vec3 uPal[3]` (three colours in Oklab, from
|
|
29
|
+
* `paletteUniform`) and `vec3 pal(float t)`, the palette looped through its
|
|
30
|
+
* colours and back, eased, in sRGB. Includes GLSL_OKLAB.
|
|
31
|
+
*/
|
|
32
|
+
export const GLSL_PALETTE = `${GLSL_OKLAB}
|
|
33
|
+
uniform vec3 uPal[3];
|
|
34
|
+
vec3 pal(float t) {
|
|
35
|
+
float x = fract(t) * 3.0;
|
|
36
|
+
float k = smoothstep(0.0, 1.0, fract(x));
|
|
37
|
+
vec3 lab = x < 1.0 ? mix(uPal[0], uPal[1], k) : x < 2.0 ? mix(uPal[1], uPal[2], k) : mix(uPal[2], uPal[0], k);
|
|
38
|
+
return fromOklab(lab);
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* GLSL: `uniform vec4 uQuiet` (from `quietUniform`) and
|
|
44
|
+
* `float quietOpen(vec2 uv)`: 0 at the quiet area's centre rising to 1 at
|
|
45
|
+
* its edge and beyond, with `uv` centred and in units of the height. Dim by
|
|
46
|
+
* `mix(1.0 - uQuiet.w, 1.0, quietOpen(uv))`.
|
|
47
|
+
*/
|
|
48
|
+
export const GLSL_QUIET = `
|
|
49
|
+
uniform vec4 uQuiet;
|
|
50
|
+
float quietOpen(vec2 uv) {
|
|
51
|
+
return uQuiet.z > 0.0 ? smoothstep(uQuiet.z * 0.06, uQuiet.z, length(uv - uQuiet.xy)) : 1.0;
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Three colours as `uPal` takes them: in Oklab, so the shader mixes there.
|
|
57
|
+
* Fewer than three repeat; more are cut to three.
|
|
58
|
+
*
|
|
59
|
+
* @param {string[]} colors CSS hex colours.
|
|
60
|
+
* @returns {Float32Array} Nine channels.
|
|
61
|
+
*/
|
|
62
|
+
export function paletteUniform(colors) {
|
|
63
|
+
return new Float32Array([0, 1, 2].flatMap((i) => toOklab(parseColor(colors[i % colors.length]))));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A quiet area as `uQuiet` takes it.
|
|
68
|
+
*
|
|
69
|
+
* @param {{ x?: number, y?: number, radius?: number, depth?: number } | null | undefined} quiet
|
|
70
|
+
* Centre x/y (0–1 from the top left, default the middle), radius (a share
|
|
71
|
+
* of the height, default 0.8) and depth (0–1, default 0.72); none for no area.
|
|
72
|
+
* @param {number} aspect The target's width over height.
|
|
73
|
+
* @returns {[number, number, number, number]} Centre (centred uv), radius, depth; all 0 for none.
|
|
74
|
+
*/
|
|
75
|
+
export function quietUniform(quiet, aspect) {
|
|
76
|
+
if (!quiet) return [0, 0, 0, 0];
|
|
77
|
+
return [((quiet.x ?? 0.5) - 0.5) * aspect, 0.5 - (quiet.y ?? 0.5), quiet.radius ?? 0.8, quiet.depth ?? 0.72];
|
|
78
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The character sets, each ordered from empty to full. */
|
|
2
|
+
export const GLYPH_SETS: {
|
|
3
|
+
data: string;
|
|
4
|
+
ascii: string;
|
|
5
|
+
bars: string;
|
|
6
|
+
blocks: string;
|
|
7
|
+
binary: string;
|
|
8
|
+
boxes: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Draws glyphs (a GLYPH_SETS key, or the characters, darkest first) into a
|
|
13
|
+
* one-row texture left bound on `unit`.
|
|
14
|
+
*/
|
|
15
|
+
export function createGlyphs(
|
|
16
|
+
gl: WebGLRenderingContext | WebGL2RenderingContext,
|
|
17
|
+
glyphs: string,
|
|
18
|
+
options?: { cell?: number; aspect?: number; font?: string; unit?: number },
|
|
19
|
+
): { texture: WebGLTexture; count: number };
|
|
20
|
+
|
|
21
|
+
/** GLSL declaring `uGlyphs`, `uGlyphCount` and `float glyph(vec2 cellUv, float level)`. */
|
|
22
|
+
export const GLSL_GLYPHS: string;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/glyphs
|
|
3
|
+
*
|
|
4
|
+
* Text characters as a texture, for effects that draw in character cells:
|
|
5
|
+
* a strip of glyphs, darkest first, that a shader picks from by brightness.
|
|
6
|
+
* `GLSL_GLYPHS` is the shader side: `glyph(cellUv, level)` returns how much
|
|
7
|
+
* of the cell the glyph for a brightness level covers.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The character sets, each ordered from empty to full. Block and bar
|
|
12
|
+
* characters are drawn by the canvas from the system's monospace font,
|
|
13
|
+
* which on every current system includes them.
|
|
14
|
+
*/
|
|
15
|
+
export const GLYPH_SETS = {
|
|
16
|
+
/**
|
|
17
|
+
* A data readout drawn as shapes, not type: empty, a low line, a hollow
|
|
18
|
+
* bar, a solid bar, so a streak fades out through outlines and then
|
|
19
|
+
* underscores at its ends. Crisp, and the same on every system.
|
|
20
|
+
*/
|
|
21
|
+
data: ' _▯▮',
|
|
22
|
+
/** Classic ASCII art. */
|
|
23
|
+
ascii: ' .:-=+*#%@',
|
|
24
|
+
/** Vertical bars filling from the left, and a solid block: a data readout. */
|
|
25
|
+
bars: ' ·▏▎▍▌▋▊▉█',
|
|
26
|
+
/** Shade blocks. */
|
|
27
|
+
blocks: ' ░▒▓█',
|
|
28
|
+
/** Ones and noughts. */
|
|
29
|
+
binary: ' 01',
|
|
30
|
+
/** Hollow and solid boxes, like a terminal missing its glyphs. */
|
|
31
|
+
boxes: ' ·▫□▢▣■',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Draws a set of glyphs into a texture: one row, one glyph a cell, each
|
|
36
|
+
* centred and sized to fill the cell's height.
|
|
37
|
+
*
|
|
38
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
|
|
39
|
+
* @param {string} glyphs The characters, darkest first (a key of GLYPH_SETS, or the characters themselves).
|
|
40
|
+
* @param {object} [options]
|
|
41
|
+
* @param {number} [options.cell=48] Each glyph's cell height in texture pixels.
|
|
42
|
+
* @param {number} [options.aspect=0.6] A cell's width over its height.
|
|
43
|
+
* @param {string} [options.font='ui-monospace, SFMono-Regular, Menlo, Consolas, monospace'] The font family.
|
|
44
|
+
* @param {number} [options.unit=0] The texture unit to leave it bound on.
|
|
45
|
+
* @returns {{ texture: WebGLTexture, count: number }} The texture and how many glyphs it holds.
|
|
46
|
+
*/
|
|
47
|
+
export function createGlyphs(gl, glyphs, { cell = 48, aspect = 0.6, font = 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', unit = 0 } = {}) {
|
|
48
|
+
const chars = [...(GLYPH_SETS[/** @type {keyof typeof GLYPH_SETS} */ (glyphs)] ?? glyphs)];
|
|
49
|
+
const width = Math.round(cell * aspect);
|
|
50
|
+
const canvas = document.createElement('canvas');
|
|
51
|
+
canvas.width = width * chars.length;
|
|
52
|
+
canvas.height = cell;
|
|
53
|
+
const ctx = /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
|
|
54
|
+
ctx.fillStyle = '#fff';
|
|
55
|
+
ctx.textAlign = 'center';
|
|
56
|
+
ctx.textBaseline = 'middle';
|
|
57
|
+
ctx.font = `${Math.round(cell * 0.92)}px ${font}`;
|
|
58
|
+
if (glyphs === 'data') {
|
|
59
|
+
// Drawn as rectangles: a solid bar nearly the cell's height (rows of
|
|
60
|
+
// them touch), and a smaller hollow one in a fine line.
|
|
61
|
+
const line = Math.max(2, cell * 0.08);
|
|
62
|
+
chars.forEach((ch, i) => {
|
|
63
|
+
const [w, h] = ch === '▮' ? [width * 0.6, cell * 0.94] : [width * 0.62, cell * 0.76];
|
|
64
|
+
const x = (i + 0.5) * width - w / 2;
|
|
65
|
+
const y = (cell - h) / 2;
|
|
66
|
+
if (ch === '_') {
|
|
67
|
+
ctx.fillRect(x, cell * 0.97 - line, w, line);
|
|
68
|
+
} else if (ch === '▯') {
|
|
69
|
+
ctx.fillRect(x, y, w, line);
|
|
70
|
+
ctx.fillRect(x, y + h - line, w, line);
|
|
71
|
+
ctx.fillRect(x, y, line, h);
|
|
72
|
+
ctx.fillRect(x + w - line, y, line, h);
|
|
73
|
+
} else if (ch === '▮') {
|
|
74
|
+
ctx.fillRect(x, y, w, h);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
chars.forEach((ch, i) => ctx.fillText(ch, (i + 0.5) * width, cell * 0.52));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const texture = /** @type {WebGLTexture} */ (gl.createTexture());
|
|
82
|
+
gl.activeTexture(gl.TEXTURE0 + unit);
|
|
83
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
84
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
85
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
86
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
87
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
88
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
89
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
|
|
90
|
+
return { texture, count: chars.length };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* GLSL (ES 1.00) for reading the strip: declares `uGlyphs` and
|
|
95
|
+
* `uGlyphCount`, and `float glyph(vec2 cellUv, float level)`, the coverage
|
|
96
|
+
* of the glyph for a brightness `level` (0–1) at a point in its cell
|
|
97
|
+
* (`cellUv` 0–1, y up).
|
|
98
|
+
*/
|
|
99
|
+
export const GLSL_GLYPHS = `
|
|
100
|
+
uniform sampler2D uGlyphs;
|
|
101
|
+
uniform float uGlyphCount;
|
|
102
|
+
float glyph(vec2 cellUv, float level) {
|
|
103
|
+
float index = floor(clamp(level, 0.0, 1.0) * (uGlyphCount - 1.0) + 0.5);
|
|
104
|
+
vec2 at = vec2((index + clamp(cellUv.x, 0.02, 0.98)) / uGlyphCount, 1.0 - clamp(cellUv.y, 0.02, 0.98));
|
|
105
|
+
return texture2D(uGlyphs, at).a;
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
|
|
3
|
+
/** The ring's outline. */
|
|
4
|
+
export type HaloShape = 'morph' | 'hexagon' | 'rect' | 'circle';
|
|
5
|
+
|
|
6
|
+
export interface HaloRingConfig {
|
|
7
|
+
/** Three colours looped around the ring, blended in Oklab. Default amber, coral, electric blue (`['#ffb020', '#ff5a6e', '#2f7bff']`). */
|
|
8
|
+
colors?: string[];
|
|
9
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
|
|
10
|
+
palette?: PaletteName | (string & {});
|
|
11
|
+
/** The outline: a rounded hexagon, a rounded rectangle fitted to the element, a circle, or a slow drift between the hexagon and a squarer rectangle. Default `morph`. */
|
|
12
|
+
shape?: HaloShape;
|
|
13
|
+
/** How round the corners are: 0 sharp, 1 as round as they go. Default 0.3. */
|
|
14
|
+
corner?: number;
|
|
15
|
+
/** Space between the ring and the element's edge, a share of its shorter side. Default 0.05. */
|
|
16
|
+
margin?: number;
|
|
17
|
+
/** The bright core line, CSS px. Default 10. */
|
|
18
|
+
thickness?: number;
|
|
19
|
+
/** How far and how strongly the light spreads; 0 for the bare line. Default 1. */
|
|
20
|
+
glow?: number;
|
|
21
|
+
/** How fast the colour travels and the shape drifts; 0 holds it still. Default 1. */
|
|
22
|
+
speed?: number;
|
|
23
|
+
/** The ground. Default `#0d0c10`. */
|
|
24
|
+
background?: string;
|
|
25
|
+
/** Whether the ring leans towards the pointer and lights up near it. Default true. */
|
|
26
|
+
interactive?: boolean;
|
|
27
|
+
/** An area kept dim behind copy: centre (0–1 from the top left), radius (a share of the height), depth (0–1). Default none; `{}` for the middle. */
|
|
28
|
+
quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The ring's sizes in pixels for a canvas: hexagon inradius and half length (`reach`), rectangle half size, circle radius and corner radius; `upright` when the shape is measured on its side for a tall canvas and turned a quarter (the hexagon and rectangle then stretch along the longer side). */
|
|
32
|
+
export function ringSize(
|
|
33
|
+
width: number,
|
|
34
|
+
height: number,
|
|
35
|
+
shape: HaloShape,
|
|
36
|
+
margin: number,
|
|
37
|
+
corner: number,
|
|
38
|
+
): { hex: number; reach: number; box: [number, number]; circle: number; corner: number; upright: boolean };
|
|
39
|
+
|
|
40
|
+
/** How far the outline is from the hexagon (0) to the rectangle (1) at `time`; only `morph` changes. */
|
|
41
|
+
export function shapeBlend(shape: HaloShape, time: number): number;
|
|
42
|
+
|
|
43
|
+
/** The outline's six corners before rounding, counter-clockwise from the right, two floats a corner, px from the centre: the hexagon's and the rectangle's blended by `blend`, pulled in by the corner radius. */
|
|
44
|
+
export function outline(size: { hex: number; reach: number; box: [number, number]; corner: number }, blend: number): Float32Array;
|
|
45
|
+
|
|
46
|
+
/** Starts a halo ring in `el`'s canvas. Returns a function that stops it. */
|
|
47
|
+
export function haloRing(el: HTMLElement, config: HaloRingConfig): () => void;
|