@margoengine/vfx 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +1642 -3
  4. package/dist/base-C9upJytz.js +658 -0
  5. package/dist/base.d.ts +767 -0
  6. package/dist/base.js +1 -0
  7. package/dist/blown-sand.d.ts +218 -0
  8. package/dist/blown-sand.js +700 -0
  9. package/dist/clouds.d.ts +229 -0
  10. package/dist/clouds.js +566 -0
  11. package/dist/compat-CVSEj1Bp.js +217 -0
  12. package/dist/compat.d.ts +59 -0
  13. package/dist/curves.d.ts +11 -0
  14. package/dist/curves.js +59 -0
  15. package/dist/debris.d.ts +111 -0
  16. package/dist/debris.js +258 -0
  17. package/dist/depth-collide.d.ts +7 -0
  18. package/dist/depth-collide.js +96 -0
  19. package/dist/emitter.d.ts +10 -0
  20. package/dist/emitter.js +125 -0
  21. package/dist/events.d.ts +9 -0
  22. package/dist/events.js +131 -0
  23. package/dist/extra-CgGjbojB.js +4 -0
  24. package/dist/extra.d.ts +2 -0
  25. package/dist/fields.d.ts +11 -0
  26. package/dist/fields.js +95 -0
  27. package/dist/fire-front.d.ts +539 -0
  28. package/dist/fire-front.js +840 -0
  29. package/dist/fire.d.ts +119 -0
  30. package/dist/fire.js +173 -0
  31. package/dist/flame-ramp-VoBKpYnM.js +75 -0
  32. package/dist/flame-ramp.d.ts +61 -0
  33. package/dist/flame.d.ts +260 -0
  34. package/dist/flame.js +605 -0
  35. package/dist/flipbook.d.ts +7 -0
  36. package/dist/flipbook.js +23 -0
  37. package/dist/fog-B-kBv7g0.js +32 -0
  38. package/dist/frame-BuvMFBPp.js +4 -0
  39. package/dist/frame.d.ts +7 -0
  40. package/dist/gunfire.d.ts +696 -0
  41. package/dist/gunfire.js +1204 -0
  42. package/dist/hash-Btsp6fGK.js +7 -0
  43. package/dist/hash.d.ts +2 -0
  44. package/dist/index.d.ts +17 -0
  45. package/dist/index.js +60 -0
  46. package/dist/json.d.ts +53 -0
  47. package/dist/json.js +237 -0
  48. package/dist/lit.d.ts +11 -0
  49. package/dist/lit.js +105 -0
  50. package/dist/mesh.d.ts +14 -0
  51. package/dist/mesh.js +225 -0
  52. package/dist/node-system.d.ts +315 -0
  53. package/dist/node-system.js +384 -0
  54. package/dist/nodes.d.ts +14 -0
  55. package/dist/nodes.js +293 -0
  56. package/dist/obstacles.d.ts +3 -0
  57. package/dist/obstacles.js +25 -0
  58. package/dist/over-life.d.ts +14 -0
  59. package/dist/over-life.js +93 -0
  60. package/dist/require-webgpu--tUXPsmA.js +7 -0
  61. package/dist/ribbons.d.ts +20 -0
  62. package/dist/ribbons.js +151 -0
  63. package/dist/schedule.d.ts +29 -0
  64. package/dist/schedule.js +47 -0
  65. package/dist/settings.d.ts +362 -0
  66. package/dist/settings.js +707 -0
  67. package/dist/shader.d.ts +44 -0
  68. package/dist/shadows.d.ts +26 -0
  69. package/dist/shadows.js +182 -0
  70. package/dist/shapes.d.ts +34 -0
  71. package/dist/shapes.js +81 -0
  72. package/dist/shared/fog.d.ts +33 -0
  73. package/dist/shared/pass.d.ts +53 -0
  74. package/dist/shared/settings.d.ts +89 -0
  75. package/dist/skinned.d.ts +11 -0
  76. package/dist/skinned.js +104 -0
  77. package/dist/smoke.d.ts +215 -0
  78. package/dist/smoke.js +280 -0
  79. package/dist/soft.d.ts +17 -0
  80. package/dist/soft.js +55 -0
  81. package/dist/solid.d.ts +168 -0
  82. package/dist/solid.js +403 -0
  83. package/dist/sort.d.ts +3 -0
  84. package/dist/sort.js +58 -0
  85. package/dist/space.d.ts +14 -0
  86. package/dist/space.js +88 -0
  87. package/dist/stretch.d.ts +7 -0
  88. package/dist/stretch.js +40 -0
  89. package/dist/texture.d.ts +8 -0
  90. package/dist/texture.js +45 -0
  91. package/dist/view-RKprOPAy.js +30 -0
  92. package/dist/view-rect-DkeiiUtw.js +13 -0
  93. package/dist/wrap.d.ts +3 -0
  94. package/dist/wrap.js +5 -0
  95. package/package.json +192 -6
package/dist/base.d.ts ADDED
@@ -0,0 +1,767 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import { type Engine, type EnginePlugin, type FrameGraph, type PassContext, type Vec3 } from '@margoengine/core/extension';
4
+ import type { FilmClock } from '@margoengine/math/clock';
5
+ import { type FogLike } from './shared/fog.js';
6
+ export type { FogLike } from './shared/fog.js';
7
+ import { type SurfaceTransparency } from './shared/pass.js';
8
+ type Context = Extract<PassContext, {
9
+ backend: 'webgpu';
10
+ }>;
11
+ /**
12
+ * Particle emitter settings. Everything except `capacity` and the four feature options (`obstacles`, `wrap`, `sort`,
13
+ * `texture`) may change between frames; validation runs before GPU commands and throws RangeError when a value is out
14
+ * of range.
15
+ */
16
+ export interface VFXOptions {
17
+ /**
18
+ * Particle slots, an integer 1-16,776,960 (64 bytes each). Fixed at construction. Default 1,000,000 (or the quality
19
+ * preset's). The device bounds it at attach: 64 x capacity must fit one storage binding, so a default WebGPU device
20
+ * (128 MiB) holds up to 2,097,152.
21
+ */
22
+ capacity?: number;
23
+ /** Births queued on attach and after device restoration, an integer 0..capacity. Default 0. */
24
+ initialCount?: number;
25
+ /** Births per second, >= 0. Default capacity / 2. */
26
+ rate?: number;
27
+ /** Emitter centre in world units. Default [0, 1, 0]. */
28
+ position?: Vec3;
29
+ /** Initial velocity in world units per second. Default [0, 3, 0]. */
30
+ velocity?: Vec3;
31
+ /** Random velocity added at birth, world units per second, >= 0. Default 1. */
32
+ spread?: number;
33
+ /** Acceleration in world units per second squared. Default [0, -9.81, 0]. */
34
+ gravity?: Vec3;
35
+ /** Linear RGBA at birth, each 0..1; alpha fades out over the life. Default [1, 0.5, 0.1, 1]. */
36
+ color?: readonly [number, number, number, number];
37
+ /** Billboard diameter in world units, > 0 (ground and obstacle collisions use half of it). Default 0.1. */
38
+ size?: number;
39
+ /** Random life [min, max] in seconds, 0 < min <= max. Default [1, 3]. */
40
+ lifetime?: readonly [number, number];
41
+ /** Height (world y) of the collision plane. Default 0. */
42
+ ground?: number;
43
+ /** Fraction of speed kept when bouncing off the ground or an obstacle, 0..1. Default 0.3. */
44
+ bounce?: number;
45
+ /** Curl-noise acceleration strength, >= 0 (0 turns it off). Default 0.5. */
46
+ turbulence?: number;
47
+ /** Spatial frequency of the curl field, per world unit, >= 0. Default 1. */
48
+ frequency?: number;
49
+ /**
50
+ * The wind: `[x, z]` in metres per second, or anything with `sample(x, y, z, t)` returning `[x, y, z]` (a
51
+ * `WindField` of `@margoengine/weather` fits), read each frame at the emitter's position. Each particle's horizontal
52
+ * velocity relaxes toward the wind with a time constant of 0.25 s (the drag of a parcel of air that moves with the
53
+ * wind; Crowe et al., Multiphase Flows with Droplets and Particles, 2nd ed., CRC 2011, eq. 1.5), so smoke that rises
54
+ * at speed w in a wind U leans atan(U / w) from the vertical. The vertical velocity is left to gravity and the launch.
55
+ * Each component is limited to 1,000 m/s. Default undefined, and `[0, 0]`, give no wind force. Change it between
56
+ * frames with `setWind`.
57
+ */
58
+ wind?: VFXWind;
59
+ /** Billboard spin in radians per second (each particle gets a random birth angle). Default 0. */
60
+ angularVelocity?: number;
61
+ /** Half extents of the box births are spread over, around `position`, each >= 0. Default [0, 0, 0] (a point). */
62
+ emissionExtent?: Vec3;
63
+ /** RGB multiplier for HDR emission, 0 to 65,504 (the largest half float). Default 1. */
64
+ intensity?: number;
65
+ /**
66
+ * A film clock (`FilmClock` from `@margoengine/math/clock`). With one, the effect steps in fixed ticks of 1/120 s, as
67
+ * many as the clock owes since the last drawn frame, instead of one step of the frame's delta: a shot drawn at 24, 30
68
+ * or 60 fps births and moves the same particles at the times it shares, a frame of any length loses no time, and a
69
+ * seek is setting the clock (a seek back replays from 0). Every owed tick runs in the next drawn frame; `advanceTime`
70
+ * and `onPreUpdate` then move nothing. Read every frame. Default none: one step of the frame's delta, as before.
71
+ */
72
+ clock?: Pick<FilmClock, 'ticks'>;
73
+ /** Up to 64 spheres/boxes that the flow bends around and particles bounce off. Contents are read each frame; pass an array (even `[]`) before attaching. */
74
+ obstacles?: readonly VFXObstacle[];
75
+ /** Keep particles inside the emission box, re-entering on the opposite face (every extent must be > 0). Read at attach. */
76
+ wrap?: boolean;
77
+ /** Draw back to front: bitonic sort of the live list each frame. Read at attach. */
78
+ sort?: boolean;
79
+ /**
80
+ * Fade distance in world units, >= 0: a particle fades out over this distance in front of any opaque surface behind it
81
+ * (measured along the view axis), so it no longer shows a hard line where it meets the floor or a wall. Needs the `soft`
82
+ * feature and `depth`; changeable between frames. Default 0 (off: no extra shader code, bindings or per-frame work).
83
+ */
84
+ softness?: number;
85
+ /**
86
+ * Scene depth for `softness`: a function returning a sampleable depth texture (reversed Z: 1 at the near plane, 0 where
87
+ * nothing is drawn; 1 sample or the scene's sample count) the size of the drawing buffer, or undefined before it
88
+ * exists. For example `() => depth.texture` with `DepthTexture` from `@margoengine/post/depth`. Throws `MargoError`
89
+ * `'state'` at draw time when it returns undefined while `softness` is on.
90
+ */
91
+ depth?: () => GPUTexture | undefined;
92
+ /** RGBA8 sRGB sprite (or atlas of frames) multiplied by the particle colour, instead of the soft disc. Read at construction. */
93
+ texture?: VFXTexture;
94
+ /** Size, opacity and colour over each particle's life. Which curves are set is read at attach; their values are read each frame. Needs the `curves` feature. */
95
+ curves?: VFXCurves;
96
+ /** Where births start and which way `speed` pushes them: a sphere, a cone or the surface of a triangle mesh. The shape (and a mesh) is read at attach; the numbers each frame. Needs the `emitter` feature. */
97
+ emitter?: VFXEmitter;
98
+ /** Moving emitter frame, inherited velocity and distance births. Needs `space` from `@margoengine/vfx/space`. */
99
+ space?: import('./space.js').VFXSpace;
100
+ /** Spin, speed, growth and speed limits over normalized lifetime. Needs `overLife`. */
101
+ overLife?: import('./over-life.js').VFXOverLife;
102
+ /** Prewarm and timed burst cycles. Needs schedule from the optional /schedule entry. */
103
+ schedule?: import('./schedule.js').VFXSchedule;
104
+ /** A ribbon behind each particle through its last positions, for smoke and magic trails. Needs `ribbons` from `@margoengine/vfx/ribbons`. */
105
+ ribbons?: VFXRibbons;
106
+ /** Draw each particle as a small lit triangle mesh instead of a billboard. Needs `mesh` from `@margoengine/vfx/mesh`. */
107
+ mesh?: VFXMeshParticles;
108
+ /** Sub-emitters: particles born on the GPU where a particle dies or hits the ground. Needs `events` from `@margoengine/vfx/events`. */
109
+ events?: VFXEvents;
110
+ /** Billboards lit by the sun, clustered point and spot lights and sun shadows, as round particles. Needs `lit` from `@margoengine/vfx/lit`. */
111
+ lit?: VFXLit;
112
+ /** Particles bounce off whatever was drawn last frame, from the scene `depth`. Needs `depthCollide` from `@margoengine/vfx/depth-collide`. */
113
+ depthCollide?: VFXDepthCollide;
114
+ /** Billboards stretched along their motion on screen, for sparks, rain and tracers. Needs `stretch` from `@margoengine/vfx/stretch`. */
115
+ stretch?: VFXStretch;
116
+ /** Point attractors and a 3D vector field added to each particle's acceleration. Needs `fields` from `@margoengine/vfx/fields`. */
117
+ fields?: VFXFields;
118
+ /** Births on the surface of an animated (skinned or morphed) mesh, following its pose. Needs `skinned` from `@margoengine/vfx/skinned`. */
119
+ skinned?: VFXSkinned;
120
+ /** Blend each lifetime atlas frame into the next. Needs `flipbook` from `@margoengine/vfx/flipbook` and a texture atlas whose frames are `'lifetime'`. */
121
+ flipbook?: VFXFlipbook;
122
+ /** Particles cast sphere shadows and the first live slots emit point lights. Needs `shadows` from `@margoengine/vfx/shadows`. */
123
+ shadows?: VFXShadows;
124
+ /** A graph of operators added to each particle's acceleration. Needs `nodes` from `@margoengine/vfx/nodes`. */
125
+ nodes?: VFXNodes;
126
+ }
127
+ /**
128
+ * What the skinned emitter reads of a primitive: an entry of `model.primitives` from `@margoengine/gltf/pbr`, with a
129
+ * deformer such as `Animation` from `@margoengine/animation` attached.
130
+ */
131
+ export interface VFXSkinnedPrimitive {
132
+ /** The bind pose, 20 floats a vertex, position first. Read at attach. */
133
+ readonly vertices: Float32Array;
134
+ /** Triangles, three vertex indices each. Read at attach. */
135
+ readonly indices: ArrayLike<number>;
136
+ /** The buffer the deformer writes the posed vertices to (80 bytes each). Read every frame; until set, the bind pose. */
137
+ readonly deformed?: GPUBuffer;
138
+ /** Bytes before the primitive's first vertex in `deformed`. Default 0. */
139
+ readonly deformedOffset?: number;
140
+ }
141
+ /**
142
+ * Births on an animated mesh: each birth picks a triangle by its bind-pose area (so a stretched limb does not emit
143
+ * more) and a uniform point of it in this frame's pose, placed by `transform` (the emitter's `position` is not used; `emissionExtent` still jitters it), and flies along
144
+ * the posed face's normal times `speed` on top of `velocity` and `spread`. Not with `emitter`. Needs the `skinned` feature.
145
+ */
146
+ export interface VFXSkinned {
147
+ primitive: VFXSkinnedPrimitive;
148
+ /** The mesh's world matrix, 16 numbers column-major (the node's world transform). Read every frame. Default identity. */
149
+ transform?: ArrayLike<number>;
150
+ /** World units per second along the posed face normal, -1000..1000 (negative flies inward). Default 0. */
151
+ speed?: number;
152
+ }
153
+ /**
154
+ * Blend successive frames of a lifetime atlas: the vertex stage passes this frame, the next (the last frame holds)
155
+ * and the fraction between them, and the fragment stage samples both cells and mixes. Pass `{}`. Needs a `texture`
156
+ * whose atlas frames are `'lifetime'`, and the `flipbook` feature.
157
+ */
158
+ export interface VFXFlipbook {
159
+ }
160
+ /** One point light packed from a live particle. `decay` is 2, the windowed inverse-square term. */
161
+ export interface VFXParticleLight {
162
+ position: [number, number, number];
163
+ /** World units, not scaled by the particle's size. */
164
+ range: number;
165
+ color: [number, number, number];
166
+ intensity: number;
167
+ decay: 2;
168
+ }
169
+ /**
170
+ * Particles cast sun shadows into `cast` and the first live slots emit point lights into `into`. `count`, `range` and
171
+ * `intensity` are read every frame; `cast` and `into` are fixed at attach. The feature sets `buffer`.
172
+ */
173
+ export interface VFXShadows {
174
+ /** How many of the first live slots, in slot order, become lights. A whole number from 0 to 64. Default 8. */
175
+ count?: number;
176
+ /** Light range in world units, finite and above 0. Default 4. */
177
+ range?: number;
178
+ /** Light intensity, finite and 0 or more. Default 1. */
179
+ intensity?: number;
180
+ /** A `Shadows` from `@margoengine/shadows`, or anything with `add`. Fixed at attach. */
181
+ cast?: {
182
+ add(source: {
183
+ drawShadow(ctx: unknown): void;
184
+ disposed?: boolean;
185
+ }, options?: {
186
+ static?: boolean;
187
+ }): () => void;
188
+ };
189
+ /** A `Clustered` from `@margoengine/clustered`, or anything with `setLights`. Fixed at attach. */
190
+ into?: {
191
+ setLights(lights: readonly VFXParticleLight[]): void;
192
+ };
193
+ /** The light list on the GPU (a header, then up to 64 lights). Set by the feature at attach. */
194
+ buffer?: GPUBuffer;
195
+ }
196
+ /** The wind of a particle effect: `[x, z]` in m/s, or a field sampled at the emitter. */
197
+ export type VFXWind = readonly [number, number] | {
198
+ sample(x: number, y: number, z: number, t: number): readonly number[];
199
+ };
200
+ /** One operator in a particle update graph. `force` and `drag` add acceleration and have no output. */
201
+ export interface VFXNode {
202
+ op: 'const' | 'attribute' | 'add' | 'mul' | 'sub' | 'mix' | 'min' | 'max' | 'scale' | 'normalize' | 'length' | 'force' | 'drag';
203
+ /** Indices of other operators. A cycle, a self input or an unknown index is a TypeError. */
204
+ inputs?: readonly number[];
205
+ /** `const`: a finite number or three. `attribute`: the name. `scale`: a finite number. */
206
+ value?: number | readonly [number, number, number] | 'position' | 'velocity' | 'size' | 'color' | 'life' | 'age';
207
+ }
208
+ /** Operators compiled into the simulation. The wires are fixed at attach; const and scale numbers are read every frame. */
209
+ export interface VFXNodes {
210
+ graph: readonly VFXNode[];
211
+ }
212
+ /** The particle values a graph reads. Age is the life already lived. */
213
+ export interface VFXNodeSample {
214
+ position: readonly [number, number, number];
215
+ velocity: readonly [number, number, number];
216
+ size: number;
217
+ color: readonly [number, number, number];
218
+ life: number;
219
+ age: number;
220
+ }
221
+ /** A point that pulls particles towards it (or pushes them away with a negative strength). */
222
+ export interface VFXAttractor {
223
+ position: Vec3;
224
+ /** Pull in world units^3 per second^2: the acceleration is strength x d / (|d|^2 + radius^2)^1.5; negative pushes. */
225
+ strength: number;
226
+ /** Softening radius in world units, > 0, so the pull stays finite at the centre. Default 0.5. */
227
+ radius?: number;
228
+ }
229
+ /** A 3D vector field over a box: one acceleration vector per cell, at the cell centres, trilinear between them. */
230
+ export interface VFXVectorField {
231
+ /** Cells along x, y and z, whole numbers >= 1, at most 2,097,152 in all. */
232
+ size: Vec3;
233
+ /** Vectors x, y, z per cell, x fastest then y then z. Copied at attach. */
234
+ data: Float32Array;
235
+ /** The box centre in world units. Default [0, 0, 0]. */
236
+ center?: Vec3;
237
+ /** Half the box size on each axis, > 0. */
238
+ halfSize: Vec3;
239
+ /** Scale on the field's vectors. Default 1. */
240
+ strength?: number;
241
+ }
242
+ /**
243
+ * Force fields: up to 16 attractors and one vector field (zero outside its box, the edge cells' value between the outer
244
+ * cell centres and the box edge) added to each particle's acceleration, with gravity and turbulence. Attractors, the
245
+ * box and the strengths are read every frame; whether there is a field, and its cells, are fixed at attach. Needs the
246
+ * `fields` feature.
247
+ */
248
+ export interface VFXFields {
249
+ attractors?: readonly VFXAttractor[];
250
+ field?: VFXVectorField;
251
+ }
252
+ /**
253
+ * Velocity-stretched billboards: each billboard's long axis follows the particle's velocity across the screen and it
254
+ * is `size + factor x speed` long (never shorter than `size`), `size` across. A particle with no motion across the
255
+ * screen stays round; spin is ignored. Read every frame. Needs the `stretch` feature.
256
+ */
257
+ export interface VFXStretch {
258
+ /** Seconds of travel the streak is long, 0..10. Default 0.05. */
259
+ factor?: number;
260
+ }
261
+ /**
262
+ * Collisions with the scene depth: each frame, before the simulation, a particle on last frame's draw list that meets
263
+ * the surface drawn under it last frame (within `thickness` behind it, or less than its radius in front) has its
264
+ * velocity into the surface reflected and scaled by the effect's `bounce`, and moves out to a radius in front. Needs
265
+ * the `depth` option (the scene depth, as for `softness`) and the `depthCollide` feature.
266
+ */
267
+ export interface VFXDepthCollide {
268
+ /** How far behind a surface, in world units, a particle still counts as touching it (and not as hidden behind it), > 0. Default 0.5. */
269
+ thickness?: number;
270
+ }
271
+ /**
272
+ * Where lit particles get their light from: `Clustered` from `@margoengine/clustered` or `Shadows` from
273
+ * `@margoengine/shadows` (or anything with their `pbr` and `bindings`), attached to the same engine.
274
+ */
275
+ export interface VFXLightSource {
276
+ pbr(group: number): {
277
+ readonly declarations: string;
278
+ };
279
+ bindings(): GPUBindGroupEntry[];
280
+ }
281
+ /**
282
+ * Lighting for the billboards: each one is shaded as a ball (its normal from where the pixel lies on the disc) in its
283
+ * own colour, by the engine's sun with wrap lighting, the ambient light, and optionally clustered lights and sun
284
+ * shadows. `lights` and `shadows` are read at attach; `wrap` and `ambient` every frame (change them on the same
285
+ * object). Needs the `lit` feature.
286
+ */
287
+ export interface VFXLit {
288
+ /** Point and spot lights: `Clustered` from `@margoengine/clustered`. Fixed at attach. */
289
+ lights?: VFXLightSource;
290
+ /** Sun shadows on the particles: `Shadows` from `@margoengine/shadows`. Fixed at attach. */
291
+ shadows?: VFXLightSource;
292
+ /** How far the sun wraps round the dark side, 0 (a hard ball) to 1 (dark only at the far pole). Default 0.5. */
293
+ wrap?: number;
294
+ /** Ambient light, linear RGB, each 0..16. Default the engine's: `lighting.radiance[3]` times `lighting.ambient`. */
295
+ ambient?: readonly [number, number, number];
296
+ /**
297
+ * A fire's glow on the particles, read every frame: a point source radiating `power` watts at `position`, softened
298
+ * over `radius` metres (default 1), of `color` (default `GLOW_COLOR`, a flame's orange). Its irradiance
299
+ * P / (4 pi (d^2 + r^2)) lights a particle as the sun at intensity pi lights it with 1,000 W/m^2, so smoke over a fire
300
+ * is lit orange from below, by night with no other light. Default none.
301
+ */
302
+ glow?: {
303
+ position: readonly [number, number, number];
304
+ power: number;
305
+ radius?: number;
306
+ color?: readonly [number, number, number];
307
+ };
308
+ }
309
+ /**
310
+ * Sub-emitters: a particle that is born from the emitter (`on: 'birth'`, a trail or a flash at the muzzle), dies (`on: 'death'`), or meets the ground faster than `speed` (`on: 'collision'`),
311
+ * raises an event on the GPU, and in the next frame `count` particles are born where it was into free slots of the same
312
+ * effect, with their own life, size, velocity and colour. Children never raise events. `on` is read at attach, the rest
313
+ * every frame. Needs the `events` feature.
314
+ */
315
+ export interface VFXEvents {
316
+ on: 'birth' | 'death' | 'collision';
317
+ /** Particles born per event, an integer 1..64. Default 8. */
318
+ count?: number;
319
+ /** Random life [min, max] of the children in seconds, 0 < min <= max. Default [0.5, 1]. */
320
+ lifetime?: readonly [number, number];
321
+ /** The children's billboard diameter in world units, > 0. Default 0.05. */
322
+ size?: number;
323
+ /** The children's velocity in world units per second, added to `inherit` times the parent's. Default [0, 0, 0]. */
324
+ velocity?: Vec3;
325
+ /** Random velocity added to each child, world units per second, >= 0. Default 1. */
326
+ spread?: number;
327
+ /** Fraction of the parent's velocity (at its death or impact) the children start with, -10..10. Default 0. */
328
+ inherit?: number;
329
+ /** With `on: 'collision'`, the slowest impact (world units per second towards the ground) that raises an event, >= 0. Default 0.5. */
330
+ speed?: number;
331
+ /** The children's linear RGBA at birth, each 0..1, times `intensity`; alpha fades over their life. Default [1, 1, 1, 1]. */
332
+ color?: readonly [number, number, number, number];
333
+ }
334
+ /**
335
+ * A mesh drawn for every particle in place of its billboard, opaque and depth written, scaled so its farthest vertex from
336
+ * the mesh origin is half the particle `size` away, in the particle colour lit by one directional light. The geometry and
337
+ * `align` are read at attach; `light`, `lightColor` and `ambient` every frame (change them on the same object). Needs the
338
+ * `mesh` feature.
339
+ */
340
+ export interface VFXMeshParticles {
341
+ /** Vertex positions as xyz triples around the mesh origin, finite, not all at the origin. */
342
+ positions: ArrayLike<number>;
343
+ /** Triangle corner indices, a multiple of 3 (1 to 65,536 triangles), counter-clockwise from outside; omit when `positions` is a triangle list. */
344
+ indices?: ArrayLike<number>;
345
+ /** One xyz normal per vertex; omitted, each triangle uses its face normal (flat shading). */
346
+ normals?: ArrayLike<number>;
347
+ /** `'random'`: each particle tumbles about its own random axis by its spin (`angularVelocity`); `'velocity'`: the mesh's +y follows the particle's motion and the spin turns it about that line. Default `'random'`. */
348
+ align?: 'random' | 'velocity';
349
+ /** Direction towards the light in world space, not zero. Default [0.4, 1, 0.3]. */
350
+ light?: readonly [number, number, number];
351
+ /** Linear RGB of the light, each 0..16. Default [1, 1, 1]. */
352
+ lightColor?: readonly [number, number, number];
353
+ /** Light that reaches faces turned away, 0..1. Default 0.35. */
354
+ ambient?: number;
355
+ }
356
+ /**
357
+ * A ribbon behind each particle: a camera-facing strip through the particle and its last `points - 1` recorded
358
+ * positions, fading from the particle's own opacity at the head to 0 at the tail. `points` is read at attach; the rest
359
+ * every frame. Needs the `ribbons` feature.
360
+ */
361
+ export interface VFXRibbons {
362
+ /** Points along the ribbon, the particle included, an integer 2..64. Default 16. Fixed at attach. */
363
+ points?: number;
364
+ /** Seconds between recorded points, 0..1; 0 records one every frame. Default 1/60. */
365
+ interval?: number;
366
+ /** Width in world units, > 0. Default the particle `size`. */
367
+ width?: number;
368
+ /** Draw the particles' billboards as well as their ribbons. Default true. */
369
+ heads?: boolean;
370
+ }
371
+ /**
372
+ * Size, opacity and colour over a particle's life, from birth (0) to death (1). Needs the `curves` feature; set at
373
+ * least one of the three.
374
+ */
375
+ export interface VFXCurves {
376
+ /** 2 to 32 multipliers of `size`, each 0..1, evenly spaced over the life and linearly interpolated: `[0, 1, 0]` swells then shrinks. */
377
+ size?: readonly number[];
378
+ /** 2 to 32 opacities, each 0..1, evenly spaced over the life; replaces the default fade-out: `[0, 1, 1, 0]` fades in and out. */
379
+ alpha?: readonly number[];
380
+ /** 2 to 8 stops ascending by `at` (0..1) with a linear RGB `color` (each 0..16) that multiplies the particle `color`: pass `color: [1, 1, 1, 1]` to draw the gradient as it is. */
381
+ color?: readonly {
382
+ at: number;
383
+ color: readonly [number, number, number];
384
+ }[];
385
+ }
386
+ /**
387
+ * An emitter shape. Births start at `position` (plus `emissionExtent`) offset by the shape and move along the shape's
388
+ * direction times `speed` (world units per second, -1000..1000, default 0; negative flies inward) on top of `velocity`
389
+ * and `spread`. Needs the `emitter` feature.
390
+ */
391
+ export type VFXEmitter = import('./shapes.js').VFXShape | {
392
+ shape: 'sphere';
393
+ /** Radius in world units, 0..1,000,000. Default 1. */
394
+ radius?: number;
395
+ /** Births on the surface only, not through the volume. Default false. */
396
+ shell?: boolean;
397
+ speed?: number;
398
+ } | {
399
+ shape: 'cone';
400
+ /** Radius of the disc at the apex that births start on, world units, 0..1,000,000. Default 0 (a point). */
401
+ radius?: number;
402
+ /** Half angle off the axis in radians, 0..PI/2. Default PI/6. */
403
+ angle?: number;
404
+ /** Direction the cone opens along; need not be unit length, not zero. Default [0, 1, 0]. */
405
+ axis?: Vec3;
406
+ speed?: number;
407
+ } | {
408
+ shape: 'mesh';
409
+ /** Vertex positions as xyz triples (world units around `position`), finite, at least one triangle. */
410
+ positions: ArrayLike<number>;
411
+ /** Triangle corner indices, a multiple of 3 (up to 262,144 triangles); omit when `positions` is a triangle list. */
412
+ indices?: ArrayLike<number>;
413
+ /** Multiplies `positions`, 1e-6..1e6. Default 1. */
414
+ scale?: number;
415
+ speed?: number;
416
+ };
417
+ /**
418
+ * A sphere or axis-aligned box (world units) the curl flow bends around within one unit and particles bounce off with
419
+ * `bounce`. Up to 64 per effect; needs the `obstacles` feature.
420
+ */
421
+ export type VFXObstacle = {
422
+ kind: 'sphere';
423
+ center: Vec3;
424
+ radius: number;
425
+ } | {
426
+ kind: 'box';
427
+ center: Vec3;
428
+ halfSize: Vec3;
429
+ };
430
+ /** A particle sprite: RGBA8 sRGB texels, row-major from the top-left. Copied at construction; needs the `texture` feature. */
431
+ export interface VFXTexture {
432
+ /** Pixels, an integer 1-4096. */
433
+ width: number;
434
+ /** Pixels, an integer 1-4096. */
435
+ height: number;
436
+ /** `width * height * 4` bytes; RGB multiplies the particle colour, alpha its opacity. */
437
+ data: Uint8Array | Uint8ClampedArray;
438
+ /** Treat the texture as a grid of frames instead of one sprite. */
439
+ atlas?: ParticleAtlas;
440
+ }
441
+ /**
442
+ * The `atlas` of a particle texture: `columns` x `rows` equal frames, numbered left to right from the top row. With
443
+ * `frames: 'random'` each particle shows one frame picked at random when it spawns (debris that uses parts of a block
444
+ * texture); with `'lifetime'` it steps through every frame in order from spawn to death. `@margoengine/vfx/flipbook`
445
+ * blends each of those frames into the next; without it the step is instant.
446
+ */
447
+ export interface ParticleAtlas {
448
+ /** Frames across, 1 to the texture width. */
449
+ columns: number;
450
+ /** Frames down, 1 to the texture height. */
451
+ rows: number;
452
+ frames: 'random' | 'lifetime';
453
+ }
454
+ /** Features add each GPU object they create here at once, so a setup that fails part-way still releases it. */
455
+ export type OwnedResources = {
456
+ destroy(): void;
457
+ }[];
458
+ /** What an added feature builds on: the effect's buffers and its simulation module. */
459
+ export interface VFXState {
460
+ device: GPUDevice;
461
+ capacity: number;
462
+ uniform: GPUBuffer;
463
+ particles: GPUBuffer;
464
+ alive: GPUBuffer;
465
+ visible: GPUBuffer;
466
+ indirect: GPUBuffer;
467
+ /** The simulation module, with every feature's patch in it, for extra entry points. */
468
+ module: GPUShaderModule;
469
+ options: VFXOptions;
470
+ /** The engine's frame statistics: a feature's own draw adds to `drawCalls`. */
471
+ stats: {
472
+ drawCalls: number;
473
+ };
474
+ /** The engine the effect is attached to (its `lighting` is read every frame by `lit`). */
475
+ engine: Engine;
476
+ /**
477
+ * Spin added where the angle is drawn, set by `overLife` at attach: WGSL declaring `fn drawnSpin(life:f32,left:f32)->f32`
478
+ * (radians the spin curve turned a particle of initial life `life` with `left` seconds left) and the bind group entry
479
+ * it reads. A feature with its own draw (`mesh`) reads it when it builds its pipeline.
480
+ */
481
+ spin?: {
482
+ code: string;
483
+ entry: GPUBindGroupEntry;
484
+ };
485
+ }
486
+ /** The GPU side of an added feature, made at attach and again after device restoration. */
487
+ export interface VFXRuntime {
488
+ /** Optional first-frame/reset warmup; each callback submits one ordinary simulation step. */
489
+ warmup?(run: (delta: number) => void): void;
490
+ /** Additional whole births before the frame budget is packed; called once per simulation step. */
491
+ emission?(delta: number): number;
492
+ /** Entries added to the simulation's bind group. */
493
+ compute?: GPUBindGroupEntry[];
494
+ /** Entries added to the billboard's bind group. */
495
+ render?: GPUBindGroupEntry[];
496
+ /** Per frame, before the simulation pass is recorded. */
497
+ write?(c: Context): void;
498
+ /** Extra dispatches at the end of the simulation pass. */
499
+ run?(pass: GPUComputePassEncoder): void;
500
+ /** The sub-emitter event list (`events`): on the WebGL2 route the route lists the events into it and `run` is skipped. */
501
+ eventList?: GPUBuffer;
502
+ /** Its own draw, after the billboards. */
503
+ draw?(c: Context): void;
504
+ /** True while the billboards are not drawn: the feature draws the particles itself. */
505
+ hides?(): boolean;
506
+ /** Births can come from the feature's own list, so the deaths and births scan run in frames without emitter births. */
507
+ births?: boolean;
508
+ /** Called by `VFX.reset()` after the particle buffers are cleared. */
509
+ reset?(): void;
510
+ /** Part of the billboard pipeline's cache key when its bind group `group` (1, or 2 under a transparency hook) is the feature's. */
511
+ key?(group: number): string;
512
+ /** The finished billboard shader with the feature's declarations for bind group `group` added. */
513
+ shade?(code: string, group: number): string;
514
+ /** Sets the feature's bind group `group` on a billboard draw with `pipeline`. */
515
+ bind?(pass: GPURenderPassEncoder, pipeline: GPURenderPipeline, group: number): void;
516
+ /** Drops what the feature registered, before its buffers are destroyed (device restore and `dispose`). */
517
+ dispose?(): void;
518
+ }
519
+ /** A feature beyond the first seven (ribbons and later). The shape is internal: pass the entry's export. */
520
+ export interface VFXExtension<T> {
521
+ /** Checks the option at construction and every frame. Values fixed at attach are checked by the runtime. */
522
+ validate(value: T, options: VFXOptions): void;
523
+ simulation?(code: string, value: T): string;
524
+ billboard?(code: string, value: T): string;
525
+ create?(state: VFXState, value: T, owned: OwnedResources): VFXRuntime;
526
+ }
527
+ /** Ticks a second of an effect stepped by a film clock ({@link VFXOptions.clock}): the dyadic solver rate of level 1. */
528
+ export declare const VFX_TICK_RATE = 120;
529
+ /** Where and how one burst's births start: each given field replaces the effect's option of the same name for that burst alone. */
530
+ export interface BurstSpawn {
531
+ position?: ArrayLike<number>;
532
+ velocity?: ArrayLike<number>;
533
+ spread?: number;
534
+ emissionExtent?: ArrayLike<number>;
535
+ }
536
+ /**
537
+ * The optional parts of a particle effect. Pass the exports of the feature entries, for example `{sort}` from
538
+ * `@margoengine/vfx/sort`; the shapes are internal. Effects without a feature compile the same WGSL as before.
539
+ */
540
+ export interface VFXFeatures {
541
+ obstacles?: {
542
+ patch(simulation: string): string;
543
+ write(list: readonly VFXObstacle[], extra: Float32Array): void;
544
+ };
545
+ wrap?: {
546
+ patch(simulation: string): string;
547
+ };
548
+ sort?: {
549
+ create(device: GPUDevice, particles: GPUBuffer, alive: GPUBuffer, indirect: GPUBuffer, extra: GPUBuffer, size: number, owned: OwnedResources): {
550
+ run(pass: GPUComputePassEncoder): void;
551
+ };
552
+ };
553
+ texture?: {
554
+ copy(texture: VFXTexture): VFXTexture;
555
+ patch(billboard: string, texture: VFXTexture): string;
556
+ create(device: GPUDevice, texture: VFXTexture, owned: OwnedResources): GPUBindGroupEntry[];
557
+ };
558
+ soft?: {
559
+ patch(billboard: string, samples: number): string;
560
+ create(device: GPUDevice, owned: OwnedResources): {
561
+ /** Bind group entries (uniform at 11, depth at 12) for the depth last given to `write`. */
562
+ entries: GPUBindGroupEntry[];
563
+ /** True when `write` was given a different depth texture than before (bind groups are stale). */
564
+ changed: boolean;
565
+ /** Validates `depth` against the pass, uploads the frame's uniform and returns the depth's sample count. */
566
+ write(c: Context, depth: GPUTexture | undefined, view: ArrayLike<number>, softness: number): number;
567
+ };
568
+ };
569
+ curves?: {
570
+ validate(curves: VFXCurves): void;
571
+ patch(billboard: string, curves: VFXCurves): string;
572
+ create(device: GPUDevice, owned: OwnedResources): {
573
+ entries: GPUBindGroupEntry[];
574
+ write(queue: GPUQueue, curves: VFXCurves): void;
575
+ };
576
+ };
577
+ emitter?: {
578
+ validate(emitter: VFXEmitter, mesh?: boolean): void;
579
+ patch(simulation: string, emitter: VFXEmitter): string;
580
+ create(device: GPUDevice, emitter: VFXEmitter, owned: OwnedResources): {
581
+ entries: GPUBindGroupEntry[];
582
+ write(queue: GPUQueue, emitter: VFXEmitter): void;
583
+ };
584
+ };
585
+ ribbons?: VFXExtension<VFXRibbons>;
586
+ mesh?: VFXExtension<VFXMeshParticles>;
587
+ events?: VFXExtension<VFXEvents>;
588
+ lit?: VFXExtension<VFXLit>;
589
+ depthCollide?: VFXExtension<VFXDepthCollide>;
590
+ stretch?: VFXExtension<VFXStretch>;
591
+ fields?: VFXExtension<VFXFields>;
592
+ skinned?: VFXExtension<VFXSkinned>;
593
+ flipbook?: VFXExtension<VFXFlipbook>;
594
+ shadows?: VFXExtension<VFXShadows>;
595
+ nodes?: VFXExtension<VFXNodes>;
596
+ space?: VFXExtension<import('./space.js').VFXSpace>;
597
+ overLife?: VFXExtension<import('./over-life.js').VFXOverLife>;
598
+ schedule?: VFXExtension<import('./schedule.js').VFXSchedule>;
599
+ }
600
+ /**
601
+ * GPU particles built from the features given: `new VFX(options, {sort})`. `VFX` from `@margoengine/vfx` has every feature.
602
+ * @throws RangeError when an option is out of range or the capacity exceeds device limits; TypeError when an option
603
+ * needs a feature that was not given.
604
+ * @throws MargoError `'unsupported'` on a WebGL engine, `'disposed'` after `dispose()`, `'state'` from `gpuState`
605
+ * before attachment.
606
+ */
607
+ export declare class VFX implements EnginePlugin {
608
+ readonly options: VFXOptions;
609
+ private readonly features;
610
+ private readonly attachment;
611
+ private readonly depthAttachment;
612
+ private readonly presentation;
613
+ private renderFormat;
614
+ private renderDepth;
615
+ private renderKey;
616
+ readonly name: string;
617
+ readonly capacity: number;
618
+ private engine?;
619
+ private device?;
620
+ private uniform?;
621
+ private particles?;
622
+ private alive?;
623
+ private indirect?;
624
+ private visible?;
625
+ private respawn?;
626
+ private simulation?;
627
+ private computeGroup?;
628
+ private births?;
629
+ private listing?;
630
+ private renderGroups;
631
+ private renders;
632
+ private billboard;
633
+ private extra?;
634
+ private readonly extraValues;
635
+ private sprite?;
636
+ private spriteEntries;
637
+ private curveRuntime?;
638
+ private emitterRuntime?;
639
+ private emitterShape?;
640
+ private readonly transparency;
641
+ private sorter?;
642
+ private runtimes;
643
+ /** On the WebGL2 layer, once loaded: the simulation as point draws on the GPU and the draw without a read-back (./compat.js). */
644
+ private route?;
645
+ private owned;
646
+ private softRuntime?;
647
+ private fogSource;
648
+ private fogBuffer?;
649
+ private readonly fogData;
650
+ private readonly values;
651
+ private readonly ints;
652
+ private readonly view;
653
+ private seconds;
654
+ private remainder;
655
+ private frames;
656
+ private burstCount;
657
+ /** Ticks of 1/120 s simulated since the start or `reset()`, with a film clock. */
658
+ private done;
659
+ /** Bursts given a place of their own, in the order asked, born before the frame's step. */
660
+ private spawnQueue;
661
+ /** This frame's step, set by `advanceTime` and taken by the simulate pass (once, however many views draw). */
662
+ private readonly tick;
663
+ /** The 0 s step of a simulate pass that has no counted step: a second view of a frame, or a pass with no update. */
664
+ private readonly still;
665
+ private ticked;
666
+ /** A frame update reached the effect once; until then each simulate pass counts its own step from the frame delta. */
667
+ private clocked;
668
+ /** Prewarm steps a runtime asked for in `advanceTime`, simulated before the frame's step. */
669
+ private warm;
670
+ /** Steps taken while the WebGL2 route is still loading, run in order when it resolves (KB-VFX-EMBERCPU1). */
671
+ private held;
672
+ private routeLoading;
673
+ private disposed;
674
+ constructor(options?: VFXOptions, features?: VFXFeatures);
675
+ static attach(instance: EngineKernel, options?: VFXOptions, features?: VFXFeatures): VFX;
676
+ private validate;
677
+ /** The fog the particles are drawn in (see `setFog`), or null. */
678
+ get fog(): FogLike | null;
679
+ /**
680
+ * Fogs the particles: `fog` is `@margoengine/environment`'s `Fog` or any object with its fields, read every frame,
681
+ * with Fog's maths (linear near/far, exp2 density, height falloff). Each pixel of a particle fades toward the fog
682
+ * colour by the fog at its world position (particles blend alpha over the scene, so fog covers them as it covers
683
+ * meshes). `null` (the default) draws exactly as without fog. The first fogged frame compiles a second billboard
684
+ * shader; changing the fog or its `enabled` flag never does.
685
+ * @throws TypeError when `fog` is neither an object nor null; RangeError or TypeError for an invalid field.
686
+ */
687
+ setFog(fog: FogLike | null): this;
688
+ /**
689
+ * Queues `count` births for the next frame, on top of `rate`. With `spawn` they are born at its position, velocity, spread and
690
+ * extent (the options of the effect for what it leaves out), and bursts with their own spawn never share a place: two in one
691
+ * frame are born where each asked.
692
+ * @throws RangeError when `count` is not a whole number from 0 to capacity; MargoError `'disposed'` after `dispose()`.
693
+ */
694
+ burst(count: number, spawn?: BurstSpawn): this;
695
+ /**
696
+ * Back to how the effect began: no particles, its clock at 0 and `initialCount` waiting, so the same frames after it
697
+ * give the same particles, for a seek. Call it between frames.
698
+ * @throws MargoError `'disposed'` after `dispose()`.
699
+ */
700
+ reset(): this;
701
+ /**
702
+ * The clock contract of `@margoengine/cutscene/seek` `resetClocks` (GAP-FILM-RESET): {@link reset}, as a clock. Time,
703
+ * counters, step seeds, queued bursts and particles go back to a fresh effect's, so the same frames after it draw
704
+ * what a fresh effect draws. Does nothing after `dispose()`.
705
+ */
706
+ resetTime(): void;
707
+ /**
708
+ * Sets the wind (see {@link VFXOptions.wind}); undefined or [0, 0] turns the wind force off. Takes effect on the next frame.
709
+ * @throws TypeError, RangeError for a wind that is not [x, z] or a sampler, or is out of range; the old wind stays.
710
+ */
711
+ setWind(wind: VFXWind | undefined): this;
712
+ setup(engine: Engine): void;
713
+ registerPasses(graph: FrameGraph): void;
714
+ /**
715
+ * Seconds on the effect's clock: the sum of its frame deltas since it started or since `reset()`; with a film clock,
716
+ * the time of the last tick simulated, exactly `ticks / 120`.
717
+ */
718
+ get time(): number;
719
+ /**
720
+ * Moves the effect's clock by `delta` seconds: the time, the birth remainder, the step number that seeds births, the
721
+ * queued bursts and the `schedule` cursor, which its frame update runs before the simulate pass draws. With no draw
722
+ * (a seek from `@margoengine/cutscene/seek`, or a hidden view) the counters move and no particle is simulated, so the
723
+ * next drawn frame births what a continuous run births there; the particles alive then come from the scene's prewarm.
724
+ * A `delta` of 0 is the same instant drawn again (a Reflector, Refractor or CubeCamera capture renders the scene with
725
+ * one inside the frame) and counts nothing: a pass drawn after it takes the 0 s step a second view takes
726
+ * (KB-FILM-TAAPHASE1).
727
+ */
728
+ advanceTime(delta: number): void;
729
+ /** The bursts with a place of their own become steps of no time, one each, born before the frame's step. */
730
+ private takeSpawns;
731
+ onPreUpdate(delta: number): void;
732
+ /** One step's counters on the CPU: the same arithmetic for a live frame, a prewarm step and a replayed step. */
733
+ private countStep;
734
+ private simulate;
735
+ /**
736
+ * The ticks a film clock owes since the last drawn frame, counted as steps of 1/120 s at their exact times: all but the
737
+ * last become steps of their own before the frame's, the last is the frame's step. A clock behind the effect (a seek
738
+ * back) restarts it from 0 and replays; a clock with nothing owed (a second view, or frames faster than 120 a second)
739
+ * takes the 0 s step.
740
+ */
741
+ private countTicks;
742
+ private countTick;
743
+ private simulateStep;
744
+ /** The pipeline and group 0 of a draw into the frame, or with `hook` into its pass. */
745
+ private prepare;
746
+ private draw;
747
+ private billboards;
748
+ /**
749
+ * Leaves the frame's draw (order 6) to an order-independent pass, which calls `drawTransparent`. Use `addEffect` from
750
+ * `@margoengine/oit/vfx`. Returns a remover; `released` runs if this effect is disposed first.
751
+ */
752
+ setTransparency(hook: SurfaceTransparency, released?: () => void): () => void;
753
+ /** Draws the particles into `hook`'s pass, depth tested and not written. */
754
+ drawTransparent(c: Context, hook: SurfaceTransparency): void;
755
+ get gpuState(): {
756
+ particles: GPUBuffer;
757
+ indirect: GPUBuffer;
758
+ alive: GPUBuffer;
759
+ visible: GPUBuffer;
760
+ };
761
+ private release;
762
+ onDeviceRestored(engine: Engine): void;
763
+ dispose(): void;
764
+ [Symbol.dispose]: () => void;
765
+ /** @deprecated Use dispose(); kept as an alias until 1.0. */
766
+ destroy(): void;
767
+ }