@arraypress/effects-astro 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +303 -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,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/particle-logo
|
|
3
|
+
*
|
|
4
|
+
* A logo or a word drawn in thousands of twinkling particles. They breathe
|
|
5
|
+
* in place; near the pointer they scatter outward and swirl round it, then
|
|
6
|
+
* drift home as it passes, and the whole mark tilts towards the pointer in
|
|
7
|
+
* a gentle perspective. Each dot is drawn with its red and blue a little
|
|
8
|
+
* apart, and two slow blooms of colour glow behind.
|
|
9
|
+
*
|
|
10
|
+
* The motion is worked out per particle on the GPU from where it lives and
|
|
11
|
+
* a seed, so there is no simulation to step: 16,000 particles cost one
|
|
12
|
+
* draw (three with the colour split).
|
|
13
|
+
*
|
|
14
|
+
* Opaque: the effect is the whole background of what it fills. Without
|
|
15
|
+
* WebGL it removes its canvas and the element's background shows.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { createStage } from './stage.js';
|
|
19
|
+
import { createPoints, GLSL_PROJECT } from './points.js';
|
|
20
|
+
import { drawShape, samplePoints } from './shape.js';
|
|
21
|
+
import { parseColor } from './color.js';
|
|
22
|
+
import { canHover, isMobileGpu } from './device.js';
|
|
23
|
+
import { pointerIn } from './pointer.js';
|
|
24
|
+
import { watchColors } from './mount.js';
|
|
25
|
+
import { pickColors } from './palettes.js';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} ParticleLogoConfig
|
|
29
|
+
* @property {string} [text] A word to draw in particles.
|
|
30
|
+
* @property {string} [font] Its CSS font, without the size (default: the page's, bold).
|
|
31
|
+
* @property {string} [src] An image (an SVG logo) to draw in particles instead.
|
|
32
|
+
* @property {{ x: number, y: number, width: number, height: number }} [area]
|
|
33
|
+
* Where the shape sits, each 0–1 from the top left (default: the middle).
|
|
34
|
+
* @property {string[]} [colors] The dots' two colours, then the two blooms' (default white and ice blue, deep teal and midnight blue).
|
|
35
|
+
* @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`. White dots, then its three colours.
|
|
36
|
+
* @property {string} [background='#030305'] The ground.
|
|
37
|
+
* @property {number} [count=16000] How many particles (half on phones).
|
|
38
|
+
* @property {number} [size=2.2] A particle's size, CSS px.
|
|
39
|
+
* @property {number} [swarm=1] How strongly they scatter round the pointer; 0 for not at all.
|
|
40
|
+
* @property {number} [tilt=1] How far the mark tilts towards the pointer.
|
|
41
|
+
* @property {number} [aberration=1.5] How far red and blue part, CSS px; 0 for none.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/** The ground and its two blooms. */
|
|
45
|
+
const GROUND = `
|
|
46
|
+
precision highp float;
|
|
47
|
+
uniform vec2 uRes;
|
|
48
|
+
uniform float uTime;
|
|
49
|
+
uniform vec3 uGround;
|
|
50
|
+
uniform vec3 uBloomA;
|
|
51
|
+
uniform vec3 uBloomB;
|
|
52
|
+
void main() {
|
|
53
|
+
vec2 uv = gl_FragCoord.xy / uRes;
|
|
54
|
+
vec2 aspect = vec2(uRes.x / uRes.y, 1.0);
|
|
55
|
+
vec2 a = (uv - vec2(0.08 + 0.04 * sin(uTime * 0.11), 0.7)) * aspect;
|
|
56
|
+
vec2 b = (uv - vec2(0.92, 0.25 + 0.05 * cos(uTime * 0.09))) * aspect;
|
|
57
|
+
vec3 col = uGround + uBloomA * exp(-dot(a, a) * 2.2) * 0.6 + uBloomB * exp(-dot(b, b) * 2.0) * 0.55;
|
|
58
|
+
gl_FragColor = vec4(col, 1.0);
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
/** Each particle: home (x, y), seed; breathing, the swarm, the tilt. */
|
|
63
|
+
const VERTEX = `
|
|
64
|
+
precision highp float;
|
|
65
|
+
attribute vec4 p;
|
|
66
|
+
uniform vec2 uRes;
|
|
67
|
+
uniform float uTime;
|
|
68
|
+
uniform float uRatio;
|
|
69
|
+
uniform vec2 uShift;
|
|
70
|
+
uniform vec2 uPtr;
|
|
71
|
+
uniform float uActive;
|
|
72
|
+
uniform vec2 uTilt;
|
|
73
|
+
uniform float uSize;
|
|
74
|
+
uniform float uSwarm;
|
|
75
|
+
uniform vec3 uDotA;
|
|
76
|
+
uniform vec3 uDotB;
|
|
77
|
+
varying vec3 vColour;
|
|
78
|
+
varying float vAlpha;
|
|
79
|
+
${GLSL_PROJECT}
|
|
80
|
+
void main() {
|
|
81
|
+
float aspect = uRes.x / uRes.y;
|
|
82
|
+
float s = p.z;
|
|
83
|
+
vec3 v = vec3((p.x * 2.0 - 1.0) * aspect, p.y * 2.0 - 1.0, (fract(s * 17.3) - 0.5) * 0.12);
|
|
84
|
+
// Breathing in place.
|
|
85
|
+
v.xy += 0.006 * vec2(sin(uTime * (0.6 + s) + s * 40.0), cos(uTime * (0.5 + s * 0.7) + s * 17.0));
|
|
86
|
+
// Round the pointer: out, and swirling, half one way and half the other.
|
|
87
|
+
vec2 ptr = vec2((uPtr.x * 2.0 - 1.0) * aspect, uPtr.y * 2.0 - 1.0);
|
|
88
|
+
vec2 d = v.xy - ptr;
|
|
89
|
+
float dist = length(d) + 1e-3;
|
|
90
|
+
float f = exp(-dist * dist / 0.07) * uActive * uSwarm;
|
|
91
|
+
vec2 out_ = d / dist;
|
|
92
|
+
v.xy += out_ * f * 0.22 + vec2(-out_.y, out_.x) * f * 0.2 * (s > 0.5 ? 1.0 : -1.0);
|
|
93
|
+
v.z += f * (s - 0.3) * 0.8;
|
|
94
|
+
// Towards the pointer, in perspective.
|
|
95
|
+
v = rotateY(v, uTilt.x * 0.35);
|
|
96
|
+
v = rotateX(v, -uTilt.y * 0.25);
|
|
97
|
+
vec4 pos = project(v, aspect);
|
|
98
|
+
gl_Position = pos + vec4(uShift * pos.w, 0.0, 0.0);
|
|
99
|
+
float twinkle = 0.55 + 0.45 * sin(uTime * (1.5 + s * 3.0) + s * 60.0);
|
|
100
|
+
gl_PointSize = uSize * uRatio * (0.6 + 0.9 * fract(s * 7.13)) * (0.8 + 0.4 * twinkle) / pos.w;
|
|
101
|
+
vColour = mix(uDotA, uDotB, fract(s * 3.7));
|
|
102
|
+
vAlpha = twinkle * 0.9;
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
|
|
106
|
+
/** The defaults: white and ice-blue dots, a deep teal and a midnight-blue bloom. */
|
|
107
|
+
const COLORS = ['#ffffff', '#a5c8ff', '#0f4c5c', '#0b1f3a'];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Starts a particle logo on an element: an opaque canvas inside it, filling it.
|
|
111
|
+
*
|
|
112
|
+
* @param {HTMLElement} el The element (its first canvas is drawn into).
|
|
113
|
+
* @param {ParticleLogoConfig} config The settings.
|
|
114
|
+
* @returns {() => void} Stops it.
|
|
115
|
+
*/
|
|
116
|
+
export function particleLogo(el, config) {
|
|
117
|
+
let colors = pickColors(config, COLORS, (p) => ['#ffffff', ...p.colors]);
|
|
118
|
+
const start = performance.now();
|
|
119
|
+
const ptr = { x: 0.5, y: 0.5 };
|
|
120
|
+
const tilt = { x: 0, y: 0 };
|
|
121
|
+
let active = 0;
|
|
122
|
+
/** @type {import('./points.js').Points | null} */
|
|
123
|
+
let points = null;
|
|
124
|
+
let generation = 0;
|
|
125
|
+
const count = Math.round((config.count ?? 16000) * (isMobileGpu() ? 0.5 : 1));
|
|
126
|
+
|
|
127
|
+
const { stage, stop } = createStage(el, {
|
|
128
|
+
fragment: GROUND,
|
|
129
|
+
alpha: false,
|
|
130
|
+
setup({ gl, program }) {
|
|
131
|
+
points = createPoints(gl, VERTEX);
|
|
132
|
+
if (!points) return false;
|
|
133
|
+
gl.useProgram(program);
|
|
134
|
+
},
|
|
135
|
+
resize({ canvas }) {
|
|
136
|
+
const mine = ++generation;
|
|
137
|
+
const width = Math.min(1024, canvas.width);
|
|
138
|
+
const height = Math.max(1, Math.round((width * canvas.height) / canvas.width));
|
|
139
|
+
drawShape({ text: config.text, font: config.font, src: config.src, area: config.area, padding: 0.12 }, width, height)
|
|
140
|
+
.then((mask) => {
|
|
141
|
+
if (mine !== generation || !points) return;
|
|
142
|
+
const homes = samplePoints(mask, count);
|
|
143
|
+
const data = new Float32Array(count * 4);
|
|
144
|
+
for (let i = 0; i < count; i++) {
|
|
145
|
+
data.set([homes[i * 2], homes[i * 2 + 1], Math.random(), 0], i * 4);
|
|
146
|
+
}
|
|
147
|
+
points.upload(data);
|
|
148
|
+
if (stage?.still) stage.redraw();
|
|
149
|
+
})
|
|
150
|
+
.catch((error) => console.warn('[effects-astro]', error));
|
|
151
|
+
},
|
|
152
|
+
uniforms({ gl, uniform }, now) {
|
|
153
|
+
gl.uniform1f(uniform('uTime'), (now - start) / 1000);
|
|
154
|
+
gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#030305'));
|
|
155
|
+
gl.uniform3fv(uniform('uBloomA'), parseColor(colors[2] ?? COLORS[2]));
|
|
156
|
+
gl.uniform3fv(uniform('uBloomB'), parseColor(colors[3] ?? colors[2] ?? COLORS[3]));
|
|
157
|
+
},
|
|
158
|
+
after({ gl, ratio, still }, now) {
|
|
159
|
+
if (!points?.count()) return;
|
|
160
|
+
const t = (now - start) / 1000;
|
|
161
|
+
const p = !still && canHover() ? pointerIn(el) : null;
|
|
162
|
+
if (p?.inside) {
|
|
163
|
+
ptr.x += (p.x - ptr.x) * 0.12;
|
|
164
|
+
ptr.y += (p.y - ptr.y) * 0.12;
|
|
165
|
+
}
|
|
166
|
+
active += ((p?.inside ? 1 : 0) - active) * 0.06;
|
|
167
|
+
// Towards the pointer, or a slow sway without one.
|
|
168
|
+
const lean = p?.inside ? { x: (p.x - 0.5) * 2, y: (p.y - 0.5) * 2 } : { x: Math.sin(t * 0.3) * 0.3, y: Math.sin(t * 0.23) * 0.2 };
|
|
169
|
+
tilt.x += (lean.x * (config.tilt ?? 1) - tilt.x) * 0.05;
|
|
170
|
+
tilt.y += (lean.y * (config.tilt ?? 1) - tilt.y) * 0.05;
|
|
171
|
+
const u = points.program.uniform;
|
|
172
|
+
points.passes((config.aberration ?? 1.5) * ratio, () => {
|
|
173
|
+
gl.uniform2f(u('uRes'), gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
174
|
+
gl.uniform1f(u('uTime'), t);
|
|
175
|
+
gl.uniform1f(u('uRatio'), ratio);
|
|
176
|
+
gl.uniform2f(u('uPtr'), ptr.x, ptr.y);
|
|
177
|
+
gl.uniform1f(u('uActive'), active);
|
|
178
|
+
gl.uniform2f(u('uTilt'), tilt.x, tilt.y);
|
|
179
|
+
gl.uniform1f(u('uSize'), config.size ?? 2.2);
|
|
180
|
+
gl.uniform1f(u('uSwarm'), config.swarm ?? 1);
|
|
181
|
+
gl.uniform3fv(u('uDotA'), parseColor(colors[0]));
|
|
182
|
+
gl.uniform3fv(u('uDotB'), parseColor(colors[1] ?? colors[0]));
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
if (!stage) return stop;
|
|
187
|
+
|
|
188
|
+
const unwatch = watchColors(el, (next) => {
|
|
189
|
+
colors = next.colors;
|
|
190
|
+
if (stage.still) stage.redraw();
|
|
191
|
+
});
|
|
192
|
+
return () => {
|
|
193
|
+
stop();
|
|
194
|
+
unwatch();
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GL } from './gl.js';
|
|
2
|
+
|
|
3
|
+
/** A float texture format a context offers for render targets. */
|
|
4
|
+
export interface FloatFormat {
|
|
5
|
+
/** The internal format. */
|
|
6
|
+
internal: number;
|
|
7
|
+
/** The texel type. */
|
|
8
|
+
type: number;
|
|
9
|
+
/** Whether it can be filtered linearly. */
|
|
10
|
+
linear: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A texture and the framebuffer that draws into it. */
|
|
14
|
+
export interface Target {
|
|
15
|
+
texture: WebGLTexture;
|
|
16
|
+
fbo: WebGLFramebuffer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Two float targets: read one, write the other, swap. */
|
|
20
|
+
export interface PingPong {
|
|
21
|
+
/** The target read this step. */
|
|
22
|
+
read: Target;
|
|
23
|
+
/** The target written this step. */
|
|
24
|
+
write: Target;
|
|
25
|
+
/** Swaps them, after a step. */
|
|
26
|
+
swap(): void;
|
|
27
|
+
/** Reallocates both at a new size, cleared; false if the GPU will not draw into them. */
|
|
28
|
+
resize(width: number, height: number): boolean;
|
|
29
|
+
/** Clears both to zero (leaves the canvas bound). */
|
|
30
|
+
clear(): void;
|
|
31
|
+
/** Their size, texels. */
|
|
32
|
+
size(): { width: number; height: number };
|
|
33
|
+
/** Whether they are filtered linearly (else nearest). */
|
|
34
|
+
linear: boolean;
|
|
35
|
+
/** Frees the textures and framebuffers. */
|
|
36
|
+
dispose(): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The float formats a context offers for render targets, best first (full floats, then half). */
|
|
40
|
+
export function floatFormats(gl: GL): FloatFormat[];
|
|
41
|
+
|
|
42
|
+
/** Makes a pair of float targets, cleared; null where the GPU cannot draw into float textures. Uses texture unit 0 while allocating. */
|
|
43
|
+
export function createPingPong(gl: GL, width: number, height: number): PingPong | null;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ping-pong
|
|
3
|
+
*
|
|
4
|
+
* Two float render targets for a simulation on the GPU: each step reads
|
|
5
|
+
* one and writes the other, then they swap. Full floats where the GPU can
|
|
6
|
+
* draw into and filter them, else half floats; none where it can do
|
|
7
|
+
* neither. WebGL 1 or 2. Uses texture unit 0 while it allocates.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const state = createPingPong(gl, 256, 128);
|
|
11
|
+
* gl.bindFramebuffer(gl.FRAMEBUFFER, state.write.fbo);
|
|
12
|
+
* // …bind state.read.texture, draw a pass…
|
|
13
|
+
* state.swap();
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A float texture format a context offers for render targets.
|
|
18
|
+
*
|
|
19
|
+
* @typedef {object} FloatFormat
|
|
20
|
+
* @property {number} internal The internal format.
|
|
21
|
+
* @property {number} type The texel type.
|
|
22
|
+
* @property {boolean} linear Whether it can be filtered linearly.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A texture and the framebuffer that draws into it.
|
|
27
|
+
*
|
|
28
|
+
* @typedef {object} Target
|
|
29
|
+
* @property {WebGLTexture} texture The texture.
|
|
30
|
+
* @property {WebGLFramebuffer} fbo The framebuffer.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {object} PingPong
|
|
35
|
+
* @property {Target} read The target read this step.
|
|
36
|
+
* @property {Target} write The target written this step.
|
|
37
|
+
* @property {() => void} swap Swaps them, after a step.
|
|
38
|
+
* @property {(width: number, height: number) => boolean} resize Reallocates
|
|
39
|
+
* both at a new size, cleared; false if the GPU will not draw into them.
|
|
40
|
+
* @property {() => void} clear Clears both to zero.
|
|
41
|
+
* @property {() => { width: number, height: number }} size Their size, texels.
|
|
42
|
+
* @property {boolean} linear Whether they are filtered linearly (else nearest).
|
|
43
|
+
* @property {() => void} dispose Frees the textures and framebuffers.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The float formats a context offers for render targets, best first: full
|
|
48
|
+
* floats where they can be filtered, then half floats, filtered where they
|
|
49
|
+
* can be. Asks for the extensions it needs on the way.
|
|
50
|
+
*
|
|
51
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
|
|
52
|
+
* @returns {FloatFormat[]} The candidates (not yet proven drawable).
|
|
53
|
+
*/
|
|
54
|
+
export function floatFormats(gl) {
|
|
55
|
+
/** @type {FloatFormat[]} */
|
|
56
|
+
const formats = [];
|
|
57
|
+
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
58
|
+
const color = gl.getExtension('EXT_color_buffer_float');
|
|
59
|
+
if (color && gl.getExtension('OES_texture_float_linear')) formats.push({ internal: gl.RGBA32F, type: gl.FLOAT, linear: true });
|
|
60
|
+
// Half floats always filter in WebGL 2.
|
|
61
|
+
if (color || gl.getExtension('EXT_color_buffer_half_float')) formats.push({ internal: gl.RGBA16F, type: gl.HALF_FLOAT, linear: true });
|
|
62
|
+
return formats;
|
|
63
|
+
}
|
|
64
|
+
const full = gl.getExtension('OES_texture_float');
|
|
65
|
+
if (full && gl.getExtension('OES_texture_float_linear')) {
|
|
66
|
+
gl.getExtension('WEBGL_color_buffer_float');
|
|
67
|
+
formats.push({ internal: gl.RGBA, type: gl.FLOAT, linear: true });
|
|
68
|
+
}
|
|
69
|
+
const half = gl.getExtension('OES_texture_half_float');
|
|
70
|
+
if (half) {
|
|
71
|
+
gl.getExtension('EXT_color_buffer_half_float');
|
|
72
|
+
formats.push({ internal: gl.RGBA, type: half.HALF_FLOAT_OES, linear: !!gl.getExtension('OES_texture_half_float_linear') });
|
|
73
|
+
}
|
|
74
|
+
return formats;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Makes a pair of float targets, cleared.
|
|
79
|
+
*
|
|
80
|
+
* @param {WebGLRenderingContext | WebGL2RenderingContext} gl The context.
|
|
81
|
+
* @param {number} width Texels across.
|
|
82
|
+
* @param {number} height Texels down.
|
|
83
|
+
* @returns {PingPong | null} The pair, or null where the GPU cannot draw into float textures.
|
|
84
|
+
*/
|
|
85
|
+
export function createPingPong(gl, width, height) {
|
|
86
|
+
const targets = [0, 1].map(() => ({
|
|
87
|
+
texture: /** @type {WebGLTexture} */ (gl.createTexture()),
|
|
88
|
+
fbo: /** @type {WebGLFramebuffer} */ (gl.createFramebuffer()),
|
|
89
|
+
}));
|
|
90
|
+
let w = 1;
|
|
91
|
+
let h = 1;
|
|
92
|
+
|
|
93
|
+
/** Frees both targets. */
|
|
94
|
+
const dispose = () => {
|
|
95
|
+
for (const { texture, fbo } of targets) {
|
|
96
|
+
gl.deleteTexture(texture);
|
|
97
|
+
gl.deleteFramebuffer(fbo);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Allocates both targets in a format, cleared.
|
|
103
|
+
*
|
|
104
|
+
* @param {FloatFormat} format The format.
|
|
105
|
+
* @returns {boolean} Whether the GPU can draw into them.
|
|
106
|
+
*/
|
|
107
|
+
const allocate = (format) => {
|
|
108
|
+
const filter = format.linear ? gl.LINEAR : gl.NEAREST;
|
|
109
|
+
for (const { texture, fbo } of targets) {
|
|
110
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
111
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
112
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);
|
|
113
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
|
|
114
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
115
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
116
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, format.internal, w, h, 0, gl.RGBA, format.type, null);
|
|
117
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
118
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
119
|
+
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** Clears both targets to zero, and leaves the canvas bound. */
|
|
125
|
+
const clear = () => {
|
|
126
|
+
gl.clearColor(0, 0, 0, 0);
|
|
127
|
+
for (const { fbo } of targets) {
|
|
128
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
|
|
129
|
+
gl.viewport(0, 0, w, h);
|
|
130
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
131
|
+
}
|
|
132
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
w = Math.max(1, Math.round(width));
|
|
136
|
+
h = Math.max(1, Math.round(height));
|
|
137
|
+
const format = floatFormats(gl).find(allocate);
|
|
138
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
139
|
+
if (!format) {
|
|
140
|
+
dispose();
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
clear();
|
|
144
|
+
const chosen = format;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Sizes both targets, cleared.
|
|
148
|
+
*
|
|
149
|
+
* @param {number} width Texels across.
|
|
150
|
+
* @param {number} height Texels down.
|
|
151
|
+
* @returns {boolean} Whether the GPU can draw into them.
|
|
152
|
+
*/
|
|
153
|
+
const resize = (width, height) => {
|
|
154
|
+
w = Math.max(1, Math.round(width));
|
|
155
|
+
h = Math.max(1, Math.round(height));
|
|
156
|
+
const ok = allocate(chosen);
|
|
157
|
+
clear();
|
|
158
|
+
return ok;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** @type {PingPong} */
|
|
162
|
+
const pair = {
|
|
163
|
+
read: targets[0],
|
|
164
|
+
write: targets[1],
|
|
165
|
+
swap() {
|
|
166
|
+
[pair.read, pair.write] = [pair.write, pair.read];
|
|
167
|
+
},
|
|
168
|
+
resize,
|
|
169
|
+
clear,
|
|
170
|
+
size: () => ({ width: w, height: h }),
|
|
171
|
+
linear: format.linear,
|
|
172
|
+
dispose,
|
|
173
|
+
};
|
|
174
|
+
return pair;
|
|
175
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PixelGlitchConfig {
|
|
2
|
+
/** The heat grid's cell, CSS px. Default 14. */
|
|
3
|
+
cell?: number;
|
|
4
|
+
/** How far the pointer's heat reaches, CSS px. Default 120. */
|
|
5
|
+
reach?: number;
|
|
6
|
+
/** Heat kept each frame (0.9 is gone in about half a second). Default 0.9. */
|
|
7
|
+
decay?: number;
|
|
8
|
+
/** The pixel block size at full heat, CSS px. Default 22. */
|
|
9
|
+
block?: number;
|
|
10
|
+
/** How far the hottest rows slip sideways, CSS px. Default 16. */
|
|
11
|
+
shift?: number;
|
|
12
|
+
/** With a width (CSS px), the text at rest is an outline that the pixels fill. Default 0 (solid). */
|
|
13
|
+
stroke?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Starts the pixel glitch on an element of text. Returns a function that stops it. */
|
|
17
|
+
export function pixelGlitch(el: HTMLElement, config: PixelGlitchConfig): () => void;
|