@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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ramp
|
|
3
|
+
*
|
|
4
|
+
* A gradient for shaders: up to MAX_COLORS colours in Oklab (from
|
|
5
|
+
* `gradientUniform`), read at any point from the first to the last. Each
|
|
6
|
+
* stretch between two colours is blended in Oklab, so a ramp from navy to
|
|
7
|
+
* sand never passes through grey.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { MAX_COLORS } from './dot-surface.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* GLSL (ES 1.00): `uniform vec3 uRamp[MAX_COLORS]` (Oklab, from
|
|
14
|
+
* `gradientUniform`), `uniform float uRamps` (how many are set) and
|
|
15
|
+
* `vec3 ramp(float t)`, the gradient at t (0 the first colour, 1 the
|
|
16
|
+
* last), in Oklab.
|
|
17
|
+
*/
|
|
18
|
+
export const GLSL_RAMP = `
|
|
19
|
+
uniform vec3 uRamp[${MAX_COLORS}];
|
|
20
|
+
uniform float uRamps;
|
|
21
|
+
vec3 ramp(float t) {
|
|
22
|
+
float x = clamp(t, 0.0, 1.0) * (uRamps - 1.0);
|
|
23
|
+
float i = min(floor(x), max(uRamps - 2.0, 0.0));
|
|
24
|
+
vec3 a = uRamp[0], b = uRamp[0];
|
|
25
|
+
for (int n = 0; n < ${MAX_COLORS - 1}; n++) {
|
|
26
|
+
if (float(n) == i) { a = uRamp[n]; b = uRamp[n + 1]; }
|
|
27
|
+
}
|
|
28
|
+
return uRamps > 1.0 ? mix(a, b, x - i) : a;
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/random
|
|
3
|
+
*
|
|
4
|
+
* A small seeded random generator (mulberry32), for effects that build
|
|
5
|
+
* something from a `seed` and must build the same thing on every load.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Makes a seeded generator: the same seed gives the same sequence.
|
|
10
|
+
*
|
|
11
|
+
* @param {number} seed Any number; its integer part is used.
|
|
12
|
+
* @returns {() => number} The next value, 0 (inclusive) to 1 (exclusive).
|
|
13
|
+
*/
|
|
14
|
+
export function seededRandom(seed) {
|
|
15
|
+
let s = Math.floor(seed) >>> 0;
|
|
16
|
+
return () => {
|
|
17
|
+
s = (s + 0x6d2b79f5) >>> 0;
|
|
18
|
+
let t = Math.imul(s ^ (s >>> 15), 1 | s);
|
|
19
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
20
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The classes reveal.css styles, as a selector list. */
|
|
2
|
+
export const REVEAL_CLASSES: string;
|
|
3
|
+
|
|
4
|
+
export interface ScrollRevealConfig {
|
|
5
|
+
/** What to reveal. Default the reveal.css classes. */
|
|
6
|
+
selector?: string;
|
|
7
|
+
/** The class added on arrival. Default `is-visible`. */
|
|
8
|
+
visibleClass?: string;
|
|
9
|
+
/** How much must be in view, 0–1. Default 0.08. */
|
|
10
|
+
threshold?: number;
|
|
11
|
+
/** The observer's margin. Default `0px 0px -10% 0px`. */
|
|
12
|
+
rootMargin?: string;
|
|
13
|
+
/** Reveal once; false hides it again when it leaves, to replay. Default true. */
|
|
14
|
+
once?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adds `visibleClass` to each matching element as it scrolls into view
|
|
19
|
+
* (at once if already on screen), and marks the page `.fx-reveal`. Calling
|
|
20
|
+
* it again replaces the previous run. Returns a function that stops it.
|
|
21
|
+
*/
|
|
22
|
+
export function scrollReveal(config?: ScrollRevealConfig): () => void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/scroll-reveal
|
|
3
|
+
*
|
|
4
|
+
* Scroll reveal for a whole page from one IntersectionObserver: every
|
|
5
|
+
* element matching the selector gets a class (`is-visible`) as it scrolls
|
|
6
|
+
* into view, and the stylesheet (reveal.css, or your own) animates it
|
|
7
|
+
* there. Elements already on screen are shown at once, so nothing
|
|
8
|
+
* flashes. Marks the page `.fx-reveal` so that, until it runs, nothing is
|
|
9
|
+
* hidden. With prefers-reduced-motion it does nothing, and all shows.
|
|
10
|
+
*
|
|
11
|
+
* Runs again after each Astro view transition, picking up only the
|
|
12
|
+
* elements not yet shown.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { prefersReducedMotion } from './device.js';
|
|
16
|
+
|
|
17
|
+
/** The classes reveal.css styles. */
|
|
18
|
+
export const REVEAL_CLASSES =
|
|
19
|
+
'.fade-in, .fade-in-up, .fade-in-down, .fade-in-left, .fade-in-right, .slide-in-up, .slide-in-down, .slide-in-left, .slide-in-right, .zoom-in, .zoom-out, .flip-up, .flip-down, .flip-left, .flip-right, .blur-in';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {object} ScrollRevealConfig
|
|
23
|
+
* @property {string} [selector] What to reveal. Default the reveal.css classes.
|
|
24
|
+
* @property {string} [visibleClass='is-visible'] The class added on arrival.
|
|
25
|
+
* @property {number} [threshold=0.08] How much must be in view, 0–1.
|
|
26
|
+
* @property {string} [rootMargin='0px 0px -10% 0px'] The observer's margin.
|
|
27
|
+
* @property {boolean} [once=true] Reveal once; false hides it again when it leaves, to replay.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** @type {IntersectionObserver | null} */
|
|
31
|
+
let observer = null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Starts revealing the page's matching elements (again, after a view
|
|
35
|
+
* transition: the previous observer is let go).
|
|
36
|
+
*
|
|
37
|
+
* @param {ScrollRevealConfig} [config] The settings.
|
|
38
|
+
* @returns {() => void} Stops it.
|
|
39
|
+
*/
|
|
40
|
+
export function scrollReveal(config = {}) {
|
|
41
|
+
const visible = config.visibleClass ?? 'is-visible';
|
|
42
|
+
const once = config.once !== false;
|
|
43
|
+
observer?.disconnect();
|
|
44
|
+
observer = null;
|
|
45
|
+
if (prefersReducedMotion() || typeof IntersectionObserver === 'undefined') return () => {};
|
|
46
|
+
document.documentElement.classList.add('fx-reveal');
|
|
47
|
+
|
|
48
|
+
const watcher = new IntersectionObserver(
|
|
49
|
+
(entries) => {
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (entry.isIntersecting) {
|
|
52
|
+
entry.target.classList.add(visible);
|
|
53
|
+
if (once) watcher.unobserve(entry.target);
|
|
54
|
+
} else if (!once) {
|
|
55
|
+
entry.target.classList.remove(visible);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{ threshold: config.threshold ?? 0.08, rootMargin: config.rootMargin ?? '0px 0px -10% 0px' },
|
|
60
|
+
);
|
|
61
|
+
observer = watcher;
|
|
62
|
+
|
|
63
|
+
const pending = (config.selector ?? REVEAL_CLASSES)
|
|
64
|
+
.split(',')
|
|
65
|
+
.map((part) => `${part.trim()}:not(.${visible})`)
|
|
66
|
+
.join(',');
|
|
67
|
+
document.querySelectorAll(pending).forEach((el) => {
|
|
68
|
+
const box = el.getBoundingClientRect();
|
|
69
|
+
if (box.top < innerHeight && box.bottom > 0) el.classList.add(visible);
|
|
70
|
+
else watcher.observe(el);
|
|
71
|
+
});
|
|
72
|
+
return () => watcher.disconnect();
|
|
73
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
import type { Rgb } from './color.js';
|
|
3
|
+
|
|
4
|
+
/** The six shader backgrounds. */
|
|
5
|
+
export type ShaderBackgroundName = 'mesh-gradient' | 'grain-gradient' | 'silk' | 'band-lens' | 'grid' | 'waves';
|
|
6
|
+
|
|
7
|
+
export interface ShaderBackgroundConfig {
|
|
8
|
+
/** Which shader background. */
|
|
9
|
+
effect: ShaderBackgroundName;
|
|
10
|
+
/** Up to four colours (hex or `rgb()`); those missing come from `--color-accent` where it sits: the accent, the accent towards `--color-bg`, its hue turned 30° towards yellow and lifted, its hue turned 45° away from yellow (in Oklab). Only mesh-gradient, grain-gradient and silk use the fourth. Default all four from the accent. */
|
|
11
|
+
colors?: string[];
|
|
12
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
|
|
13
|
+
palette?: PaletteName | (string & {});
|
|
14
|
+
/** How fast it moves, 0–4. Default 1. */
|
|
15
|
+
speed?: number;
|
|
16
|
+
/** How strong it is (brightness and contrast, not opacity), 0–2. Default 1. */
|
|
17
|
+
intensity?: number;
|
|
18
|
+
/** One frame, never the loop: for a shader background that is wallpaper. Default false. */
|
|
19
|
+
static?: boolean;
|
|
20
|
+
/** With `static`, the moment drawn, in seconds. Default 12. */
|
|
21
|
+
frame?: number;
|
|
22
|
+
/** Lean towards the pointer, on devices that hover. Default false. */
|
|
23
|
+
interactive?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Every shader background's fragment shader, by name. */
|
|
27
|
+
export const SHADER_BACKGROUNDS: Record<ShaderBackgroundName, string>;
|
|
28
|
+
|
|
29
|
+
/** Reads `#rgb`, `#rrggbb` or `rgb()`/`rgba()`; null for anything else. */
|
|
30
|
+
export function readColor(value: string): Rgb | null;
|
|
31
|
+
|
|
32
|
+
/** The four colours: those given (unreadable ones skipped), the rest derived from the accent and background tokens. */
|
|
33
|
+
export function shaderBackgroundPalette(from: { accent?: string; background?: string; colors?: string[] }): [Rgb, Rgb, Rgb, Rgb];
|
|
34
|
+
|
|
35
|
+
/** Speed (0–4, default 1), intensity (0–2, default 1) and the still frame (default 12), read and clamped. */
|
|
36
|
+
export function shaderBackgroundSettings(config: Partial<ShaderBackgroundConfig>): { speed: number; intensity: number; frame: number };
|
|
37
|
+
|
|
38
|
+
/** The CSS `background` that stands in without WebGL: soft pools of the first and third colours. */
|
|
39
|
+
export function shaderBackgroundFallback(palette: Rgb[]): string;
|
|
40
|
+
|
|
41
|
+
/** Starts a shader background in `el`'s canvas. Returns a function that stops it. */
|
|
42
|
+
export function shaderBackground(el: HTMLElement, config: ShaderBackgroundConfig): () => void;
|
|
@@ -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
|
+
`;
|