@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
@@ -0,0 +1,658 @@
1
+ // @margo/core-built 0.1.0
2
+ import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
+ const o=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { t as e } from "./view-RKprOPAy.js";
5
+ import { n as t, r as n, t as r } from "./fog-B-kBv7g0.js";
6
+ import { t as i } from "./frame-BuvMFBPp.js";
7
+ import { t as a } from "./view-rect-DkeiiUtw.js";
8
+ import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
9
+ import { finiteVector as s } from "@margoengine/math/validate";
10
+ import { MargoError as c } from "@margoengine/math/errors";
11
+ //#region ../shared/preset.js
12
+ function l(e, t) {
13
+ let n = globalThis.margoPreset?.[e];
14
+ if (!n) return t;
15
+ let r = { ...t };
16
+ for (let e in n) r[e] ??= n[e];
17
+ return r;
18
+ }
19
+ //#endregion
20
+ //#region ../shared/pass.js
21
+ function u(e, t, n, r, i) {
22
+ let a = e.includes("var<private> margoCoverage:u32");
23
+ return `\n@fragment fn transparent(${t}${a ? ",@builtin(sample_mask) margoMask:u32" : ""})->MargoTransparent {${a ? "margoCoverage=margoMask;" : ""}return margoTransparentAt(${n},${r},${i});}\n`;
24
+ }
25
+ function d() {
26
+ return {
27
+ hook: void 0,
28
+ released: void 0,
29
+ set(e, t) {
30
+ return this.hook = e, this.released = t, () => {
31
+ this.hook === e && (this.hook = this.released = void 0);
32
+ };
33
+ }
34
+ };
35
+ }
36
+ function f(e, t, n, r) {
37
+ let i = t.begin();
38
+ return i.setPipeline(n), i.setBindGroup(0, r), i.setBindGroup(1, e.createBindGroup({
39
+ layout: n.getBindGroupLayout(1),
40
+ entries: t.bindings()
41
+ })), i;
42
+ }
43
+ //#endregion
44
+ //#region src/shader.ts
45
+ var p = i + "\n@group(0) @binding(1) var<storage,read_write> particles:array<vec4f>;\n@group(0) @binding(2) var<storage,read_write> groups:array<u32>;\n@group(0) @binding(3) var<storage,read_write> alive:array<u32>;\nstruct Indirect {vertexCount:u32,instanceCount:atomic<u32>,rest:array<u32,3>}\n@group(0) @binding(4) var<storage,read_write> indirect:Indirect;\n@group(0) @binding(5) var<storage,read> births:array<u32>;\n@group(0) @binding(9) var<storage,read_write> listed:array<u32>;\n@group(0) @binding(10) var<storage,read_write> total:array<u32,5>;\nvar<workgroup> scratch:array<u32,256>;\nfn prefix(l:u32,v:u32)->u32 {scratch[l]=v;workgroupBarrier();for(var o=1u;o<256u;o=o<<1u){var a=0u;if(l>=o){a=scratch[l-o];}workgroupBarrier();scratch[l]+=a;workgroupBarrier();}return scratch[l];}\nfn dies(i:u32)->u32 {return select(0u,1u,i<f.control.x&&particles[i*2].w-f.gravityDelta.w<=0);}\nfn hash(v:u32)->u32 {var x=v;x=(x^(x>>16u))*0x7feb352du;x=(x^(x>>15u))*0x846ca68bu;return x^(x>>16u);}\nfn random(seed:u32)->f32{return f32(hash(seed)>>8u)/16777216.0;}\nfn curlNoise(p:vec3f)->vec3f {\n var curl=vec3f(0);var frequency=f.physics.y;var amplitude=1.0;\n for(var octave=0u;octave<3u;octave++){\n let q=p*frequency+f.emitterTime.w*0.3;\n\n curl+=vec3f(-sin(q.y)-cos(q.z),-sin(q.z)-cos(q.x),-sin(q.x)-cos(q.y))*amplitude;\n frequency*=2.03;amplitude*=0.5;\n }\n return curl*f.physics.x;\n}\nfn update(i:u32,ticket:u32)->u32 {\n let dt=f.gravityDelta.w;\n let at=i*2;let cold=f.control.x*2+at;var p=Particle(particles[at],particles[at+1],vec4f(0),vec4f(0));\n p.positionLife.w-=dt;\n if(p.positionLife.w<=0){\n if(ticket>=f.control.y){particles[at].w=0;return 0u;}\n let seed=hash(hash(ticket)^hash(f.control.z));\n let life=mix(f.shape.y,f.shape.z,random(seed));\n let origin=f.emitterTime.xyz+(vec3f(random(seed+5u),random(seed+6u),random(seed+7u))*2-1)*f.emissionExtent.xyz;\n p.positionLife=vec4f(origin,max(0.0,life-dt));\n p.velocitySize=vec4f(f.velocitySpread.xyz+(vec3f(random(seed+1u),random(seed+2u),random(seed+3u))*2-1)*f.velocitySpread.w,f.shape.x);\n p.color=vec4f(f.color.rgb*f.emissionExtent.w,f.color.a);p.rotation=vec4f(random(seed+4u)*6.2831853,f.physics.w,life,0);\n particles[cold]=p.color;particles[cold+1]=p.rotation;\n }\n p.velocitySize=vec4f(p.velocitySize.xyz+(f.gravityDelta.xyz+curlNoise(p.positionLife.xyz))*dt,p.velocitySize.w);\n if(f.control.w!=0u){let wind=unpack2x16float(f.control.w);let k=1.0-exp(-4.0*dt);p.velocitySize=vec4f(p.velocitySize.x+(wind.x-p.velocitySize.x)*k,p.velocitySize.y,p.velocitySize.z+(wind.y-p.velocitySize.z)*k,p.velocitySize.w);}\n p.positionLife=vec4f(p.positionLife.xyz+p.velocitySize.xyz*dt,p.positionLife.w);\n if(p.positionLife.y-p.velocitySize.w*0.5<f.shape.w){p.positionLife.y=f.shape.w+p.velocitySize.w*0.5;if(p.velocitySize.y<0){p.velocitySize.y=-p.velocitySize.y*f.physics.z;}}\n particles[at]=p.positionLife;particles[at+1]=p.velocitySize;\n if(p.positionLife.w<=0){return 0u;}\n atomicAdd(&indirect.instanceCount,1u);\n let c=f.camera*vec4f(p.positionLife.xyz,1);let m=transpose(f.camera);let r=p.velocitySize.w*1.01;\n if(any(vec4f(c.x-c.w,-c.x-c.w,c.y-c.w,-c.y-c.w)>vec4f(length(m[0].xyz-m[3].xyz),length(m[0].xyz+m[3].xyz),length(m[1].xyz-m[3].xyz),length(m[1].xyz+m[3].xyz))*r+abs(c.w)*1e-5)){return 0u;}\n return 1u;\n}\n@compute @workgroup_size(256) fn main(@builtin(global_invocation_id) id:vec3u,@builtin(local_invocation_index) l:u32,@builtin(workgroup_id) w:vec3u){\n let d=dies(id.x);let ticket=births[w.x]+prefix(l,d)-d;\n var drawn=0u;if(id.x<f.control.x){drawn=update(id.x,ticket);}\n let rank=prefix(l,drawn);if(drawn==1u){listed[w.x*256u+rank-1u]=id.x;}if(l==255u){groups[w.x]=rank;}\n}\n@compute @workgroup_size(256) fn deaths(@builtin(global_invocation_id) id:vec3u,@builtin(local_invocation_index) l:u32,@builtin(workgroup_id) w:vec3u){\n let d=prefix(l,dies(id.x));if(l==255u){groups[w.x]=d;}\n}\n@compute @workgroup_size(256) fn scan(@builtin(local_invocation_index) l:u32){\n let n=(f.control.x+255u)/256u;let per=(n+255u)/256u;let a=min(l*per,n);let b=min(a+per,n);\n var sum=0u;for(var k=a;k<b;k++){sum+=groups[k];}\n var run=prefix(l,sum)-sum;for(var k=a;k<b;k++){let v=groups[k];groups[k]=run;run+=v;}\n if(l==255u){total[1]=run;}\n}\n@compute @workgroup_size(256) fn compact(@builtin(workgroup_id) w:vec3u,@builtin(local_invocation_index) l:u32){\n let start=groups[w.x];var end=total[1];if(w.x+1u<(f.control.x+255u)/256u){end=groups[w.x+1u];}\n if(l<end-start){alive[start+l]=listed[w.x*256u+l];}\n}", m = i + "\n@group(0) @binding(1) var<storage,read> particles:array<vec4f>;\n@group(0) @binding(2) var<storage,read> alive:array<u32>;\nstruct Out {@builtin(position) clip:vec4f,@location(0) uv:vec2f,@location(1) color:vec4f}\n@vertex fn vertex(@builtin(vertex_index) vertex:u32,@builtin(instance_index) instance:u32)->Out {\n let corners=array<vec2f,3>(vec2f(-1.7320509,-1),vec2f(1.7320509,-1),vec2f(0,2));let corner=corners[vertex];let at=alive[instance]*2;let cold=f.control.x*2+at;let p=Particle(particles[at],particles[at+1],particles[cold],particles[cold+1]);\n let angle=p.rotation.x+p.rotation.y*(p.rotation.z-p.positionLife.w);let cs=cos(angle);let sn=sin(angle);let rotated=vec2f(corner.x*cs-corner.y*sn,corner.x*sn+corner.y*cs);\n\n\n let pixels=p.velocitySize.w*f.up.w/max(abs((f.camera*vec4f(p.positionLife.xyz,1)).w),1e-6);let grow=select(1.0,max(1.0,1.5/pixels),pixels>0);\n let position=p.positionLife.xyz+(f.right.xyz*rotated.x+f.up.xyz*rotated.y)*p.velocitySize.w*0.5*grow;\n var o:Out;o.clip=f.camera*vec4f(position,1);o.uv=corner;o.color=vec4f(p.color.rgb,p.color.a*clamp(p.positionLife.w/p.rotation.z,0.0,1.0)/(grow*grow));return o;\n}\n@fragment fn fragment(i:Out)->@location(0) vec4f {\n let radius=dot(i.uv,i.uv);if(radius>1){discard;}return vec4f(i.color.rgb,i.color.a*(1-radius)*(1-radius));\n}", h = (e) => e.replace("@fragment fn fragment(i:Out)->@location(0) vec4f {", "struct Samples {@location(0) color:vec4f,@builtin(sample_mask) mask:u32}\n@fragment fn fragment(i:Out,@builtin(sample_mask) covered:u32)->Samples {\n let dx=dpdx(i.uv);let dy=dpdy(i.uv);let offsets=array<vec2f,4>(vec2f(-0.125,-0.375),vec2f(0.375,-0.125),vec2f(-0.375,0.125),vec2f(0.125,0.375));var mask=0u;\n for(var s=0u;s<4u;s++){let q=abs(i.uv+dx*offsets[s].x+dy*offsets[s].y);if(max(q.x,q.y)<=1){mask|=1u<<s;}}\n return Samples(shade(i),covered&mask);\n}\nfn shade(i:Out)->vec4f {"), g = [
46
+ ["@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(3) margoDepth:f32,"],
47
+ ["o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);o.margoDepth=-dot(cross(f.right.xyz,f.up.xyz),position)-f.right.w;"],
48
+ ["@fragment fn fragment(i:Out)->@location(0) vec4f {", "fn margoShade(i:Out)->vec4f {"]
49
+ ], _ = (e, t) => {
50
+ let n = e;
51
+ for (let [e, t] of g) {
52
+ if (n.split(e).length !== 2) throw new c("unsupported", "VFX transparency needs the billboard shader it was written for; update its edits");
53
+ n = n.replace(e, t);
54
+ }
55
+ return t + n + u(t, "i:Out", "margoShade(i)", "i.clip", "i.margoDepth");
56
+ }, v = [
57
+ ["@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(7) fogWorld:vec3f,"],
58
+ ["o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);o.fogWorld=position;"],
59
+ ["@fragment fn fragment(i:Out)->@location(0) vec4f {", "@fragment fn fragment(i:Out)->@location(0) vec4f {return fogged(i,unfogged(i));}\nfn unfogged(i:Out)->vec4f {"]
60
+ ], y = (e) => {
61
+ let n = e;
62
+ for (let [e, t] of v) {
63
+ if (n.split(e).length !== 2) throw new c("unsupported", "VFX fog needs the billboard shader it was written for; update the fog edits");
64
+ n = n.replace(e, t);
65
+ }
66
+ return n + t(0, 5) + "fn fogged(i:Out,c:vec4f)->vec4f {return vec4f(mix(c.rgb,margoFog.color.rgb,fogAmount(i.fogWorld)),c.a);}\n";
67
+ };
68
+ function b(e) {
69
+ return e?.adapterInfo?.vendor === "margo-webgl2" ? "webgl2" : "native";
70
+ }
71
+ function x(e, t) {
72
+ return b(e) === "webgl2" ? t() : void 0;
73
+ }
74
+ //#endregion
75
+ //#region src/base.ts
76
+ var S = 16776960, C = 65504;
77
+ function w(e) {
78
+ return Math.min(S, Math.floor(Math.min(e.maxStorageBufferBindingSize, e.maxBufferSize) / 64), e.maxComputeWorkgroupsPerDimension * 256);
79
+ }
80
+ var T = [
81
+ 0,
82
+ 1,
83
+ 0
84
+ ], E = [
85
+ 0,
86
+ 3,
87
+ 0
88
+ ], D = [
89
+ 0,
90
+ -9.81,
91
+ 0
92
+ ], O = [
93
+ 1,
94
+ .5,
95
+ .1,
96
+ 1
97
+ ], k = [1, 3], A = /* @__PURE__ */ new Float32Array(1), j = new Uint32Array(A.buffer);
98
+ function M(e) {
99
+ A[0] = e;
100
+ let t = j[0], n = t >>> 16 & 32768, r = (t >>> 23 & 255) - 112, i = t & 8388607;
101
+ return r <= 0 ? r < -10 ? n : (i = (i | 8388608) >> 1 - r, n | i + 4096 >> 13) : n | (r << 10) + (i + 4096 >> 13);
102
+ }
103
+ function N(e, t) {
104
+ return (M(t) << 16 | M(e)) >>> 0;
105
+ }
106
+ var P = (e, t, n) => {
107
+ let r = "sample" in e ? e.sample(t[0], t[1], t[2], n) : e, i = r[0], a = "sample" in e ? r[2] : r[1];
108
+ if (!(Math.abs(i) <= 1e3 && Math.abs(a) <= 1e3)) throw RangeError("VFX wind must give finite x and z of at most 1,000 m/s; check the wind option.");
109
+ return [i, a];
110
+ }, F = [
111
+ "ribbons",
112
+ "mesh",
113
+ "events",
114
+ "lit",
115
+ "depthCollide",
116
+ "stretch",
117
+ "fields",
118
+ "skinned",
119
+ "flipbook",
120
+ "shadows",
121
+ "nodes",
122
+ "space",
123
+ "overLife",
124
+ "schedule"
125
+ ], I = 120, L = (e) => ({
126
+ ...e.position && { position: Array.from(e.position) },
127
+ ...e.velocity && { velocity: Array.from(e.velocity) },
128
+ ...e.spread !== void 0 && { spread: e.spread },
129
+ ...e.emissionExtent && { emissionExtent: Array.from(e.emissionExtent) }
130
+ }), R = 0, z = class t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
131
+ constructor(e = {}, t = {}) {
132
+ this.options = e, this.features = t, this.attachment = {
133
+ view: void 0,
134
+ loadOp: "load",
135
+ storeOp: "store"
136
+ }, this.depthAttachment = {
137
+ view: void 0,
138
+ depthReadOnly: !0
139
+ }, this.presentation = {
140
+ colorAttachments: [this.attachment],
141
+ depthStencilAttachment: this.depthAttachment
142
+ }, this.renderFormat = "", this.renderDepth = "", this.renderKey = "", this.name = "vfx:" + R++, this.renderGroups = /* @__PURE__ */ new Map(), this.renders = /* @__PURE__ */ new Map(), this.billboard = "", this.extraValues = /* @__PURE__ */ new Float32Array(524), this.spriteEntries = [], this.transparency = d(), this.runtimes = [], this.owned = [], this.fogSource = null, this.fogData = /* @__PURE__ */ new Float32Array(12), this.values = /* @__PURE__ */ new Float32Array(56), this.ints = new Uint32Array(this.values.buffer), this.view = /* @__PURE__ */ new Float32Array(16), this.seconds = 0, this.remainder = 0, this.frames = 0, this.burstCount = 0, this.done = 0, this.spawnQueue = [], this.tick = {
143
+ delta: 0,
144
+ time: 0,
145
+ budget: 0,
146
+ frame: 0
147
+ }, this.still = {
148
+ delta: 0,
149
+ time: 0,
150
+ budget: 0,
151
+ frame: 0
152
+ }, this.ticked = !1, this.clocked = !1, this.warm = [], this.held = [], this.routeLoading = !1, this.disposed = !1;
153
+ let n = l("vfx", e);
154
+ this.options = (n.capacity ?? 0) < (e.initialCount ?? 0) ? e : n, this.capacity = this.options.capacity ?? 1e6, this.validate();
155
+ let r = e.texture;
156
+ if (r) {
157
+ if (!t.texture) throw TypeError("VFX texture needs textureFeature from @margoengine/vfx/texture: pass {texture: textureFeature}");
158
+ this.sprite = t.texture.copy(r);
159
+ }
160
+ }
161
+ static attach(e, n = {}, r = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
162
+ let i = new t(n, r);
163
+ return o(e).use(i), i;
164
+ }
165
+ validate() {
166
+ let e = this.options;
167
+ if (!Number.isInteger(e.initialCount ?? 0) || (e.initialCount ?? 0) < 0 || (e.initialCount ?? 0) > this.capacity) throw RangeError("initialCount must be a whole number up to capacity; pass a smaller count.");
168
+ if (e.emissionExtent) {
169
+ s(e.emissionExtent, 3, "Emission extent");
170
+ for (let t = 0; t < 3; t++) if (e.emissionExtent[t] < 0) throw RangeError("Emission extent must be nonnegative; pass half-sizes of 0 or more.");
171
+ }
172
+ if (e.clock !== void 0 && typeof e.clock?.ticks != "function") throw TypeError("A VFX clock needs ticks(rate); pass a FilmClock from @margoengine/math/clock.");
173
+ if (!Number.isFinite(e.intensity ?? 1) || (e.intensity ?? 1) < 0 || (e.intensity ?? 1) > C) throw RangeError("Particle intensity must be between 0 and 65,504; pass a value in range.");
174
+ if (!Number.isInteger(this.capacity) || this.capacity < 1 || this.capacity > S || e.capacity !== void 0 && e.capacity !== this.capacity || !Number.isFinite(e.rate ?? this.capacity / 2) || (e.rate ?? this.capacity / 2) < 0 || !Number.isFinite(Math.fround(e.ground ?? 0)) || !Number.isFinite(Math.fround(e.angularVelocity ?? 0)) || !Number.isFinite(e.bounce ?? .3) || (e.bounce ?? .3) < 0 || (e.bounce ?? .3) > 1 || !Number.isFinite(Math.fround(e.size ?? .1)) || (e.size ?? .1) <= 0) throw RangeError("VFX capacity, rate, bounce, size or ground is out of range; check the options.");
175
+ for (let t = 0; t < 3; t++) {
176
+ let n = t === 0 ? e.spread ?? 1 : t === 1 ? e.turbulence ?? .5 : e.frequency ?? 1;
177
+ if (!Number.isFinite(Math.fround(n)) || n < 0) throw RangeError("VFX spread, turbulence and frequency must be 0 or more; check the options.");
178
+ }
179
+ if (e.wind !== void 0) {
180
+ if (typeof e.wind != "object" || e.wind === null || !("sample" in e.wind) && !Array.isArray(e.wind)) throw TypeError("VFX wind must be [x, z] in m/s or an object with sample(x, y, z, t); check the wind option.");
181
+ "sample" in e.wind || P(e.wind, T, 0);
182
+ }
183
+ s(e.position ?? T, 3, "Emitter position"), s(e.velocity ?? E, 3, "Emitter velocity"), s(e.gravity ?? D, 3, "Particle gravity"), s(e.color ?? O, 4, "Particle color");
184
+ let t = e.color ?? O;
185
+ for (let e = 0; e < 4; e++) if (t[e] < 0 || t[e] > 1) throw RangeError("Particle color channels must be between 0 and 1; pass [r, g, b, a].");
186
+ let n = e.lifetime ?? k;
187
+ if (s(n, 2, "Particle lifetime"), n[0] <= 0 || n[1] < n[0]) throw RangeError("Particle lifetime must be [min, max] seconds, 0 < min <= max; pass both.");
188
+ if (e.sort !== void 0 && typeof e.sort != "boolean" || e.wrap !== void 0 && typeof e.wrap != "boolean" || e.wrap && !e.emissionExtent?.every((e) => e > 0)) throw RangeError("VFX sort and wrap must be booleans; wrap needs emissionExtent above 0.");
189
+ if (e.softness !== void 0 && (!Number.isFinite(Math.fround(e.softness)) || e.softness < 0)) throw RangeError("VFX softness must be a world distance of 0 or more; pass e.g. 0.5, or 0 to turn it off.");
190
+ if (e.depth !== void 0 && typeof e.depth != "function") throw TypeError("VFX depth must be a function returning the scene depth texture; pass () => depth.texture");
191
+ if (e.softness) {
192
+ if (!this.features.soft) throw TypeError("VFX softness needs soft from @margoengine/vfx/soft: pass {soft}");
193
+ if (!e.depth) throw TypeError("VFX softness needs scene depth: add DepthTexture from @margoengine/post/depth and pass depth: () => depth.texture");
194
+ }
195
+ for (let t of [
196
+ "obstacles",
197
+ "wrap",
198
+ "sort",
199
+ "curves",
200
+ "emitter"
201
+ ]) if (e[t] && !this.features[t]) throw TypeError(`VFX ${t} needs ${t} from @margoengine/vfx/${t}`);
202
+ if (e.curves && (this.features.curves.validate(e.curves), !e.curves.size && !e.curves.alpha && !e.curves.color)) throw TypeError("VFX curves needs at least one of size, alpha or color; pass e.g. {size: [0, 1, 0]}");
203
+ if (e.emitter) {
204
+ if (this.features.emitter.validate(e.emitter, !this.emitterShape), this.emitterShape && e.emitter.shape !== this.emitterShape) throw TypeError(`VFX emitter shape is fixed at attach (${this.emitterShape}); attach a new VFX to change it`);
205
+ } else if (this.emitterShape) throw TypeError("VFX emitter was set at attach and cannot be removed; attach a new VFX to drop it");
206
+ e.obstacles && this.features.obstacles.write(e.obstacles, this.extraValues);
207
+ for (let t of F) {
208
+ let n = e[t], r = this.features[t];
209
+ if (n !== void 0) {
210
+ if (!r) throw TypeError(`VFX ${t} needs ${t} from @margoengine/vfx/${t.replace(/[A-Z]/g, (e) => "-" + e.toLowerCase())}: pass {${t}}`);
211
+ r.validate(n, e);
212
+ }
213
+ }
214
+ }
215
+ get fog() {
216
+ return this.fogSource;
217
+ }
218
+ setFog(e) {
219
+ return this.fogSource = r(e), this;
220
+ }
221
+ burst(e, t) {
222
+ if (this.disposed) throw new c("disposed", "VFX is disposed; attach a new VFX to burst it");
223
+ if (!Number.isInteger(e) || e < 0 || e > this.capacity) throw RangeError("Particle burst must be a whole number up to capacity; pass a smaller count.");
224
+ return t ? e > 0 && this.spawnQueue.push({
225
+ count: e,
226
+ spawn: L(t)
227
+ }) : this.burstCount = Math.min(this.capacity, this.burstCount + e), this;
228
+ }
229
+ reset() {
230
+ if (this.disposed) throw new c("disposed", "VFX is disposed; attach a new VFX to reset it");
231
+ this.seconds = this.remainder = this.frames = this.burstCount = this.done = 0, this.spawnQueue.length = 0;
232
+ for (let e of [this.tick, this.still]) e.delta = e.time = e.budget = e.frame = 0;
233
+ if (this.ticked = this.clocked = !1, this.warm = [], this.held.length = 0, !this.device) return this;
234
+ this.burstCount = this.options.initialCount ?? 0;
235
+ for (let e of [this.particles, this.alive]) this.device.queue.writeBuffer(e, 0, new Uint8Array(e.size));
236
+ for (let e of [this.indirect, this.visible]) this.device.queue.writeBuffer(e, 0, new Uint32Array([
237
+ 3,
238
+ 0,
239
+ 0,
240
+ 0,
241
+ 0
242
+ ]));
243
+ for (let e of this.runtimes) e.reset?.();
244
+ return this;
245
+ }
246
+ resetTime() {
247
+ this.disposed || this.reset();
248
+ }
249
+ setWind(e) {
250
+ let t = this.options.wind;
251
+ this.options.wind = e;
252
+ try {
253
+ this.validate();
254
+ } catch (e) {
255
+ throw this.options.wind = t, e;
256
+ }
257
+ return this;
258
+ }
259
+ setup(e) {
260
+ if (this.disposed || !e.gpu) throw new c(this.disposed ? "disposed" : "unsupported", "VFX requires WebGPU and a live effect; attach a new VFX to a WebGPU engine; see https://margoengine.com/errors#webgpu");
261
+ this.engine = e, this.device = e.gpu;
262
+ let t = this.device.limits;
263
+ if (this.capacity * 64 > t.maxStorageBufferBindingSize || this.capacity * 64 > t.maxBufferSize || Math.ceil(this.capacity / 256) > t.maxComputeWorkgroupsPerDimension || this.options.sort && 2 ** Math.ceil(Math.log2(this.capacity)) / 256 > t.maxComputeWorkgroupsPerDimension || t.maxComputeInvocationsPerWorkgroup < 256 || t.maxComputeWorkgroupSizeX < 256) throw RangeError(`VFX capacity ${this.capacity} exceeds the device limits (64 bytes a slot: at most ${w(t)} here); reduce capacity.`);
264
+ let n = (e, t) => this.device.createBuffer({
265
+ size: e,
266
+ usage: t | GPUBufferUsage.COPY_DST
267
+ }), r = this.options, i = this.features;
268
+ this.uniform = n(224, GPUBufferUsage.UNIFORM), this.particles = n(this.capacity * 64, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC);
269
+ let a = r.sort ? 2 ** Math.ceil(Math.log2(this.capacity)) : this.capacity;
270
+ (r.obstacles || r.sort) && (this.extra = n(2096, GPUBufferUsage.UNIFORM));
271
+ let o = p;
272
+ r.obstacles && (o = i.obstacles.patch(o)), r.wrap && (o = i.wrap.patch(o)), r.emitter && (o = i.emitter.patch(o, r.emitter), this.emitterRuntime = i.emitter.create(this.device, r.emitter, this.owned), this.emitterShape = r.emitter.shape), this.billboard = this.sprite ? i.texture.patch(m, this.sprite) : m, r.curves && (this.billboard = i.curves.patch(this.billboard, r.curves), this.curveRuntime = i.curves.create(this.device, this.owned));
273
+ let s = F.flatMap((e) => r[e] === void 0 ? [] : [[i[e], r[e]]]);
274
+ for (let [e, t] of s) e.simulation && (o = e.simulation(o, t)), e.billboard && (this.billboard = e.billboard(this.billboard, t));
275
+ this.alive = n(a * 4, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC), this.indirect = n(20, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC), this.respawn = n(20, GPUBufferUsage.STORAGE), this.visible = n(20, GPUBufferUsage.STORAGE | GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_SRC);
276
+ for (let e of [this.indirect, this.visible]) this.device.queue.writeBuffer(e, 0, new Uint32Array([
277
+ 3,
278
+ 0,
279
+ 0,
280
+ 0,
281
+ 0
282
+ ]));
283
+ let l = Math.ceil(this.capacity / 256), u = (e) => {
284
+ let t = n(e, GPUBufferUsage.STORAGE);
285
+ return this.owned.push(t), t;
286
+ }, d = u(l * 4), f = u(l * 4), h = u(l * 1024), g = this.device.createShaderModule({ code: o }), _ = this.uniform, v = (e, t, n = []) => {
287
+ let r = this.device.createComputePipeline({
288
+ layout: "auto",
289
+ compute: {
290
+ module: g,
291
+ entryPoint: e
292
+ }
293
+ });
294
+ return [r, this.device.createBindGroup({
295
+ layout: r.getBindGroupLayout(0),
296
+ entries: [...t.flatMap((e, t) => e ? [{
297
+ binding: t,
298
+ resource: { buffer: e }
299
+ }] : []), ...n]
300
+ })];
301
+ }, y = {
302
+ device: this.device,
303
+ capacity: this.capacity,
304
+ uniform: _,
305
+ particles: this.particles,
306
+ alive: this.alive,
307
+ visible: this.visible,
308
+ indirect: this.indirect,
309
+ module: g,
310
+ options: r,
311
+ stats: this.engine.stats,
312
+ engine: this.engine
313
+ };
314
+ this.runtimes = s.flatMap(([e, t]) => e.create ? [e.create(y, t, this.owned)] : []);
315
+ let b = this.runtimes.flatMap((e) => e.compute ?? []);
316
+ [this.simulation, this.computeGroup] = v("main", [
317
+ _,
318
+ this.particles,
319
+ f,
320
+ 0,
321
+ this.indirect,
322
+ d,
323
+ 0,
324
+ 0,
325
+ 0,
326
+ h
327
+ ], [
328
+ ...r.obstacles ? [{
329
+ binding: 6,
330
+ resource: { buffer: this.extra }
331
+ }] : [],
332
+ ...this.emitterRuntime?.entries ?? [],
333
+ ...b
334
+ ]), this.births = [v("deaths", [
335
+ _,
336
+ this.particles,
337
+ d
338
+ ]), v("scan", [
339
+ _,
340
+ 0,
341
+ d,
342
+ 0,
343
+ 0,
344
+ 0,
345
+ 0,
346
+ 0,
347
+ 0,
348
+ 0,
349
+ this.respawn
350
+ ])], this.listing = [v("scan", [
351
+ _,
352
+ 0,
353
+ f,
354
+ 0,
355
+ 0,
356
+ 0,
357
+ 0,
358
+ 0,
359
+ 0,
360
+ 0,
361
+ this.visible
362
+ ]), v("compact", [
363
+ _,
364
+ 0,
365
+ f,
366
+ this.alive,
367
+ 0,
368
+ 0,
369
+ 0,
370
+ 0,
371
+ 0,
372
+ h,
373
+ this.visible
374
+ ])], r.sort && (this.sorter = i.sort.create(this.device, this.particles, this.alive, this.visible, this.extra, a, this.owned)), this.sprite && (this.spriteEntries = i.texture.create(this.device, this.sprite, this.owned)), this.burst(this.options.initialCount ?? 0);
375
+ let S = this.particles, C = x(this.device, () => import("./compat-CVSEj1Bp.js"));
376
+ C && (this.routeLoading = !0), C?.then((e) => {
377
+ this.particles === S && (this.route = {
378
+ kernels: new e.SimulationRoute(this.device, o, this.capacity, {
379
+ uniform: _,
380
+ particles: S,
381
+ alive: this.alive,
382
+ indirect: this.indirect,
383
+ visible: this.visible,
384
+ events: this.runtimes.find((e) => e.eventList)?.eventList
385
+ }, [
386
+ ...r.obstacles ? [{
387
+ binding: 6,
388
+ resource: { buffer: this.extra }
389
+ }] : [],
390
+ ...this.emitterRuntime?.entries ?? [],
391
+ ...b
392
+ ], this.owned),
393
+ billboard: e.countedBillboard,
394
+ binding: e.COUNT_BINDING
395
+ }, this.renders.clear(), this.renderGroups.clear());
396
+ }).finally(() => {
397
+ this.particles === S && (this.routeLoading = !1);
398
+ });
399
+ }
400
+ registerPasses(e) {
401
+ e.add({
402
+ name: this.name + ":simulate",
403
+ order: -8,
404
+ execute: (e) => {
405
+ e.backend === "webgpu" && this.simulate(e);
406
+ }
407
+ }), e.add({
408
+ name: this.name + ":draw",
409
+ order: 6,
410
+ execute: (e) => {
411
+ e.backend === "webgpu" && this.draw(e);
412
+ }
413
+ });
414
+ }
415
+ get time() {
416
+ return this.seconds;
417
+ }
418
+ advanceTime(e) {
419
+ if (!this.disposed) {
420
+ if (this.validate(), !(e > 0) || this.options.clock) this.clocked = !0;
421
+ else {
422
+ this.warm.length = 0;
423
+ for (let e of this.runtimes) e.warmup?.((e) => this.warm.push(this.countStep(e, {})));
424
+ this.takeSpawns(), this.countStep(e, this.tick), this.ticked = this.clocked = !0;
425
+ }
426
+ }
427
+ }
428
+ takeSpawns() {
429
+ for (let { count: e, spawn: t } of this.spawnQueue) this.warm.push({
430
+ delta: 0,
431
+ time: this.seconds,
432
+ budget: e,
433
+ frame: this.frames++,
434
+ spawn: t
435
+ });
436
+ this.spawnQueue.length = 0;
437
+ }
438
+ onPreUpdate(e) {
439
+ this.advanceTime(e);
440
+ }
441
+ countStep(e, t, n = !1, r) {
442
+ let i = this.options;
443
+ this.seconds = r ?? this.seconds + e;
444
+ let a = this.runtimes.reduce((t, n) => t + (n.emission?.(e) ?? 0), 0), o = (i.rate ?? this.capacity / 2) * e + this.remainder;
445
+ return this.remainder = o % 1, t.budget = Math.min(this.capacity, Math.floor(o) + this.burstCount + a), this.burstCount = 0, t.delta = e, t.time = this.seconds, t.frame = n && !t.budget ? this.frames : this.frames++, t;
446
+ }
447
+ simulate(e) {
448
+ if (this.validate(), this.options.clock) this.countTicks(this.options.clock);
449
+ else if (this.clocked) this.ticked || (this.takeSpawns(), this.countStep(0, this.still, !0));
450
+ else {
451
+ this.warm.length = 0;
452
+ for (let e of this.runtimes) e.warmup?.((e) => this.warm.push(this.countStep(e, {})));
453
+ this.takeSpawns(), this.countStep(e.delta, this.tick), this.ticked = !0;
454
+ }
455
+ if (this.routeLoading && (this.warm.length || this.held.length)) {
456
+ this.held.push(...this.warm), this.warm.length = 0, this.ticked ? this.held.push({ ...this.tick }) : this.still.budget && this.held.push({ ...this.still }), this.ticked = !1;
457
+ return;
458
+ }
459
+ this.held.length && (this.warm.unshift(...this.held), this.held.length = 0);
460
+ for (let t of this.warm) {
461
+ let n = e.device.createCommandEncoder();
462
+ this.simulateStep({
463
+ ...e,
464
+ delta: t.delta,
465
+ encoder: n
466
+ }, t), e.device.queue.submit([n.finish()]);
467
+ }
468
+ this.warm.length = 0;
469
+ let t = e.delta, n = this.ticked, r = n ? this.tick : this.still;
470
+ this.ticked = !1, (this.options.clock || !n) && (e.delta = r.delta);
471
+ try {
472
+ this.simulateStep(e, r);
473
+ } finally {
474
+ e.delta = t;
475
+ }
476
+ }
477
+ countTicks(e) {
478
+ let t = e.ticks(120);
479
+ if (!Number.isSafeInteger(t) || t < 0) throw RangeError(`A VFX clock gives whole ticks from 0; got ${t}. Pass a FilmClock.`);
480
+ t < this.done && this.reset(), this.warm.length = 0;
481
+ for (let e of this.runtimes) e.warmup?.((e) => this.warm.push(this.countStep(e, {})));
482
+ if (this.takeSpawns(), t === this.done) this.countStep(0, this.still, !0);
483
+ else {
484
+ for (; this.done < t - 1;) this.warm.push(this.countTick({}));
485
+ this.countTick(this.tick), this.ticked = !0;
486
+ }
487
+ }
488
+ countTick(e) {
489
+ return this.done++, this.countStep(1 / 120, e, !1, this.done / 120);
490
+ }
491
+ simulateStep(t, n) {
492
+ let r = this.options, i = n.budget;
493
+ this.values.set(t.camera.matrix), e(this.view, t.camera);
494
+ let a = n.spawn, o = a?.position ?? r.position ?? T;
495
+ for (let e = 0; e < 3; e++) this.values[16 + e] = this.view[e * 4], this.values[20 + e] = this.view[e * 4 + 1], this.values[48 + e] = a?.emissionExtent?.[e] ?? r.emissionExtent?.[e] ?? 0;
496
+ this.values[19] = this.transparency.hook ? this.view[14] : 0;
497
+ let s = this.values, c = s[0] * s[20] + s[4] * s[21] + s[8] * s[22], l = s[1] * s[20] + s[5] * s[21] + s[9] * s[22];
498
+ s[23] = Math.sqrt(c * c + l * l) * t.height * .5, this.values.set(r.gravity ?? D, 24), this.values[27] = n.delta, this.values.set(o, 28), this.values[31] = n.time, this.values.set(a?.velocity ?? r.velocity ?? E, 32), this.values[35] = a?.spread ?? r.spread ?? 1, this.values.set(r.color ?? O, 36);
499
+ let u = r.lifetime ?? k;
500
+ if (this.values[40] = r.size ?? .1, this.values[41] = u[0], this.values[42] = u[1], this.values[43] = r.ground ?? 0, this.values[44] = r.turbulence ?? .5, this.values[45] = r.frequency ?? 1, this.values[46] = r.bounce ?? .3, this.values[47] = r.angularVelocity ?? 0, this.values[51] = r.intensity ?? 1, this.ints[52] = this.capacity, this.ints[53] = i, this.ints[54] = n.frame, r.wind) {
501
+ let [e, t] = P(r.wind, [
502
+ o[0],
503
+ o[1],
504
+ o[2]
505
+ ], n.time);
506
+ this.ints[55] = N(e, t);
507
+ } else this.ints[55] = 0;
508
+ if (t.device.queue.writeBuffer(this.uniform, 0, this.values), this.extra) {
509
+ let e = this.extraValues;
510
+ e.set(t.camera.position);
511
+ for (let t = 0; t < 3; t++) e[4 + t] = -this.view[t * 4 + 2];
512
+ t.device.queue.writeBuffer(this.extra, 0, e);
513
+ }
514
+ r.curves && this.curveRuntime.write(t.device.queue, r.curves), r.emitter && this.emitterRuntime.write(t.device.queue, r.emitter);
515
+ for (let e of this.runtimes) e.write?.(t);
516
+ this.route || t.encoder.clearBuffer(this.indirect, 4, 4);
517
+ let d = t.encoder.beginComputePass(), f = Math.ceil(this.capacity / 256), p = ([e, t], n) => {
518
+ d.setPipeline(e), d.setBindGroup(0, t), d.dispatchWorkgroups(n);
519
+ }, [m, h] = this.births, [g, _] = this.listing, v = i > 0 || this.runtimes.some((e) => e.births);
520
+ this.route ? this.route.kernels.encode(d, v) : (v && (p(m, f), p(h, 1)), p([this.simulation, this.computeGroup], f), p(g, 1), p(_, f)), this.sorter?.run(d);
521
+ for (let e of this.runtimes) this.route && e.eventList || e.run?.(d);
522
+ d.end();
523
+ }
524
+ prepare(e, t) {
525
+ (this.renderFormat !== e.format || this.renderDepth !== e.descriptor.depthStencil.format) && (this.renderFormat = e.format, this.renderDepth = e.descriptor.depthStencil.format, this.renderKey = this.renderFormat + ":" + this.renderDepth);
526
+ let r = this.fogSource;
527
+ r && (n(r, e.camera.position, this.fogData, !e.format.includes("float") && !e.format.endsWith("-srgb")), this.fogBuffer ??= e.device.createBuffer({
528
+ size: 48,
529
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
530
+ }), e.device.queue.writeBuffer(this.fogBuffer, 0, this.fogData));
531
+ let i = this.options.softness ?? 0, a = 0;
532
+ i > 0 && (this.softRuntime ??= this.features.soft.create(e.device, this.owned), a = this.softRuntime.write(e, this.options.depth(), this.view, i), this.softRuntime.changed && this.renderGroups.clear());
533
+ let o = t?.surface(1), s = t ? 2 : 1, c = this.renderKey + ":" + e.descriptor.multisample?.count + (r ? ":fog" : "") + (a ? ":soft" + a : "") + (o ?? "");
534
+ for (let e of this.runtimes) e.key && (c += e.key(s));
535
+ let l = this.renders.get(c);
536
+ if (!l) {
537
+ let n = a ? this.features.soft.patch(this.billboard, a) : this.billboard, i = r ? y(n) : n, u = this.route ? this.route.billboard(i) : i, d = o ? _(u, o) : (e.descriptor.multisample?.count ?? 1) > 1 ? h(u) : u;
538
+ for (let e of this.runtimes) e.shade && (d = e.shade(d, s));
539
+ let f = e.device.createShaderModule({ code: d });
540
+ l = e.device.createRenderPipeline({
541
+ layout: "auto",
542
+ vertex: {
543
+ module: f,
544
+ entryPoint: "vertex"
545
+ },
546
+ fragment: {
547
+ module: f,
548
+ entryPoint: t ? "transparent" : "fragment",
549
+ ...t?.blends ? { constants: { margoKind: 0 } } : {},
550
+ targets: t ? [...t.targets] : [{
551
+ format: e.format,
552
+ blend: {
553
+ color: {
554
+ srcFactor: "src-alpha",
555
+ dstFactor: "one-minus-src-alpha"
556
+ },
557
+ alpha: {
558
+ srcFactor: "one",
559
+ dstFactor: "one-minus-src-alpha"
560
+ }
561
+ }
562
+ }]
563
+ },
564
+ multisample: e.descriptor.multisample,
565
+ depthStencil: {
566
+ format: e.descriptor.depthStencil.format,
567
+ depthWriteEnabled: !1,
568
+ depthCompare: "greater-equal"
569
+ }
570
+ }), this.renders.set(c, l);
571
+ }
572
+ let u = this.renderGroups.get(l);
573
+ return u || (u = e.device.createBindGroup({
574
+ layout: l.getBindGroupLayout(0),
575
+ entries: [
576
+ ...[
577
+ this.uniform,
578
+ this.particles,
579
+ this.alive
580
+ ].map((e, t) => ({
581
+ binding: t,
582
+ resource: { buffer: e }
583
+ })),
584
+ ...this.spriteEntries,
585
+ ...this.curveRuntime?.entries ?? [],
586
+ ...this.runtimes.flatMap((e) => e.render ?? []),
587
+ ...r ? [{
588
+ binding: 5,
589
+ resource: { buffer: this.fogBuffer }
590
+ }] : [],
591
+ ...a ? this.softRuntime.entries : [],
592
+ ...this.route ? [{
593
+ binding: this.route.binding,
594
+ resource: { buffer: this.visible }
595
+ }] : []
596
+ ]
597
+ }), this.renderGroups.set(l, u)), [l, u];
598
+ }
599
+ draw(e) {
600
+ !this.transparency.hook && !this.runtimes.some((e) => e.hides?.()) && this.billboards(e);
601
+ for (let t of this.runtimes) t.draw?.(e);
602
+ }
603
+ billboards(e) {
604
+ let [t, n] = this.prepare(e);
605
+ this.attachment.view = e.color, this.depthAttachment.view = e.depth, this.depthAttachment.stencilReadOnly = e.descriptor.depthStencil.format.includes("stencil") ? !0 : void 0;
606
+ let r = e.encoder.beginRenderPass(this.presentation);
607
+ r.setPipeline(t), r.setBindGroup(0, n);
608
+ for (let e of this.runtimes) e.bind?.(r, t, 1);
609
+ a(r, e), this.route ? r.draw(3, this.capacity) : r.drawIndirect(this.visible, 0), r.end(), this.engine.stats.drawCalls++;
610
+ }
611
+ setTransparency(e, t) {
612
+ return this.transparency.set(e, t);
613
+ }
614
+ drawTransparent(e, t) {
615
+ if (!this.visible || this.runtimes.some((e) => e.hides?.())) return;
616
+ let [n, r] = this.prepare(e, t), i = f(e.device, t, n, r);
617
+ for (let e of this.runtimes) e.bind?.(i, n, 2);
618
+ this.route ? i.draw(3, this.capacity) : i.drawIndirect(this.visible, 0), this.engine.stats.drawCalls++;
619
+ }
620
+ get gpuState() {
621
+ if (!this.indirect || !this.particles || !this.alive || !this.visible) throw new c("state", "VFX is not attached; attach it to an engine first");
622
+ return {
623
+ particles: this.particles,
624
+ indirect: this.indirect,
625
+ alive: this.alive,
626
+ visible: this.visible
627
+ };
628
+ }
629
+ release() {
630
+ for (let e of this.runtimes) e.dispose?.();
631
+ for (let e of [
632
+ this.uniform,
633
+ this.particles,
634
+ this.alive,
635
+ this.indirect,
636
+ this.visible,
637
+ this.respawn,
638
+ this.extra,
639
+ this.fogBuffer,
640
+ ...this.owned
641
+ ]) e?.destroy();
642
+ this.fogBuffer = void 0, this.softRuntime = void 0, this.owned = [], this.spriteEntries = [], this.curveRuntime = this.emitterRuntime = void 0, this.extra = this.sorter = this.route = void 0, this.held.length = 0, this.routeLoading = !1, this.runtimes = [], this.uniform = this.particles = this.alive = this.indirect = this.visible = this.respawn = void 0, this.computeGroup = this.births = this.listing = void 0, this.renderGroups.clear(), this.renders.clear(), this.simulation = void 0;
643
+ }
644
+ onDeviceRestored(e) {
645
+ this.release(), this.setup(e);
646
+ }
647
+ dispose() {
648
+ this.disposed || (this.disposed = !0, this.transparency.released?.(), this.engine?.sceneOf(this)?.removePlugin(this.name), this.release(), this.engine = this.device = void 0);
649
+ }
650
+ [Symbol.dispose ?? Symbol()]() {
651
+ this.dispose();
652
+ }
653
+ destroy() {
654
+ this.dispose();
655
+ }
656
+ };
657
+ //#endregion
658
+ export { I as n, z as t };