@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.js ADDED
@@ -0,0 +1 @@
1
+ export { t as VFX, n as VFX_TICK_RATE } from "./base-C9upJytz.js";
@@ -0,0 +1,218 @@
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
+ export type { ColorInput } from '@margoengine/math/color';
6
+ type Vec3 = readonly [number, number, number];
7
+ /** Ground heights on a grid, metres, row by row along x. */
8
+ export interface BlownSandHeights {
9
+ readonly samples: ArrayLike<number>;
10
+ readonly width: number;
11
+ readonly depth: number;
12
+ /** Metres between samples. Default 1. */
13
+ readonly cellSize?: number;
14
+ /** World x and z of the first sample. Default [0, 0]. */
15
+ readonly origin?: readonly [number, number];
16
+ }
17
+ /** The ground: a height function of world (x, z) or a grid of heights. */
18
+ export type BlownSandGround = ((x: number, z: number) => number) | BlownSandHeights;
19
+ /** The wind the sand sees, as `@margoengine/weather`'s `WindOptions` (a `WindField` can be passed as it is). */
20
+ export interface BlownSandWind {
21
+ /** Mean speed at `windHeight` (10 m by default), m/s, 0 to 60. */
22
+ readonly speed: number;
23
+ /** Direction the wind blows toward, radians: 0 is +z, pi/2 is +x. Default 0. */
24
+ readonly direction?: number;
25
+ /** Gustiness 0..1, used when `gustiness` is not set. Default 0.35. */
26
+ readonly gust?: number;
27
+ /** Seconds between gusts, 0.5 to 600. Default 8. */
28
+ readonly gustPeriod?: number;
29
+ }
30
+ /**
31
+ * A sky that lights the scene, as `Sky` from `@margoengine/sky` with `lighting.ambient` or `environment` is: its native
32
+ * PBR hook (WGSL declaring `skyIrradiance(n)` and the sky light map, and their bind group entries).
33
+ */
34
+ export interface BlownSandSkyLight {
35
+ pbr(group: number): {
36
+ readonly declarations: string;
37
+ } | undefined;
38
+ bindings(): GPUBindGroupEntry[];
39
+ }
40
+ /** Local saltation sampled from a resolved bed, such as `AeolianTransport` from `@margoengine/physics/aeolian`. */
41
+ export interface BlownSandTransport {
42
+ /** Changes when the solver updates its field. */
43
+ readonly revision: number;
44
+ /** Horizontal limits in metres, [minX, minZ, maxX, maxZ]. */
45
+ readonly bounds: readonly [number, number, number, number];
46
+ /** Areal moving mass (kg/m²) and horizontal velocity (m/s). */
47
+ sample(x: number, z: number): {
48
+ readonly mass: number;
49
+ readonly velocity: readonly [number, number];
50
+ } | undefined;
51
+ }
52
+ /** Options of {@link BlownSand}. Read every frame when drawing the particles. */
53
+ export interface BlownSandOptions {
54
+ /** The terrain, as a height function or a height grid. Required. */
55
+ ground: BlownSandGround;
56
+ /** Prescribed `{speed, direction, gust, gustPeriod}` or a `WindField`. Required unless `transport` is supplied. */
57
+ wind?: BlownSandWind | {
58
+ readonly options: BlownSandWind;
59
+ };
60
+ /** Live saltation for blowing sand or snow. When set, the renderer uses the solver's mass and velocity. */
61
+ transport?: BlownSandTransport;
62
+ /** Moving mass for half-strength opacity with live transport, kg/m². Default 0.02. */
63
+ referenceMass?: number;
64
+ /** Share of the ground that can lose sand, 0..1 at world (x, z): 0 where it is wet, grassed or paved. Default all 1. */
65
+ mask?: ((x: number, z: number) => number) | null;
66
+ /** Density of the blowing sand, 0 (none) to 1. Default 1. */
67
+ amount?: number;
68
+ /** Wind speed at `windHeight` at which dry sand starts to move, m/s. Default {@link sandThreshold} of `grainSize` (6.6 m/s for 0.25 mm sand). */
69
+ threshold?: number;
70
+ /** Grain diameter for the default threshold, metres, 0.00006 to 0.002. Default 0.00025 (medium sand). */
71
+ grainSize?: number;
72
+ /** Height the wind speed is given at, metres, 0.5 to 100. Default 10 (the standard anemometer height). */
73
+ windHeight?: number;
74
+ /** Grain colour (albedo): hex is sRGB, an [r, g, b] array linear. Default [0.5, 0.42, 0.29], terrain's dry sand. */
75
+ color?: ColorInput;
76
+ /** Length of a streak of moving sand, metres, 0.05 to 5. Default 0.6. */
77
+ streak?: number;
78
+ /** Height under which most moving sand travels, metres, 0.02 to 3. Default 0.3; crest plumes rise to about 4 times it. */
79
+ height?: number;
80
+ /** Opacity, 0..1. Default 0.6. */
81
+ opacity?: number;
82
+ /** How far gusts swing the wind, 0..1. Default the wind's `gust`, else 0.35. */
83
+ gustiness?: number;
84
+ /** Seed: the same seed and time draw the same sand. Default 1. */
85
+ seed?: number;
86
+ /** Most particles drawn, 1 to 1,048,576. Default 32,768. */
87
+ limit?: number;
88
+ /** Radius around the camera with blowing sand, metres, 10 to 2,000. Default 250. */
89
+ range?: number;
90
+ /** Exponential fog density the sand fades by with distance, per metre, 0 to 1. Default 0. */
91
+ fog?: number;
92
+ /** World units over which the sand fades in front of the surface behind it (needs `depth`); 0 is off. Default 0. */
93
+ softness?: number;
94
+ /** The scene depth for `softness`: `() => depthTexture.texture` with `DepthTexture` from `@margoengine/post/depth`. */
95
+ depth?: () => GPUTexture | undefined;
96
+ /**
97
+ * The sky that lights the scene (a `Sky` with `lighting.ambient` or `environment`): the grains take its diffuse light
98
+ * (the mean of its irradiance over all directions) and, through their forward diffraction, the sky behind them, as
99
+ * the ground does. Default none: the engine's ambient term (`lighting.radiance[3]` times `lighting.ambient`).
100
+ */
101
+ sky?: BlownSandSkyLight | null;
102
+ }
103
+ /** One setting of {@link BLOWN_SAND_SETTINGS}: its default, range or values, unit and meaning. */
104
+ export interface BlownSandSetting {
105
+ readonly default: unknown;
106
+ readonly range?: readonly [number, number];
107
+ readonly unit?: string;
108
+ readonly about: string;
109
+ }
110
+ /**
111
+ * Wind speed at `height` metres (default 10) at which dry sand of `grainSize` metres (default 0.25 mm) starts to move:
112
+ * Bagnold's fluid threshold u*t = 0.1 sqrt(((rho_s - rho_a) / rho_a) g d) carried up the logarithmic profile
113
+ * u(z) = (u*t / 0.4) ln(z / z0), over a rippled bed of roughness `roughness` (default 0.1 mm).
114
+ */
115
+ export declare function sandThreshold(grainSize?: number, height?: number, roughness?: number): number;
116
+ /** The settings of {@link BlownSand}, as data: default, range, unit and meaning of each (for tools and scene settings). */
117
+ export declare const BLOWN_SAND_SETTINGS: Readonly<Record<string, BlownSandSetting>>;
118
+ /** Owen's flux law over the threshold, saturating: 1 - exp(-1.5 (r^3 - r) / 6), r = u* / u*t; 0 at or below r = 1. */
119
+ export declare function sandFlux(ratio: number): number;
120
+ /** One particle as the shader draws it: centre, axis, half length and width, opacity. */
121
+ export interface BlownSandGrain {
122
+ position: [number, number, number];
123
+ /** 0 a streak of saltating sand, 1 spindrift off a crest, 2 a haze sheet. */
124
+ kind: number;
125
+ /** Half length along the wind and half width (metres), before the pixel floor. */
126
+ size: [number, number];
127
+ /** Opacity before the view terms (pixel floor, fog, range fade and soft depth); 0 when no sand moves there. */
128
+ alpha: number;
129
+ }
130
+ /**
131
+ * How much sand the mean wind moves at world (x, z), with no engine: `speedUp` is the shear velocity over that of
132
+ * flat open ground (crests above 1, troughs below, 0 on a slip face, in its lee and where `mask` is 0), `flux` the
133
+ * saturating flux 0..1 of {@link sandFlux} for the mean wind, and `brink` whether spindrift blows off there. The same
134
+ * rule {@link BlownSand} emits by.
135
+ */
136
+ export declare function sandEmission(options: Pick<BlownSandOptions, 'ground' | 'wind' | 'mask' | 'threshold' | 'grainSize' | 'windHeight'>, x: number, z: number): {
137
+ speedUp: number;
138
+ flux: number;
139
+ brink: boolean;
140
+ };
141
+ /**
142
+ * Wind-blown sand over a terrain: streaks of saltating sand drifting low over the ground in streamers, spindrift
143
+ * blowing off dune brinks out over their slip faces, and the haze sheet of moving sand near the ground, wherever the
144
+ * wind (with its gusts and the speed-up over crests and windward slopes) is above the threshold of motion. Particles
145
+ * live in 8 m tiles around the camera, each a pure function of its tile, the seed and the clock, so the same seed and
146
+ * time draw the same sand from any camera path. One instanced draw at frame-graph order 6. WebGPU and the WebGL2
147
+ * compatibility layer.
148
+ */
149
+ export declare class BlownSand implements EnginePlugin {
150
+ readonly name: string;
151
+ /** Read every frame. */
152
+ readonly options: BlownSandOptions;
153
+ /** Counts of the last drawn frame: tiles and particles drawn, particles past `limit`. */
154
+ readonly stats: {
155
+ tiles: number;
156
+ particles: number;
157
+ dropped: number;
158
+ };
159
+ private seconds;
160
+ private engine?;
161
+ private instances?;
162
+ private capacity;
163
+ private uniform?;
164
+ private owned;
165
+ private softRuntime?;
166
+ private readonly pipelines;
167
+ private readonly groups;
168
+ private readonly values;
169
+ private readonly view;
170
+ private data;
171
+ private count;
172
+ private uploaded;
173
+ private layoutKey;
174
+ private readonly tiles;
175
+ private height;
176
+ private groundSource;
177
+ private maskSource;
178
+ private transportSource?;
179
+ private disposed;
180
+ private skyEntries?;
181
+ private skyPipeline?;
182
+ private skyGroup?;
183
+ private readonly attachment;
184
+ private readonly depthAttachment;
185
+ constructor(options: BlownSandOptions);
186
+ /** Same as `engine.use(new BlownSand(options))`; returns it. */
187
+ static attach(engine: EngineKernel, options: BlownSandOptions): BlownSand;
188
+ /** Seconds on the sand's clock: the sum of frame deltas and `advanceTime` calls. Set it to seek a shot. */
189
+ get time(): number;
190
+ set time(seconds: number);
191
+ /** Moves the clock by `delta` seconds; the same deltas give the same sand. */
192
+ advanceTime(delta: number): void;
193
+ onPreUpdate(delta: number): void;
194
+ /** Back to time 0, as a fresh one with the same options, for several cuts in one process (GAP-FILM-RESET): the sand at the start. */
195
+ resetTime(): void;
196
+ private validate;
197
+ private frameValues;
198
+ /** Particles of tile (tx, tz) at detail level `level` (2^-level of the templates), built once and cached. */
199
+ private tile;
200
+ /**
201
+ * Lays out the particles around `eye` (culled by `planes` when given) in `this.data`, nearest tiles first up to the
202
+ * limit, then far to near for the blend; returns a key of the layout.
203
+ */
204
+ private collect;
205
+ /**
206
+ * Every particle around world point `eye` at the current time, as the GPU draws it (no view culling, no pixel
207
+ * floor): the CPU twin of the vertex shader, for tests and tools. Particles where no sand moves have alpha 0.
208
+ */
209
+ grains(eye: Vec3): BlownSandGrain[];
210
+ setup(engine: Engine): void;
211
+ registerPasses(graph: FrameGraph): void;
212
+ private draw;
213
+ private release;
214
+ onDeviceRestored(engine: Engine): void;
215
+ /** Releases the GPU objects and leaves the engine. */
216
+ dispose(): void;
217
+ [Symbol.dispose]: () => void;
218
+ }