@ultimat3/effects 0.0.0-stage → 31.53.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.
Files changed (71) hide show
  1. package/CATALOG.md +169 -0
  2. package/CLAUDE.md +29 -0
  3. package/LICENSE +21 -0
  4. package/README.md +64 -2
  5. package/package.json +56 -4
  6. package/src/_effect.scss +53 -0
  7. package/src/aurora/Aurora.module.scss +56 -0
  8. package/src/aurora/Aurora.tsx +35 -0
  9. package/src/aurora/aurora-view.ts +32 -0
  10. package/src/backend.ts +34 -0
  11. package/src/canvas-mount.ts +61 -0
  12. package/src/count-up/CountUp.tsx +51 -0
  13. package/src/count-up/count-up-run.ts +59 -0
  14. package/src/count-up/count-up-view.ts +56 -0
  15. package/src/css-pause.ts +50 -0
  16. package/src/effect-canvas/EffectCanvas.module.scss +23 -0
  17. package/src/effect-canvas/EffectCanvas.tsx +51 -0
  18. package/src/effect-canvas/effect-canvas-view.ts +33 -0
  19. package/src/effect-host.ts +54 -0
  20. package/src/effect-mount.ts +114 -0
  21. package/src/errors.ts +33 -0
  22. package/src/glass-surface/GlassSurface.module.scss +25 -0
  23. package/src/glass-surface/GlassSurface.tsx +29 -0
  24. package/src/glass-surface/glass-surface-view.ts +33 -0
  25. package/src/gradient-orbs/GradientOrbs.module.scss +49 -0
  26. package/src/gradient-orbs/GradientOrbs.tsx +41 -0
  27. package/src/gradient-orbs/gradient-orbs-view.ts +77 -0
  28. package/src/grid-glow/GridGlow.module.scss +50 -0
  29. package/src/grid-glow/GridGlow.tsx +39 -0
  30. package/src/grid-glow/grid-glow-view.ts +40 -0
  31. package/src/index.ts +45 -0
  32. package/src/marquee/Marquee.module.scss +52 -0
  33. package/src/marquee/Marquee.tsx +31 -0
  34. package/src/marquee/marquee-view.ts +25 -0
  35. package/src/mosaic-grid/MosaicGrid.module.scss +39 -0
  36. package/src/mosaic-grid/MosaicGrid.tsx +59 -0
  37. package/src/mosaic-grid/mosaic-grid-view.ts +96 -0
  38. package/src/motion-port.ts +22 -0
  39. package/src/noise/Noise.module.scss +22 -0
  40. package/src/noise/Noise.tsx +49 -0
  41. package/src/noise/noise-view.ts +38 -0
  42. package/src/palette.ts +41 -0
  43. package/src/pixel-budget.ts +42 -0
  44. package/src/props.ts +61 -0
  45. package/src/shader-background/ShaderBackground.module.scss +70 -0
  46. package/src/shader-background/ShaderBackground.tsx +60 -0
  47. package/src/shader-background/load-preset.ts +19 -0
  48. package/src/shader-background/presets/dots.ts +59 -0
  49. package/src/shader-background/presets/grain.ts +59 -0
  50. package/src/shader-background/presets/mesh.ts +78 -0
  51. package/src/shader-background/shader-background-canvas.ts +116 -0
  52. package/src/shader-background/shader-background-view.ts +98 -0
  53. package/src/shader-background/uniform-pack.ts +11 -0
  54. package/src/shader-load.ts +17 -0
  55. package/src/shader-mount.ts +197 -0
  56. package/src/shimmer/Shimmer.module.scss +23 -0
  57. package/src/shimmer/Shimmer.tsx +19 -0
  58. package/src/spotlight-card/SpotlightCard.module.scss +29 -0
  59. package/src/spotlight-card/SpotlightCard.tsx +28 -0
  60. package/src/spotlight-card/spotlight-card-view.ts +37 -0
  61. package/src/spotlight-card/spotlight-wire.ts +34 -0
  62. package/src/text-reveal/TextReveal.module.scss +47 -0
  63. package/src/text-reveal/TextReveal.tsx +48 -0
  64. package/src/text-reveal/text-reveal-view.ts +38 -0
  65. package/src/tilt/Tilt.module.scss +18 -0
  66. package/src/tilt/Tilt.tsx +30 -0
  67. package/src/tilt/tilt-view.ts +64 -0
  68. package/src/tilt/tilt-wire.ts +50 -0
  69. package/src/use-css-pause.ts +35 -0
  70. package/src/use-effect-mount.ts +35 -0
  71. package/src/visibility.ts +26 -0
@@ -0,0 +1,49 @@
1
+ // Film grain over a surface: an SVG turbulence filter tinted with a colour role. Static by nature
2
+ // (no animation, no frame loop, no script), so it costs a `site/` page nothing and has no motion
3
+ // for reduced motion to take away.
4
+
5
+ import type { ColorRole } from '@ultimat3/ui';
6
+ import { cx, useId } from '@ultimat3/ui';
7
+ import type { JSX } from 'solid-js';
8
+ import styles from './Noise.module.scss';
9
+ import { NOISE_ALPHA_MATRIX, NOISE_BACKEND, NOISE_TURBULENCE, noiseView } from './noise-view';
10
+
11
+ export interface NoiseProps {
12
+ /** Grain opacity, 0..1. Default 0.12. */
13
+ opacity?: number | undefined;
14
+ /** The grain's colour role. Default `'fg'`. */
15
+ role?: ColorRole | undefined;
16
+ /** What the grain lies over. */
17
+ children?: JSX.Element | undefined;
18
+ class?: string | undefined;
19
+ }
20
+
21
+ export function Noise(props: NoiseProps): JSX.Element {
22
+ const view = noiseView(props);
23
+ const filter = useId('fx-noise');
24
+ return (
25
+ <div
26
+ class={cx(styles['root'], props.class)}
27
+ style={view.vars}
28
+ data-effect-backend={NOISE_BACKEND}
29
+ >
30
+ <svg class={styles['layer']} aria-hidden="true">
31
+ <filter id={filter}>
32
+ <feTurbulence
33
+ type="fractalNoise"
34
+ baseFrequency={NOISE_TURBULENCE.baseFrequency}
35
+ numOctaves={NOISE_TURBULENCE.numOctaves}
36
+ seed={NOISE_TURBULENCE.seed}
37
+ stitchTiles="stitch"
38
+ result="turbulence"
39
+ />
40
+ <feColorMatrix in="turbulence" type="matrix" values={NOISE_ALPHA_MATRIX} result="grain" />
41
+ <feFlood flood-color="currentColor" result="tint" />
42
+ <feComposite in="tint" in2="grain" operator="in" />
43
+ </filter>
44
+ <rect width="100%" height="100%" filter={`url(#${filter})`} />
45
+ </svg>
46
+ <div class={styles['content']}>{props.children}</div>
47
+ </div>
48
+ );
49
+ }
@@ -0,0 +1,38 @@
1
+ // Noise's rules: the grain's opacity, screened, and the fixed turbulence it is drawn from. Still
2
+ // by nature — an SVG filter, no animation and no frame loop — so its tier is `static` everywhere.
3
+
4
+ import type { ColorRole } from '@ultimat3/ui';
5
+ import type { EffectBackend } from '../backend';
6
+ import { rangeProp, rolesProp } from '../props';
7
+
8
+ export const NOISE_BACKEND: EffectBackend = 'static';
9
+
10
+ /** `feTurbulence` inputs. Fixed: a seed that moved would be an animation this entry promises not to be. */
11
+ export const NOISE_TURBULENCE = Object.freeze({
12
+ baseFrequency: '0.8',
13
+ numOctaves: '3',
14
+ seed: '7',
15
+ });
16
+
17
+ /** RGB dropped, alpha = 3 x luminance - 1: the grain keeps its contrast, the tint is the role's. */
18
+ export const NOISE_ALPHA_MATRIX = '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 -1';
19
+
20
+ export interface NoiseInput {
21
+ readonly opacity?: number | undefined;
22
+ readonly role?: ColorRole | undefined;
23
+ }
24
+
25
+ export interface NoiseView {
26
+ readonly vars: Record<string, string>;
27
+ }
28
+
29
+ export function noiseView(input: NoiseInput): NoiseView {
30
+ const opacity = rangeProp('Noise', 'opacity', input.opacity, { min: 0, max: 1, fallback: 0.12 });
31
+ const [role = 'fg'] = rolesProp(
32
+ 'Noise',
33
+ input.role === undefined ? undefined : [input.role],
34
+ ['fg'],
35
+ { min: 1, max: 1 },
36
+ );
37
+ return { vars: { '--fx-opacity': String(opacity), '--fx-c0': `var(--color-${role})` } };
38
+ }
package/src/palette.ts ADDED
@@ -0,0 +1,41 @@
1
+ // Colour for a canvas or a shader, read from the RESOLVED role tokens on the element — the same
2
+ // `--color-<role>` channels the stylesheet's `t.role()` reads, so a brand, a preset and dark mode
3
+ // recolour every backend at once and no entry carries a colour literal.
4
+
5
+ import type { ColorRole } from '@ultimat3/ui';
6
+ import type { EffectHost } from './effect-host';
7
+
8
+ /** One colour, each channel 0..1. */
9
+ export type Rgb = readonly [number, number, number];
10
+
11
+ /** `"12 34 56"` (the token's channel form) → 0..1 channels; anything else is `undefined`. */
12
+ export function parseChannels(text: string): Rgb | undefined {
13
+ const parts = text.trim().split(/[\s,]+/);
14
+ if (parts.length !== 3) return undefined;
15
+ const channels = parts.map(Number);
16
+ if (channels.some((channel) => !Number.isFinite(channel) || channel < 0 || channel > 255))
17
+ return undefined;
18
+ const [r = 0, g = 0, b = 0] = channels;
19
+ return [r / 255, g / 255, b / 255];
20
+ }
21
+
22
+ /** Every role resolved on `el`, or `undefined` when one is unset (no theme stylesheet loaded). */
23
+ export function resolvePalette(
24
+ host: EffectHost,
25
+ el: Element,
26
+ roles: readonly ColorRole[],
27
+ ): readonly Rgb[] | undefined {
28
+ const colours: Rgb[] = [];
29
+ for (const role of roles) {
30
+ const colour = parseChannels(host.readVar(el, `--color-${role}`));
31
+ if (colour === undefined) return undefined;
32
+ colours.push(colour);
33
+ }
34
+ return colours;
35
+ }
36
+
37
+ /** A canvas fill for `colour` at `alpha`: built from resolved channels, never authored. */
38
+ export function cssRgb(colour: Rgb, alpha = 1): string {
39
+ const [r, g, b] = colour.map((channel) => Math.round(channel * 255));
40
+ return `rgb(${r} ${g} ${b} / ${alpha})`;
41
+ }
@@ -0,0 +1,42 @@
1
+ // How many device pixels an effect canvas may draw: one token for the DPR floor, the DPR cap and
2
+ // the pixel ceiling, so a 3x phone and a 5K monitor pay a bounded fill rate and no entry picks its
3
+ // own numbers. A shader's cost is per pixel; the ceiling is what keeps a full-bleed hero cheap.
4
+
5
+ export interface PixelBudget {
6
+ /** The lowest ratio drawn: a zoomed-out page (ratio < 1) still draws crisp. */
7
+ readonly dprFloor: number;
8
+ /** The highest ratio drawn: past 2x the eye gains nothing a gradient can show. */
9
+ readonly dprCap: number;
10
+ /** Backing-store pixels, width x height. Wins over the floor: a 5K canvas draws under 1x. */
11
+ readonly maxPixelCount: number;
12
+ }
13
+
14
+ export const EFFECT_PIXELS: PixelBudget = Object.freeze({
15
+ dprFloor: 1,
16
+ dprCap: 2,
17
+ maxPixelCount: 1920 * 1080 * 2,
18
+ });
19
+
20
+ export interface BackingSize {
21
+ readonly width: number;
22
+ readonly height: number;
23
+ readonly scale: number;
24
+ }
25
+
26
+ /** The backing-store size for a box of `cssWidth` x `cssHeight` CSS pixels. Never 0 wide. */
27
+ export function backingSize(
28
+ cssWidth: number,
29
+ cssHeight: number,
30
+ devicePixelRatio: number,
31
+ budget: PixelBudget = EFFECT_PIXELS,
32
+ ): BackingSize {
33
+ const ratio = Number.isFinite(devicePixelRatio) ? devicePixelRatio : budget.dprFloor;
34
+ let scale = Math.min(budget.dprCap, Math.max(budget.dprFloor, ratio));
35
+ const area = cssWidth * cssHeight * scale * scale;
36
+ if (area > budget.maxPixelCount) scale = Math.sqrt(budget.maxPixelCount / (cssWidth * cssHeight));
37
+ return {
38
+ width: Math.max(1, Math.floor(cssWidth * scale)),
39
+ height: Math.max(1, Math.floor(cssHeight * scale)),
40
+ scale,
41
+ };
42
+ }
package/src/props.ts ADDED
@@ -0,0 +1,61 @@
1
+ // The prop screens every entry runs before it draws: a number inside the range the effect can
2
+ // render, a role the palette has. A JavaScript caller (or a `defineTheme`-less island) gets
3
+ // `X_EFFECTS_INVALID_VALUE` naming the entry, the prop and the range, never a NaN in a shader.
4
+
5
+ import { COLOR_ROLES, type ColorRole } from '@ultimat3/ui';
6
+ import { EffectsInvalidValueError } from './errors';
7
+
8
+ /** `value`, or `fallback` when unset; anything outside `[min, max]` or not finite is refused. */
9
+ export function rangeProp(
10
+ entry: string,
11
+ prop: string,
12
+ value: number | undefined,
13
+ range: { readonly min: number; readonly max: number; readonly fallback: number },
14
+ ): number {
15
+ if (value === undefined) return range.fallback;
16
+ if (
17
+ typeof value === 'number' &&
18
+ Number.isFinite(value) &&
19
+ value >= range.min &&
20
+ value <= range.max
21
+ )
22
+ return value;
23
+ // The call to paste, built first: its tag is the entry's name, so the line opens with it.
24
+ const call = `<${entry} ${prop}={${range.fallback}} />`;
25
+ throw new EffectsInvalidValueError({
26
+ cause: `<${entry} ${prop}> is ${String(value)}, outside ${range.min}..${range.max}`,
27
+ fix: `${call} // any finite number from ${range.min} to ${range.max}`,
28
+ });
29
+ }
30
+
31
+ const KNOWN_ROLES: ReadonlySet<string> = new Set(COLOR_ROLES);
32
+
33
+ /** A palette of roles, `fallback` when unset; an unknown role or a size outside `count` is refused. */
34
+ export function rolesProp(
35
+ entry: string,
36
+ value: readonly ColorRole[] | undefined,
37
+ fallback: readonly ColorRole[],
38
+ count: { readonly min: number; readonly max: number },
39
+ ): readonly ColorRole[] {
40
+ if (value === undefined) return fallback;
41
+ const unknown = value.find((role) => !KNOWN_ROLES.has(role));
42
+ const sized = value.length >= count.min && value.length <= count.max;
43
+ if (unknown === undefined && sized) return value;
44
+ const call = `<${entry} roles={${JSON.stringify(fallback)}} />`;
45
+ throw new EffectsInvalidValueError({
46
+ cause:
47
+ unknown === undefined
48
+ ? `<${entry} roles> names ${value.length} roles, outside ${count.min}..${count.max}`
49
+ : `<${entry} roles> names '${String(unknown)}', which is not a colour role`,
50
+ fix: `${call} // ${count.min} to ${count.max} names from COLOR_ROLES in @ultimat3/ui`,
51
+ });
52
+ }
53
+
54
+ /** The inline custom properties carrying a palette: `--fx-c0: var(--color-accent)` and so on. */
55
+ export function roleVars(roles: readonly ColorRole[]): Record<string, string> {
56
+ const vars: Record<string, string> = {};
57
+ roles.forEach((role, index) => {
58
+ vars[`--fx-c${index}`] = `var(--color-${role})`;
59
+ });
60
+ return vars;
61
+ }
@@ -0,0 +1,70 @@
1
+ @use '@ultimat3/ui/tokens' as t;
2
+ @use '../effect' as fx;
3
+
4
+ // Frame 0 of each preset, in CSS. The mesh stops are `0.9 x (1 - smoothstep)` at quarters — the
5
+ // falloff the GLSL computes (`MESH_STOPS` in `shader-background-canvas.ts`, pinned by a test).
6
+ @function mesh-point($i) {
7
+ $c: var(--fx-c#{$i + 1});
8
+ @return radial-gradient(
9
+ ellipse 60% 60% at var(--fx-p#{$i}x) var(--fx-p#{$i}y),
10
+ rgb($c / 0.9) 0%,
11
+ rgb($c / 0.759) 25%,
12
+ rgb($c / 0.45) 50%,
13
+ rgb($c / 0.141) 75%,
14
+ rgb($c / 0) 100%
15
+ );
16
+ }
17
+
18
+ .root {
19
+ @include fx.root;
20
+ }
21
+
22
+ .layer {
23
+ @include fx.layer;
24
+ }
25
+
26
+ .content {
27
+ @include fx.content;
28
+ }
29
+
30
+ .frame {
31
+ @include fx.frame('.root');
32
+ position: absolute;
33
+ inset: 0;
34
+ }
35
+
36
+ // Later points paint over earlier ones in the shader; CSS lists its top layer first.
37
+ .mesh {
38
+ background: mesh-point(2), mesh-point(1), mesh-point(0), rgb(var(--fx-c0));
39
+ }
40
+
41
+ .grain {
42
+ background: linear-gradient(var(--fx-angle), rgb(var(--fx-c1)), rgb(var(--fx-c2)));
43
+ }
44
+
45
+ .dots {
46
+ background:
47
+ radial-gradient(circle at center, rgb(var(--fx-c1)) var(--fx-dot), transparent calc(var(--fx-dot) + #{t.stroke(hairline)}))
48
+ 0 0 / var(--fx-pitch) var(--fx-pitch),
49
+ rgb(var(--fx-c0));
50
+ }
51
+
52
+ .canvas {
53
+ @include fx.canvas('.root');
54
+ }
55
+
56
+ // The SVG grain lies over the gradient and over a Canvas2D frame; the shader draws its own.
57
+ .layer > .grain-overlay {
58
+ position: absolute;
59
+ inset: 0;
60
+
61
+ .root[data-effect-backend='webgl2'] & {
62
+ display: none;
63
+ }
64
+ }
65
+
66
+ @media (forced-colors: active) {
67
+ .layer {
68
+ display: none;
69
+ }
70
+ }
@@ -0,0 +1,60 @@
1
+ // A GPU background behind a hero: `mesh`, `grain` or `dots`, our own GLSL on our own WebGL2 mount.
2
+ // The server paints frame 0 in CSS (no script, no flash); an island fetches only its preset's
3
+ // chunk, draws on WebGL2 or else Canvas2D, and falls back to that frame under reduced motion.
4
+
5
+ import type { ColorRole } from '@ultimat3/ui';
6
+ import { cx } from '@ultimat3/ui';
7
+ import type { JSX } from 'solid-js';
8
+ import { Noise } from '../noise/Noise';
9
+ import { loadShader } from '../shader-load';
10
+ import { useEffectMount } from '../use-effect-mount';
11
+ import { loadPreset } from './load-preset';
12
+ import styles from './ShaderBackground.module.scss';
13
+ import { presetCanvas } from './shader-background-canvas';
14
+ import {
15
+ SHADER_BACKGROUND_BACKEND,
16
+ type ShaderPreset,
17
+ shaderBackgroundView,
18
+ } from './shader-background-view';
19
+
20
+ export interface ShaderBackgroundProps {
21
+ /** Which shader. Default `'mesh'`. */
22
+ preset?: ShaderPreset | undefined;
23
+ /** `[ground, a, b, c]`: four colour roles. Default `['bg-soft', 'accent', 'info', 'chart-3']`. */
24
+ roles?: readonly ColorRole[] | undefined;
25
+ /** Animation speed multiplier, 0.25..4. Default 1. */
26
+ speed?: number | undefined;
27
+ /** What the background sits behind. */
28
+ children?: JSX.Element | undefined;
29
+ class?: string | undefined;
30
+ }
31
+
32
+ export function ShaderBackground(props: ShaderBackgroundProps): JSX.Element {
33
+ const view = shaderBackgroundView(props);
34
+ const fx = useEffectMount(
35
+ {
36
+ css: false,
37
+ wants: 'webgl2',
38
+ speed: view.speed,
39
+ roles: view.roles,
40
+ shader: (colours) => loadShader(loadPreset(view.preset).then((program) => program(colours))),
41
+ draw2d: (colours) => presetCanvas(view.preset, colours),
42
+ },
43
+ SHADER_BACKGROUND_BACKEND,
44
+ );
45
+ return (
46
+ <div
47
+ ref={fx.root}
48
+ class={cx(styles['root'], props.class)}
49
+ style={view.vars}
50
+ data-effect-backend={fx.backend()}
51
+ >
52
+ <div class={styles['layer']} aria-hidden="true">
53
+ <div class={cx(styles['frame'], styles[view.preset])} />
54
+ <canvas ref={fx.canvas} class={styles['canvas']} />
55
+ {view.preset === 'grain' ? <Noise class={styles['grain-overlay']} opacity={0.18} /> : null}
56
+ </div>
57
+ <div class={styles['content']}>{props.children}</div>
58
+ </div>
59
+ );
60
+ }
@@ -0,0 +1,19 @@
1
+ // One dynamic `import()` per preset, each a literal path, so a splitting bundler emits each
2
+ // preset's GLSL as its own chunk and an island fetches only the one it draws.
3
+
4
+ import type { Rgb } from '../palette';
5
+ import type { ShaderProgram } from '../shader-mount';
6
+ import type { ShaderPreset } from './shader-background-view';
7
+
8
+ export type ProgramFactory = (colours: () => readonly Rgb[]) => ShaderProgram;
9
+
10
+ export function loadPreset(preset: ShaderPreset): Promise<ProgramFactory> {
11
+ switch (preset) {
12
+ case 'mesh':
13
+ return import('./presets/mesh').then((module) => module.meshProgram);
14
+ case 'grain':
15
+ return import('./presets/grain').then((module) => module.grainProgram);
16
+ case 'dots':
17
+ return import('./presets/dots').then((module) => module.dotsProgram);
18
+ }
19
+ }
@@ -0,0 +1,59 @@
1
+ // The `dots` preset's GLSL, written for Ultimate: a dot grid on the CSS frame's pitch whose radius
2
+ // ripples outward from the centre and whose hue drifts between two roles — both scaled by
3
+ // `dotsRamp(t)`, so frame 0 is the server's uniform `radial-gradient` grid. Its own lazy chunk.
4
+
5
+ import type { Rgb } from '../../palette';
6
+ import type { ShaderProgram } from '../../shader-mount';
7
+ import { DOT_PITCH, DOT_RADIUS, dotsRamp } from '../shader-background-view';
8
+ import { packColours } from '../uniform-pack';
9
+
10
+ // Duplicated in each preset on purpose: see `mesh.ts`.
11
+ const VERTEX = `#version 300 es
12
+ void main() {
13
+ vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
14
+ gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);
15
+ }`;
16
+
17
+ const FRAGMENT = `#version 300 es
18
+ precision highp float;
19
+ uniform vec2 u_resolution;
20
+ uniform float u_time;
21
+ uniform float u_scale;
22
+ uniform float u_ramp;
23
+ uniform vec3 u_colors[4];
24
+ out vec4 fragColor;
25
+
26
+ const float PITCH = ${DOT_PITCH.toFixed(3)};
27
+ const float RADIUS = ${DOT_RADIUS.toFixed(3)};
28
+
29
+ void main() {
30
+ vec2 px = vec2(gl_FragCoord.x, u_resolution.y - gl_FragCoord.y) / u_scale;
31
+ vec2 cell = floor(px / PITCH);
32
+ vec2 local = mod(px, PITCH) - 0.5 * PITCH;
33
+ vec2 centre = 0.5 * u_resolution / u_scale / PITCH;
34
+ float wave = sin(length(cell - centre) * 0.35 - u_time * 1.6);
35
+ float radius = RADIUS * (1.0 + u_ramp * 0.7 * wave);
36
+ float coverage = 1.0 - smoothstep(radius - 0.5, radius + 0.5, length(local));
37
+ float hue = u_ramp * (0.5 + 0.5 * sin(cell.x * 0.3 + cell.y * 0.2 + u_time * 0.8));
38
+ vec3 ink = mix(u_colors[1], u_colors[2], hue);
39
+ fragColor = vec4(mix(u_colors[0], ink, coverage), 1.0);
40
+ }`;
41
+
42
+ export function dotsProgram(colours: () => readonly Rgb[]): ShaderProgram {
43
+ const palette = new Float32Array(12);
44
+ const resolution = new Float32Array(2);
45
+ return {
46
+ vertex: VERTEX,
47
+ fragment: FRAGMENT,
48
+ uniforms: (frame) => {
49
+ resolution.set([frame.width, frame.height]);
50
+ return {
51
+ u_resolution: ['2fv', resolution],
52
+ u_time: ['1f', frame.time],
53
+ u_scale: ['1f', frame.scale],
54
+ u_ramp: ['1f', dotsRamp(frame.time)],
55
+ u_colors: ['3fv', packColours(colours(), palette)],
56
+ };
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,59 @@
1
+ // The `grain` preset's GLSL, written for Ultimate: a two-role linear gradient at `grainAngle(t)`,
2
+ // placed exactly as CSS places `linear-gradient(<angle>, a, b)` (the corner-to-corner gradient
3
+ // line), with per-CSS-pixel film grain that changes 24 times a second. Its own lazy chunk.
4
+
5
+ import type { Rgb } from '../../palette';
6
+ import type { ShaderProgram } from '../../shader-mount';
7
+ import { grainAngle } from '../shader-background-view';
8
+ import { packColours } from '../uniform-pack';
9
+
10
+ // Duplicated in each preset on purpose: see `mesh.ts`.
11
+ const VERTEX = `#version 300 es
12
+ void main() {
13
+ vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
14
+ gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);
15
+ }`;
16
+
17
+ const FRAGMENT = `#version 300 es
18
+ precision highp float;
19
+ uniform vec2 u_resolution;
20
+ uniform float u_time;
21
+ uniform float u_scale;
22
+ uniform float u_angle;
23
+ uniform vec3 u_colors[4];
24
+ out vec4 fragColor;
25
+
26
+ float hash(vec2 p) {
27
+ p = fract(p * vec2(443.897, 441.423));
28
+ p += dot(p, p.yx + 19.19);
29
+ return fract((p.x + p.y) * p.x);
30
+ }
31
+
32
+ void main() {
33
+ vec2 p = vec2(gl_FragCoord.x, u_resolution.y - gl_FragCoord.y) - 0.5 * u_resolution;
34
+ vec2 dir = vec2(sin(u_angle), -cos(u_angle));
35
+ float span = abs(u_resolution.x * dir.x) + abs(u_resolution.y * dir.y);
36
+ float t = clamp(dot(p, dir) / span + 0.5, 0.0, 1.0);
37
+ vec3 colour = mix(u_colors[1], u_colors[2], t);
38
+ float grain = hash(floor(gl_FragCoord.xy / u_scale) + floor(u_time * 24.0)) - 0.5;
39
+ fragColor = vec4(colour + grain * 0.08, 1.0);
40
+ }`;
41
+
42
+ export function grainProgram(colours: () => readonly Rgb[]): ShaderProgram {
43
+ const palette = new Float32Array(12);
44
+ const resolution = new Float32Array(2);
45
+ return {
46
+ vertex: VERTEX,
47
+ fragment: FRAGMENT,
48
+ uniforms: (frame) => {
49
+ resolution.set([frame.width, frame.height]);
50
+ return {
51
+ u_resolution: ['2fv', resolution],
52
+ u_time: ['1f', frame.time],
53
+ u_scale: ['1f', frame.scale],
54
+ u_angle: ['1f', (grainAngle(frame.time) * Math.PI) / 180],
55
+ u_colors: ['3fv', packColours(colours(), palette)],
56
+ };
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,78 @@
1
+ // The `mesh` preset's GLSL, written for Ultimate: three role colours laid over a ground as soft
2
+ // ellipses whose centres follow `meshPoints(t)`, with a value-noise warp that grows in from zero.
3
+ // At frame 0 it is exactly the server's layered `radial-gradient` frame. Its own lazy chunk.
4
+
5
+ import type { Rgb } from '../../palette';
6
+ import type { ShaderProgram } from '../../shader-mount';
7
+ import { MESH_PEAK, MESH_RADIUS, meshPoints } from '../shader-background-view';
8
+ import { packColours } from '../uniform-pack';
9
+
10
+ // Duplicated in each preset on purpose: a shared module would be a fourth chunk every preset
11
+ // loads, for 180 bytes. One triangle covering the viewport, no vertex buffer (`gl_VertexID`).
12
+ const VERTEX = `#version 300 es
13
+ void main() {
14
+ vec2 corner = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2));
15
+ gl_Position = vec4(corner * 2.0 - 1.0, 0.0, 1.0);
16
+ }`;
17
+
18
+ const FRAGMENT = `#version 300 es
19
+ precision highp float;
20
+ uniform vec2 u_resolution;
21
+ uniform float u_time;
22
+ uniform vec3 u_colors[4];
23
+ uniform vec2 u_points[3];
24
+ out vec4 fragColor;
25
+
26
+ float hash(vec2 p) {
27
+ p = fract(p * vec2(127.1, 311.7));
28
+ p += dot(p, p + 19.19);
29
+ return fract(p.x * p.y);
30
+ }
31
+
32
+ float valueNoise(vec2 p) {
33
+ vec2 i = floor(p);
34
+ vec2 f = fract(p);
35
+ vec2 u = f * f * (3.0 - 2.0 * f);
36
+ return mix(
37
+ mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
38
+ mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),
39
+ u.y
40
+ );
41
+ }
42
+
43
+ void main() {
44
+ vec2 uv = vec2(gl_FragCoord.x, u_resolution.y - gl_FragCoord.y) / u_resolution;
45
+ float warp = 0.06 * smoothstep(0.0, 3.0, u_time);
46
+ uv += warp * (vec2(
47
+ valueNoise(uv * 3.0 + u_time * 0.07),
48
+ valueNoise(uv * 3.0 + 9.0 - u_time * 0.05)
49
+ ) - 0.5);
50
+ vec3 colour = u_colors[0];
51
+ for (int i = 0; i < 3; i++) {
52
+ float d = length((uv - u_points[i]) / ${MESH_RADIUS.toFixed(3)});
53
+ colour = mix(colour, u_colors[i + 1], ${MESH_PEAK.toFixed(3)} * (1.0 - smoothstep(0.0, 1.0, d)));
54
+ }
55
+ fragColor = vec4(colour, 1.0);
56
+ }`;
57
+
58
+ export function meshProgram(colours: () => readonly Rgb[]): ShaderProgram {
59
+ const palette = new Float32Array(12);
60
+ const points = new Float32Array(6);
61
+ const resolution = new Float32Array(2);
62
+ return {
63
+ vertex: VERTEX,
64
+ fragment: FRAGMENT,
65
+ uniforms: (frame) => {
66
+ meshPoints(frame.time).forEach((point, index) => {
67
+ points.set(point, index * 2);
68
+ });
69
+ resolution.set([frame.width, frame.height]);
70
+ return {
71
+ u_resolution: ['2fv', resolution],
72
+ u_time: ['1f', frame.time],
73
+ u_colors: ['3fv', packColours(colours(), palette)],
74
+ u_points: ['2fv', points],
75
+ };
76
+ },
77
+ };
78
+ }