@vfx-js/effects 1.2.0 → 1.4.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 (182) hide show
  1. package/README.md +2 -0
  2. package/lib/cjs/_figma-common.d.ts +8 -0
  3. package/lib/cjs/_figma-common.js +46 -0
  4. package/lib/cjs/_figma-common.js.map +1 -0
  5. package/lib/cjs/_pad.d.ts +2 -0
  6. package/lib/cjs/_pad.js +12 -0
  7. package/lib/cjs/_pad.js.map +1 -0
  8. package/lib/cjs/_particle-common.d.ts +0 -1
  9. package/lib/cjs/_particle-common.js +1 -6
  10. package/lib/cjs/_particle-common.js.map +1 -1
  11. package/lib/cjs/ascii.d.ts +137 -0
  12. package/lib/cjs/ascii.js +482 -0
  13. package/lib/cjs/ascii.js.map +1 -0
  14. package/lib/cjs/bloom.d.ts +2 -2
  15. package/lib/cjs/bloom.js +2 -7
  16. package/lib/cjs/bloom.js.map +1 -1
  17. package/lib/cjs/chromatic.d.ts +15 -0
  18. package/lib/cjs/chromatic.js +70 -0
  19. package/lib/cjs/chromatic.js.map +1 -0
  20. package/lib/cjs/colored-edges.d.ts +23 -0
  21. package/lib/cjs/colored-edges.js +88 -0
  22. package/lib/cjs/colored-edges.js.map +1 -0
  23. package/lib/cjs/datamosh.d.ts +11 -0
  24. package/lib/cjs/datamosh.js +28 -6
  25. package/lib/cjs/datamosh.js.map +1 -1
  26. package/lib/cjs/dither.d.ts +24 -0
  27. package/lib/cjs/dither.js +120 -0
  28. package/lib/cjs/dither.js.map +1 -0
  29. package/lib/cjs/duotone.d.ts +17 -0
  30. package/lib/cjs/duotone.js +62 -0
  31. package/lib/cjs/duotone.js.map +1 -0
  32. package/lib/cjs/fluid.js +1 -6
  33. package/lib/cjs/fluid.js.map +1 -1
  34. package/lib/cjs/glitch.d.ts +13 -0
  35. package/lib/cjs/glitch.js +108 -0
  36. package/lib/cjs/glitch.js.map +1 -0
  37. package/lib/cjs/gradient-map.d.ts +25 -0
  38. package/lib/cjs/gradient-map.js +154 -0
  39. package/lib/cjs/gradient-map.js.map +1 -0
  40. package/lib/cjs/hue-shift.d.ts +11 -0
  41. package/lib/cjs/hue-shift.js +65 -0
  42. package/lib/cjs/hue-shift.js.map +1 -0
  43. package/lib/cjs/index.d.ts +21 -0
  44. package/lib/cjs/index.js +45 -1
  45. package/lib/cjs/index.js.map +1 -1
  46. package/lib/cjs/light-streak.d.ts +91 -0
  47. package/lib/cjs/light-streak.js +385 -0
  48. package/lib/cjs/light-streak.js.map +1 -0
  49. package/lib/cjs/matrix.d.ts +135 -0
  50. package/lib/cjs/matrix.js +593 -0
  51. package/lib/cjs/matrix.js.map +1 -0
  52. package/lib/cjs/package.json +6 -6
  53. package/lib/cjs/particle-explode.d.ts +2 -2
  54. package/lib/cjs/particle-explode.js +4 -4
  55. package/lib/cjs/particle-explode.js.map +1 -1
  56. package/lib/cjs/particle.d.ts +2 -2
  57. package/lib/cjs/particle.js +1 -1
  58. package/lib/cjs/particle.js.map +1 -1
  59. package/lib/cjs/pattern-refraction.d.ts +31 -0
  60. package/lib/cjs/pattern-refraction.js +190 -0
  61. package/lib/cjs/pattern-refraction.js.map +1 -0
  62. package/lib/cjs/pixel-stretch.d.ts +21 -0
  63. package/lib/cjs/pixel-stretch.js +78 -0
  64. package/lib/cjs/pixel-stretch.js.map +1 -0
  65. package/lib/cjs/rainbow.d.ts +13 -0
  66. package/lib/cjs/rainbow.js +79 -0
  67. package/lib/cjs/rainbow.js.map +1 -0
  68. package/lib/cjs/rgb-glitch.d.ts +13 -0
  69. package/lib/cjs/rgb-glitch.js +79 -0
  70. package/lib/cjs/rgb-glitch.js.map +1 -0
  71. package/lib/cjs/rgb-shift.d.ts +13 -0
  72. package/lib/cjs/rgb-shift.js +76 -0
  73. package/lib/cjs/rgb-shift.js.map +1 -0
  74. package/lib/cjs/sinewave.d.ts +17 -0
  75. package/lib/cjs/sinewave.js +76 -0
  76. package/lib/cjs/sinewave.js.map +1 -0
  77. package/lib/cjs/slice-shift.d.ts +21 -0
  78. package/lib/cjs/slice-shift.js +75 -0
  79. package/lib/cjs/slice-shift.js.map +1 -0
  80. package/lib/cjs/tile-pixelate.d.ts +28 -0
  81. package/lib/cjs/tile-pixelate.js +168 -0
  82. package/lib/cjs/tile-pixelate.js.map +1 -0
  83. package/lib/cjs/tritone.d.ts +18 -0
  84. package/lib/cjs/tritone.js +67 -0
  85. package/lib/cjs/tritone.js.map +1 -0
  86. package/lib/cjs/vignette.d.ts +15 -0
  87. package/lib/cjs/vignette.js +59 -0
  88. package/lib/cjs/vignette.js.map +1 -0
  89. package/lib/cjs/warp.d.ts +22 -0
  90. package/lib/cjs/warp.js +92 -0
  91. package/lib/cjs/warp.js.map +1 -0
  92. package/lib/esm/_figma-common.d.ts +8 -0
  93. package/lib/esm/_figma-common.js +42 -0
  94. package/lib/esm/_figma-common.js.map +1 -0
  95. package/lib/esm/_pad.d.ts +2 -0
  96. package/lib/esm/_pad.js +9 -0
  97. package/lib/esm/_pad.js.map +1 -0
  98. package/lib/esm/_particle-common.d.ts +0 -1
  99. package/lib/esm/_particle-common.js +0 -5
  100. package/lib/esm/_particle-common.js.map +1 -1
  101. package/lib/esm/ascii.d.ts +137 -0
  102. package/lib/esm/ascii.js +478 -0
  103. package/lib/esm/ascii.js.map +1 -0
  104. package/lib/esm/bloom.d.ts +2 -2
  105. package/lib/esm/bloom.js +2 -7
  106. package/lib/esm/bloom.js.map +1 -1
  107. package/lib/esm/chromatic.d.ts +15 -0
  108. package/lib/esm/chromatic.js +66 -0
  109. package/lib/esm/chromatic.js.map +1 -0
  110. package/lib/esm/colored-edges.d.ts +23 -0
  111. package/lib/esm/colored-edges.js +84 -0
  112. package/lib/esm/colored-edges.js.map +1 -0
  113. package/lib/esm/datamosh.d.ts +11 -0
  114. package/lib/esm/datamosh.js +28 -6
  115. package/lib/esm/datamosh.js.map +1 -1
  116. package/lib/esm/dither.d.ts +24 -0
  117. package/lib/esm/dither.js +116 -0
  118. package/lib/esm/dither.js.map +1 -0
  119. package/lib/esm/duotone.d.ts +17 -0
  120. package/lib/esm/duotone.js +58 -0
  121. package/lib/esm/duotone.js.map +1 -0
  122. package/lib/esm/fluid.js +1 -6
  123. package/lib/esm/fluid.js.map +1 -1
  124. package/lib/esm/glitch.d.ts +13 -0
  125. package/lib/esm/glitch.js +104 -0
  126. package/lib/esm/glitch.js.map +1 -0
  127. package/lib/esm/gradient-map.d.ts +25 -0
  128. package/lib/esm/gradient-map.js +150 -0
  129. package/lib/esm/gradient-map.js.map +1 -0
  130. package/lib/esm/hue-shift.d.ts +11 -0
  131. package/lib/esm/hue-shift.js +61 -0
  132. package/lib/esm/hue-shift.js.map +1 -0
  133. package/lib/esm/index.d.ts +21 -0
  134. package/lib/esm/index.js +21 -0
  135. package/lib/esm/index.js.map +1 -1
  136. package/lib/esm/light-streak.d.ts +91 -0
  137. package/lib/esm/light-streak.js +381 -0
  138. package/lib/esm/light-streak.js.map +1 -0
  139. package/lib/esm/matrix.d.ts +135 -0
  140. package/lib/esm/matrix.js +589 -0
  141. package/lib/esm/matrix.js.map +1 -0
  142. package/lib/esm/package.json +6 -6
  143. package/lib/esm/particle-explode.d.ts +2 -2
  144. package/lib/esm/particle-explode.js +5 -5
  145. package/lib/esm/particle-explode.js.map +1 -1
  146. package/lib/esm/particle.d.ts +2 -2
  147. package/lib/esm/particle.js +2 -2
  148. package/lib/esm/particle.js.map +1 -1
  149. package/lib/esm/pattern-refraction.d.ts +31 -0
  150. package/lib/esm/pattern-refraction.js +186 -0
  151. package/lib/esm/pattern-refraction.js.map +1 -0
  152. package/lib/esm/pixel-stretch.d.ts +21 -0
  153. package/lib/esm/pixel-stretch.js +74 -0
  154. package/lib/esm/pixel-stretch.js.map +1 -0
  155. package/lib/esm/rainbow.d.ts +13 -0
  156. package/lib/esm/rainbow.js +75 -0
  157. package/lib/esm/rainbow.js.map +1 -0
  158. package/lib/esm/rgb-glitch.d.ts +13 -0
  159. package/lib/esm/rgb-glitch.js +75 -0
  160. package/lib/esm/rgb-glitch.js.map +1 -0
  161. package/lib/esm/rgb-shift.d.ts +13 -0
  162. package/lib/esm/rgb-shift.js +72 -0
  163. package/lib/esm/rgb-shift.js.map +1 -0
  164. package/lib/esm/sinewave.d.ts +17 -0
  165. package/lib/esm/sinewave.js +72 -0
  166. package/lib/esm/sinewave.js.map +1 -0
  167. package/lib/esm/slice-shift.d.ts +21 -0
  168. package/lib/esm/slice-shift.js +71 -0
  169. package/lib/esm/slice-shift.js.map +1 -0
  170. package/lib/esm/tile-pixelate.d.ts +28 -0
  171. package/lib/esm/tile-pixelate.js +164 -0
  172. package/lib/esm/tile-pixelate.js.map +1 -0
  173. package/lib/esm/tritone.d.ts +18 -0
  174. package/lib/esm/tritone.js +63 -0
  175. package/lib/esm/tritone.js.map +1 -0
  176. package/lib/esm/vignette.d.ts +15 -0
  177. package/lib/esm/vignette.js +55 -0
  178. package/lib/esm/vignette.js.map +1 -0
  179. package/lib/esm/warp.d.ts +22 -0
  180. package/lib/esm/warp.js +88 -0
  181. package/lib/esm/warp.js.map +1 -0
  182. package/package.json +7 -7
@@ -0,0 +1,385 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _LightStreakEffect_geometry, _LightStreakEffect_geometryDensity, _LightStreakEffect_accum, _LightStreakEffect_highlight, _LightStreakEffect_lastW, _LightStreakEffect_lastH;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LightStreakEffect = void 0;
16
+ const _pad_js_1 = require("./_pad.js");
17
+ // Premultiplied base copy, hard-masked to the inner rect so the pad
18
+ // region doesn't clamp-replicate the capture's edge texels.
19
+ const FRAG_BASE = `#version 300 es
20
+ precision highp float;
21
+ in vec2 uvSrc;
22
+ in vec2 uvContent;
23
+ out vec4 outColor;
24
+ uniform sampler2D src;
25
+
26
+ void main() {
27
+ vec2 inS = step(vec2(0.0), uvSrc) * step(uvSrc, vec2(1.0));
28
+ vec2 inC = step(vec2(0.0), uvContent) * step(uvContent, vec2(1.0));
29
+ float m = inS.x * inS.y * inC.x * inC.y;
30
+ vec4 base = texture(src, clamp(uvSrc, 0.0, 1.0)) * m;
31
+ outColor = vec4(base.rgb * base.a, base.a);
32
+ }
33
+ `;
34
+ // Integer hash and the jittered sample point of a grid cell (src uv
35
+ // space). Shared by the highlight pre-pass and the streak VS so anchor
36
+ // positions and sampled colors agree.
37
+ const GLSL_CELL = `
38
+ float hash(uint n) {
39
+ n = (n ^ 61u) ^ (n >> 16u);
40
+ n *= 9u;
41
+ n = n ^ (n >> 4u);
42
+ n *= 0x27d4eb2du;
43
+ n = n ^ (n >> 15u);
44
+ return float(n & 0x00ffffffu) / 16777216.0;
45
+ }
46
+
47
+ vec2 cellUv(ivec2 cell, int dim) {
48
+ uint i = uint(cell.y * dim + cell.x);
49
+ vec2 j = vec2(hash(i * 2u + 1u), hash(i * 2u + 2u)) - 0.5;
50
+ return (vec2(cell) + 0.5 + j * 0.8) / float(dim);
51
+ }
52
+ `;
53
+ // Highlight pre-pass into a dim×dim buffer: rgb = clamped highlight
54
+ // color, a = gate. Runs once per frame so the per-ray streak VS reads a
55
+ // tiny texture instead of re-extracting from the full-res source.
56
+ const FRAG_HIGHLIGHT = `#version 300 es
57
+ precision highp float;
58
+ out vec4 outColor;
59
+ uniform sampler2D src;
60
+ uniform float threshold; // highlight cutoff
61
+ uniform float highlightClamp; // upper clamp on source highlight brightness
62
+ uniform int dim;
63
+ ${GLSL_CELL}
64
+ void main() {
65
+ ivec2 cell = ivec2(gl_FragCoord.xy);
66
+ vec3 c = texture(src, cellUv(cell, dim)).rgb;
67
+ // Max-channel knee, hue preserved, clamped so blown-out sources
68
+ // don't dominate. gate is the highlight factor in [0,1].
69
+ float vmax = max(max(c.r, c.g), c.b);
70
+ if (vmax > highlightClamp) {
71
+ c *= highlightClamp / vmax;
72
+ vmax = highlightClamp;
73
+ }
74
+ float gate = max(0.0, vmax - threshold) / max(vmax, 1e-5);
75
+ outColor = vec4(c, gate);
76
+ }
77
+ `;
78
+ // Per-instance streak quad. `position.x` runs 0→1 from the source point
79
+ // to the tip; `position.y` runs -1→1 across the (thin) width. The VS
80
+ // reads the pre-extracted highlight for its cell and lays the quad down
81
+ // in the target's NDC. Cells below threshold collapse to a degenerate
82
+ // off-screen point so the rasteriser skips them entirely.
83
+ const VERT_STREAK = `#version 300 es
84
+ precision highp float;
85
+ in vec2 position;
86
+
87
+ uniform sampler2D highlight; // dim×dim pre-pass output
88
+ uniform int dim;
89
+ // Source buffer rect and this stage's output rect, in element-local
90
+ // physical px. The host viewport equals dstRect.
91
+ uniform vec4 srcRect;
92
+ uniform vec4 dstRect;
93
+ uniform float angle; // streak direction (rad)
94
+ uniform float lengthPx; // max streak length (physical px)
95
+ uniform float widthPx; // streak cross-section width (physical px)
96
+
97
+ out float v_along;
98
+ out float v_cross;
99
+ out vec3 v_color;
100
+ out float v_gate;
101
+ ${GLSL_CELL}
102
+ void main() {
103
+ ivec2 cell = ivec2(gl_InstanceID % dim, gl_InstanceID / dim);
104
+ vec4 hl = texelFetch(highlight, cell, 0);
105
+ vec3 c = hl.rgb;
106
+ float gate = hl.a;
107
+
108
+ // Cull dim cells: collapse the quad to a single off-screen point.
109
+ if (gate < 0.003) {
110
+ gl_Position = vec4(2.0, 2.0, 0.0, 1.0);
111
+ v_along = 0.0;
112
+ v_cross = 0.0;
113
+ v_color = vec3(0.0);
114
+ v_gate = 0.0;
115
+ return;
116
+ }
117
+
118
+ vec2 srcPx = srcRect.xy + cellUv(cell, dim) * srcRect.zw;
119
+ vec2 centerNdc = (srcPx - dstRect.xy) / dstRect.zw * 2.0 - 1.0;
120
+
121
+ vec2 dir = vec2(cos(angle), sin(angle));
122
+ vec2 perp = vec2(-dir.y, dir.x);
123
+
124
+ vec2 offPx = dir * (position.x * lengthPx)
125
+ + perp * (position.y * widthPx * 0.5);
126
+
127
+ // px → NDC delta; the divide by w/h is undone by the viewport mapping.
128
+ vec2 ndc = centerNdc + offPx * 2.0 / dstRect.zw;
129
+ gl_Position = vec4(ndc, 0.0, 1.0);
130
+
131
+ v_along = position.x;
132
+ v_cross = position.y;
133
+ v_color = c;
134
+ v_gate = gate;
135
+ }
136
+ `;
137
+ // Streak profile. Emits raw premultiplied color into the float
138
+ // accumulation buffer; tint and tone map happen in the composite.
139
+ const FRAG_STREAK = `#version 300 es
140
+ precision highp float;
141
+ in float v_along;
142
+ in float v_cross;
143
+ in vec3 v_color;
144
+ in float v_gate;
145
+
146
+ uniform float falloff; // length fade decay rate
147
+ uniform float dispersion; // -1 = blue tip, +1 = red tip
148
+ uniform float fringe; // diffraction fringe contrast
149
+ uniform float fringeCount; // fringes along the streak (green reference)
150
+
151
+ out vec4 outColor;
152
+
153
+ void main() {
154
+ // Normalized exponential length falloff, pinned to 1 at the source
155
+ // and 0 at the tip. Floor k so falloff -> 0 approaches the linear
156
+ // limit instead of degenerating to zero output.
157
+ float k = max(falloff, 1e-3);
158
+ float eEnd = exp(-k);
159
+ float base = max((exp(-k * v_along) - eEnd) / max(1.0 - eEnd, 1e-4), 0.0);
160
+ // Dispersion: per-channel exponential reach ratio pivoting on green,
161
+ // applied over the normalized profile so the tip fringe survives.
162
+ float spread = dispersion * 0.8;
163
+ vec3 perChannel = base * exp(k * spread * vec3(1.0, 0.0, -1.0) * v_along);
164
+ // Soft gaussian cross-section so neighbouring sprites overlap into a
165
+ // continuous sheet instead of discrete stripes.
166
+ float crossFall = exp(-v_cross * v_cross * 2.0);
167
+ vec3 rgb = v_color * perChannel * (crossFall * v_gate);
168
+
169
+ // Diffraction fringes: per-channel intensity modulation whose period
170
+ // scales with wavelength (630/530/465 nm), so all channels peak at the
171
+ // source (white core) and separate into rainbow bands further out.
172
+ if (fringe > 1e-4) {
173
+ vec3 freq = fringeCount * vec3(0.8413, 1.0, 1.1398);
174
+ vec3 m = 0.5 + 0.5 * cos(6.2831853 * freq * v_along);
175
+ rgb *= mix(vec3(1.0), m, fringe);
176
+ }
177
+
178
+ if (max(max(rgb.r, rgb.g), rgb.b) < 1e-4) {
179
+ discard;
180
+ }
181
+ outColor = vec4(rgb, 1.0);
182
+ }
183
+ `;
184
+ // Tone-mapped composite of the accumulated streaks over the source.
185
+ // `1 - exp(-x)` softly saturates dense overlaps toward `tint`.
186
+ const FRAG_COMPOSITE = `#version 300 es
187
+ precision highp float;
188
+ in vec2 uv;
189
+ out vec4 outColor;
190
+ uniform sampler2D accum;
191
+ uniform vec3 tint;
192
+ uniform float intensity;
193
+ uniform float norm; // core-gain normalisation (cross-method calibration)
194
+
195
+ void main() {
196
+ vec3 acc = max(texture(accum, uv).rgb, vec3(0.0));
197
+ vec3 s = (1.0 - exp(-acc * norm * intensity)) * tint;
198
+ float a = clamp(dot(s, vec3(0.2126, 0.7152, 0.0722)), 0.0, 1.0);
199
+ outColor = vec4(s, a);
200
+ }
201
+ `;
202
+ // Density the brightness calibration is anchored to.
203
+ const REF_DENSITY = 256;
204
+ const DEFAULT_PARAMS = {
205
+ streaks: 2,
206
+ angle: 0,
207
+ length: 300,
208
+ width: 3,
209
+ falloff: 2.0,
210
+ threshold: 0.9,
211
+ highlightClamp: 1.0,
212
+ intensity: 0.5,
213
+ tint: [1.0, 1.0, 1.0],
214
+ dispersion: -0.3,
215
+ fringe: 0.5,
216
+ fringeCount: 1.5,
217
+ density: 256,
218
+ resolution: 0.2,
219
+ pad: 300,
220
+ };
221
+ /**
222
+ * Light-streak effect (anamorphic flare / aperture starburst) built from
223
+ * instanced streak sprites. Mutate `params` directly or via `setParams`;
224
+ * uniforms are read live each frame, so a reactive UI (e.g. Tweakpane)
225
+ * can bind straight to `effect.params`.
226
+ */
227
+ class LightStreakEffect {
228
+ constructor(initial = {}) {
229
+ _LightStreakEffect_geometry.set(this, null);
230
+ _LightStreakEffect_geometryDensity.set(this, 0);
231
+ _LightStreakEffect_accum.set(this, null);
232
+ _LightStreakEffect_highlight.set(this, null);
233
+ _LightStreakEffect_lastW.set(this, 0);
234
+ _LightStreakEffect_lastH.set(this, 0);
235
+ this.params = { ...DEFAULT_PARAMS, ...initial };
236
+ }
237
+ setParams(updates) {
238
+ Object.assign(this.params, updates);
239
+ }
240
+ render(ctx) {
241
+ const dim = Math.max(2, Math.floor(this.params.density));
242
+ if (!__classPrivateFieldGet(this, _LightStreakEffect_geometry, "f") || __classPrivateFieldGet(this, _LightStreakEffect_geometryDensity, "f") !== dim) {
243
+ if (__classPrivateFieldGet(this, _LightStreakEffect_geometry, "f")) {
244
+ ctx.releaseGeometry(__classPrivateFieldGet(this, _LightStreakEffect_geometry, "f"));
245
+ }
246
+ __classPrivateFieldSet(this, _LightStreakEffect_geometry, buildGeometry(dim), "f");
247
+ __classPrivateFieldSet(this, _LightStreakEffect_geometryDensity, dim, "f");
248
+ __classPrivateFieldGet(this, _LightStreakEffect_highlight, "f")?.dispose();
249
+ __classPrivateFieldSet(this, _LightStreakEffect_highlight, ctx.createRenderTarget({
250
+ size: [dim, dim],
251
+ float: true,
252
+ filter: "nearest",
253
+ }), "f");
254
+ }
255
+ const highlight = __classPrivateFieldGet(this, _LightStreakEffect_highlight, "f");
256
+ if (!highlight) {
257
+ return;
258
+ }
259
+ const dst = this.outputRect(ctx.dims);
260
+ const src = ctx.dims.srcRect;
261
+ const pr = ctx.dims.pixelRatio;
262
+ // Float accumulation buffer, scaled by `resolution` (streaks
263
+ // accumulate past 1.0, tone-mapped at composite).
264
+ const res = Math.min(Math.max(this.params.resolution, 0.1), 1);
265
+ const aw = Math.max(2, Math.round(dst[2] * res));
266
+ const ah = Math.max(2, Math.round(dst[3] * res));
267
+ if (aw !== __classPrivateFieldGet(this, _LightStreakEffect_lastW, "f") || ah !== __classPrivateFieldGet(this, _LightStreakEffect_lastH, "f")) {
268
+ __classPrivateFieldGet(this, _LightStreakEffect_accum, "f")?.dispose();
269
+ __classPrivateFieldSet(this, _LightStreakEffect_accum, ctx.createRenderTarget({
270
+ size: [aw, ah],
271
+ float: true,
272
+ filter: "linear",
273
+ }), "f");
274
+ __classPrivateFieldSet(this, _LightStreakEffect_lastW, aw, "f");
275
+ __classPrivateFieldSet(this, _LightStreakEffect_lastH, ah, "f");
276
+ }
277
+ const accum = __classPrivateFieldGet(this, _LightStreakEffect_accum, "f");
278
+ if (!accum) {
279
+ return;
280
+ }
281
+ // Base image into the output (masked copy, not ctx.blit).
282
+ ctx.draw({
283
+ frag: FRAG_BASE,
284
+ target: ctx.target,
285
+ uniforms: { src: ctx.src },
286
+ });
287
+ // Extract highlights once; every ray reads this small buffer.
288
+ ctx.draw({
289
+ frag: FRAG_HIGHLIGHT,
290
+ target: highlight,
291
+ blend: "none",
292
+ uniforms: {
293
+ src: ctx.src,
294
+ threshold: this.params.threshold,
295
+ // Keep the clamp above threshold; below it the knee would
296
+ // zero every highlight and the effect would vanish.
297
+ highlightClamp: Math.max(this.params.threshold + 1e-3, this.params.highlightClamp),
298
+ dim,
299
+ },
300
+ });
301
+ // Accumulate every ray's streaks into the float buffer.
302
+ ctx.clear(accum);
303
+ const rays = Math.max(1, Math.round(this.params.streaks));
304
+ const lengthPx = this.params.length * pr;
305
+ // Streak width, taken straight as a pixel value. Thinner than the
306
+ // sampling grid cell and streaks break into stripes; raise density.
307
+ const widthPx = this.params.width * pr;
308
+ const baseAngle = (this.params.angle * Math.PI) / 180;
309
+ for (let k = 0; k < rays; k++) {
310
+ const angle = baseAngle + (k * Math.PI * 2) / rays;
311
+ ctx.draw({
312
+ vert: VERT_STREAK,
313
+ frag: FRAG_STREAK,
314
+ geometry: __classPrivateFieldGet(this, _LightStreakEffect_geometry, "f"),
315
+ blend: "additive",
316
+ target: accum,
317
+ uniforms: {
318
+ highlight,
319
+ dim,
320
+ srcRect: [src[0], src[1], src[2], src[3]],
321
+ dstRect: [dst[0], dst[1], dst[2], dst[3]],
322
+ angle,
323
+ lengthPx,
324
+ widthPx,
325
+ falloff: this.params.falloff,
326
+ dispersion: this.params.dispersion,
327
+ fringe: this.params.fringe,
328
+ fringeCount: this.params.fringeCount,
329
+ },
330
+ });
331
+ }
332
+ // Sprite overlap per pixel scales with density² (width is a fixed
333
+ // pixel value, so it cancels); divide it out against a reference
334
+ // density so brightness holds as density changes.
335
+ const densityNorm = (REF_DENSITY / dim) ** 2;
336
+ // Tone-mapped, tinted composite of the accumulation over the base.
337
+ // `norm` cancels the method's core gain (≈ rays × overlap) so the
338
+ // streak core brightness stays stable as the ray count changes.
339
+ ctx.draw({
340
+ frag: FRAG_COMPOSITE,
341
+ target: ctx.target,
342
+ blend: "additive",
343
+ uniforms: {
344
+ accum,
345
+ intensity: this.params.intensity,
346
+ norm: densityNorm / (rays * 0.9),
347
+ tint: [
348
+ this.params.tint[0],
349
+ this.params.tint[1],
350
+ this.params.tint[2],
351
+ ],
352
+ },
353
+ });
354
+ }
355
+ outputRect(dims) {
356
+ return (0, _pad_js_1.padOutputRect)(this.params.pad, dims);
357
+ }
358
+ dispose() {
359
+ __classPrivateFieldSet(this, _LightStreakEffect_geometry, null, "f");
360
+ __classPrivateFieldSet(this, _LightStreakEffect_geometryDensity, 0, "f");
361
+ __classPrivateFieldGet(this, _LightStreakEffect_accum, "f")?.dispose();
362
+ __classPrivateFieldSet(this, _LightStreakEffect_accum, null, "f");
363
+ __classPrivateFieldGet(this, _LightStreakEffect_highlight, "f")?.dispose();
364
+ __classPrivateFieldSet(this, _LightStreakEffect_highlight, null, "f");
365
+ __classPrivateFieldSet(this, _LightStreakEffect_lastW, 0, "f");
366
+ __classPrivateFieldSet(this, _LightStreakEffect_lastH, 0, "f");
367
+ }
368
+ }
369
+ exports.LightStreakEffect = LightStreakEffect;
370
+ _LightStreakEffect_geometry = new WeakMap(), _LightStreakEffect_geometryDensity = new WeakMap(), _LightStreakEffect_accum = new WeakMap(), _LightStreakEffect_highlight = new WeakMap(), _LightStreakEffect_lastW = new WeakMap(), _LightStreakEffect_lastH = new WeakMap();
371
+ // One thin quad, instanced per grid cell. The VS derives each cell (and
372
+ // its jittered sample point) from gl_InstanceID.
373
+ function buildGeometry(dim) {
374
+ return {
375
+ attributes: {
376
+ position: {
377
+ data: new Float32Array([0, -1, 1, -1, 1, 1, 0, 1]),
378
+ itemSize: 2,
379
+ },
380
+ },
381
+ indices: new Uint16Array([0, 1, 2, 0, 2, 3]),
382
+ instanceCount: dim * dim,
383
+ };
384
+ }
385
+ //# sourceMappingURL=light-streak.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"light-streak.js","sourceRoot":"","sources":["../../src/light-streak.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAaA,uCAA0C;AAE1C,oEAAoE;AACpE,4DAA4D;AAC5D,MAAM,SAAS,GAAG;;;;;;;;;;;;;;CAcjB,CAAC;AAEF,oEAAoE;AACpE,uEAAuE;AACvE,sCAAsC;AACtC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;CAejB,CAAC;AAEF,oEAAoE;AACpE,wEAAwE;AACxE,kEAAkE;AAClE,MAAM,cAAc,GAAG;;;;;;;EAOrB,SAAS;;;;;;;;;;;;;;CAcV,CAAC;AAEF,wEAAwE;AACxE,qEAAqE;AACrE,wEAAwE;AACxE,sEAAsE;AACtE,0DAA0D;AAC1D,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;EAkBlB,SAAS;;;;;;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AAI,MAAA,CAAC;QACnB,uBAAA,IAAI,oCAAW,EAAE,OAAO,EAAE,CAAC;QAC3B,uBAAA,IAAI,gCAAc,IAAI,MAAA,CAAC;QACvB,uBAAA,IAAI,4BAAU,CAAC,MAAA,CAAC;QAChB,uBAAA,IAAI,4BAAU,CAAC,MAAA,CAAC;IACpB,CAAC;CACJ;AAhKD,8CAgKC;;AAED,wEAAwE;AACxE,iDAAiD;AACjD,SAAS,aAAa,CAAC,GAAW;IAC9B,OAAO;QACH,UAAU,EAAE;YACR,QAAQ,EAAE;gBACN,IAAI,EAAE,IAAI,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;gBAClD,QAAQ,EAAE,CAAC;aACd;SACJ;QACD,OAAO,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5C,aAAa,EAAE,GAAG,GAAG,GAAG;KAC3B,CAAC;AACN,CAAC"}
@@ -0,0 +1,135 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ /** RGBA colour, each channel in [0, 1]. */
3
+ export type MatrixColor = [number, number, number, number];
4
+ /**
5
+ * Trail colour: a single {@link MatrixColor}, or an array of two or more
6
+ * colour stops forming a gradient along each drop's trail (first stop at the
7
+ * head, last at the tail end). Stops are interpolated in OKLCH.
8
+ */
9
+ export type MatrixTrailColor = MatrixColor | MatrixColor[];
10
+ /**
11
+ * The pool of glyphs rained down the columns. Pass a string (split per
12
+ * Unicode code point) or an array of single chars. The order is irrelevant
13
+ * — a random glyph is picked for every cell.
14
+ */
15
+ export type MatrixGlyphs = string | readonly string[];
16
+ /**
17
+ * Default glyph pool: half-width katakana (the look the film used) plus
18
+ * digits and a few symbols. Mirrored katakana isn't reproducible from a
19
+ * normal font, so these render upright.
20
+ */
21
+ export declare const MATRIX_GLYPHS = "\uFF8A\uFF8B\uFF8C\uFF8D\uFF8E\uFF71\uFF72\uFF73\uFF74\uFF75\uFF76\uFF77\uFF78\uFF79\uFF7A\uFF7B\uFF7C\uFF7D\uFF7E\uFF7F\uFF80\uFF81\uFF82\uFF83\uFF84\uFF85\uFF86\uFF87\uFF88\uFF89\uFF8F\uFF90\uFF91\uFF92\uFF93\uFF94\uFF95\uFF96\uFF97\uFF98\uFF99\uFF9A\uFF9B\uFF9C\uFF66\uFF9D0123456789Z:.\"=*+-<>|";
22
+ export type MatrixParams = {
23
+ /**
24
+ * Cell size in CSS px. A single number is a square cell; a
25
+ * `[width, height]` tuple sets the axes independently. Glyphs keep
26
+ * their native aspect (contain-fitted), so a non-square cell
27
+ * letterboxes rather than stretching.
28
+ */
29
+ grid: number | [number, number];
30
+ /**
31
+ * Glyph pool rained down the columns, picked at random per cell.
32
+ * Defaults to {@link MATRIX_GLYPHS}. Baked into the atlas at `init()`;
33
+ * change it (or `font` / `fontWeight`) then call
34
+ * {@link MatrixEffect.updateAtlas} (or re-add the effect) to rebuild.
35
+ */
36
+ glyphs?: MatrixGlyphs;
37
+ /** CSS font family used to render the glyph atlas. */
38
+ font: string;
39
+ /** CSS font weight for the glyph atlas (`"normal"`, `"bold"`, 100–900). */
40
+ fontWeight: string | number;
41
+ /**
42
+ * Character box aspect ratio (width / height). Omit to auto-measure it
43
+ * from the font (advance over em height).
44
+ */
45
+ charAspect?: number;
46
+ /**
47
+ * Trail colour — the classic phosphor green. Pass an array of two or
48
+ * more {@link MatrixColor} stops for a gradient along each drop's trail
49
+ * (first at the head, last at the tail end), interpolated in OKLCH. Pair
50
+ * with `tailFade: 0` to fade purely via the gradient.
51
+ */
52
+ color: MatrixTrailColor;
53
+ /** Leading-glyph colour at the head of each stream (usually near-white). */
54
+ headColor: MatrixColor;
55
+ /** Cell backdrop behind the rain, non-premultiplied. */
56
+ background: MatrixColor;
57
+ /** Base fall speed in cells per second. Per-column randomised ±50%. */
58
+ speed: number;
59
+ /** Trail length in cells (how far the trail extends behind the head). */
60
+ tail: number;
61
+ /**
62
+ * How much the trail dims toward its tail, in `[0, 1]`. `1` is the
63
+ * classic bright-head / dim-tail falloff; `0` keeps the whole trail at
64
+ * full brightness so you control the fade yourself via the colour
65
+ * gradient (e.g. a `color` stop fading to transparent or black).
66
+ */
67
+ tailFade: number;
68
+ /**
69
+ * Drop spawn rate: how many new falling streams are born per second in
70
+ * each column. Higher values spawn drops frequently (a busy, dense
71
+ * downpour — drops overlap into near-continuous streams); lower values
72
+ * leave long gaps between drops (sparse, intermittent rain).
73
+ */
74
+ birthRate: number;
75
+ /** Glyph reshuffle rate in changes per second (`0` = static glyphs). */
76
+ glyphSpeed: number;
77
+ /** Overall gain on the rain brightness. */
78
+ brightness: number;
79
+ /**
80
+ * Contrast of the source luminance, pivoting around mid-grey (0.5).
81
+ * `1` leaves the input unchanged; `< 1` flattens it toward grey; `> 1`
82
+ * deepens the split between dark and bright regions, so the picture
83
+ * reads more sharply through the rain.
84
+ */
85
+ contrast: number;
86
+ /** Flip the source luminance (rain shows through dark areas instead). */
87
+ invert: boolean;
88
+ /**
89
+ * Random seed for the rain pattern (per-column speed/phase and the glyph
90
+ * sequence). Any number; the same seed always reproduces the same
91
+ * pattern, so pin it (with {@link VFX.setTime}) for deterministic
92
+ * snapshots / visual regression tests. `0` is the default look.
93
+ */
94
+ seed: number;
95
+ };
96
+ /**
97
+ * "Digital rain" / Matrix-movie effect.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * vfx.add(el, { effect: new MatrixEffect({ grid: [12, 16] }) });
102
+ * vfx.add(el, { effect: new MatrixEffect({ glyphs: "01", color: [0, 1, 0, 1] }) });
103
+ * ```
104
+ *
105
+ * Splits the element into a grid and rains a random glyph down each column,
106
+ * with a bright leading tip and a fading green trail. The source image's
107
+ * grayscale is multiplied into the rain, so the picture emerges from the
108
+ * falling characters.
109
+ *
110
+ * `grid`, `color`, `headColor`, `background`, `speed`, `tail`, `tailFade`,
111
+ * `birthRate`, `glyphSpeed`, `brightness`, `contrast`, `invert`, and `seed`
112
+ * are live (read every frame). `glyphs` / `font` / `fontWeight` / `charAspect` are
113
+ * baked into the atlas at `init()` — after changing them via `setParams`,
114
+ * call {@link MatrixEffect.updateAtlas} (or re-add the effect) to rebuild.
115
+ */
116
+ export declare class MatrixEffect implements Effect {
117
+ #private;
118
+ constructor(initial?: Partial<MatrixParams>);
119
+ setParams(updates: Partial<MatrixParams>): void;
120
+ init(ctx: EffectContext): Promise<void>;
121
+ /**
122
+ * Rebuild the atlas from the current params, applying changes to the
123
+ * baked fields (`glyphs` / `font` / `fontWeight` / `charAspect`) without
124
+ * removing and re-adding the effect. Async — it may load fonts. No-op
125
+ * before `init()`.
126
+ *
127
+ * Allocates a fresh atlas texture and disposes the previous one once the
128
+ * swap is live, so repeated calls don't leak. Still rasterises the
129
+ * atlas, so prefer occasional calls (e.g. on a settings change) over
130
+ * per-frame use.
131
+ */
132
+ updateAtlas(): Promise<void>;
133
+ render(ctx: EffectContext): void;
134
+ dispose(): void;
135
+ }