@uxfront/scene 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.
Files changed (51) hide show
  1. package/README.md +128 -0
  2. package/dist/experience.d.ts +40 -0
  3. package/dist/experience.js +306 -0
  4. package/dist/formations/corridor/index.d.ts +8 -0
  5. package/dist/formations/corridor/index.js +52 -0
  6. package/dist/formations/corridor/shader.js +37 -0
  7. package/dist/formations/index.d.ts +11 -0
  8. package/dist/formations/index.js +11 -0
  9. package/dist/formations/ink/index.d.ts +10 -0
  10. package/dist/formations/ink/index.js +53 -0
  11. package/dist/formations/ink/shader.js +177 -0
  12. package/dist/formations/monolith/index.d.ts +5 -0
  13. package/dist/formations/monolith/index.js +49 -0
  14. package/dist/formations/monolith/mark.js +89 -0
  15. package/dist/formations/monolith/shader.js +120 -0
  16. package/dist/formations/plates/art.d.ts +46 -0
  17. package/dist/formations/plates/art.js +238 -0
  18. package/dist/formations/plates/geometry.d.ts +5 -0
  19. package/dist/formations/plates/geometry.js +8 -0
  20. package/dist/formations/plates/index.d.ts +13 -0
  21. package/dist/formations/plates/index.js +67 -0
  22. package/dist/formations/plates/shader.js +97 -0
  23. package/dist/formations/prism/geometry.d.ts +4 -0
  24. package/dist/formations/prism/geometry.js +15 -0
  25. package/dist/formations/prism/index.d.ts +9 -0
  26. package/dist/formations/prism/index.js +64 -0
  27. package/dist/formations/prism/shader.js +140 -0
  28. package/dist/formations/tokens/geometry.d.ts +4 -0
  29. package/dist/formations/tokens/geometry.js +22 -0
  30. package/dist/formations/tokens/index.d.ts +18 -0
  31. package/dist/formations/tokens/index.js +79 -0
  32. package/dist/formations/tokens/shader.js +125 -0
  33. package/dist/gl/compose.d.ts +14 -0
  34. package/dist/gl/compose.js +52 -0
  35. package/dist/gl/constants.d.ts +6 -0
  36. package/dist/gl/constants.js +7 -0
  37. package/dist/gl/engine.js +559 -0
  38. package/dist/gl/formation.d.ts +7 -0
  39. package/dist/gl/formation.js +39 -0
  40. package/dist/gl/glsl.d.ts +9 -0
  41. package/dist/gl/glsl.js +419 -0
  42. package/dist/gl/math.d.ts +16 -0
  43. package/dist/gl/math.js +102 -0
  44. package/dist/gl/stage.d.ts +28 -0
  45. package/dist/gl/stage.js +55 -0
  46. package/dist/gl/types.d.ts +103 -0
  47. package/dist/index.d.ts +10 -0
  48. package/dist/index.js +9 -0
  49. package/dist/layout.d.ts +9 -0
  50. package/dist/layout.js +10 -0
  51. package/package.json +51 -0
@@ -0,0 +1,238 @@
1
+ import { PLATE } from "./geometry.js";
2
+ //#region src/formations/plates/art.ts
3
+ /** A line segment. */
4
+ const seg = (plate, a, b, bright = .8) => ({
5
+ kind: "seg",
6
+ plate,
7
+ a,
8
+ b,
9
+ bright
10
+ });
11
+ /** A rounded rectangle outline: centre, half size and corner radius. */
12
+ const rrect = (plate, c, h, r, bright = .8) => ({
13
+ kind: "rrect",
14
+ plate,
15
+ c,
16
+ h,
17
+ r,
18
+ bright
19
+ });
20
+ /** A circle outline. */
21
+ const circle = (plate, c, r, bright = .8) => ({
22
+ kind: "circle",
23
+ plate,
24
+ c,
25
+ r,
26
+ bright
27
+ });
28
+ /** A filled disc. */
29
+ const disc = (plate, c, r, bright = 1) => ({
30
+ kind: "disc",
31
+ plate,
32
+ c,
33
+ r,
34
+ bright
35
+ });
36
+ /** The plate's own border. */
37
+ const plateBorder = (plate, bright) => rrect(plate, [0, 0], PLATE, .14, bright);
38
+ const uxPlate = [
39
+ plateBorder(0, .9),
40
+ seg(0, [-1.52, .82], [-.4, .82], 1.1),
41
+ seg(0, [-1.52, .64], [.3, .64], .5),
42
+ circle(0, [1.32, .72], .2, .95),
43
+ rrect(0, [-.3, .12], [1.22, .17], .06, .85),
44
+ seg(0, [-1.34, .03], [-1.34, .21], 1.3),
45
+ rrect(0, [1.33, .12], [.27, .15], .15, .95),
46
+ disc(0, [1.45, .12], .095, 1.2),
47
+ rrect(0, [-1.4, -.42], [.11, .11], .03, .95),
48
+ seg(0, [-1.47, -.42], [-1.42, -.48], 1.3),
49
+ seg(0, [-1.42, -.48], [-1.32, -.35], 1.3),
50
+ seg(0, [-1.18, -.42], [-.34, -.42], .45),
51
+ seg(0, [-.02, -.42], [1.52, -.42], .45),
52
+ seg(0, [-.02, -.42], [.78, -.42], 1.1),
53
+ disc(0, [.78, -.42], .08, 1.2),
54
+ rrect(0, [.92, -.84], [.58, .16], .16, 1.15),
55
+ seg(0, [.7, -.84], [1.14, -.84], .85),
56
+ rrect(0, [-.42, -.84], [.56, .16], .16, .6),
57
+ seg(0, [-.62, -.84], [-.22, -.84], .5)
58
+ ];
59
+ const dxPlate = [
60
+ plateBorder(1, .7),
61
+ ...[
62
+ [
63
+ 0,
64
+ 1.1,
65
+ .9
66
+ ],
67
+ [
68
+ 1,
69
+ 1.5,
70
+ .55
71
+ ],
72
+ [
73
+ 2,
74
+ .9,
75
+ .55
76
+ ],
77
+ [
78
+ 2,
79
+ 1.2,
80
+ .8
81
+ ],
82
+ [
83
+ 1,
84
+ .4,
85
+ .55
86
+ ],
87
+ [
88
+ 1,
89
+ 1.3,
90
+ .55
91
+ ],
92
+ [
93
+ 2,
94
+ .7,
95
+ .8
96
+ ],
97
+ [
98
+ 1,
99
+ .4,
100
+ .55
101
+ ],
102
+ [
103
+ 0,
104
+ .3,
105
+ .9
106
+ ]
107
+ ].map(([indent, length, bright], row) => {
108
+ const x = -1.52 + indent * .22;
109
+ const y = .84 - row * .21;
110
+ return seg(1, [x, y], [x + length, y], bright);
111
+ }),
112
+ seg(1, [1.12, .84], [.98, .72], 1),
113
+ seg(1, [.98, .72], [1.12, .6], 1),
114
+ seg(1, [1.2, .58], [1.32, .86], 1),
115
+ seg(1, [1.4, .84], [1.54, .72], 1),
116
+ seg(1, [1.54, .72], [1.4, .6], 1)
117
+ ];
118
+ const axPlate = [
119
+ plateBorder(2, .7),
120
+ disc(2, [0, .78], .1, 1.2),
121
+ circle(2, [-1.1, .2], .085, 1),
122
+ circle(2, [0, .2], .085, 1),
123
+ circle(2, [1.1, .2], .085, 1),
124
+ circle(2, [-1.45, -.46], .075, .9),
125
+ circle(2, [-.75, -.46], .075, .9),
126
+ disc(2, [1.1, -.46], .075, 1.1),
127
+ seg(2, [0, .68], [0, .46], .7),
128
+ seg(2, [-1.1, .46], [1.1, .46], .7),
129
+ seg(2, [-1.1, .46], [-1.1, .285], .7),
130
+ seg(2, [0, .46], [0, .285], .7),
131
+ seg(2, [1.1, .46], [1.1, .285], .7),
132
+ seg(2, [-1.1, .115], [-1.1, -.2], .7),
133
+ seg(2, [-1.45, -.2], [-.75, -.2], .7),
134
+ seg(2, [-1.45, -.2], [-1.45, -.385], .7),
135
+ seg(2, [-.75, -.2], [-.75, -.385], .7),
136
+ seg(2, [1.1, .115], [1.1, -.385], .7)
137
+ ];
138
+ /** Open Components: an interface (UX), its API (DX) and its semantic tree (AX). */
139
+ const OPEN_COMPONENTS_ART = [
140
+ ...uxPlate,
141
+ ...dxPlate,
142
+ ...axPlate
143
+ ];
144
+ const shapeWeight = (shape) => {
145
+ if (shape.kind === "seg") return Math.hypot(shape.b[0] - shape.a[0], shape.b[1] - shape.a[1]);
146
+ if (shape.kind === "rrect") {
147
+ const r = Math.min(shape.r, shape.h[0], shape.h[1]);
148
+ return 4 * (shape.h[0] + shape.h[1]) - 8 * r + 2 * Math.PI * r;
149
+ }
150
+ if (shape.kind === "circle") return 2 * Math.PI * shape.r;
151
+ return Math.PI * shape.r * shape.r * 24;
152
+ };
153
+ /**
154
+ * Packs plate artwork into uniform arrays. Particles pick a shape by
155
+ * binary-searching the CDF, so every line gets the same particle density.
156
+ */
157
+ function buildShapeTable(shapes) {
158
+ if (shapes.length === 0) throw new Error("Plate artwork needs at least one shape");
159
+ if (shapes.length > 64) throw new Error(`Plate artwork is limited to 64 shapes`);
160
+ const a = /* @__PURE__ */ new Float32Array(256);
161
+ const b = /* @__PURE__ */ new Float32Array(256);
162
+ const cdf = /* @__PURE__ */ new Float32Array(64);
163
+ const weights = shapes.map(shapeWeight);
164
+ const totalWeight = weights.reduce((sum, w) => sum + w, 0);
165
+ let running = 0;
166
+ shapes.forEach((shape, i) => {
167
+ running += weights[i];
168
+ cdf[i] = running / totalWeight;
169
+ const o = i * 4;
170
+ switch (shape.kind) {
171
+ case "seg":
172
+ a.set([
173
+ shape.a[0],
174
+ shape.a[1],
175
+ shape.b[0],
176
+ shape.b[1]
177
+ ], o);
178
+ b.set([
179
+ 0,
180
+ 0,
181
+ shape.plate,
182
+ shape.bright
183
+ ], o);
184
+ break;
185
+ case "rrect":
186
+ a.set([
187
+ shape.c[0],
188
+ shape.c[1],
189
+ shape.h[0],
190
+ shape.h[1]
191
+ ], o);
192
+ b.set([
193
+ 1,
194
+ shape.r,
195
+ shape.plate,
196
+ shape.bright
197
+ ], o);
198
+ break;
199
+ case "circle":
200
+ a.set([
201
+ shape.c[0],
202
+ shape.c[1],
203
+ shape.r,
204
+ 0
205
+ ], o);
206
+ b.set([
207
+ 2,
208
+ 0,
209
+ shape.plate,
210
+ shape.bright
211
+ ], o);
212
+ break;
213
+ case "disc":
214
+ a.set([
215
+ shape.c[0],
216
+ shape.c[1],
217
+ shape.r,
218
+ 0
219
+ ], o);
220
+ b.set([
221
+ 3,
222
+ 0,
223
+ shape.plate,
224
+ shape.bright
225
+ ], o);
226
+ }
227
+ });
228
+ cdf[shapes.length - 1] = 1.0001;
229
+ return {
230
+ a,
231
+ b,
232
+ cdf,
233
+ count: shapes.length,
234
+ totalWeight
235
+ };
236
+ }
237
+ //#endregion
238
+ export { OPEN_COMPONENTS_ART, buildShapeTable, circle, disc, plateBorder, rrect, seg };
@@ -0,0 +1,5 @@
1
+ import { Vec2 } from "../../gl/math.js";
2
+ //#region src/formations/plates/geometry.d.ts
3
+ /** Half extents of each plate: u to the right, v away from the viewer. */
4
+ export declare const PLATE: Vec2;
5
+ //#endregion
@@ -0,0 +1,8 @@
1
+ import { lerp, smoothstep } from "../../gl/math.js";
2
+ //#region src/formations/plates/geometry.ts
3
+ /** Half extents of each plate: u to the right, v away from the viewer. */
4
+ const PLATE = [1.8, 1.15];
5
+ /** Vertical gap between neighbouring plates as the chapter is read. */
6
+ const layersSeparation = (local) => lerp(.16, .95, smoothstep(0, 1, local));
7
+ //#endregion
8
+ export { PLATE, layersSeparation };
@@ -0,0 +1,13 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ import { PlateShape } from "./art.js";
3
+ //#region src/formations/plates/index.d.ts
4
+ export interface PlatesOptions extends FormationOptions {
5
+ /** Artwork on the three plates. Defaults to Open Components' UX, DX and AX plates. */
6
+ art?: PlateShape[];
7
+ }
8
+ /**
9
+ * Three glass plates drifting apart as the chapter is read, each drawn with
10
+ * line art. Anchors `plates:0` to `plates:2` sit at the plates' right edges.
11
+ */
12
+ export declare function plates(options: PlatesOptions): Formation;
13
+ //#endregion
@@ -0,0 +1,67 @@
1
+ import { smoothstep } from "../../gl/math.js";
2
+ import { defineFormation, mergeViews } from "../../gl/formation.js";
3
+ import { PLATE, layersSeparation } from "./geometry.js";
4
+ //#region src/formations/plates/index.ts
5
+ /**
6
+ * Three glass plates drifting apart as the chapter is read, each drawn with
7
+ * line art. Anchors `plates:0` to `plates:2` sit at the plates' right edges.
8
+ */
9
+ function plates(options) {
10
+ const anchors = [
11
+ 0,
12
+ 1,
13
+ 2
14
+ ].map((plate) => ({
15
+ id: String(plate),
16
+ place: ({ local }, out) => {
17
+ out[0] = PLATE[0];
18
+ out[1] = layersSeparation(local) * (1 - plate);
19
+ out[2] = -PLATE[1];
20
+ return smoothstep(.08, .3, local);
21
+ }
22
+ }));
23
+ return defineFormation({
24
+ key: options.key ?? "plates",
25
+ label: options.label,
26
+ views: mergeViews({
27
+ desktop: {
28
+ eye: [
29
+ 6.1,
30
+ 5,
31
+ 8.1
32
+ ],
33
+ target: [
34
+ 0,
35
+ -.1,
36
+ 0
37
+ ],
38
+ fov: 30,
39
+ span: [2.4, 2],
40
+ shift: [.16, .02]
41
+ },
42
+ mobile: {
43
+ eye: [
44
+ 5,
45
+ 4.2,
46
+ 6.6
47
+ ],
48
+ target: [
49
+ 0,
50
+ -.1,
51
+ 0
52
+ ],
53
+ fov: 34,
54
+ span: [2.3, 1.9],
55
+ shift: [0, .5]
56
+ }
57
+ }, options.views),
58
+ look: {
59
+ bloom: .9,
60
+ ...options.look
61
+ },
62
+ anchors,
63
+ shader: () => import("./shader.js").then((m) => m.createShader(options.art))
64
+ });
65
+ }
66
+ //#endregion
67
+ export { plates };
@@ -0,0 +1,97 @@
1
+ import { BASE_PARTICLES } from "../../gl/constants.js";
2
+ import { glslFloat } from "../../gl/glsl.js";
3
+ import { PLATE } from "./geometry.js";
4
+ import { OPEN_COMPONENTS_ART, buildShapeTable } from "./art.js";
5
+ //#region src/formations/plates/shader.ts
6
+ const glsl = `
7
+ const vec2 $PLATE = vec2(${glslFloat(PLATE[0])}, ${glslFloat(PLATE[1])});
8
+
9
+ uniform vec4 $shapeA[64];
10
+ uniform vec4 $shapeB[64];
11
+ uniform vec4 $shapeCdf[16];
12
+ uniform int $shapeCount;
13
+ uniform float $shapeGain;
14
+
15
+ float $separation(float local) {
16
+ return mix(0.16, 0.95, smoothstep(0.0, 1.0, local));
17
+ }
18
+
19
+ vec3 $tint(int k) {
20
+ if (k == 0) return vec3(0.7, 0.92, 1.0);
21
+ if (k == 1) return vec3(0.6, 0.7, 1.0);
22
+ return vec3(0.8, 0.66, 1.0);
23
+ }
24
+
25
+ int $findShape(float x) {
26
+ int lo = 0;
27
+ int hi = $shapeCount - 1;
28
+ for (int it = 0; it < 7; it++) {
29
+ if (lo >= hi) break;
30
+ int mid = (lo + hi) / 2;
31
+ if (x < $shapeCdf[mid / 4][mid % 4]) hi = mid;
32
+ else lo = mid + 1;
33
+ }
34
+ return lo;
35
+ }
36
+
37
+ Particle $main(uint id, float sel, Frame f) {
38
+ float local = f.local;
39
+ float time = f.time;
40
+ uint s = seedOf(id, 0x2F6B4A1Du);
41
+ float a = rnd(s);
42
+ float b = rnd(s);
43
+ float c = rnd(s);
44
+ Particle P = blank();
45
+ float sep = $separation(local);
46
+ float sweep = mod(time * 0.45, 5.2) - 2.6;
47
+
48
+ if (sel < 0.05) {
49
+ // Dotted corner posts tying the plates together.
50
+ int corner = min(int(a * 4.0), 3);
51
+ vec2 cxz = vec2((corner & 1) == 0 ? -$PLATE.x : $PLATE.x, (corner & 2) == 0 ? -$PLATE.y : $PLATE.y);
52
+ float y = clamp((floor(mix(-sep, sep, b) / 0.05) + 0.5) * 0.05, -sep, sep);
53
+ P.pos = vec3(cxz.x, y, cxz.y);
54
+ P.col = vec3(0.7, 0.8, 1.0) * 0.35;
55
+ P.size = 0.7;
56
+ } else if (sel < 0.33) {
57
+ // Frosted glass.
58
+ int k = min(int(a * 3.0), 2);
59
+ vec2 q = (vec2(b, c) * 2.0 - 1.0) * $PLATE;
60
+ float glint = exp(-pow((q.x - sweep) * 3.0, 2.0));
61
+ P.pos = vec3(q.x, sep * (1.0 - float(k)), -q.y);
62
+ P.col = $tint(k) * (0.035 + glint * 0.08);
63
+ P.size = 0.75;
64
+ } else {
65
+ int i = $findShape(a);
66
+ vec4 A = $shapeA[i];
67
+ vec4 B = $shapeB[i];
68
+ int type = int(B.x + 0.5);
69
+ vec2 q;
70
+ if (type == 0) q = mix(A.xy, A.zw, b);
71
+ else if (type == 1) q = rrectPoint(A, B.y, b);
72
+ else if (type == 2) q = A.xy + A.z * vec2(cos(b * TAU), sin(b * TAU));
73
+ else q = A.xy + A.z * sqrt(c) * vec2(cos(b * TAU), sin(b * TAU));
74
+ int k = int(B.z + 0.5);
75
+ float glint = exp(-pow((q.x - sweep) * 3.0, 2.0));
76
+ P.pos = vec3(q.x, sep * (1.0 - float(k)), -q.y);
77
+ P.col = $tint(k) * B.w * $shapeGain * (1.0 + glint * 1.2);
78
+ P.size = 0.75;
79
+ }
80
+ return P;
81
+ }
82
+ `;
83
+ function createShader(art = OPEN_COMPONENTS_ART) {
84
+ const shapes = buildShapeTable(art);
85
+ return {
86
+ glsl,
87
+ setup({ gl, get }) {
88
+ gl.uniform4fv(get("shapeA"), shapes.a);
89
+ gl.uniform4fv(get("shapeB"), shapes.b);
90
+ gl.uniform4fv(get("shapeCdf"), shapes.cdf);
91
+ gl.uniform1i(get("shapeCount"), shapes.count);
92
+ gl.uniform1f(get("shapeGain"), shapes.totalWeight / (BASE_PARTICLES * .67) * 120);
93
+ }
94
+ };
95
+ }
96
+ //#endregion
97
+ export { createShader };
@@ -0,0 +1,4 @@
1
+ //#region src/formations/prism/geometry.d.ts
2
+ /** One beam in, seven rails out. */
3
+ export declare const RAILS = 7;
4
+ //#endregion
@@ -0,0 +1,15 @@
1
+ import { lerp, smoothstep } from "../../gl/math.js";
2
+ //#region src/formations/prism/geometry.ts
3
+ /** One beam in, seven rails out. */
4
+ const RAILS = 7;
5
+ const RAIL_X0 = 2.6;
6
+ const RAIL_X1 = 4.6;
7
+ const railY = (index) => .19 + (3 - index) * .34;
8
+ /** Rails light up one after another as the chapter is read. */
9
+ const railReach = (index, progress) => lerp(.1, 1, smoothstep(index * .08, index * .08 + .45, progress));
10
+ /** Share of the rails' growth that happens while the chapter scrolls in. */
11
+ const RAIL_APPROACH = .35;
12
+ /** Rail progress: starts with the morph into the formation, not once it's held. */
13
+ const railProgress = (approach, local) => approach < 1 ? approach * RAIL_APPROACH : lerp(RAIL_APPROACH, 1, local);
14
+ //#endregion
15
+ export { RAILS, RAIL_APPROACH, RAIL_X0, RAIL_X1, railProgress, railReach, railY };
@@ -0,0 +1,9 @@
1
+ import { Formation, FormationOptions } from "../../gl/types.js";
2
+ //#region src/formations/prism/index.d.ts
3
+ /**
4
+ * A beam of white light split by a prism into seven coloured rails, one per
5
+ * compile target. Anchors `prism:0` to `prism:6` sit at the rails' ends, top
6
+ * to bottom, and show once each rail has reached them.
7
+ */
8
+ export declare function prism(options: FormationOptions): Formation;
9
+ //#endregion
@@ -0,0 +1,64 @@
1
+ import { smoothstep } from "../../gl/math.js";
2
+ import { defineFormation, mergeViews } from "../../gl/formation.js";
3
+ import { RAIL_X1, railProgress, railReach, railY } from "./geometry.js";
4
+ //#region src/formations/prism/index.ts
5
+ /**
6
+ * A beam of white light split by a prism into seven coloured rails, one per
7
+ * compile target. Anchors `prism:0` to `prism:6` sit at the rails' ends, top
8
+ * to bottom, and show once each rail has reached them.
9
+ */
10
+ function prism(options) {
11
+ const anchors = Array.from({ length: 7 }, (_, index) => ({
12
+ id: String(index),
13
+ place: ({ approach, local }, out) => {
14
+ out[0] = RAIL_X1;
15
+ out[1] = railY(index);
16
+ out[2] = 0;
17
+ return smoothstep(.9, 1, railReach(index, railProgress(approach, local)));
18
+ }
19
+ }));
20
+ return defineFormation({
21
+ key: options.key ?? "prism",
22
+ label: options.label,
23
+ views: mergeViews({
24
+ desktop: {
25
+ eye: [
26
+ 1,
27
+ .6,
28
+ 11
29
+ ],
30
+ target: [
31
+ 1.2,
32
+ .15,
33
+ 0
34
+ ],
35
+ fov: 30,
36
+ span: [5.2, 1.7],
37
+ shift: [.08, .3]
38
+ },
39
+ mobile: {
40
+ eye: [
41
+ 1.6,
42
+ .6,
43
+ 11
44
+ ],
45
+ target: [
46
+ 1.9,
47
+ .15,
48
+ 0
49
+ ],
50
+ fov: 34,
51
+ span: [3.9, 1.5],
52
+ shift: [0, .5]
53
+ }
54
+ }, options.views),
55
+ look: {
56
+ bloom: 1.15,
57
+ ...options.look
58
+ },
59
+ anchors,
60
+ shader: () => import("./shader.js").then((m) => m.shader)
61
+ });
62
+ }
63
+ //#endregion
64
+ export { prism };
@@ -0,0 +1,140 @@
1
+ import { glslFloat } from "../../gl/glsl.js";
2
+ import { RAIL_APPROACH, RAIL_X0, RAIL_X1 } from "./geometry.js";
3
+ //#region src/formations/prism/shader.ts
4
+ const shader = { glsl: `
5
+ const vec2 $PA = vec2(0.0, 1.097);
6
+ const vec2 $PB = vec2(-0.95, -0.5485);
7
+ const vec2 $PC = vec2(0.95, -0.5485);
8
+ const float $PRISM_Z = 0.7;
9
+ const vec2 $SRC = vec2(-9.5, -0.62);
10
+ const float $RAIL_X0 = ${glslFloat(RAIL_X0)};
11
+ const float $RAIL_X1 = ${glslFloat(RAIL_X1)};
12
+
13
+ // Angular, Svelte, Astro, Vue, React, Solid, Qwik: the spectrum happens to
14
+ // land close to each framework's own colour.
15
+ const vec3 $SPECTRUM[7] = vec3[7](
16
+ vec3(1.0, 0.13, 0.16),
17
+ vec3(1.0, 0.4, 0.06),
18
+ vec3(1.0, 0.8, 0.14),
19
+ vec3(0.2, 1.0, 0.45),
20
+ vec3(0.16, 0.75, 1.0),
21
+ vec3(0.25, 0.36, 1.0),
22
+ vec3(0.64, 0.26, 1.0)
23
+ );
24
+
25
+ // Rails start growing as the chapter scrolls in (see railProgress).
26
+ float $progress(Frame f) {
27
+ if (f.approach < 1.0) return f.approach * ${glslFloat(RAIL_APPROACH)};
28
+ return mix(${glslFloat(RAIL_APPROACH)}, 1.0, f.local);
29
+ }
30
+
31
+ vec2 $entryPoint() { return mix($PB, $PA, 0.45); }
32
+ vec2 $exitPoint(int i) { return mix($PA, $PC, 0.47 + 0.012 * float(i)); }
33
+ float $railY(int i) { return 0.19 + (3.0 - float(i)) * 0.34; }
34
+ float $railReach(int i, float local) {
35
+ float o = float(i) * 0.08;
36
+ return mix(0.1, 1.0, smoothstep(o, o + 0.45, local));
37
+ }
38
+
39
+ vec2 $outPath(int i, float s) {
40
+ vec2 x0 = $exitPoint(i);
41
+ float ang = radians(8.0 - 3.4 * float(i));
42
+ vec2 dir = vec2(cos(ang), sin(ang));
43
+ vec2 r0 = vec2($RAIL_X0, $railY(i));
44
+ if (s < 0.5) return bezier3(x0, x0 + dir * 0.9, r0 - vec2(0.9, 0.0), r0, s * 2.0);
45
+ return mix(r0, vec2($RAIL_X1, r0.y), (s - 0.5) * 2.0);
46
+ }
47
+
48
+ Particle $main(uint id, float sel, Frame f) {
49
+ float local = $progress(f);
50
+ float time = f.time;
51
+ uint s = seedOf(id, 0x68E31DA4u);
52
+ float a = rnd(s);
53
+ float b = rnd(s);
54
+ float c = rnd(s);
55
+ float d = rnd(s);
56
+ Particle P = blank();
57
+ vec2 g = gauss(b, c);
58
+ float halo = step(0.82, d);
59
+
60
+ if (sel < 0.2) {
61
+ // The single source beam.
62
+ float sp = fract(a + time * 0.05);
63
+ vec2 q = mix($SRC, $entryPoint(), sp);
64
+ vec2 off = g * mix(0.016, 0.06, halo);
65
+ float pulse = pow(0.5 + 0.5 * sin(sp * 60.0 - time * 4.0), 10.0);
66
+ P.pos = vec3(q.x, q.y + off.x, off.y);
67
+ P.col = vec3(1.0, 0.96, 0.9) * mix(0.9, 0.12, halo) * (1.0 + pulse * 1.5) * smoothstep(0.0, 0.3, sp);
68
+ P.size = mix(0.8, 1.1, halo);
69
+ } else if (sel < 0.26) {
70
+ // Dispersion inside the glass.
71
+ int i = min(int(a * 7.0), 6);
72
+ vec2 q = mix($entryPoint(), $exitPoint(i), b);
73
+ P.pos = vec3(q.x, q.y + g.x * 0.01, g.y * 0.04);
74
+ P.col = mix(vec3(1.0), $SPECTRUM[i], b) * 0.4;
75
+ P.size = 0.8;
76
+ } else if (sel < 0.31) {
77
+ // Prism edges.
78
+ float e = a * 15.6;
79
+ vec3 p;
80
+ if (e < 11.4) {
81
+ float z = e < 5.7 ? -$PRISM_Z : $PRISM_Z;
82
+ float ee = mod(e, 5.7) / 1.9;
83
+ int k = min(int(ee), 2);
84
+ vec2 v0 = k == 0 ? $PA : (k == 1 ? $PB : $PC);
85
+ vec2 v1 = k == 0 ? $PB : (k == 1 ? $PC : $PA);
86
+ p = vec3(mix(v0, v1, ee - float(k)), z);
87
+ } else {
88
+ float ee = (e - 11.4) / 1.4;
89
+ int k = min(int(ee), 2);
90
+ vec2 v = k == 0 ? $PA : (k == 1 ? $PB : $PC);
91
+ p = vec3(v, mix(-$PRISM_Z, $PRISM_Z, ee - float(k)));
92
+ }
93
+ P.pos = p;
94
+ P.col = vec3(0.78, 0.85, 1.0) * 0.4;
95
+ P.size = 0.75;
96
+ } else if (sel < 0.35) {
97
+ // Glass faces.
98
+ int k = min(int(a * 3.0), 2);
99
+ vec2 v0 = k == 0 ? $PA : (k == 1 ? $PB : $PC);
100
+ vec2 v1 = k == 0 ? $PB : (k == 1 ? $PC : $PA);
101
+ P.pos = vec3(mix(v0, v1, b), mix(-$PRISM_Z, $PRISM_Z, c));
102
+ P.col = vec3(0.7, 0.8, 1.0) * 0.05;
103
+ P.size = 0.8;
104
+ } else if (sel < 0.92) {
105
+ // Seven rails, extending as the chapter is read.
106
+ int i = min(int((sel - 0.35) / 0.57 * 7.0), 6);
107
+ float reach = $railReach(i, local);
108
+ float sp = fract(a + time * 0.06) * reach;
109
+ vec2 q = $outPath(i, sp);
110
+ vec2 off = g * mix(0.014, 0.05, halo);
111
+ float pulse = pow(0.5 + 0.5 * sin(sp * 42.0 - time * 4.5 + float(i) * 1.3), 10.0);
112
+ float front = smoothstep(reach - 0.05, reach, sp) * (1.0 - smoothstep(0.97, 1.0, reach));
113
+ // A short rail packs all its particles into a few pixels: dim it until it
114
+ // has room, or the prism's exit blows out into a flare.
115
+ float packed = mix(0.25, 1.0, smoothstep(0.1, 0.6, reach));
116
+ P.pos = vec3(q.x, q.y + off.x, off.y);
117
+ P.col = $SPECTRUM[i] * mix(0.8, 0.1, halo) * (1.0 + pulse * 1.6 + front * 3.0) * packed;
118
+ P.size = mix(0.8, 1.1, halo);
119
+ } else if (sel < 0.965) {
120
+ // Terminal nodes.
121
+ int i = min(int(a * 7.0), 6);
122
+ vec2 center = vec2($RAIL_X1, $railY(i));
123
+ bool ring = b < 0.7;
124
+ vec2 q = ring ? center + 0.075 * vec2(cos(c * TAU), sin(c * TAU)) : center + g * 0.012;
125
+ P.pos = vec3(q, 0.0);
126
+ P.col = $SPECTRUM[i] * (ring ? 0.6 : 1.4) * smoothstep(0.9, 1.0, $railReach(i, local));
127
+ P.size = 0.8;
128
+ } else {
129
+ // Dust caught in the light.
130
+ vec3 p = vec3(mix(-6.0, 7.5, a), mix(-2.6, 2.6, b), mix(-2.5, 2.5, c));
131
+ p.x = mod(p.x + time * 0.05 + 6.0, 13.5) - 6.0;
132
+ P.pos = p;
133
+ P.col = vec3(0.7, 0.75, 0.9) * 0.05;
134
+ P.size = 0.9;
135
+ }
136
+ return P;
137
+ }
138
+ ` };
139
+ //#endregion
140
+ export { shader };
@@ -0,0 +1,4 @@
1
+ //#region src/formations/tokens/geometry.d.ts
2
+ export declare const THEMES: readonly ["aurora", "ember", "mono"];
3
+ export type Theme = (typeof THEMES)[number];
4
+ //#endregion
@@ -0,0 +1,22 @@
1
+ //#region src/formations/tokens/geometry.ts
2
+ const TOKEN_PITCH = .44;
3
+ const TOKEN_FRAME = [2.86, 1.76];
4
+ const THEMES = [
5
+ "aurora",
6
+ "ember",
7
+ "mono"
8
+ ];
9
+ /**
10
+ * Theme phase of the top-left token, one unit per theme; the other tokens run
11
+ * ahead of it along the diagonal. `shift` is added by `next()`.
12
+ */
13
+ const themePhase = (time, local, shift) => time * .06 + local * .75 + shift;
14
+ /** Themes the top-left token has reached, counted once its colour change is mostly done. */
15
+ const themeStep = (phase) => Math.floor(phase + .15);
16
+ /** The phase offset that lands the whole matrix `skips` themes further on. */
17
+ function skipThemes(state, skips) {
18
+ const phase = themePhase(state.time, state.local, state.shift);
19
+ return state.shift + themeStep(phase) + skips - phase;
20
+ }
21
+ //#endregion
22
+ export { THEMES, TOKEN_FRAME, TOKEN_PITCH, skipThemes, themePhase, themeStep };