@margoengine/vfx 0.0.0-stage → 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 +201 -0
- package/NOTICE +4 -0
- package/README.md +2240 -2
- package/dist/base-LGs65K7K.js +709 -0
- package/dist/base.d.ts +869 -0
- package/dist/base.js +1 -0
- package/dist/blown-sand.d.ts +218 -0
- package/dist/blown-sand.js +700 -0
- package/dist/clouds.d.ts +237 -0
- package/dist/clouds.js +583 -0
- package/dist/compat-BFjXAQuu.js +14 -0
- package/dist/compat-CVSEj1Bp.js +217 -0
- package/dist/compat.d.ts +59 -0
- package/dist/curves.d.ts +11 -0
- package/dist/curves.js +59 -0
- package/dist/debris.d.ts +154 -0
- package/dist/debris.js +290 -0
- package/dist/depth-collide.d.ts +7 -0
- package/dist/depth-collide.js +96 -0
- package/dist/dust-current.d.ts +66 -0
- package/dist/dust-current.js +92 -0
- package/dist/emitter.d.ts +10 -0
- package/dist/emitter.js +125 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +131 -0
- package/dist/extra-CgGjbojB.js +4 -0
- package/dist/extra.d.ts +2 -0
- package/dist/fields.d.ts +11 -0
- package/dist/fields.js +95 -0
- package/dist/fire-front.d.ts +610 -0
- package/dist/fire-front.js +1080 -0
- package/dist/fire.d.ts +140 -0
- package/dist/fire.js +194 -0
- package/dist/flame-ramp-VoBKpYnM.js +75 -0
- package/dist/flame-ramp.d.ts +61 -0
- package/dist/flame.d.ts +428 -0
- package/dist/flame.js +817 -0
- package/dist/flipbook.d.ts +7 -0
- package/dist/flipbook.js +23 -0
- package/dist/flocking-shaders.d.ts +48 -0
- package/dist/flocking-sim.d.ts +623 -0
- package/dist/flocking.d.ts +145 -0
- package/dist/flocking.js +1846 -0
- package/dist/fog-B-kBv7g0.js +32 -0
- package/dist/frame-BuvMFBPp.js +4 -0
- package/dist/frame.d.ts +7 -0
- package/dist/gunfire.d.ts +742 -0
- package/dist/gunfire.js +1214 -0
- package/dist/hash-Btsp6fGK.js +7 -0
- package/dist/hash.d.ts +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +60 -0
- package/dist/json.d.ts +53 -0
- package/dist/json.js +239 -0
- package/dist/lit-Dx2tNwP-.js +152 -0
- package/dist/lit.d.ts +18 -0
- package/dist/lit.js +1 -0
- package/dist/mesh.d.ts +16 -0
- package/dist/mesh.js +248 -0
- package/dist/node-system.d.ts +315 -0
- package/dist/node-system.js +384 -0
- package/dist/nodes.d.ts +14 -0
- package/dist/nodes.js +293 -0
- package/dist/obstacles.d.ts +3 -0
- package/dist/obstacles.js +25 -0
- package/dist/over-life.d.ts +14 -0
- package/dist/over-life.js +94 -0
- package/dist/reactive-mask-B8xbyzlk.js +69 -0
- package/dist/require-webgpu--tUXPsmA.js +7 -0
- package/dist/ribbons.d.ts +22 -0
- package/dist/ribbons.js +165 -0
- package/dist/schedule.d.ts +29 -0
- package/dist/schedule.js +47 -0
- package/dist/settings.d.ts +362 -0
- package/dist/settings.js +707 -0
- package/dist/shader.d.ts +49 -0
- package/dist/shadows.d.ts +26 -0
- package/dist/shadows.js +182 -0
- package/dist/shapes.d.ts +34 -0
- package/dist/shapes.js +81 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/shared/settings.d.ts +89 -0
- package/dist/skinned.d.ts +11 -0
- package/dist/skinned.js +104 -0
- package/dist/smoke.d.ts +283 -0
- package/dist/smoke.js +504 -0
- package/dist/soft.d.ts +17 -0
- package/dist/soft.js +55 -0
- package/dist/solid.d.ts +168 -0
- package/dist/solid.js +403 -0
- package/dist/sort.d.ts +3 -0
- package/dist/sort.js +58 -0
- package/dist/space.d.ts +14 -0
- package/dist/space.js +88 -0
- package/dist/stretch.d.ts +7 -0
- package/dist/stretch.js +40 -0
- package/dist/texture.d.ts +8 -0
- package/dist/texture.js +45 -0
- package/dist/view-RKprOPAy.js +30 -0
- package/dist/view-rect-DkeiiUtw.js +13 -0
- package/dist/wrap.d.ts +3 -0
- package/dist/wrap.js +5 -0
- package/package.json +198 -4
package/dist/clouds.d.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel } from '@margoengine/core';
|
|
3
|
+
import type { Engine, EnginePlugin, FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
import { type ColorInput } from '@margoengine/math/color';
|
|
5
|
+
import { type FogLike } from './shared/fog.js';
|
|
6
|
+
export type { FogLike } from './shared/fog.js';
|
|
7
|
+
export type { ColorInput } from '@margoengine/math/color';
|
|
8
|
+
type Vec3 = readonly [number, number, number];
|
|
9
|
+
/** RGBA8 texels, row-major from the top left, sRGB. */
|
|
10
|
+
export interface CloudPixels {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
data: Uint8Array | Uint8ClampedArray;
|
|
14
|
+
}
|
|
15
|
+
/** A puff texture: pixels, or an image source drawn into a canvas once (in a browser). */
|
|
16
|
+
export type CloudTexture = CloudPixels | ImageData | ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas;
|
|
17
|
+
/** What `distribute` returns for one puff: its centre in the box (-1..1 on each axis) and its size (0..1). */
|
|
18
|
+
export interface CloudPuffPlacement {
|
|
19
|
+
point: Vec3;
|
|
20
|
+
/** Size as a fraction of `volume`, 0..1. Default 1. */
|
|
21
|
+
volume?: number;
|
|
22
|
+
/** This puff's colour, linear RGB 0 or more, in place of the cloud's `color`. Default: the cloud's colour. */
|
|
23
|
+
color?: Vec3;
|
|
24
|
+
/** Light the puff gives off, linear RGB 0 or more, added after the lighting (a fire inside smoke). Default none. */
|
|
25
|
+
emission?: Vec3;
|
|
26
|
+
}
|
|
27
|
+
/** Options of one cloud (`Clouds.add`). Read every frame: change a field and the next frame shows it. */
|
|
28
|
+
export interface CloudOptions {
|
|
29
|
+
/** Seed of the puff layout: the same seed gives the same cloud. Default: the cloud's number in its Clouds (1, 2, ...). */
|
|
30
|
+
seed?: number;
|
|
31
|
+
/** Number of puffs, an integer 0 or more. Default 20. */
|
|
32
|
+
segments?: number;
|
|
33
|
+
/** Size of the box the puff centres lie in, local units, centred on the cloud. Default [5, 1, 1]. */
|
|
34
|
+
bounds?: Vec3;
|
|
35
|
+
/** 'inside' makes puffs smaller toward the box edges, 'outside' larger, 'random' any size. Default 'inside'. */
|
|
36
|
+
concentrate?: 'inside' | 'outside' | 'random';
|
|
37
|
+
/** Width of a full-size puff, local units, 0 or more. Default 6. */
|
|
38
|
+
volume?: number;
|
|
39
|
+
/** Smallest puff as a fraction of `volume`, 0..1. Default 0.25. */
|
|
40
|
+
smallestVolume?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Places puff `index` itself (overrides `bounds`' layout, `concentrate`, `volume`'s fraction and `smallestVolume`):
|
|
43
|
+
* return its centre in -1..1 box units and its size fraction. `random` is the cloud's seeded stream. Default null.
|
|
44
|
+
*/
|
|
45
|
+
distribute?: ((index: number, random: () => number) => CloudPuffPlacement) | null;
|
|
46
|
+
/** With `speed` above 0 each puff breathes by up to 1 / growth of its size. Above 0. Default 4. */
|
|
47
|
+
growth?: number;
|
|
48
|
+
/** Animation rate: puffs turn at up to `speed` radians a second and breathe at `speed` radians of phase a second. Default 0. */
|
|
49
|
+
speed?: number;
|
|
50
|
+
/** Camera distance (world units) under which a puff fades out, to nothing at the camera; 0 turns it off. Default 10. */
|
|
51
|
+
fade?: number;
|
|
52
|
+
/** Opacity, 0..1. Default 1. */
|
|
53
|
+
opacity?: number;
|
|
54
|
+
/** Colour: hex is sRGB, an [r, g, b] array linear. Default white. */
|
|
55
|
+
color?: ColorInput;
|
|
56
|
+
}
|
|
57
|
+
/** Options of {@link Clouds}. Read every frame except `limit`, which sizes the instance buffer when it changes. */
|
|
58
|
+
export interface CloudsOptions {
|
|
59
|
+
/** Most puffs drawn, over all clouds (later puffs are left out and counted in `stats.dropped`). Integer 1 or more. Default 200. */
|
|
60
|
+
limit?: number;
|
|
61
|
+
/** Draw only the first `range` puffs, in the order clouds were added. Default: all. */
|
|
62
|
+
range?: number;
|
|
63
|
+
/** Puff texture; its alpha is the puff's coverage. Default: a generated soft, lumpy puff. */
|
|
64
|
+
texture?: CloudTexture | null;
|
|
65
|
+
/** Leave out puffs wholly outside the view. Default true. */
|
|
66
|
+
frustumCulled?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 'scatter' (default) lights each puff by the light that reaches it through the other puffs of its cloud and the
|
|
69
|
+
* phase toward the eye, plus `ambient`; 'unlit' draws the colour as it is.
|
|
70
|
+
*/
|
|
71
|
+
shading?: 'scatter' | 'unlit';
|
|
72
|
+
/** Direction toward the light, world space, not zero. Default [0.4, 1, 0.3]. */
|
|
73
|
+
lightDirection?: Vec3;
|
|
74
|
+
/** Light colour, linear RGB or sRGB hex. Default white. */
|
|
75
|
+
lightColor?: ColorInput;
|
|
76
|
+
/** Light every puff gets whatever is in front of it, 0 or more. Default 0.55. */
|
|
77
|
+
ambient?: number;
|
|
78
|
+
/** Optical depth through the centre of a full-size puff, for the light reaching the puffs behind it, 0 or more. Default 1. */
|
|
79
|
+
density?: number;
|
|
80
|
+
/**
|
|
81
|
+
* 0..1: shades each puff of 'scatter' as a lit surface instead of a flat disc, so a heap of puffs reads as rounded
|
|
82
|
+
* lobes with lit tops and dark undersides: the direct light by the half-Lambert of the normal, and the ambient by the
|
|
83
|
+
* sky the normal faces times the sky light left after the puffs above it. The normal is the heap's own (the gradient
|
|
84
|
+
* of its puffs' density, {@link CloudPuff.normal}) with the puff's sphere as a lobe on it, so a column of many puffs
|
|
85
|
+
* shades as one rounded body, not a stack of balls; a puff alone is its sphere. Above 0 the light through the cloud
|
|
86
|
+
* also counts multiple scattering (three octaves, Wrenninge et al. 2013). 0 keeps flat puffs. Default 0.
|
|
87
|
+
*/
|
|
88
|
+
relief?: number;
|
|
89
|
+
/** World units over which a puff fades out in front of the surface behind it (needs `depth`); 0 is off. Default 0. */
|
|
90
|
+
softness?: number;
|
|
91
|
+
/**
|
|
92
|
+
* The scene depth for `softness`: a function returning a sampleable reversed-Z depth texture the size of the drawing
|
|
93
|
+
* buffer, e.g. `() => depthTexture.texture` with `DepthTexture` from `@margoengine/post/depth`.
|
|
94
|
+
*/
|
|
95
|
+
depth?: () => GPUTexture | undefined;
|
|
96
|
+
}
|
|
97
|
+
/** One puff as drawn this frame (world space), from {@link Clouds.puffs}. */
|
|
98
|
+
export interface CloudPuff {
|
|
99
|
+
cloud: Cloud;
|
|
100
|
+
centre: [number, number, number];
|
|
101
|
+
/** Quad width, world units. */
|
|
102
|
+
size: number;
|
|
103
|
+
/** Screen-plane rotation, radians. */
|
|
104
|
+
angle: number;
|
|
105
|
+
/** Share of the light that reaches the puff, 0..1. */
|
|
106
|
+
light: number;
|
|
107
|
+
/** Share of the sky light from straight above that reaches the puff, 0..1 (1 unless `relief` is above 0). */
|
|
108
|
+
sky: number;
|
|
109
|
+
/**
|
|
110
|
+
* With `relief`, the heap's outward normal at the puff, unnormalised: minus the gradient of the other puffs' Gaussian
|
|
111
|
+
* density there (Levoy 1988's gradient normal), in units of the puff's radius, so it is about 1 at a heap's surface
|
|
112
|
+
* and near 0 for a puff alone or deep inside. The puff's own sphere adds to it as a lobe. [0, 0, 0] without relief.
|
|
113
|
+
*/
|
|
114
|
+
normal: [number, number, number];
|
|
115
|
+
/** Light the puff gives off, linear RGB. */
|
|
116
|
+
emission: [number, number, number];
|
|
117
|
+
/** Linear RGB and opacity (before the near fade). */
|
|
118
|
+
color: [number, number, number, number];
|
|
119
|
+
/** The cloud's `fade`. */
|
|
120
|
+
fade: number;
|
|
121
|
+
}
|
|
122
|
+
/** Counts of the last drawn frame. */
|
|
123
|
+
export interface CloudsStats {
|
|
124
|
+
/** Puffs of every cloud. */
|
|
125
|
+
puffs: number;
|
|
126
|
+
/** Puffs past `limit` or `range`. */
|
|
127
|
+
dropped: number;
|
|
128
|
+
/** Puffs outside the view. */
|
|
129
|
+
culled: number;
|
|
130
|
+
/** Puffs drawn. */
|
|
131
|
+
drawn: number;
|
|
132
|
+
}
|
|
133
|
+
/** One cloud of a {@link Clouds}: its options and world matrix. */
|
|
134
|
+
export declare class Cloud {
|
|
135
|
+
/** Read every frame. */
|
|
136
|
+
readonly options: CloudOptions;
|
|
137
|
+
/** Column-major world matrix of the cloud (position, rotation and scale). Write it any time. */
|
|
138
|
+
readonly matrix: Float32Array<ArrayBuffer>;
|
|
139
|
+
/** @internal */ layout: Float32Array;
|
|
140
|
+
/** @internal Per puff: colour rgb (NaN: the cloud's) and emission rgb, from `distribute`. */
|
|
141
|
+
tints: Float32Array;
|
|
142
|
+
/** @internal */ key: string;
|
|
143
|
+
/** @internal */ distribute: CloudOptions['distribute'];
|
|
144
|
+
/** @internal */ readonly number: number;
|
|
145
|
+
/** @internal */ owner: Clouds | null;
|
|
146
|
+
/** @internal */
|
|
147
|
+
constructor(owner: Clouds, number: number, options: CloudOptions);
|
|
148
|
+
/** Takes the cloud out of its Clouds. */
|
|
149
|
+
remove(): void;
|
|
150
|
+
/** @internal Checks the options and lays the puffs out again when a layout option changed. */
|
|
151
|
+
update(): void;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The puffs of one cloud in its local space, 6 floats each: centre xyz, size, start angle, phase. Puff centres are
|
|
155
|
+
* uniform in the box; the size fraction follows `concentrate` and never drops under `smallestVolume`.
|
|
156
|
+
*/
|
|
157
|
+
export declare function layoutPuffs(segments: number, bounds: Vec3, concentrate: 'inside' | 'outside' | 'random', volume: number, smallestVolume: number, seed: number, distribute?: CloudOptions['distribute'], tints?: Float32Array): Float32Array;
|
|
158
|
+
/** Transmittance with multiple scattering: sum of 0.5^i exp(-0.25^i depth), i = 0..2, over 1.75. */
|
|
159
|
+
export declare const scattered: (depth: number) => number;
|
|
160
|
+
/** A soft, lumpy puff: a smooth radial falloff times value-noise octaves, white, alpha the coverage. */
|
|
161
|
+
export declare function defaultPuffTexture(size?: number): CloudPixels;
|
|
162
|
+
/**
|
|
163
|
+
* drei's Clouds and Cloud for Margo: puff clouds, every puff of every cloud drawn back to front in one instanced draw
|
|
164
|
+
* (frame-graph order 6, with the other transparent billboards). Puffs are camera-facing quads of a soft texture, laid
|
|
165
|
+
* out by seed in each cloud's box, turned and breathing with `speed`, fading out near the camera, lit by the light that
|
|
166
|
+
* reaches them through the puffs between them and the light, optionally soft against the scene depth and fogged.
|
|
167
|
+
* WebGPU and the WebGL2 compatibility layer.
|
|
168
|
+
*/
|
|
169
|
+
export declare class Clouds implements EnginePlugin {
|
|
170
|
+
readonly name: string;
|
|
171
|
+
/** Read every frame (`limit` reallocates when it changes). */
|
|
172
|
+
readonly options: CloudsOptions;
|
|
173
|
+
/** Counts of the last drawn frame. */
|
|
174
|
+
readonly stats: CloudsStats;
|
|
175
|
+
private readonly list;
|
|
176
|
+
private added;
|
|
177
|
+
private seconds;
|
|
178
|
+
private engine?;
|
|
179
|
+
private instances?;
|
|
180
|
+
private capacity;
|
|
181
|
+
private uniform?;
|
|
182
|
+
private fogBuffer?;
|
|
183
|
+
private texture?;
|
|
184
|
+
private textureSource;
|
|
185
|
+
private sampler?;
|
|
186
|
+
private owned;
|
|
187
|
+
private softRuntime?;
|
|
188
|
+
private readonly pipelines;
|
|
189
|
+
private readonly groups;
|
|
190
|
+
private fogSource;
|
|
191
|
+
private readonly fogData;
|
|
192
|
+
private readonly values;
|
|
193
|
+
private readonly view;
|
|
194
|
+
private data;
|
|
195
|
+
private disposed;
|
|
196
|
+
private readonly attachment;
|
|
197
|
+
private readonly depthAttachment;
|
|
198
|
+
constructor(options?: CloudsOptions);
|
|
199
|
+
/** Same as `engine.use(new Clouds(options))`; returns it. */
|
|
200
|
+
static attach(engine: EngineKernel, options?: CloudsOptions): Clouds;
|
|
201
|
+
/** The clouds, in the order they were added. */
|
|
202
|
+
get clouds(): readonly Cloud[];
|
|
203
|
+
/** Seconds on the clouds' clock: the sum of frame deltas (and `advanceTime` calls). */
|
|
204
|
+
get time(): number;
|
|
205
|
+
/** Adds a cloud and returns it; its options are read every frame. */
|
|
206
|
+
add(options?: CloudOptions): Cloud;
|
|
207
|
+
/** Takes `cloud` out; returns false when it is not one of these. */
|
|
208
|
+
remove(cloud: Cloud): boolean;
|
|
209
|
+
/** Moves the clock by `delta` seconds; the same deltas give the same animation. */
|
|
210
|
+
advanceTime(delta: number): void;
|
|
211
|
+
onPreUpdate(delta: number): void;
|
|
212
|
+
/** Back to time 0, as a fresh one with the same options, for several cuts in one process (GAP-FILM-RESET): the clouds (they stay, with their options) at the start. */
|
|
213
|
+
resetTime(): void;
|
|
214
|
+
/** The fog the puffs are drawn in (see `setFog`), or null. */
|
|
215
|
+
get fog(): FogLike | null;
|
|
216
|
+
/** Fogs the puffs with `@margoengine/environment`'s `Fog` (or any object with its fields), read every frame; null for none. */
|
|
217
|
+
setFog(fog: FogLike | null): this;
|
|
218
|
+
private validate;
|
|
219
|
+
/**
|
|
220
|
+
* Every puff at the current time, world space, in the order the clouds were added (before `range`, `limit` and
|
|
221
|
+
* culling). The light term is computed for each cloud along `lightDirection` (Harris 2002, equation 4: the light
|
|
222
|
+
* reaching a puff is the product of the transmittances of the puffs nearer the light, each weighted by how far the
|
|
223
|
+
* puff lies off that puff's light ray).
|
|
224
|
+
*/
|
|
225
|
+
puffs(): CloudPuff[];
|
|
226
|
+
setup(engine: Engine): void;
|
|
227
|
+
registerPasses(graph: FrameGraph): void;
|
|
228
|
+
/** Lays the frame's puffs out in `data`, culled and sorted far to near; returns how many. */
|
|
229
|
+
private collect;
|
|
230
|
+
private textureFor;
|
|
231
|
+
private draw;
|
|
232
|
+
private release;
|
|
233
|
+
onDeviceRestored(engine: Engine): void;
|
|
234
|
+
/** Releases the GPU objects and leaves the engine. */
|
|
235
|
+
dispose(): void;
|
|
236
|
+
[Symbol.dispose]: () => void;
|
|
237
|
+
}
|