@vfx-js/effects 1.0.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/LICENSE +20 -0
  2. package/README.md +58 -0
  3. package/lib/cjs/_curl-noise.d.ts +3 -0
  4. package/lib/cjs/_curl-noise.js +115 -0
  5. package/lib/cjs/_curl-noise.js.map +1 -0
  6. package/lib/cjs/_particle-common.d.ts +10 -0
  7. package/lib/cjs/_particle-common.js +98 -0
  8. package/lib/cjs/_particle-common.js.map +1 -0
  9. package/lib/cjs/bloom.d.ts +50 -0
  10. package/lib/cjs/bloom.js +452 -0
  11. package/lib/cjs/bloom.js.map +1 -0
  12. package/lib/cjs/fluid.d.ts +35 -0
  13. package/lib/cjs/fluid.js +407 -0
  14. package/lib/cjs/fluid.js.map +1 -0
  15. package/lib/cjs/halftone.d.ts +65 -0
  16. package/lib/cjs/halftone.js +272 -0
  17. package/lib/cjs/halftone.js.map +1 -0
  18. package/lib/cjs/index.d.ts +8 -0
  19. package/lib/cjs/index.js +20 -0
  20. package/lib/cjs/index.js.map +1 -0
  21. package/lib/cjs/package.json +57 -0
  22. package/lib/cjs/particle-explode.d.ts +48 -0
  23. package/lib/cjs/particle-explode.js +466 -0
  24. package/lib/cjs/particle-explode.js.map +1 -0
  25. package/lib/cjs/particle.d.ts +78 -0
  26. package/lib/cjs/particle.js +710 -0
  27. package/lib/cjs/particle.js.map +1 -0
  28. package/lib/cjs/pixelate.d.ts +11 -0
  29. package/lib/cjs/pixelate.js +48 -0
  30. package/lib/cjs/pixelate.js.map +1 -0
  31. package/lib/cjs/scanline.d.ts +11 -0
  32. package/lib/cjs/scanline.js +48 -0
  33. package/lib/cjs/scanline.js.map +1 -0
  34. package/lib/cjs/voronoi.d.ts +35 -0
  35. package/lib/cjs/voronoi.js +266 -0
  36. package/lib/cjs/voronoi.js.map +1 -0
  37. package/lib/esm/_curl-noise.d.ts +3 -0
  38. package/lib/esm/_curl-noise.js +112 -0
  39. package/lib/esm/_curl-noise.js.map +1 -0
  40. package/lib/esm/_particle-common.d.ts +10 -0
  41. package/lib/esm/_particle-common.js +91 -0
  42. package/lib/esm/_particle-common.js.map +1 -0
  43. package/lib/esm/bloom.d.ts +50 -0
  44. package/lib/esm/bloom.js +448 -0
  45. package/lib/esm/bloom.js.map +1 -0
  46. package/lib/esm/fluid.d.ts +35 -0
  47. package/lib/esm/fluid.js +403 -0
  48. package/lib/esm/fluid.js.map +1 -0
  49. package/lib/esm/halftone.d.ts +65 -0
  50. package/lib/esm/halftone.js +268 -0
  51. package/lib/esm/halftone.js.map +1 -0
  52. package/lib/esm/index.d.ts +8 -0
  53. package/lib/esm/index.js +9 -0
  54. package/lib/esm/index.js.map +1 -0
  55. package/lib/esm/package.json +57 -0
  56. package/lib/esm/particle-explode.d.ts +48 -0
  57. package/lib/esm/particle-explode.js +462 -0
  58. package/lib/esm/particle-explode.js.map +1 -0
  59. package/lib/esm/particle.d.ts +78 -0
  60. package/lib/esm/particle.js +706 -0
  61. package/lib/esm/particle.js.map +1 -0
  62. package/lib/esm/pixelate.d.ts +11 -0
  63. package/lib/esm/pixelate.js +44 -0
  64. package/lib/esm/pixelate.js.map +1 -0
  65. package/lib/esm/scanline.d.ts +11 -0
  66. package/lib/esm/scanline.js +44 -0
  67. package/lib/esm/scanline.js.map +1 -0
  68. package/lib/esm/voronoi.d.ts +35 -0
  69. package/lib/esm/voronoi.js +262 -0
  70. package/lib/esm/voronoi.js.map +1 -0
  71. package/package.json +69 -0
@@ -0,0 +1,452 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _BloomEffect_instances, _BloomEffect_bright, _BloomEffect_mipsDown, _BloomEffect_mipsUp, _BloomEffect_allocated, _BloomEffect_lastBaseW, _BloomEffect_lastBaseH, _BloomEffect_allocateMips;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BloomEffect = void 0;
16
+ // Threshold + sRGB→linear decode. Bloom math runs in linear space so
17
+ // downsample averages reflect light intensity (not perceptual levels)
18
+ // and Rec.709 luma coefficients apply correctly. `pow(2.2)` is the
19
+ // standard fast approximation of the sRGB EOTF.
20
+ //
21
+ // The inner-rect boundary is *smoothly* masked (was a hard cutoff):
22
+ // the pyramid would otherwise capture a bright↔0 step at the pad edge,
23
+ // which reappears as a visible ring after gamma-encoded composite.
24
+ // Fading `f` (and the lin*f it premultiplies) across `edgeFade` uv
25
+ // units past the inner rect gives the cascade a continuous input and
26
+ // kills the ring at the source.
27
+ const FRAG_THRESHOLD = `#version 300 es
28
+ precision highp float;
29
+ in vec2 uvSrc;
30
+ in vec2 uvContent;
31
+ out vec4 outColor;
32
+ uniform sampler2D src;
33
+ uniform float threshold;
34
+ uniform float softness;
35
+ uniform float edgeFade;
36
+
37
+ void main() {
38
+ // Hard-gate sampling to uvSrc in [0,1]: a bare clamp would smear
39
+ // src's edge pixels into the pad (visible as a stretched image
40
+ // when edgeFade x pad reaches past the src buffer). The clamp on
41
+ // texture() keeps the sampler happy; srcMask zeroes what lies
42
+ // outside the actual src content.
43
+ vec2 insideSrc = step(vec2(0.0), uvSrc) * step(uvSrc, vec2(1.0));
44
+ float srcMask = insideSrc.x * insideSrc.y;
45
+ vec3 srgb = texture(src, clamp(uvSrc, 0.0, 1.0)).rgb * srcMask;
46
+ vec3 lin = pow(srgb, vec3(2.2));
47
+
48
+ // COD:AW (Jimenez 2014) / Unity HDRP soft-knee brightness
49
+ // response. Quadratic ramp of half-width (threshold * softness)
50
+ // centred on the cutoff — softness gates mid-luma pixels on
51
+ // BOTH sides of threshold, so raising it *widens* the bloom
52
+ // (the previous one-sided smoothstep did the opposite).
53
+ // softness=0 collapses to a hard threshold; softness=1 extends
54
+ // the knee down to zero. br uses max-channel (COD convention)
55
+ // so saturated primaries still trigger bloom where a Rec.709
56
+ // luma would have hidden them.
57
+ float br = max(max(lin.r, lin.g), lin.b);
58
+ float knee = threshold * softness;
59
+ float rq = clamp(br - threshold + knee, 0.0, 2.0 * knee);
60
+ rq = rq * rq / (4.0 * knee + 1e-4);
61
+ float contribution = max(rq, br - threshold) / max(br, 1e-4);
62
+
63
+ // Chebyshev distance outside the inner rect in uvContent units;
64
+ // 0 inside, positive in the pad region.
65
+ vec2 outside = max(vec2(0.0), max(-uvContent, uvContent - 1.0));
66
+ float outDist = max(outside.x, outside.y);
67
+ float mask = 1.0 - smoothstep(0.0, edgeFade, outDist);
68
+ float f = contribution * mask;
69
+
70
+ outColor = vec4(lin * f, f);
71
+ }
72
+ `;
73
+ // 13-tap downsample. Five 2×2 boxes (4 outer + 1 inner). Default path
74
+ // weights them 0.125×4 + 0.5 (COD:AW partial-overlap). `karis=1`
75
+ // replaces that with a per-box Karis average — boxes are weighted
76
+ // equally and modulated by 1/(1+luma) — to suppress fireflies on the
77
+ // first downsample.
78
+ const FRAG_DOWNSAMPLE = `#version 300 es
79
+ precision highp float;
80
+ in vec2 uv;
81
+ out vec4 outColor;
82
+ uniform sampler2D src;
83
+ uniform vec2 texelSize;
84
+ uniform int karis;
85
+
86
+ vec4 s(vec2 o) { return texture(src, uv + o); }
87
+ float luma(vec3 c) { return dot(c, vec3(0.2126, 0.7152, 0.0722)); }
88
+
89
+ void main() {
90
+ vec2 t = texelSize;
91
+ vec4 a = s(vec2(-2.0 * t.x, -2.0 * t.y));
92
+ vec4 b = s(vec2( 0.0, -2.0 * t.y));
93
+ vec4 c = s(vec2( 2.0 * t.x, -2.0 * t.y));
94
+ vec4 d = s(vec2(-2.0 * t.x, 0.0));
95
+ vec4 e = s(vec2( 0.0, 0.0));
96
+ vec4 f = s(vec2( 2.0 * t.x, 0.0));
97
+ vec4 g = s(vec2(-2.0 * t.x, 2.0 * t.y));
98
+ vec4 h = s(vec2( 0.0, 2.0 * t.y));
99
+ vec4 i = s(vec2( 2.0 * t.x, 2.0 * t.y));
100
+ vec4 j = s(vec2(-1.0 * t.x, -1.0 * t.y));
101
+ vec4 k = s(vec2( 1.0 * t.x, -1.0 * t.y));
102
+ vec4 l = s(vec2(-1.0 * t.x, 1.0 * t.y));
103
+ vec4 m = s(vec2( 1.0 * t.x, 1.0 * t.y));
104
+
105
+ vec4 box1 = (a + b + d + e) * 0.25;
106
+ vec4 box2 = (b + c + e + f) * 0.25;
107
+ vec4 box3 = (d + e + g + h) * 0.25;
108
+ vec4 box4 = (e + f + h + i) * 0.25;
109
+ vec4 box5 = (j + k + l + m) * 0.25;
110
+
111
+ vec4 color;
112
+ if (karis == 1) {
113
+ float w1 = 1.0 / (1.0 + luma(box1.rgb));
114
+ float w2 = 1.0 / (1.0 + luma(box2.rgb));
115
+ float w3 = 1.0 / (1.0 + luma(box3.rgb));
116
+ float w4 = 1.0 / (1.0 + luma(box4.rgb));
117
+ float w5 = 1.0 / (1.0 + luma(box5.rgb));
118
+ color = (box1 * w1 + box2 * w2 + box3 * w3 + box4 * w4 + box5 * w5)
119
+ / (w1 + w2 + w3 + w4 + w5);
120
+ } else {
121
+ color = box1 * 0.125 + box2 * 0.125 + box3 * 0.125 + box4 * 0.125
122
+ + box5 * 0.5;
123
+ }
124
+ outColor = color;
125
+ }
126
+ `;
127
+ // 3×3 tent upsample — COD:AW additive pyramid. Each level contributes
128
+ // `mipsDown[i] * weightLarge + tent(deeper) * weightSmall`; weights are
129
+ // driven from JS so scatter maps to halo radius linearly.
130
+ // (Unity HDRP's `mix(down, tent, scatter)` is geometric in radius —
131
+ // replaced here with a per-level linear gate.)
132
+ const FRAG_UPSAMPLE = `#version 300 es
133
+ precision highp float;
134
+ in vec2 uv;
135
+ out vec4 outColor;
136
+ uniform sampler2D srcSmall;
137
+ uniform sampler2D srcLarge;
138
+ uniform vec2 texelSize;
139
+ uniform float weightLarge;
140
+ uniform float weightSmall;
141
+
142
+ void main() {
143
+ vec2 t = texelSize;
144
+ vec4 sum = vec4(0.0);
145
+ sum += texture(srcSmall, uv + vec2(-t.x, -t.y)) * 1.0;
146
+ sum += texture(srcSmall, uv + vec2( 0.0, -t.y)) * 2.0;
147
+ sum += texture(srcSmall, uv + vec2( t.x, -t.y)) * 1.0;
148
+ sum += texture(srcSmall, uv + vec2(-t.x, 0.0)) * 2.0;
149
+ sum += texture(srcSmall, uv ) * 4.0;
150
+ sum += texture(srcSmall, uv + vec2( t.x, 0.0)) * 2.0;
151
+ sum += texture(srcSmall, uv + vec2(-t.x, t.y)) * 1.0;
152
+ sum += texture(srcSmall, uv + vec2( 0.0, t.y)) * 2.0;
153
+ sum += texture(srcSmall, uv + vec2( t.x, t.y)) * 1.0;
154
+ sum *= (1.0 / 16.0);
155
+ outColor = texture(srcLarge, uv) * weightLarge + sum * weightSmall;
156
+ }
157
+ `;
158
+ // Composite: 5×5 binomial-gaussian upsample of bloom from half-res →
159
+ // full-res, decode the sRGB src to linear, add the linear halo, then
160
+ // re-encode once. Doing the single pow at the end means dither can be
161
+ // injected right before 8-bit quantisation — where banding actually
162
+ // forms. Gaussian (vs tent) gives a round falloff with no step
163
+ // response, so concentric rings from the pyramid's reconstruction no
164
+ // longer show up on the visible pass.
165
+ //
166
+ // Output is *premultiplied*: the runtime blends with (ONE, 1-SRC_ALPHA)
167
+ // when writing to screen, so the low-intensity halo in the pad area
168
+ // (where sRGB-encoded `rgb` is still visibly bright due to pow(1/2.2)'s
169
+ // infinite slope at 0) correctly fades via its alpha instead of painting
170
+ // a visible ring.
171
+ const FRAG_COMPOSITE = `#version 300 es
172
+ precision highp float;
173
+ in vec2 uv;
174
+ in vec2 uvSrc;
175
+ in vec2 uvContent;
176
+ out vec4 outColor;
177
+ uniform sampler2D src;
178
+ uniform sampler2D bloom;
179
+ uniform vec2 texelSize;
180
+ uniform float intensity;
181
+ uniform float dither;
182
+ uniform float edgeFade;
183
+
184
+ // Interleaved gradient noise (Jimenez 2014). Cheap, high-quality,
185
+ // spatially decorrelated — perfect for breaking 8-bit quantisation
186
+ // bands in the gamma-encoded bloom halo.
187
+ float ign(vec2 p) {
188
+ return fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715))));
189
+ }
190
+
191
+ void main() {
192
+ // 5×5 binomial gaussian ([1,4,6,4,1]/16 outer-producted) via 9
193
+ // bilinear taps at ±1.2 source texels. Each bilinear fetch
194
+ // integrates a tap-pair perfectly, so result ≡ 25-tap convolution.
195
+ vec2 t = texelSize * 1.2;
196
+ vec4 b = vec4(0.0);
197
+ b += texture(bloom, uv + vec2(-t.x, -t.y)) * 25.0;
198
+ b += texture(bloom, uv + vec2( 0.0, -t.y)) * 30.0;
199
+ b += texture(bloom, uv + vec2( t.x, -t.y)) * 25.0;
200
+ b += texture(bloom, uv + vec2(-t.x, 0.0)) * 30.0;
201
+ b += texture(bloom, uv ) * 36.0;
202
+ b += texture(bloom, uv + vec2( t.x, 0.0)) * 30.0;
203
+ b += texture(bloom, uv + vec2(-t.x, t.y)) * 25.0;
204
+ b += texture(bloom, uv + vec2( 0.0, t.y)) * 30.0;
205
+ b += texture(bloom, uv + vec2( t.x, t.y)) * 25.0;
206
+ b *= (1.0 / 256.0);
207
+
208
+ // Same soft edge-fade as threshold so base and bloom share a
209
+ // coverage footprint — base alpha tapers into the pad instead of
210
+ // stepping from 1 to 0. The hard srcMask (same shape as the
211
+ // threshold pass) kills anything outside src's valid [0,1] so
212
+ // bloom pad extending past the src buffer doesn't repeat edge
213
+ // pixels.
214
+ vec2 insideSrc = step(vec2(0.0), uvSrc) * step(uvSrc, vec2(1.0));
215
+ float srcMask = insideSrc.x * insideSrc.y;
216
+ vec4 baseColor = texture(src, clamp(uvSrc, 0.0, 1.0)) * srcMask;
217
+ vec2 outside = max(vec2(0.0), max(-uvContent, uvContent - 1.0));
218
+ float outDist = max(outside.x, outside.y);
219
+ float baseMask = 1.0 - smoothstep(0.0, edgeFade, outDist);
220
+ baseColor.a *= baseMask;
221
+
222
+ // Linear composite: decode base, add linear bloom, single pow out.
223
+ vec3 baseLin = pow(baseColor.rgb, vec3(2.2));
224
+ vec3 lin = baseLin + max(b.rgb, vec3(0.0)) * intensity;
225
+ vec3 rgb = pow(max(lin, vec3(0.0)), vec3(1.0 / 2.2));
226
+
227
+ // TPDF dither just before 8-bit quantisation. Two IGN samples
228
+ // summed give a triangular PDF in [-1, 1], which decorrelates the
229
+ // quantisation error from the signal (uniform dither doesn't).
230
+ // Independent per channel to avoid tinted bands.
231
+ vec3 n1 = vec3(
232
+ ign(gl_FragCoord.xy),
233
+ ign(gl_FragCoord.xy + 17.0),
234
+ ign(gl_FragCoord.xy + 41.0)
235
+ );
236
+ vec3 n2 = vec3(
237
+ ign(gl_FragCoord.xy + 113.0),
238
+ ign(gl_FragCoord.xy + 131.0),
239
+ ign(gl_FragCoord.xy + 149.0)
240
+ );
241
+ vec3 n = n1 + n2 - 1.0;
242
+ rgb += n * dither / 255.0;
243
+
244
+ // Premultiply with the union coverage of base and bloom. At pad
245
+ // edges both feed zero so rgb × a → 0 and the halo dissolves
246
+ // instead of leaving a gamma-boosted floor behind.
247
+ float a = clamp(max(baseColor.a, b.a * intensity), 0.0, 1.0);
248
+ outColor = vec4(rgb * a, a);
249
+ }
250
+ `;
251
+ const DEFAULT_PARAMS = {
252
+ threshold: 0.7,
253
+ softness: 0.1,
254
+ intensity: 1.2,
255
+ scatter: 0.7,
256
+ pad: 50,
257
+ dither: 0,
258
+ edgeFade: 0.02,
259
+ };
260
+ // Tent offset in mip-texel units. 0.5 here combined with the
261
+ // base-anchored offset (`levelScale / base`) produces a 1-texel tent
262
+ // on srcSmall — the classic HDRP reconstruction kernel, fixed now
263
+ // that scatter no longer dials the filter width.
264
+ const TENT_FILTER = 0.5;
265
+ /**
266
+ * COD:AW-style bloom. Mutate `params` directly or via `setParams` —
267
+ * uniforms and `outputRect` read live each frame, so a reactive UI
268
+ * (e.g. Tweakpane) can bind directly to `effect.params`.
269
+ */
270
+ class BloomEffect {
271
+ constructor(initial = {}) {
272
+ _BloomEffect_instances.add(this);
273
+ _BloomEffect_bright.set(this, null);
274
+ _BloomEffect_mipsDown.set(this, []);
275
+ _BloomEffect_mipsUp.set(this, []);
276
+ _BloomEffect_allocated.set(this, false);
277
+ _BloomEffect_lastBaseW.set(this, 0);
278
+ _BloomEffect_lastBaseH.set(this, 0);
279
+ this.params = { ...DEFAULT_PARAMS, ...initial };
280
+ }
281
+ setParams(partial) {
282
+ Object.assign(this.params, partial);
283
+ }
284
+ init(ctx) {
285
+ // Full-output, auto-resize — threshold needs inner-rect gating.
286
+ // Float storage so linear-space bloom values keep precision in
287
+ // the dark end across the downsample chain (8-bit would band).
288
+ __classPrivateFieldSet(this, _BloomEffect_bright, ctx.createRenderTarget({ float: true }), "f");
289
+ }
290
+ render(ctx) {
291
+ if (!__classPrivateFieldGet(this, _BloomEffect_bright, "f")) {
292
+ return;
293
+ }
294
+ const { threshold, softness, intensity } = this.params;
295
+ const scatter = Math.min(Math.max(this.params.scatter, 0), 1);
296
+ const dither = Math.max(0, this.params.dither);
297
+ const edgeFade = Math.max(1e-6, this.params.edgeFade);
298
+ // If `pad` changed (outputRect is re-queried every frame by
299
+ // the host), `bright` auto-resizes — rebuild the pyramid so
300
+ // mip dims keep matching the buffer.
301
+ if (__classPrivateFieldGet(this, _BloomEffect_bright, "f").width !== __classPrivateFieldGet(this, _BloomEffect_lastBaseW, "f") ||
302
+ __classPrivateFieldGet(this, _BloomEffect_bright, "f").height !== __classPrivateFieldGet(this, _BloomEffect_lastBaseH, "f")) {
303
+ __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f").length = 0;
304
+ __classPrivateFieldGet(this, _BloomEffect_mipsUp, "f").length = 0;
305
+ __classPrivateFieldSet(this, _BloomEffect_allocated, false, "f");
306
+ __classPrivateFieldSet(this, _BloomEffect_lastBaseW, __classPrivateFieldGet(this, _BloomEffect_bright, "f").width, "f");
307
+ __classPrivateFieldSet(this, _BloomEffect_lastBaseH, __classPrivateFieldGet(this, _BloomEffect_bright, "f").height, "f");
308
+ }
309
+ __classPrivateFieldGet(this, _BloomEffect_instances, "m", _BloomEffect_allocateMips).call(this, ctx, __classPrivateFieldGet(this, _BloomEffect_bright, "f").width, __classPrivateFieldGet(this, _BloomEffect_bright, "f").height);
310
+ const n = __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f").length;
311
+ if (n === 0) {
312
+ return;
313
+ }
314
+ ctx.draw({
315
+ frag: FRAG_THRESHOLD,
316
+ uniforms: { src: ctx.src, threshold, softness, edgeFade },
317
+ target: __classPrivateFieldGet(this, _BloomEffect_bright, "f"),
318
+ });
319
+ // Downsample: bright → mipsDown[0] (Karis) → ... → mipsDown[n-1]
320
+ ctx.draw({
321
+ frag: FRAG_DOWNSAMPLE,
322
+ uniforms: {
323
+ src: __classPrivateFieldGet(this, _BloomEffect_bright, "f"),
324
+ texelSize: [1 / __classPrivateFieldGet(this, _BloomEffect_bright, "f").width, 1 / __classPrivateFieldGet(this, _BloomEffect_bright, "f").height],
325
+ karis: 1,
326
+ },
327
+ target: __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[0],
328
+ });
329
+ for (let i = 1; i < n; i++) {
330
+ const prev = __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[i - 1];
331
+ ctx.draw({
332
+ frag: FRAG_DOWNSAMPLE,
333
+ uniforms: {
334
+ src: prev,
335
+ texelSize: [1 / prev.width, 1 / prev.height],
336
+ karis: 0,
337
+ },
338
+ target: __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[i],
339
+ });
340
+ }
341
+ // Additive pyramid upsample with per-level weights.
342
+ // upsample[D-1] = mipsDown[D-1] × w[D-1]
343
+ // upsample[i] = mipsDown[i] × w[i] + tent(upsample[i+1])
344
+ // weight[i] = clamp(activeDepth − i, 0, 1). activeDepth is
345
+ // linear in scatter (each step of 1/(n−1) activates one more
346
+ // level), giving ~even perceptual change across the knob.
347
+ // A radius-linear (log2) mapping bunches all visible motion
348
+ // into scatter < 0.2 because halo reach is dominated by the
349
+ // outermost level — octave-linear is what "feels" linear.
350
+ //
351
+ // Tent offsets use the *ideal* (non-floored) texel size
352
+ // idealTexelUV = 2^smallLevel / base
353
+ // where smallLevel = i + 2. Anchoring to the base dimensions
354
+ // cancels the cumulative floor error from the halving chain.
355
+ const baseW = __classPrivateFieldGet(this, _BloomEffect_bright, "f").width;
356
+ const baseH = __classPrivateFieldGet(this, _BloomEffect_bright, "f").height;
357
+ const activeDepth = 1 + scatter * Math.max(0, n - 1);
358
+ const weightFor = (i) => Math.min(1, Math.max(0, activeDepth - i));
359
+ for (let i = n - 2; i >= 0; i--) {
360
+ const small = i === n - 2 ? __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[n - 1] : __classPrivateFieldGet(this, _BloomEffect_mipsUp, "f")[i + 1];
361
+ const levelScale = 2 ** (i + 2);
362
+ // Bottom mip is raw downsample — its weight is applied here.
363
+ // Intermediate upsamples already carry per-level weights
364
+ // baked in from previous iterations, so pass-through = 1.
365
+ const wSmall = i === n - 2 ? weightFor(n - 1) : 1.0;
366
+ ctx.draw({
367
+ frag: FRAG_UPSAMPLE,
368
+ uniforms: {
369
+ srcSmall: small,
370
+ srcLarge: __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[i],
371
+ texelSize: [
372
+ (TENT_FILTER * levelScale) / baseW,
373
+ (TENT_FILTER * levelScale) / baseH,
374
+ ],
375
+ weightLarge: weightFor(i),
376
+ weightSmall: wSmall,
377
+ },
378
+ target: __classPrivateFieldGet(this, _BloomEffect_mipsUp, "f")[i],
379
+ });
380
+ }
381
+ const bloomTex = n >= 2 ? __classPrivateFieldGet(this, _BloomEffect_mipsUp, "f")[0] : __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[0];
382
+ // Normalise by active depth so bloom amplitude stays roughly
383
+ // constant across scatter — fully-additive pyramid sums N
384
+ // levels, so raw amplitude scales with level count otherwise.
385
+ const effectiveIntensity = intensity / Math.max(1, activeDepth);
386
+ // bloomTex is always at level 1 (half of base).
387
+ ctx.draw({
388
+ frag: FRAG_COMPOSITE,
389
+ uniforms: {
390
+ src: ctx.src,
391
+ bloom: bloomTex,
392
+ texelSize: [
393
+ (TENT_FILTER * 2) / baseW,
394
+ (TENT_FILTER * 2) / baseH,
395
+ ],
396
+ intensity: effectiveIntensity,
397
+ dither,
398
+ edgeFade,
399
+ },
400
+ target: ctx.target,
401
+ });
402
+ }
403
+ outputRect(dims) {
404
+ const { pad } = this.params;
405
+ if (pad === "fullscreen") {
406
+ return dims.canvasRect;
407
+ }
408
+ const px = pad * dims.pixelRatio;
409
+ const [, , ew, eh] = dims.contentRect;
410
+ return [-px, -px, ew + 2 * px, eh + 2 * px];
411
+ }
412
+ dispose() {
413
+ __classPrivateFieldSet(this, _BloomEffect_bright, null, "f");
414
+ __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f").length = 0;
415
+ __classPrivateFieldGet(this, _BloomEffect_mipsUp, "f").length = 0;
416
+ __classPrivateFieldSet(this, _BloomEffect_allocated, false, "f");
417
+ __classPrivateFieldSet(this, _BloomEffect_lastBaseW, 0, "f");
418
+ __classPrivateFieldSet(this, _BloomEffect_lastBaseH, 0, "f");
419
+ }
420
+ }
421
+ exports.BloomEffect = BloomEffect;
422
+ _BloomEffect_bright = new WeakMap(), _BloomEffect_mipsDown = new WeakMap(), _BloomEffect_mipsUp = new WeakMap(), _BloomEffect_allocated = new WeakMap(), _BloomEffect_lastBaseW = new WeakMap(), _BloomEffect_lastBaseH = new WeakMap(), _BloomEffect_instances = new WeakSet(), _BloomEffect_allocateMips = function _BloomEffect_allocateMips(ctx, baseW, baseH) {
423
+ if (__classPrivateFieldGet(this, _BloomEffect_allocated, "f")) {
424
+ return;
425
+ }
426
+ // Auto-depth: halve until both axes hit 1 px, capped at 8
427
+ // levels. Going past the 13-tap stencil's "nice" size (4 px)
428
+ // is intentional — the deepest mips become degenerate box
429
+ // averages over the whole buffer, which is exactly what
430
+ // contributes the wide low-frequency halo tail that smears
431
+ // the 8-bit cutoff across enough pixels for dither to dissolve.
432
+ let w = Math.max(1, Math.floor(baseW / 2));
433
+ let h = Math.max(1, Math.floor(baseH / 2));
434
+ for (let i = 0; i < 8; i++) {
435
+ __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f").push(ctx.createRenderTarget({ size: [w, h], float: true }));
436
+ const nw = Math.max(1, Math.floor(w / 2));
437
+ const nh = Math.max(1, Math.floor(h / 2));
438
+ if (nw === w && nh === h) {
439
+ break;
440
+ }
441
+ w = nw;
442
+ h = nh;
443
+ }
444
+ for (let i = 0; i < __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f").length - 1; i++) {
445
+ __classPrivateFieldGet(this, _BloomEffect_mipsUp, "f").push(ctx.createRenderTarget({
446
+ size: [__classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[i].width, __classPrivateFieldGet(this, _BloomEffect_mipsDown, "f")[i].height],
447
+ float: true,
448
+ }));
449
+ }
450
+ __classPrivateFieldSet(this, _BloomEffect_allocated, true, "f");
451
+ };
452
+ //# sourceMappingURL=bloom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bloom.js","sourceRoot":"","sources":["../../src/bloom.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,qEAAqE;AACrE,sEAAsE;AACtE,mEAAmE;AACnE,gDAAgD;AAChD,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,mEAA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CAAC,CACL,CAAC;IACN,CAAC;IACD,uBAAA,IAAI,0BAAc,IAAI,MAAA,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { Effect, EffectContext } from "@vfx-js/core";
2
+ export type FluidParams = {
3
+ /** Simulation grid resolution in physical px. */
4
+ simSize: [number, number];
5
+ /** Jacobi iterations per frame (1 is the established default). */
6
+ pressureIterations: number;
7
+ /** Vorticity confinement strength. */
8
+ curlStrength: number;
9
+ /** Per-frame velocity decay. */
10
+ velocityDissipation: number;
11
+ /** Per-frame dye decay. */
12
+ densityDissipation: number;
13
+ /** Velocity injected per uv-unit of mouse motion. */
14
+ splatForce: number;
15
+ /** Velocity-splat falloff (uv² units). */
16
+ splatRadius: number;
17
+ /** Dye-splat falloff (uv² units). */
18
+ dyeSplatRadius: number;
19
+ /** Dye intensity per uv-unit/sec of mouse speed. */
20
+ dyeSplatIntensity: number;
21
+ /** When true, output is the raw dye buffer instead of advected src. */
22
+ showDye: boolean;
23
+ };
24
+ /**
25
+ * Stable Fluid as a single Effect. Mutate `params` directly for runtime
26
+ * tweaks; tracked sim state is owned by the effect and reset on dispose.
27
+ */
28
+ export declare class FluidEffect implements Effect {
29
+ #private;
30
+ params: FluidParams;
31
+ constructor(initial?: Partial<FluidParams>);
32
+ init(ctx: EffectContext): void;
33
+ render(ctx: EffectContext): void;
34
+ dispose(): void;
35
+ }