@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,466 @@
|
|
|
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 _ParticleExplodeEffect_instances, _ParticleExplodeEffect_params, _ParticleExplodeEffect_posTex, _ParticleExplodeEffect_colorTex, _ParticleExplodeEffect_stampTex, _ParticleExplodeEffect_trail, _ParticleExplodeEffect_particleGeometry, _ParticleExplodeEffect_stateSize, _ParticleExplodeEffect_triggered, _ParticleExplodeEffect_burstPending, _ParticleExplodeEffect_startTime, _ParticleExplodeEffect_lastElapsed, _ParticleExplodeEffect_fadeOutFrames, _ParticleExplodeEffect_estimatedFadeFrames, _ParticleExplodeEffect_allocStateRTs, _ParticleExplodeEffect_disposeStateRTs, _ParticleExplodeEffect_cap;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ParticleExplodeEffect = void 0;
|
|
16
|
+
const _curl_noise_1 = require("./_curl-noise");
|
|
17
|
+
const _particle_common_1 = require("./_particle-common");
|
|
18
|
+
const LIFE_JITTER_MIN_GLSL = _curl_noise_1.LIFE_JITTER_MIN.toFixed(4);
|
|
19
|
+
const LIFE_JITTER_MAX_GLSL = _curl_noise_1.LIFE_JITTER_MAX.toFixed(4);
|
|
20
|
+
// State texture size is decoupled from image resolution and auto-
|
|
21
|
+
// derived from `count` (smallest power-of-two square grid that fits).
|
|
22
|
+
// Each texel is a particle slot; on burst, slots with id < params.count
|
|
23
|
+
// emit at a hashed random uv across the element. 1024² is the 1M cap
|
|
24
|
+
// at the default `count`.
|
|
25
|
+
// On burst: slots with id < count emit at a hashed uv (random point on
|
|
26
|
+
// the element); slots beyond count are written dead (age=2). Otherwise
|
|
27
|
+
// advects via curl + radial outward bias.
|
|
28
|
+
const FRAG_UPDATE_POS = `#version 300 es
|
|
29
|
+
precision highp float;
|
|
30
|
+
in vec2 uv;
|
|
31
|
+
out vec4 outColor;
|
|
32
|
+
|
|
33
|
+
uniform sampler2D posTex;
|
|
34
|
+
uniform vec2 stateSize;
|
|
35
|
+
uniform vec2 elementPixel;
|
|
36
|
+
uniform float time;
|
|
37
|
+
uniform float dt;
|
|
38
|
+
uniform float noiseSpeed;
|
|
39
|
+
uniform float noiseScale;
|
|
40
|
+
uniform float noiseAnimation;
|
|
41
|
+
uniform float speedDecay;
|
|
42
|
+
uniform float outwardBias;
|
|
43
|
+
uniform float duration;
|
|
44
|
+
uniform float count;
|
|
45
|
+
uniform int uBurst;
|
|
46
|
+
${_particle_common_1.GLSL_HASH}
|
|
47
|
+
${_curl_noise_1.GLSL_CURL_NOISE}
|
|
48
|
+
|
|
49
|
+
void main() {
|
|
50
|
+
if (uBurst == 1) {
|
|
51
|
+
ivec2 pix = ivec2(floor(uv * stateSize));
|
|
52
|
+
float fid = float(pix.y * int(stateSize.x) + pix.x);
|
|
53
|
+
if (fid >= count) {
|
|
54
|
+
outColor = vec4(0.0, 0.0, 0.0, 2.0); // dead
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
vec2 spawnUv = vec2(
|
|
58
|
+
hash21(uv * 31.7 + 11.13),
|
|
59
|
+
hash21(uv * 73.13 + 7.71)
|
|
60
|
+
);
|
|
61
|
+
float z0 = (hash21(uv * 53.7 + 0.81) - 0.5) * 0.02;
|
|
62
|
+
outColor = vec4(spawnUv, z0, 0.0);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
vec4 s = texture(posTex, uv);
|
|
67
|
+
float age = s.w;
|
|
68
|
+
if (age >= 1.0) {
|
|
69
|
+
outColor = s;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
vec3 vNoise = sampleCurl(s.xyz, elementPixel, noiseScale, time * noiseAnimation);
|
|
74
|
+
vec3 outward = vec3(s.xy - vec2(0.5), s.z) * outwardBias;
|
|
75
|
+
|
|
76
|
+
float taper = pow(clamp(1.0 - age, 0.0, 1.0), speedDecay);
|
|
77
|
+
vec3 pos = s.xyz + (vNoise + outward) * noiseSpeed * dt * taper;
|
|
78
|
+
|
|
79
|
+
float lifespanScale = mix(
|
|
80
|
+
${LIFE_JITTER_MIN_GLSL},
|
|
81
|
+
${LIFE_JITTER_MAX_GLSL},
|
|
82
|
+
hash21(uv * 91.7 + 1.234)
|
|
83
|
+
);
|
|
84
|
+
age += dt / max(duration * lifespanScale, 1e-3);
|
|
85
|
+
|
|
86
|
+
outColor = vec4(pos, age);
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
// Burst-only color seed: slots with id < count sample src at the same
|
|
90
|
+
// hashed uv FRAG_UPDATE_POS uses for their spawn position; slots
|
|
91
|
+
// beyond count are cleared. Color is static after burst, so this runs
|
|
92
|
+
// once per trigger and colorTex is single-buffer (no ping-pong).
|
|
93
|
+
const FRAG_BURST_COLOR = `#version 300 es
|
|
94
|
+
precision highp float;
|
|
95
|
+
in vec2 uv;
|
|
96
|
+
out vec4 outColor;
|
|
97
|
+
|
|
98
|
+
uniform sampler2D src;
|
|
99
|
+
uniform vec4 srcRectUv;
|
|
100
|
+
uniform vec2 stateSize;
|
|
101
|
+
uniform float count;
|
|
102
|
+
uniform vec3 color;
|
|
103
|
+
uniform float colorMix;
|
|
104
|
+
${_particle_common_1.GLSL_HASH}
|
|
105
|
+
|
|
106
|
+
void main() {
|
|
107
|
+
ivec2 pix = ivec2(floor(uv * stateSize));
|
|
108
|
+
float fid = float(pix.y * int(stateSize.x) + pix.x);
|
|
109
|
+
if (fid >= count) {
|
|
110
|
+
outColor = vec4(0.0);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
vec2 spawnUv = vec2(
|
|
114
|
+
hash21(uv * 31.7 + 11.13),
|
|
115
|
+
hash21(uv * 73.13 + 7.71)
|
|
116
|
+
);
|
|
117
|
+
vec2 sampleUv = srcRectUv.xy + spawnUv * srcRectUv.zw;
|
|
118
|
+
vec4 c = texture(src, sampleUv);
|
|
119
|
+
outColor = vec4(mix(c.rgb, color, colorMix), c.a);
|
|
120
|
+
}
|
|
121
|
+
`;
|
|
122
|
+
const VERT_PARTICLE = `#version 300 es
|
|
123
|
+
precision highp float;
|
|
124
|
+
in vec2 position;
|
|
125
|
+
|
|
126
|
+
uniform sampler2D posTex;
|
|
127
|
+
uniform sampler2D colorTex;
|
|
128
|
+
uniform vec2 stateSize;
|
|
129
|
+
uniform float pointSize;
|
|
130
|
+
uniform vec2 elementPixel;
|
|
131
|
+
uniform int particleCount;
|
|
132
|
+
uniform float alpha;
|
|
133
|
+
uniform float alphaDecay;
|
|
134
|
+
uniform float fog;
|
|
135
|
+
uniform vec4 contentRectUv;
|
|
136
|
+
|
|
137
|
+
out vec2 vCorner;
|
|
138
|
+
out vec4 vColor;
|
|
139
|
+
|
|
140
|
+
void main() {
|
|
141
|
+
int id = gl_InstanceID;
|
|
142
|
+
if (id >= particleCount) {
|
|
143
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
144
|
+
vCorner = vec2(0.0);
|
|
145
|
+
vColor = vec4(0.0);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
int sx = id % int(stateSize.x);
|
|
149
|
+
int sy = id / int(stateSize.x);
|
|
150
|
+
vec2 stateUv = (vec2(float(sx), float(sy)) + 0.5) / stateSize;
|
|
151
|
+
vec4 s = texture(posTex, stateUv);
|
|
152
|
+
vec4 c = texture(colorTex, stateUv);
|
|
153
|
+
|
|
154
|
+
float age = s.w;
|
|
155
|
+
// Quarter-cosine envelope: full alpha at trigger, 0 at age=1.
|
|
156
|
+
// alphaDecay > 1 holds peak alpha longer; < 1 makes the fade snappy.
|
|
157
|
+
float lifeAlpha = (age >= 0.0 && age < 1.0)
|
|
158
|
+
? pow(cos(age * 1.5707963), alphaDecay)
|
|
159
|
+
: 0.0;
|
|
160
|
+
if (lifeAlpha <= 0.0) {
|
|
161
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
162
|
+
vCorner = vec2(0.0);
|
|
163
|
+
vColor = vec4(0.0);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
float fogFactor = fog > 0.0
|
|
168
|
+
? mix(1.0, smoothstep(1.0, -0.5, s.z), fog)
|
|
169
|
+
: 1.0;
|
|
170
|
+
|
|
171
|
+
vec2 bufferUv = contentRectUv.xy + s.xy * contentRectUv.zw;
|
|
172
|
+
vec2 ndcPos = bufferUv * 2.0 - 1.0;
|
|
173
|
+
|
|
174
|
+
vec2 bufferPixel = elementPixel / max(contentRectUv.zw, vec2(1e-6));
|
|
175
|
+
vec2 ndcOffset = position * pointSize * 2.0 / bufferPixel;
|
|
176
|
+
gl_Position = vec4(ndcPos + ndcOffset, 0.0, 1.0);
|
|
177
|
+
|
|
178
|
+
vCorner = position;
|
|
179
|
+
vColor = vec4(c.rgb, c.a * lifeAlpha * alpha * fogFactor);
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
182
|
+
// Particles only — the source element is "shattered" away on trigger
|
|
183
|
+
// and never composited back in until reset().
|
|
184
|
+
const FRAG_OUTPUT = `#version 300 es
|
|
185
|
+
precision highp float;
|
|
186
|
+
in vec2 uv;
|
|
187
|
+
out vec4 outColor;
|
|
188
|
+
|
|
189
|
+
uniform sampler2D trail;
|
|
190
|
+
|
|
191
|
+
void main() {
|
|
192
|
+
outColor = texture(trail, uv);
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
195
|
+
const FRAG_PASSTHROUGH = `#version 300 es
|
|
196
|
+
precision highp float;
|
|
197
|
+
in vec2 uvSrc;
|
|
198
|
+
out vec4 outColor;
|
|
199
|
+
uniform sampler2D src;
|
|
200
|
+
void main() {
|
|
201
|
+
outColor = texture(src, uvSrc);
|
|
202
|
+
}
|
|
203
|
+
`;
|
|
204
|
+
const DEFAULT_PARAMS = {
|
|
205
|
+
count: 100000,
|
|
206
|
+
duration: 1.0,
|
|
207
|
+
noiseSpeed: 1.5,
|
|
208
|
+
noiseScale: 1.0,
|
|
209
|
+
noiseAnimation: 1.0,
|
|
210
|
+
outwardBias: 1.0,
|
|
211
|
+
pointSize: 3.0,
|
|
212
|
+
alpha: 1.0,
|
|
213
|
+
alphaDecay: 5.0,
|
|
214
|
+
speedDecay: 2.0,
|
|
215
|
+
fog: 0.0,
|
|
216
|
+
trailFade: 0.5,
|
|
217
|
+
color: 0xffffff,
|
|
218
|
+
colorMix: 0,
|
|
219
|
+
blend: "add",
|
|
220
|
+
};
|
|
221
|
+
// One-shot explode. Construct a new instance per `vfx.add()`. Call
|
|
222
|
+
// `trigger()` to start; query `isDone()` to detect completion.
|
|
223
|
+
class ParticleExplodeEffect {
|
|
224
|
+
get params() {
|
|
225
|
+
return __classPrivateFieldGet(this, _ParticleExplodeEffect_params, "f");
|
|
226
|
+
}
|
|
227
|
+
constructor(initial = {}) {
|
|
228
|
+
_ParticleExplodeEffect_instances.add(this);
|
|
229
|
+
_ParticleExplodeEffect_params.set(this, void 0);
|
|
230
|
+
_ParticleExplodeEffect_posTex.set(this, null);
|
|
231
|
+
_ParticleExplodeEffect_colorTex.set(this, null);
|
|
232
|
+
_ParticleExplodeEffect_stampTex.set(this, null);
|
|
233
|
+
_ParticleExplodeEffect_trail.set(this, null);
|
|
234
|
+
_ParticleExplodeEffect_particleGeometry.set(this, null);
|
|
235
|
+
_ParticleExplodeEffect_stateSize.set(this, void 0);
|
|
236
|
+
_ParticleExplodeEffect_triggered.set(this, false);
|
|
237
|
+
_ParticleExplodeEffect_burstPending.set(this, false);
|
|
238
|
+
_ParticleExplodeEffect_startTime.set(this, -1);
|
|
239
|
+
_ParticleExplodeEffect_lastElapsed.set(this, 0);
|
|
240
|
+
_ParticleExplodeEffect_fadeOutFrames.set(this, 0);
|
|
241
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_params, { ...DEFAULT_PARAMS, ...initial }, "f");
|
|
242
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_params, "f").count = (0, _particle_common_1.sanitizeCount)(__classPrivateFieldGet(this, _ParticleExplodeEffect_params, "f").count);
|
|
243
|
+
const s = (0, _particle_common_1.stateSizeFromCount)(__classPrivateFieldGet(this, _ParticleExplodeEffect_params, "f").count);
|
|
244
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_stateSize, [s, s], "f");
|
|
245
|
+
}
|
|
246
|
+
trigger() {
|
|
247
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_triggered, true, "f");
|
|
248
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_burstPending, true, "f");
|
|
249
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_startTime, -1, "f");
|
|
250
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_lastElapsed, 0, "f");
|
|
251
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_fadeOutFrames, 0, "f");
|
|
252
|
+
}
|
|
253
|
+
reset() {
|
|
254
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_triggered, false, "f");
|
|
255
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_burstPending, false, "f");
|
|
256
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_startTime, -1, "f");
|
|
257
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_lastElapsed, 0, "f");
|
|
258
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_fadeOutFrames, 0, "f");
|
|
259
|
+
}
|
|
260
|
+
isDone() {
|
|
261
|
+
if (!__classPrivateFieldGet(this, _ParticleExplodeEffect_triggered, "f")) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
if (__classPrivateFieldGet(this, _ParticleExplodeEffect_lastElapsed, "f") < this.params.duration) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return __classPrivateFieldGet(this, _ParticleExplodeEffect_fadeOutFrames, "f") >= __classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_estimatedFadeFrames).call(this);
|
|
268
|
+
}
|
|
269
|
+
init(ctx) {
|
|
270
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_allocStateRTs).call(this, ctx);
|
|
271
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_stampTex, ctx.createRenderTarget({
|
|
272
|
+
float: false,
|
|
273
|
+
wrap: "clamp",
|
|
274
|
+
filter: "linear",
|
|
275
|
+
}), "f");
|
|
276
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_trail, ctx.createRenderTarget({
|
|
277
|
+
float: false,
|
|
278
|
+
persistent: true,
|
|
279
|
+
wrap: "clamp",
|
|
280
|
+
filter: "linear",
|
|
281
|
+
}), "f");
|
|
282
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_particleGeometry, {
|
|
283
|
+
attributes: { position: _particle_common_1.QUAD_VERTS },
|
|
284
|
+
}, "f");
|
|
285
|
+
}
|
|
286
|
+
render(ctx) {
|
|
287
|
+
var _a;
|
|
288
|
+
if (!__classPrivateFieldGet(this, _ParticleExplodeEffect_posTex, "f") ||
|
|
289
|
+
!__classPrivateFieldGet(this, _ParticleExplodeEffect_colorTex, "f") ||
|
|
290
|
+
!__classPrivateFieldGet(this, _ParticleExplodeEffect_stampTex, "f") ||
|
|
291
|
+
!__classPrivateFieldGet(this, _ParticleExplodeEffect_trail, "f") ||
|
|
292
|
+
!__classPrivateFieldGet(this, _ParticleExplodeEffect_particleGeometry, "f")) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
// Off-screen: pause everything. The burst's elapsed timer only
|
|
296
|
+
// ticks while visible, so the user sees the full animation
|
|
297
|
+
// whenever they scroll into view (no silent "burst already
|
|
298
|
+
// played" surprise).
|
|
299
|
+
if (ctx.intersection <= 0) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
// Resize state RTs while idle. We never realloc mid-burst —
|
|
303
|
+
// doing so would discard the in-flight particle state. Allowed
|
|
304
|
+
// before the first trigger and after a burst has fully faded.
|
|
305
|
+
const newSize = (0, _particle_common_1.stateSizeFromCount)(this.params.count);
|
|
306
|
+
const idle = !__classPrivateFieldGet(this, _ParticleExplodeEffect_triggered, "f") || this.isDone();
|
|
307
|
+
if (newSize !== __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f")[0] && idle) {
|
|
308
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_disposeStateRTs).call(this);
|
|
309
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_stateSize, [newSize, newSize], "f");
|
|
310
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_allocStateRTs).call(this, ctx);
|
|
311
|
+
}
|
|
312
|
+
if (!__classPrivateFieldGet(this, _ParticleExplodeEffect_triggered, "f")) {
|
|
313
|
+
ctx.draw({
|
|
314
|
+
frag: FRAG_PASSTHROUGH,
|
|
315
|
+
uniforms: { src: ctx.src },
|
|
316
|
+
target: ctx.target,
|
|
317
|
+
});
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (__classPrivateFieldGet(this, _ParticleExplodeEffect_startTime, "f") < 0) {
|
|
321
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_startTime, ctx.time, "f");
|
|
322
|
+
}
|
|
323
|
+
const elapsed = ctx.time - __classPrivateFieldGet(this, _ParticleExplodeEffect_startTime, "f");
|
|
324
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_lastElapsed, elapsed, "f");
|
|
325
|
+
const inFadeOut = elapsed >= this.params.duration;
|
|
326
|
+
// Particles done AND trail decayed to invisible — stop drawing.
|
|
327
|
+
if (inFadeOut && __classPrivateFieldGet(this, _ParticleExplodeEffect_fadeOutFrames, "f") >= __classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_estimatedFadeFrames).call(this)) {
|
|
328
|
+
ctx.draw({ frag: _particle_common_1.FRAG_CLEAR, target: ctx.target });
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const dt = (0, _particle_common_1.clampDt)(ctx.deltaTime);
|
|
332
|
+
const elementPixel = [
|
|
333
|
+
ctx.dims.elementPixel[0],
|
|
334
|
+
ctx.dims.elementPixel[1],
|
|
335
|
+
];
|
|
336
|
+
if (!inFadeOut) {
|
|
337
|
+
const burst = __classPrivateFieldGet(this, _ParticleExplodeEffect_burstPending, "f") ? 1 : 0;
|
|
338
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_burstPending, false, "f");
|
|
339
|
+
const cap = __classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_cap).call(this);
|
|
340
|
+
ctx.draw({
|
|
341
|
+
frag: FRAG_UPDATE_POS,
|
|
342
|
+
uniforms: {
|
|
343
|
+
posTex: __classPrivateFieldGet(this, _ParticleExplodeEffect_posTex, "f"),
|
|
344
|
+
stateSize: __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f"),
|
|
345
|
+
elementPixel,
|
|
346
|
+
time: ctx.time,
|
|
347
|
+
dt,
|
|
348
|
+
noiseSpeed: this.params.noiseSpeed,
|
|
349
|
+
noiseScale: this.params.noiseScale,
|
|
350
|
+
noiseAnimation: this.params.noiseAnimation,
|
|
351
|
+
speedDecay: this.params.speedDecay,
|
|
352
|
+
outwardBias: this.params.outwardBias,
|
|
353
|
+
duration: this.params.duration,
|
|
354
|
+
count: cap,
|
|
355
|
+
uBurst: burst,
|
|
356
|
+
},
|
|
357
|
+
target: __classPrivateFieldGet(this, _ParticleExplodeEffect_posTex, "f"),
|
|
358
|
+
});
|
|
359
|
+
if (burst === 1) {
|
|
360
|
+
ctx.draw({
|
|
361
|
+
frag: FRAG_BURST_COLOR,
|
|
362
|
+
uniforms: {
|
|
363
|
+
src: ctx.src,
|
|
364
|
+
stateSize: __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f"),
|
|
365
|
+
count: cap,
|
|
366
|
+
color: (0, _particle_common_1.hexToRgb)(this.params.color),
|
|
367
|
+
colorMix: this.params.colorMix,
|
|
368
|
+
},
|
|
369
|
+
target: __classPrivateFieldGet(this, _ParticleExplodeEffect_colorTex, "f"),
|
|
370
|
+
});
|
|
371
|
+
// Drop residual trail from a previous burst so the new
|
|
372
|
+
// burst doesn't composite the old image on top of itself.
|
|
373
|
+
ctx.draw({ frag: _particle_common_1.FRAG_CLEAR, target: __classPrivateFieldGet(this, _ParticleExplodeEffect_trail, "f") });
|
|
374
|
+
}
|
|
375
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_particleGeometry, "f").instanceCount = cap;
|
|
376
|
+
ctx.draw({ frag: _particle_common_1.FRAG_CLEAR, target: __classPrivateFieldGet(this, _ParticleExplodeEffect_stampTex, "f") });
|
|
377
|
+
ctx.draw({
|
|
378
|
+
vert: VERT_PARTICLE,
|
|
379
|
+
frag: _particle_common_1.FRAG_PARTICLE,
|
|
380
|
+
uniforms: {
|
|
381
|
+
posTex: __classPrivateFieldGet(this, _ParticleExplodeEffect_posTex, "f"),
|
|
382
|
+
colorTex: __classPrivateFieldGet(this, _ParticleExplodeEffect_colorTex, "f"),
|
|
383
|
+
stateSize: __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f"),
|
|
384
|
+
pointSize: this.params.pointSize,
|
|
385
|
+
elementPixel,
|
|
386
|
+
particleCount: cap,
|
|
387
|
+
alpha: this.params.alpha,
|
|
388
|
+
alphaDecay: this.params.alphaDecay,
|
|
389
|
+
fog: this.params.fog,
|
|
390
|
+
},
|
|
391
|
+
geometry: __classPrivateFieldGet(this, _ParticleExplodeEffect_particleGeometry, "f"),
|
|
392
|
+
target: __classPrivateFieldGet(this, _ParticleExplodeEffect_stampTex, "f"),
|
|
393
|
+
blend: this.params.blend === "normal"
|
|
394
|
+
? "premultiplied"
|
|
395
|
+
: "additive",
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
// Particles done; keep decaying the trail with an empty stamp
|
|
400
|
+
// so trailFade can fade out gracefully instead of cutting.
|
|
401
|
+
ctx.draw({ frag: _particle_common_1.FRAG_CLEAR, target: __classPrivateFieldGet(this, _ParticleExplodeEffect_stampTex, "f") });
|
|
402
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_fadeOutFrames, (_a = __classPrivateFieldGet(this, _ParticleExplodeEffect_fadeOutFrames, "f"), _a++, _a), "f");
|
|
403
|
+
}
|
|
404
|
+
ctx.draw({
|
|
405
|
+
frag: _particle_common_1.FRAG_TRAIL_COMPOSITE,
|
|
406
|
+
uniforms: {
|
|
407
|
+
trailPrev: __classPrivateFieldGet(this, _ParticleExplodeEffect_trail, "f"),
|
|
408
|
+
particleStamp: __classPrivateFieldGet(this, _ParticleExplodeEffect_stampTex, "f"),
|
|
409
|
+
trailFade: this.params.trailFade,
|
|
410
|
+
blendMode: this.params.blend === "normal" ? 1 : 0,
|
|
411
|
+
},
|
|
412
|
+
target: __classPrivateFieldGet(this, _ParticleExplodeEffect_trail, "f"),
|
|
413
|
+
});
|
|
414
|
+
ctx.draw({
|
|
415
|
+
frag: FRAG_OUTPUT,
|
|
416
|
+
uniforms: { trail: __classPrivateFieldGet(this, _ParticleExplodeEffect_trail, "f") },
|
|
417
|
+
target: ctx.target,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
dispose() {
|
|
421
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_instances, "m", _ParticleExplodeEffect_disposeStateRTs).call(this);
|
|
422
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_stampTex, "f")?.dispose();
|
|
423
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_trail, "f")?.dispose();
|
|
424
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_stampTex, null, "f");
|
|
425
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_trail, null, "f");
|
|
426
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_particleGeometry, null, "f");
|
|
427
|
+
}
|
|
428
|
+
// Particles can scatter past the element bounds.
|
|
429
|
+
outputRect(dims) {
|
|
430
|
+
return dims.canvasRect;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
exports.ParticleExplodeEffect = ParticleExplodeEffect;
|
|
434
|
+
_ParticleExplodeEffect_params = new WeakMap(), _ParticleExplodeEffect_posTex = new WeakMap(), _ParticleExplodeEffect_colorTex = new WeakMap(), _ParticleExplodeEffect_stampTex = new WeakMap(), _ParticleExplodeEffect_trail = new WeakMap(), _ParticleExplodeEffect_particleGeometry = new WeakMap(), _ParticleExplodeEffect_stateSize = new WeakMap(), _ParticleExplodeEffect_triggered = new WeakMap(), _ParticleExplodeEffect_burstPending = new WeakMap(), _ParticleExplodeEffect_startTime = new WeakMap(), _ParticleExplodeEffect_lastElapsed = new WeakMap(), _ParticleExplodeEffect_fadeOutFrames = new WeakMap(), _ParticleExplodeEffect_instances = new WeakSet(), _ParticleExplodeEffect_estimatedFadeFrames = function _ParticleExplodeEffect_estimatedFadeFrames() {
|
|
435
|
+
const tf = this.params.trailFade;
|
|
436
|
+
if (tf <= 0) {
|
|
437
|
+
return 1;
|
|
438
|
+
}
|
|
439
|
+
if (tf >= 0.999) {
|
|
440
|
+
return 600;
|
|
441
|
+
}
|
|
442
|
+
return Math.ceil(-Math.log(255) / Math.log(tf));
|
|
443
|
+
}, _ParticleExplodeEffect_allocStateRTs = function _ParticleExplodeEffect_allocStateRTs(ctx) {
|
|
444
|
+
const stateBase = {
|
|
445
|
+
size: __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f"),
|
|
446
|
+
float: true,
|
|
447
|
+
wrap: "clamp",
|
|
448
|
+
filter: "nearest",
|
|
449
|
+
};
|
|
450
|
+
// posTex needs ping-pong (advect reads + writes); colorTex is
|
|
451
|
+
// burst-seeded once and never advected, so single-buffer is enough.
|
|
452
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_posTex, ctx.createRenderTarget({
|
|
453
|
+
...stateBase,
|
|
454
|
+
persistent: true,
|
|
455
|
+
}), "f");
|
|
456
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_colorTex, ctx.createRenderTarget(stateBase), "f");
|
|
457
|
+
}, _ParticleExplodeEffect_disposeStateRTs = function _ParticleExplodeEffect_disposeStateRTs() {
|
|
458
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_posTex, "f")?.dispose();
|
|
459
|
+
__classPrivateFieldGet(this, _ParticleExplodeEffect_colorTex, "f")?.dispose();
|
|
460
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_posTex, null, "f");
|
|
461
|
+
__classPrivateFieldSet(this, _ParticleExplodeEffect_colorTex, null, "f");
|
|
462
|
+
}, _ParticleExplodeEffect_cap = function _ParticleExplodeEffect_cap() {
|
|
463
|
+
const max = __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f")[0] * __classPrivateFieldGet(this, _ParticleExplodeEffect_stateSize, "f")[1];
|
|
464
|
+
return Math.max(1, Math.min(max, Math.floor(this.params.count)));
|
|
465
|
+
};
|
|
466
|
+
//# sourceMappingURL=particle-explode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"particle-explode.js","sourceRoot":"","sources":["../../src/particle-explode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,+CAIuB;AACvB,yDAU4B;AAE5B,MAAM,oBAAoB,GAAG,6BAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,oBAAoB,GAAG,6BAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAExD,kEAAkE;AAClE,sEAAsE;AACtE,wEAAwE;AACxE,qEAAqE;AACrE,0BAA0B;AAE1B,uEAAuE;AACvE,uEAAuE;AACvE,0CAA0C;AAC1C,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;EAkBtB,4BAAS;EACT,6BAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAiCP,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I,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AACpD,CAAC,uFAoBc,GAAkB;IAC7B,MAAM,SAAS,GAAG;QACd,IAAI,EAAE,uBAAA,IAAI,wCAAW;QACrB,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,OAAgB;QACtB,MAAM,EAAE,SAAkB;KAC7B,CAAC;IACF,8DAA8D;IAC9D,oEAAoE;IACpE,uBAAA,IAAI,iCAAW,GAAG,CAAC,kBAAkB,CAAC;QAClC,GAAG,SAAS;QACZ,UAAU,EAAE,IAAI;KACnB,CAAC,MAAA,CAAC;IACH,uBAAA,IAAI,mCAAa,GAAG,CAAC,kBAAkB,CAAC,SAAS,CAAC,MAAA,CAAC;AACvD,CAAC;IAGG,uBAAA,IAAI,qCAAQ,EAAE,OAAO,EAAE,CAAC;IACxB,uBAAA,IAAI,uCAAU,EAAE,OAAO,EAAE,CAAC;IAC1B,uBAAA,IAAI,iCAAW,IAAI,MAAA,CAAC;IACpB,uBAAA,IAAI,mCAAa,IAAI,MAAA,CAAC;AAC1B,CAAC;IAuJG,MAAM,GAAG,GAAG,uBAAA,IAAI,wCAAW,CAAC,CAAC,CAAC,GAAG,uBAAA,IAAI,wCAAW,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Effect, EffectContext } from "@vfx-js/core";
|
|
2
|
+
export type ParticleParams = {
|
|
3
|
+
/** Max particles. Capped at construction by the state texture size. */
|
|
4
|
+
count: number;
|
|
5
|
+
/** Particles per second emitted within `radius` of the mouse while
|
|
6
|
+
* the mouse is active. */
|
|
7
|
+
birthRate: number;
|
|
8
|
+
/** Particles per second emitted at uniform-random positions across
|
|
9
|
+
* the element. Independent of mouse motion; only gated by visibility
|
|
10
|
+
* and the same alpha-rejection as mouse spawns. */
|
|
11
|
+
screenBirthRate: number;
|
|
12
|
+
/** Base lifespan (sec); actual life is jittered per-particle. */
|
|
13
|
+
life: number;
|
|
14
|
+
/** Curl-noise drift speed (uv/sec, short-axis-normalized) once the
|
|
15
|
+
* emit impulse decays. */
|
|
16
|
+
noiseSpeed: number;
|
|
17
|
+
/** Initial outward speed (uv/sec, short-axis-normalized) applied
|
|
18
|
+
* to mouse-spawned particles — fades to curl-noise drift over
|
|
19
|
+
* `noiseDelay`. Screen-spawned particles ignore this. */
|
|
20
|
+
emitSpeed: number;
|
|
21
|
+
/** Fraction of life (0..1) over which motion smoothstep-blends from
|
|
22
|
+
* the radial impulse at spawn to the curl-noise field. 0 disables
|
|
23
|
+
* the radial phase entirely. */
|
|
24
|
+
noiseDelay: number;
|
|
25
|
+
/** Approximate swirl size in uv units (larger → bigger swirls). */
|
|
26
|
+
noiseScale: number;
|
|
27
|
+
/** Morph rate on the 4th simplex axis (units per second). */
|
|
28
|
+
noiseAnimation: number;
|
|
29
|
+
/** Particle quad size in element px. */
|
|
30
|
+
pointSize: number;
|
|
31
|
+
/** Global alpha multiplier on each particle (0..1). */
|
|
32
|
+
alpha: number;
|
|
33
|
+
/** Spawn radius around the cursor in element px. */
|
|
34
|
+
radius: number;
|
|
35
|
+
/** Life-taper curve exponent (>1 holds full speed longer). */
|
|
36
|
+
speedDecay: number;
|
|
37
|
+
/** Alpha-envelope shape exponent (>1 holds peak alpha longer; <1 sharpens fade). */
|
|
38
|
+
alphaDecay: number;
|
|
39
|
+
/** Fraction of life over which the particle ramps from 0 to peak
|
|
40
|
+
* alpha. Small values (≈0.05) keep the radial-emit phase visible;
|
|
41
|
+
* larger values (≈0.5) restore the slow fade-in look. */
|
|
42
|
+
fadeIn: number;
|
|
43
|
+
/** Reject spawns where src.a is below this. */
|
|
44
|
+
alphaThreshold: number;
|
|
45
|
+
/** Emit even when the mouse is stationary. */
|
|
46
|
+
spawnOnIdle: boolean;
|
|
47
|
+
/** Source element opacity (0..1) shown beneath the particles. */
|
|
48
|
+
srcOpacity: number;
|
|
49
|
+
/** Per-frame trail decay (0..1). Higher = longer trails. */
|
|
50
|
+
trailFade: number;
|
|
51
|
+
/** Depth fog 0..1. */
|
|
52
|
+
fog: number;
|
|
53
|
+
/** Base color blended into particle rgb (hex 0xRRGGBB). */
|
|
54
|
+
color: number;
|
|
55
|
+
/** Mix amount between src color (0) and `color` (1). */
|
|
56
|
+
colorMix: number;
|
|
57
|
+
/** Stamp blend mode. "add" brightens overlaps; "normal" composites
|
|
58
|
+
* with premultiplied-alpha over. */
|
|
59
|
+
blend: "add" | "normal";
|
|
60
|
+
};
|
|
61
|
+
export declare class ParticleEffect implements Effect {
|
|
62
|
+
#private;
|
|
63
|
+
/** Read-only view of the current params. Use `setParam(key, value)`
|
|
64
|
+
* to mutate so values like `count` are sanitized. (External tools
|
|
65
|
+
* such as tweakpane bind directly to the underlying object and
|
|
66
|
+
* skip the validation; the type marker is for programmatic use.) */
|
|
67
|
+
get params(): Readonly<ParticleParams>;
|
|
68
|
+
constructor(initial?: Partial<ParticleParams>);
|
|
69
|
+
get maxCount(): number;
|
|
70
|
+
/** Validated bulk setter. Pass any subset of params; bad inputs
|
|
71
|
+
* (NaN / negative `count`, etc) are coerced to valid values
|
|
72
|
+
* before applying. */
|
|
73
|
+
setParam(updates: Partial<ParticleParams>): void;
|
|
74
|
+
init(ctx: EffectContext): void;
|
|
75
|
+
render(ctx: EffectContext): void;
|
|
76
|
+
dispose(): void;
|
|
77
|
+
outputRect(dims: Parameters<NonNullable<Effect["outputRect"]>>[0]): readonly [number, number, number, number];
|
|
78
|
+
}
|