@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.
Files changed (104) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2240 -2
  4. package/dist/base-LGs65K7K.js +709 -0
  5. package/dist/base.d.ts +869 -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 +237 -0
  10. package/dist/clouds.js +583 -0
  11. package/dist/compat-BFjXAQuu.js +14 -0
  12. package/dist/compat-CVSEj1Bp.js +217 -0
  13. package/dist/compat.d.ts +59 -0
  14. package/dist/curves.d.ts +11 -0
  15. package/dist/curves.js +59 -0
  16. package/dist/debris.d.ts +154 -0
  17. package/dist/debris.js +290 -0
  18. package/dist/depth-collide.d.ts +7 -0
  19. package/dist/depth-collide.js +96 -0
  20. package/dist/dust-current.d.ts +66 -0
  21. package/dist/dust-current.js +92 -0
  22. package/dist/emitter.d.ts +10 -0
  23. package/dist/emitter.js +125 -0
  24. package/dist/events.d.ts +9 -0
  25. package/dist/events.js +131 -0
  26. package/dist/extra-CgGjbojB.js +4 -0
  27. package/dist/extra.d.ts +2 -0
  28. package/dist/fields.d.ts +11 -0
  29. package/dist/fields.js +95 -0
  30. package/dist/fire-front.d.ts +610 -0
  31. package/dist/fire-front.js +1080 -0
  32. package/dist/fire.d.ts +140 -0
  33. package/dist/fire.js +194 -0
  34. package/dist/flame-ramp-VoBKpYnM.js +75 -0
  35. package/dist/flame-ramp.d.ts +61 -0
  36. package/dist/flame.d.ts +428 -0
  37. package/dist/flame.js +817 -0
  38. package/dist/flipbook.d.ts +7 -0
  39. package/dist/flipbook.js +23 -0
  40. package/dist/flocking-shaders.d.ts +48 -0
  41. package/dist/flocking-sim.d.ts +623 -0
  42. package/dist/flocking.d.ts +145 -0
  43. package/dist/flocking.js +1846 -0
  44. package/dist/fog-B-kBv7g0.js +32 -0
  45. package/dist/frame-BuvMFBPp.js +4 -0
  46. package/dist/frame.d.ts +7 -0
  47. package/dist/gunfire.d.ts +742 -0
  48. package/dist/gunfire.js +1214 -0
  49. package/dist/hash-Btsp6fGK.js +7 -0
  50. package/dist/hash.d.ts +2 -0
  51. package/dist/index.d.ts +17 -0
  52. package/dist/index.js +60 -0
  53. package/dist/json.d.ts +53 -0
  54. package/dist/json.js +239 -0
  55. package/dist/lit-Dx2tNwP-.js +152 -0
  56. package/dist/lit.d.ts +18 -0
  57. package/dist/lit.js +1 -0
  58. package/dist/mesh.d.ts +16 -0
  59. package/dist/mesh.js +248 -0
  60. package/dist/node-system.d.ts +315 -0
  61. package/dist/node-system.js +384 -0
  62. package/dist/nodes.d.ts +14 -0
  63. package/dist/nodes.js +293 -0
  64. package/dist/obstacles.d.ts +3 -0
  65. package/dist/obstacles.js +25 -0
  66. package/dist/over-life.d.ts +14 -0
  67. package/dist/over-life.js +94 -0
  68. package/dist/reactive-mask-B8xbyzlk.js +69 -0
  69. package/dist/require-webgpu--tUXPsmA.js +7 -0
  70. package/dist/ribbons.d.ts +22 -0
  71. package/dist/ribbons.js +165 -0
  72. package/dist/schedule.d.ts +29 -0
  73. package/dist/schedule.js +47 -0
  74. package/dist/settings.d.ts +362 -0
  75. package/dist/settings.js +707 -0
  76. package/dist/shader.d.ts +49 -0
  77. package/dist/shadows.d.ts +26 -0
  78. package/dist/shadows.js +182 -0
  79. package/dist/shapes.d.ts +34 -0
  80. package/dist/shapes.js +81 -0
  81. package/dist/shared/fog.d.ts +33 -0
  82. package/dist/shared/pass.d.ts +53 -0
  83. package/dist/shared/settings.d.ts +89 -0
  84. package/dist/skinned.d.ts +11 -0
  85. package/dist/skinned.js +104 -0
  86. package/dist/smoke.d.ts +283 -0
  87. package/dist/smoke.js +504 -0
  88. package/dist/soft.d.ts +17 -0
  89. package/dist/soft.js +55 -0
  90. package/dist/solid.d.ts +168 -0
  91. package/dist/solid.js +403 -0
  92. package/dist/sort.d.ts +3 -0
  93. package/dist/sort.js +58 -0
  94. package/dist/space.d.ts +14 -0
  95. package/dist/space.js +88 -0
  96. package/dist/stretch.d.ts +7 -0
  97. package/dist/stretch.js +40 -0
  98. package/dist/texture.d.ts +8 -0
  99. package/dist/texture.js +45 -0
  100. package/dist/view-RKprOPAy.js +30 -0
  101. package/dist/view-rect-DkeiiUtw.js +13 -0
  102. package/dist/wrap.d.ts +3 -0
  103. package/dist/wrap.js +5 -0
  104. package/package.json +198 -4
package/dist/smoke.js ADDED
@@ -0,0 +1,504 @@
1
+ // @margo/core-built 1.0.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const e=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
5
+ import { finiteVector as t } from "@margoengine/math/validate";
6
+ import { VFX as n } from "@margoengine/vfx/base";
7
+ import { curves as r } from "@margoengine/vfx/curves";
8
+ import { soft as i } from "@margoengine/vfx/soft";
9
+ import { overLife as a } from "@margoengine/vfx/over-life";
10
+ import { schedule as o } from "@margoengine/vfx/schedule";
11
+ import { lit as s } from "@margoengine/vfx/lit";
12
+ import { nodes as c } from "@margoengine/vfx/nodes";
13
+ import { obstacles as l } from "@margoengine/vfx/obstacles";
14
+ import { textureFeature as u } from "@margoengine/vfx/texture";
15
+ //#region src/smoke.ts
16
+ var d = 4, f = .093, p = .5, m = 1.6, h = 5, g = 2.9, _ = 9.81, v = 1.225, y = 1005, b = 1e5, x = .35, S = .5, C = 32, w = 1, T = .3;
17
+ function E(e) {
18
+ let t = [], n = [
19
+ 1,
20
+ 1,
21
+ 1,
22
+ .85,
23
+ .5,
24
+ 0
25
+ ];
26
+ for (let r = 0; r < C; r++) {
27
+ let i = r / 31, a = i * 5, o = Math.min(4, Math.floor(a)), s = n[o] + (n[o + 1] - n[o]) * (a - o);
28
+ t.push(Math.max(0, Math.min(1, Math.min(1, i * e / 1) * s)));
29
+ }
30
+ return t[0] = Math.max(0, 1 - 1 / (e / 31)), t;
31
+ }
32
+ function D(e, t = 288.15) {
33
+ if (!(e >= 0 && Number.isFinite(e))) throw RangeError("Smoke heat must be a finite number of watts, 0 or more");
34
+ if (!(t > 0 && Number.isFinite(t))) throw RangeError("Smoke airTemperature must be a finite temperature above 0 K");
35
+ return _ * e / (Math.PI * v * y * t);
36
+ }
37
+ function O(e, t = 288.15) {
38
+ if (!Number.isFinite(e) || e < 0) throw RangeError("Smoke lapse must be a finite rise of 0 or more kelvin a metre");
39
+ return _ / t * e;
40
+ }
41
+ function k(e, t, n, r, i = 0, a) {
42
+ let o = f, s = Math.cbrt(25 * t / (48 * o * o)), c = r / (1.2 * o), l = Math.max(0, e), u = l > 0 ? (4 / 3 * s * l + c ** (4 / 3)) ** .75 : c, d = u - c, h = s / Math.cbrt(u), _ = a ?? {
43
+ rise: 0,
44
+ speed: 0,
45
+ radius: 0,
46
+ bent: !1,
47
+ level: !1
48
+ };
49
+ if (_.rise = d, _.speed = h, _.radius = 1.2 * o * u, _.bent = !1, _.level = !1, n > 1e-6) {
50
+ let e = m * Math.cbrt(t / n), i = r / p, a = (i / e) ** 1.5, o = e * (l + a) ** (2 / 3) - i, s = 2 / 3 * e / Math.cbrt(l + a);
51
+ (l > 0 ? o < d : s < h) && (_.rise = o, _.speed = s, _.radius = p * (o + i), _.bent = !0);
52
+ }
53
+ if (i > 0) {
54
+ let e = n > 1e-6 ? Math.min(g * Math.cbrt(t / (n * i)), 5 * t ** .25 * i ** -.375) : 5 * t ** .25 * i ** -.375;
55
+ _.rise >= e && (_.rise = e, _.speed = 0, _.level = !0);
56
+ }
57
+ return _;
58
+ }
59
+ function A(e, t, n = t) {
60
+ if (!(e >= 0 && Number.isFinite(e))) throw RangeError("Smoke heat must be a finite number of watts, 0 or more");
61
+ if (!(t > 0 && Number.isFinite(t))) throw RangeError("Smoke ceiling height must be a finite number of metres above 0");
62
+ if (!(n >= 0 && Number.isFinite(n))) throw RangeError("Smoke ceiling distance must be a finite number of metres, 0 or more");
63
+ let r = e / 1e3;
64
+ return n <= .15 * t ? .96 * Math.cbrt(r / t) : .195 * Math.cbrt(r) * Math.sqrt(t) / n ** (5 / 6);
65
+ }
66
+ function j(e, t, n) {
67
+ let r = 1.2 * f, i = Math.max(0, (e - t) / 1.1116);
68
+ return {
69
+ rise: i,
70
+ radius: Math.min(n, t + r * i)
71
+ };
72
+ }
73
+ var M = () => ({
74
+ kind: "box",
75
+ center: [
76
+ 0,
77
+ 0,
78
+ 0
79
+ ],
80
+ halfSize: [
81
+ b,
82
+ b,
83
+ b
84
+ ]
85
+ }), N = (e) => [
86
+ {
87
+ op: "attribute",
88
+ value: "position"
89
+ },
90
+ {
91
+ op: "const",
92
+ value: e.from
93
+ },
94
+ {
95
+ op: "add",
96
+ inputs: [4, 5]
97
+ },
98
+ {
99
+ op: "attribute",
100
+ value: "age"
101
+ },
102
+ e.arrive,
103
+ {
104
+ op: "add",
105
+ inputs: [7, 8]
106
+ },
107
+ {
108
+ op: "const",
109
+ value: 1 / S
110
+ },
111
+ {
112
+ op: "mul",
113
+ inputs: [9, 10]
114
+ },
115
+ {
116
+ op: "const",
117
+ value: 0
118
+ },
119
+ {
120
+ op: "max",
121
+ inputs: [11, 12]
122
+ },
123
+ {
124
+ op: "const",
125
+ value: 1
126
+ },
127
+ {
128
+ op: "min",
129
+ inputs: [13, 14]
130
+ },
131
+ {
132
+ op: "const",
133
+ value: e.spread
134
+ },
135
+ {
136
+ op: "mul",
137
+ inputs: [6, 16]
138
+ },
139
+ {
140
+ op: "normalize",
141
+ inputs: [17]
142
+ },
143
+ {
144
+ op: "const",
145
+ value: e.push
146
+ },
147
+ {
148
+ op: "mul",
149
+ inputs: [18, 19]
150
+ },
151
+ {
152
+ op: "const",
153
+ value: [
154
+ 0,
155
+ -4,
156
+ 0
157
+ ]
158
+ },
159
+ {
160
+ op: "mul",
161
+ inputs: [0, 21]
162
+ },
163
+ {
164
+ op: "add",
165
+ inputs: [20, 22]
166
+ },
167
+ {
168
+ op: "const",
169
+ value: [
170
+ 0,
171
+ -4,
172
+ 0
173
+ ]
174
+ },
175
+ {
176
+ op: "mul",
177
+ inputs: [6, 24]
178
+ },
179
+ {
180
+ op: "add",
181
+ inputs: [23, 25]
182
+ },
183
+ {
184
+ op: "mul",
185
+ inputs: [26, 15]
186
+ },
187
+ {
188
+ op: "force",
189
+ inputs: [27]
190
+ }
191
+ ], P = (e) => e?.particles.flames?.options ?? e?.flame?.options, F = (e, t, n) => {
192
+ if (!e) return 0;
193
+ if (typeof e == "object" && "sample" in e) {
194
+ let r = e.sample(t[0], t[1], t[2], n);
195
+ return Math.hypot(r[0], r[2]);
196
+ }
197
+ let r = e;
198
+ return Math.hypot(r[0], r[1]);
199
+ }, I = (e, t, n, r, i = !1) => {
200
+ if (!(Number.isFinite(e) && (i ? e > n : e >= n) && e <= r)) throw RangeError(`Smoke ${t} is ${e}; pass a finite number ${i ? "above" : "from"} ${n} ${i ? "and at most" : "to"} ${r}`);
201
+ return e;
202
+ }, L = 0, R = class p {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
203
+ constructor(e, t) {
204
+ this.name = "vfx-smoke:" + L++, this.disposed = !1, this.clock = 0, this.speed = Array(C).fill(1), this.size = Array(C).fill(1), this.point = {
205
+ rise: 0,
206
+ speed: 0,
207
+ radius: 0,
208
+ bent: !1,
209
+ level: !1
210
+ }, this.key = [
211
+ NaN,
212
+ NaN,
213
+ NaN,
214
+ NaN,
215
+ NaN,
216
+ NaN,
217
+ NaN
218
+ ], this.velocity = [
219
+ 0,
220
+ 0,
221
+ 0
222
+ ], this.extent = [
223
+ 0,
224
+ 0,
225
+ 0
226
+ ], this.rgba = [
227
+ 0,
228
+ 0,
229
+ 0,
230
+ 0
231
+ ], this.at = [
232
+ 0,
233
+ 0,
234
+ 0
235
+ ], this.still = [
236
+ -4,
237
+ 0,
238
+ -4
239
+ ], this.glowAt = [
240
+ 0,
241
+ 0,
242
+ 0
243
+ ];
244
+ let d = t.fire;
245
+ if (d && !d.particles?.flames && !d.flame?.options) throw TypeError("Invalid Smoke fire; pass a Fire from @margoengine/vfx/fire");
246
+ if (this.options = t, t.gallery !== void 0 && t.ceiling === void 0) throw TypeError("Smoke gallery needs a ceiling; pass the roof as ceiling with the walls");
247
+ if (this.roof = t.ceiling === void 0 ? void 0 : {
248
+ box: M(),
249
+ walls: t.gallery === void 0 ? void 0 : [M(), M()],
250
+ spread: [
251
+ 1,
252
+ 0,
253
+ 1
254
+ ],
255
+ from: [
256
+ 0,
257
+ 0,
258
+ 0
259
+ ],
260
+ arrive: {
261
+ op: "const",
262
+ value: 0
263
+ },
264
+ push: [
265
+ 0,
266
+ 0,
267
+ 0
268
+ ]
269
+ }, this.lifetime = I(t.lifetime ?? 60, "lifetime", 0, 3600, !0), t.prewarm !== void 0 && typeof t.prewarm != "boolean" && !(typeof t.prewarm == "number" && t.prewarm >= 0 && Number.isFinite(t.prewarm))) throw TypeError("Smoke prewarm must be true, false or the seconds the source has burned (0 or more)");
270
+ let f = I(t.rate ?? 20, "rate", 0, 1e5, !0);
271
+ this.capacity = Math.max(64, Math.ceil(f * this.lifetime * 1.05) + 16), this.lit = {
272
+ wrap: .6,
273
+ ...t.lights ? { lights: t.lights } : {},
274
+ ...t.shadows ? { shadows: t.shadows } : {}
275
+ }, this.check(), this.write();
276
+ let p = {
277
+ capacity: this.capacity,
278
+ rate: f,
279
+ position: [...this.at],
280
+ velocity: [...this.velocity],
281
+ spread: 0,
282
+ gravity: [
283
+ 0,
284
+ 0,
285
+ 0
286
+ ],
287
+ color: [...this.rgba],
288
+ size: 2 * this.radius(),
289
+ lifetime: [this.lifetime, this.lifetime],
290
+ ground: -1e9,
291
+ turbulence: this.options.turbulence ?? .4,
292
+ frequency: 1 / (8 * this.radius()),
293
+ emissionExtent: [...this.extent],
294
+ angularVelocity: .05,
295
+ ...t.wind ? { wind: t.wind } : {},
296
+ ...t.texture ? { texture: t.texture } : {},
297
+ curves: { alpha: E(this.lifetime) },
298
+ overLife: {
299
+ speed: this.speed,
300
+ size: this.size
301
+ },
302
+ lit: this.lit,
303
+ ...t.depth ? {
304
+ softness: 1,
305
+ depth: t.depth
306
+ } : {},
307
+ ...t.prewarm ?? !0 ? { schedule: {
308
+ prewarm: typeof t.prewarm == "number" ? Math.min(t.prewarm, this.lifetime) : this.lifetime,
309
+ step: Math.max(.1, this.lifetime / 600)
310
+ } } : {},
311
+ ...this.roof ? {
312
+ obstacles: [this.roof.box, ...this.roof.walls ?? []],
313
+ bounce: 0
314
+ } : {},
315
+ nodes: { graph: [
316
+ {
317
+ op: "attribute",
318
+ value: "velocity"
319
+ },
320
+ {
321
+ op: "const",
322
+ value: this.still
323
+ },
324
+ {
325
+ op: "mul",
326
+ inputs: [0, 1]
327
+ },
328
+ {
329
+ op: "force",
330
+ inputs: [2]
331
+ },
332
+ ...this.roof ? N(this.roof) : []
333
+ ] }
334
+ };
335
+ this.ownWind = t.wind, this.calm(p.wind ?? P(d)?.wind), this.effect = n.attach(e, p, {
336
+ curves: r,
337
+ soft: i,
338
+ lit: s,
339
+ overLife: a,
340
+ schedule: o,
341
+ texture: u,
342
+ nodes: c,
343
+ ...this.roof ? { obstacles: l } : {}
344
+ });
345
+ }
346
+ calm(e) {
347
+ let t = 0, n = 0;
348
+ if (e && "sample" in e) {
349
+ let r = e.sample(this.at[0], this.at[1], this.at[2], this.clock);
350
+ t = r[0], n = r[2];
351
+ } else e && (t = e[0], n = e[1]);
352
+ this.still[0] = this.still[2] = t === 0 && n === 0 ? -4 : 0;
353
+ }
354
+ heat() {
355
+ return this.options.heat ?? (this.options.fire ? 2e4 : 5e6);
356
+ }
357
+ radius() {
358
+ return this.options.radius ?? (this.options.fire ? .3 : 2);
359
+ }
360
+ check() {
361
+ let e = this.options, n = e.position ?? P(e.fire)?.position;
362
+ if (!n) throw TypeError("Smoke needs a position [x, y, z] or a fire");
363
+ t(n, 3, "Smoke position"), this.at[0] = n[0], this.at[1] = n[1], this.at[2] = n[2], D(this.heat(), e.airTemperature);
364
+ let r = I(this.radius(), "radius", 0, 1e4, !0);
365
+ if (I(e.stability ?? 0, "stability", 0, 1), this.roof) this.placeRoof(this.roof, r);
366
+ else if (e.ceiling !== void 0) throw TypeError("Smoke ceiling is chosen at attach; attach the smoke with a ceiling to move it later");
367
+ if (e.gallery !== void 0 && !this.roof?.walls) throw TypeError("Smoke gallery is chosen at attach; attach the smoke with a gallery to move it later");
368
+ I(e.rate ?? 20, "rate", 0, 1e5, !0), I(e.turbulence ?? .4, "turbulence", 0, 1e3);
369
+ let i = I(e.opacity ?? .5, "opacity", 0, 1), a = e.color ?? [
370
+ .3,
371
+ .29,
372
+ .28
373
+ ];
374
+ t(a, 3, "Smoke color");
375
+ for (let e = 0; e < 3; e++) this.rgba[e] = I(a[e], "color channel", 0, 1);
376
+ if (this.rgba[3] = i, this.extent[0] = this.extent[2] = r * .7, this.roof?.walls) {
377
+ let t = e.gallery?.axis === "x" ? 0 : 2, n = j(this.roof.box.center[1] - b - this.at[1], r, this.halfWidth());
378
+ this.extent[t] = Math.max(this.extent[t], n.radius);
379
+ }
380
+ let o = I(e.glow ?? 1, "glow", 0, 10);
381
+ if (o > 0) {
382
+ this.glowAt[0] = this.at[0], this.glowAt[1] = this.at[1], this.glowAt[2] = this.at[2];
383
+ let e = this.lit.glow ??= {
384
+ position: this.glowAt,
385
+ power: 0
386
+ };
387
+ e.position = this.glowAt, e.power = o * T / .7 * this.heat(), e.radius = Math.max(r, .01);
388
+ } else delete this.lit.glow;
389
+ if (e.noon === void 0 ? delete this.lit.noon : this.lit.noon = I(e.noon, "noon", 0, 1e7, !0), e.air === void 0) delete this.lit.air;
390
+ else {
391
+ t(e.air, 3, "Smoke air");
392
+ for (let t = 0; t < 3; t++) I(e.air[t], "air channel", 0, 1e3);
393
+ this.lit.air = [
394
+ e.air[0],
395
+ e.air[1],
396
+ e.air[2]
397
+ ];
398
+ }
399
+ if (e.airReflectance === void 0) delete this.lit.airReflectance;
400
+ else {
401
+ t(e.airReflectance, 3, "Smoke airReflectance");
402
+ for (let t = 0; t < 3; t++) I(e.airReflectance[t], "airReflectance channel", 0, 1);
403
+ this.lit.airReflectance = [
404
+ e.airReflectance[0],
405
+ e.airReflectance[1],
406
+ e.airReflectance[2]
407
+ ];
408
+ }
409
+ e.ground === void 0 ? delete this.lit.ground : this.lit.ground = I(e.ground, "ground", 0, 1);
410
+ }
411
+ placeRoof(e, t) {
412
+ let n = this.options.ceiling;
413
+ if (typeof n != "number" || !Number.isFinite(n)) throw RangeError(`Smoke ceiling is ${n}; pass the roof's world height, a finite number of metres`);
414
+ let r = n - this.at[1], i = this.placeWalls(e), a = j(r, t, i), o = f, s = Math.cbrt(25 * D(this.heat(), this.options.airTemperature) / (48 * o * o)), c = t / (1.2 * o);
415
+ e.box.center[0] = this.at[0], e.box.center[1] = n + b, e.box.center[2] = this.at[2], e.from[0] = -this.at[0], e.from[1] = -(n - a.radius), e.from[2] = -this.at[2], e.arrive.value = s > 0 ? -(((c + a.rise) ** (4 / 3) - c ** (4 / 3)) * 3) / (4 * s) : -3600;
416
+ let l = Math.max(r, t), u = i === Infinity ? l : Math.max(i, t);
417
+ e.push[0] = e.push[2] = d * A(this.heat() / .7, l, u);
418
+ }
419
+ placeWalls(e) {
420
+ if (!e.walls) return Infinity;
421
+ let t = this.options.gallery?.axis, n = this.options.gallery?.walls;
422
+ if (t !== "x" && t !== "z") throw TypeError("Smoke gallery axis must be 'x' or 'z'");
423
+ if (!(n?.length === 2 && Number.isFinite(n[0]) && Number.isFinite(n[1]) && n[0] < n[1])) throw RangeError("Smoke gallery walls must be two finite numbers of metres, the lower first");
424
+ let r = t === "x" ? 2 : 0;
425
+ for (let t = 0; t < 2; t++) {
426
+ let i = e.walls[t].center;
427
+ i[0] = this.at[0], i[1] = this.at[1], i[2] = this.at[2], i[r] = n[t] + (t ? b : -1e5);
428
+ }
429
+ return e.spread[0] = e.spread[2] = 1, e.spread[r] = x, (n[1] - n[0]) / 2;
430
+ }
431
+ halfWidth() {
432
+ let e = this.options.gallery?.walls;
433
+ return e ? (e[1] - e[0]) / 2 : Infinity;
434
+ }
435
+ wind() {
436
+ return F(this.options.wind ?? this.effect?.options.wind ?? P(this.options.fire)?.wind, this.at, this.clock);
437
+ }
438
+ write() {
439
+ let e = this.options, t = D(this.heat(), e.airTemperature), n = this.radius(), r = this.wind(), i = e.stability ?? 0, a = e.ceiling === void 0 ? Infinity : e.ceiling - this.at[1], o = this.halfWidth(), s = this.key;
440
+ if (s[0] === t && s[1] === r && s[2] === n && s[3] === i && s[4] === this.lifetime && s[5] === a && s[6] === o) return;
441
+ s[5] = a, s[6] = o, s[0] = t, s[1] = r, s[2] = n, s[3] = i, s[4] = this.lifetime;
442
+ let c = this.point, l = k(0, t, 0, n, 0, c).speed;
443
+ this.velocity[1] = l;
444
+ let u = a === Infinity ? void 0 : j(a, n, o);
445
+ for (let e = 0; e < C; e++) {
446
+ k(e / 31 * this.lifetime, t, r, n, i, c);
447
+ let a = u !== void 0 && e > 0 && c.rise >= u.rise;
448
+ this.speed[e] = a ? this.speed[e - 1] : l > 0 ? Math.min(1e3, c.speed / l) : 0, this.size[e] = Math.min(1e3, (u ? Math.min(c.radius, u.radius) : c.radius) / n);
449
+ }
450
+ }
451
+ column(e) {
452
+ let t = this.options, n = k(e, D(this.heat(), t.airTemperature), this.wind(), this.radius(), t.stability ?? 0);
453
+ if (t.ceiling !== void 0) {
454
+ let e = j(t.ceiling - this.at[1], this.radius(), this.halfWidth());
455
+ n.rise >= e.rise && (n.rise = e.rise, n.speed = 0, n.level = !0), n.radius = Math.min(n.radius, e.radius);
456
+ }
457
+ return n;
458
+ }
459
+ setup(e) {
460
+ this.engine = e;
461
+ }
462
+ get time() {
463
+ return this.clock;
464
+ }
465
+ onPreUpdate(e) {
466
+ this.advanceTime(e);
467
+ }
468
+ advanceTime(e) {
469
+ if (this.disposed) return;
470
+ this.clock += e > 0 ? e : 0;
471
+ let t = this.options, n = this.effect, r = n.options, i = P(t.fire);
472
+ this.check(), t.wind !== this.ownWind && (n.setWind(t.wind), this.ownWind = t.wind), !t.wind && i && r.wind !== i.wind && n.setWind(i.wind), this.calm(r.wind), this.write();
473
+ let a = this.radius();
474
+ r.position = this.at, r.velocity = this.velocity, r.emissionExtent = this.extent, r.color = this.rgba, r.size = 2 * a, r.frequency = 1 / (8 * a), r.rate = t.rate ?? 20, r.turbulence = t.turbulence ?? .4;
475
+ }
476
+ resetTime() {
477
+ this.disposed || (this.clock = 0, this.check(), this.write(), this.calm(this.effect.options.wind), this.effect.resetTime());
478
+ }
479
+ refill() {
480
+ return this.effect.reset(), this;
481
+ }
482
+ setHeat(e) {
483
+ return D(e, this.options.airTemperature), this.options.heat = e, this;
484
+ }
485
+ setWind(e) {
486
+ return this.effect.setWind(e), this.options.wind = this.ownWind = e, this;
487
+ }
488
+ setFog(e) {
489
+ return this.effect.setFog(e), this;
490
+ }
491
+ static attach(t, n) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
492
+ if (!n || typeof n != "object") throw TypeError("Invalid Smoke options; pass {position: [x, y, z]} or {fire}");
493
+ let r = new p(t, n);
494
+ return e(t).use(r), r;
495
+ }
496
+ dispose() {
497
+ this.disposed || (this.disposed = !0, this.engine?.sceneOf(this)?.removePlugin(this.name), this.engine = void 0, this.effect.dispose());
498
+ }
499
+ [Symbol.dispose]() {
500
+ this.dispose();
501
+ }
502
+ };
503
+ //#endregion
504
+ export { p as BENT_PLUME_RADIUS, f as PLUME_ENTRAINMENT, T as RADIANT_FRACTION, w as SMOKE_FADE_IN, h as STABLE_CALM_RISE, g as STABLE_WIND_RISE, R as Smoke, m as TWO_THIRDS_LAW, O as airStability, D as buoyancyFlux, A as ceilingJetSpeed, k as plumeRise, E as smokeAlphaCurve };
package/dist/soft.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import type { VFXFeatures } from './base.js';
2
+ /**
3
+ * WGSL for depth-soft billboards, shared by the particle billboard and `@margoengine/vfx/clouds`: the uniform at
4
+ * `@group(0) @binding(11)` and the scene depth at binding 12 (multisampled when `samples` > 1), with
5
+ * `softGap(position, viewDepth)`, the gap from a fragment at `viewDepth` (its depth along the view axis,
6
+ * `dot(soft.plane.xyz, world) + soft.plane.w`) to the scene depth behind it, over the softness. Above 1 where the scene
7
+ * depth is empty. Clamp it to [0, 1] for a linear fade (Lorach 2007, "Soft Particles", NVIDIA).
8
+ */
9
+ export declare function softDepthWgsl(samples: number): string;
10
+ /**
11
+ * The `soft` feature: `softness` (world units) fades each particle out over that distance in front of whatever opaque
12
+ * surface is behind it, so a particle meeting the floor or a wall no longer shows a hard line. Scene depth comes from the
13
+ * `depth` option, a function returning a sampleable reversed-Z depth texture the size of the drawing buffer (for example
14
+ * `() => depthTexture.texture` with `DepthTexture` from `@margoengine/post/depth`). Pass it as `{soft}` to `VFX` from
15
+ * `@margoengine/vfx/base`; `VFX` from `@margoengine/vfx` already has it.
16
+ */
17
+ export declare const soft: NonNullable<VFXFeatures['soft']>;
package/dist/soft.js ADDED
@@ -0,0 +1,55 @@
1
+ import { n as e } from "./view-rect-DkeiiUtw.js";
2
+ import { MargoError as t } from "@margoengine/math/errors";
3
+ import { invertMatrix as n } from "@margoengine/math/mat4";
4
+ //#region src/soft.ts
5
+ var r = 112;
6
+ function i(e) {
7
+ let t = e > 1;
8
+ return `
9
+ struct Soft {inverse:mat4x4f,plane:vec4f,screen:vec4f,softness:vec4f}
10
+ @group(0) @binding(11) var<uniform> soft:Soft;
11
+ @group(0) @binding(12) var sceneDepth:texture_depth${t ? "_multisampled" : ""}_2d;
12
+
13
+ fn softGap(position:vec4f,viewDepth:f32)->f32 {
14
+ let at=vec2i(position.xy);var d=textureLoad(sceneDepth,at,0);
15
+ ${t ? `for(var s=1;s<${e};s++){d=max(d,textureLoad(sceneDepth,at,s));}` : ""}
16
+ if(d<=0.0){return 2.0;}
17
+ let ndc=vec2f((position.x-soft.screen.z)/soft.screen.x*2-1,1-(position.y-soft.screen.w)/soft.screen.y*2);
18
+ let w=soft.inverse*vec4f(ndc,d,1);
19
+ return (dot(soft.plane.xyz,w.xyz/w.w)+soft.plane.w-viewDepth)/soft.softness.x;
20
+ }
21
+ `;
22
+ }
23
+ var a = {
24
+ patch(e, t) {
25
+ return e.replace("@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(6) viewDepth:f32,").replace("o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);o.viewDepth=dot(soft.plane.xyz,position)+soft.plane.w;").replace("@fragment fn fragment(i:Out)->@location(0) vec4f {", "@fragment fn fragment(i:Out)->@location(0) vec4f {return softened(i,unsoftened(i));}\nfn unsoftened(i:Out)->vec4f {") + i(t) + "\nfn softened(i:Out,c:vec4f)->vec4f {return vec4f(c.rgb,c.a*clamp(softGap(i.clip,i.viewDepth),0.0,1.0));}\n";
26
+ },
27
+ create(i, a) {
28
+ let o = i.createBuffer({
29
+ size: r,
30
+ usage: 72
31
+ });
32
+ a.push(o);
33
+ let s = new Float32Array(r / 4), c = s.subarray(0, 16), l = [{
34
+ binding: 11,
35
+ resource: { buffer: o }
36
+ }, {
37
+ binding: 12,
38
+ resource: void 0
39
+ }], u;
40
+ return {
41
+ entries: l,
42
+ changed: !1,
43
+ write(r, i, a, d) {
44
+ if (!i) throw new t("state", "VFX softness needs scene depth but depth() returned undefined; add DepthTexture from @margoengine/post/depth before the first frame, or set softness to 0");
45
+ let f = i.sampleCount;
46
+ if (!i.format.startsWith("depth") || i.dimension !== "2d" || i.width !== r.width || i.height !== r.height || !(i.usage & 4) || f !== 1 && f !== (r.descriptor.multisample?.count ?? 1)) throw RangeError("VFX depth must be a sampleable depth texture of the drawing size, with 1 sample or the scene sample count; pass the texture of DepthTexture from @margoengine/post/depth");
47
+ if (this.changed = i !== u, this.changed && (u = i, l[1].resource = i.createView({ aspect: "depth-only" })), !n(r.camera.matrix, c)) return f;
48
+ let p = -a[2], m = -a[6], h = -a[10], g = r.camera.position, _ = e(r);
49
+ return s[16] = p, s[17] = m, s[18] = h, s[19] = -(p * g[0] + m * g[1] + h * g[2]), s[20] = _?.[2] ?? r.width, s[21] = _?.[3] ?? r.height, s[22] = _?.[0] ?? 0, s[23] = _?.[1] ?? 0, s[24] = d, r.device.queue.writeBuffer(o, 0, s), f;
50
+ }
51
+ };
52
+ }
53
+ };
54
+ //#endregion
55
+ export { a as soft, i as softDepthWgsl };