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