@margoengine/vfx 0.1.0 → 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 (46) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +2241 -1642
  4. package/dist/{base-C9upJytz.js → base-LGs65K7K.js} +174 -123
  5. package/dist/base.d.ts +104 -2
  6. package/dist/base.js +1 -1
  7. package/dist/blown-sand.js +3 -3
  8. package/dist/clouds.d.ts +12 -4
  9. package/dist/clouds.js +35 -18
  10. package/dist/compat-BFjXAQuu.js +14 -0
  11. package/dist/debris.d.ts +43 -0
  12. package/dist/debris.js +33 -1
  13. package/dist/dust-current.d.ts +66 -0
  14. package/dist/dust-current.js +92 -0
  15. package/dist/fire-front.d.ts +72 -1
  16. package/dist/fire-front.js +309 -69
  17. package/dist/fire.d.ts +24 -3
  18. package/dist/fire.js +114 -93
  19. package/dist/flame.d.ts +171 -3
  20. package/dist/flame.js +343 -131
  21. package/dist/flocking-shaders.d.ts +48 -0
  22. package/dist/flocking-sim.d.ts +623 -0
  23. package/dist/flocking.d.ts +145 -0
  24. package/dist/flocking.js +1846 -0
  25. package/dist/gunfire.d.ts +52 -6
  26. package/dist/gunfire.js +108 -98
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +5 -5
  29. package/dist/json.js +2 -0
  30. package/dist/lit-Dx2tNwP-.js +152 -0
  31. package/dist/lit.d.ts +8 -1
  32. package/dist/lit.js +1 -105
  33. package/dist/mesh.d.ts +2 -0
  34. package/dist/mesh.js +92 -69
  35. package/dist/over-life.js +16 -15
  36. package/dist/reactive-mask-B8xbyzlk.js +69 -0
  37. package/dist/ribbons.d.ts +4 -2
  38. package/dist/ribbons.js +87 -73
  39. package/dist/settings.js +1 -1
  40. package/dist/shader.d.ts +5 -0
  41. package/dist/shared/fog.d.ts +33 -33
  42. package/dist/shared/pass.d.ts +53 -53
  43. package/dist/shared/settings.d.ts +89 -89
  44. package/dist/smoke.d.ts +72 -4
  45. package/dist/smoke.js +280 -56
  46. package/package.json +200 -192
@@ -1,15 +1,17 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
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);
3
+ const d=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
4
  import { t as e } from "./view-RKprOPAy.js";
5
5
  import { n as t, r as n, t as r } from "./fog-B-kBv7g0.js";
6
6
  import { t as i } from "./frame-BuvMFBPp.js";
7
7
  import { t as a } from "./view-rect-DkeiiUtw.js";
8
+ import { n as o, r as s, t as c } from "./reactive-mask-B8xbyzlk.js";
9
+ import { r as l, t as u } from "./compat-BFjXAQuu.js";
8
10
  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
+ import { finiteVector as f } from "@margoengine/math/validate";
12
+ import { MargoError as p } from "@margoengine/math/errors";
11
13
  //#region ../shared/preset.js
12
- function l(e, t) {
14
+ function m(e, t) {
13
15
  let n = globalThis.margoPreset?.[e];
14
16
  if (!n) return t;
15
17
  let r = { ...t };
@@ -18,11 +20,11 @@ function l(e, t) {
18
20
  }
19
21
  //#endregion
20
22
  //#region ../shared/pass.js
21
- function u(e, t, n, r, i) {
23
+ function h(e, t, n, r, i) {
22
24
  let a = e.includes("var<private> margoCoverage:u32");
23
25
  return `\n@fragment fn transparent(${t}${a ? ",@builtin(sample_mask) margoMask:u32" : ""})->MargoTransparent {${a ? "margoCoverage=margoMask;" : ""}return margoTransparentAt(${n},${r},${i});}\n`;
24
26
  }
25
- function d() {
27
+ function g() {
26
28
  return {
27
29
  hook: void 0,
28
30
  released: void 0,
@@ -33,7 +35,7 @@ function d() {
33
35
  }
34
36
  };
35
37
  }
36
- function f(e, t, n, r) {
38
+ function _(e, t, n, r) {
37
39
  let i = t.begin();
38
40
  return i.setPipeline(n), i.setBindGroup(0, r), i.setBindGroup(1, e.createBindGroup({
39
41
  layout: n.getBindGroupLayout(1),
@@ -42,72 +44,77 @@ function f(e, t, n, r) {
42
44
  }
43
45
  //#endregion
44
46
  //#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 = [
47
+ var v = 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}", y = 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}", b = (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 {"), x = (e) => {
48
+ let t = "@fragment fn fragment(i:Out)->@location(0) vec4f {";
49
+ if (e.split(t).length !== 2) throw new p("unsupported", "VFX reactive masks need the billboard shader they were written for");
50
+ return e.replace(t, "fn margoParticle(i:Out)->vec4f {") + "\n@fragment fn reactive(i:Out)->@location(0) vec4f {return vec4f(clamp(margoParticle(i).a,0.0,1.0),0,0,1);}\n";
51
+ }, S = [
46
52
  ["@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(3) margoDepth:f32,"],
47
53
  ["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
54
  ["@fragment fn fragment(i:Out)->@location(0) vec4f {", "fn margoShade(i:Out)->vec4f {"]
49
- ], _ = (e, t) => {
55
+ ], C = (e, t) => {
50
56
  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");
57
+ for (let [e, t] of S) {
58
+ if (n.split(e).length !== 2) throw new p("unsupported", "VFX transparency needs the billboard shader it was written for; update its edits");
53
59
  n = n.replace(e, t);
54
60
  }
55
- return t + n + u(t, "i:Out", "margoShade(i)", "i.clip", "i.margoDepth");
56
- }, v = [
61
+ return t + n + h(t, "i:Out", "margoShade(i)", "i.clip", "i.margoDepth");
62
+ }, w = [
57
63
  ["@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(7) fogWorld:vec3f,"],
58
64
  ["o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);o.fogWorld=position;"],
59
65
  ["@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) => {
66
+ ], T = (e) => {
61
67
  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");
68
+ for (let [e, t] of w) {
69
+ if (n.split(e).length !== 2) throw new p("unsupported", "VFX fog needs the billboard shader it was written for; update the fog edits");
64
70
  n = n.replace(e, t);
65
71
  }
66
72
  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
+ }, E = /* @__PURE__ */ Symbol.for("margoengine.ambientVeils");
74
+ function D(e, t) {
75
+ e[E] || (e[E] = /* @__PURE__ */ new Set());
76
+ let n = e[E];
77
+ return n.add(t), () => {
78
+ n.delete(t);
79
+ };
73
80
  }
74
81
  //#endregion
75
82
  //#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);
83
+ var O = 16776960, k = 65504;
84
+ function A(e) {
85
+ return Math.min(O, Math.floor(Math.min(e.maxStorageBufferBindingSize, e.maxBufferSize) / 64), e.maxComputeWorkgroupsPerDimension * 256);
79
86
  }
80
- var T = [
87
+ var j = [
81
88
  0,
82
89
  1,
83
90
  0
84
- ], E = [
91
+ ], M = [
85
92
  0,
86
93
  3,
87
94
  0
88
- ], D = [
95
+ ], N = [
89
96
  0,
90
97
  -9.81,
91
98
  0
92
- ], O = [
99
+ ], P = [
93
100
  1,
94
101
  .5,
95
102
  .1,
96
103
  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;
104
+ ], F = [1, 3], I = /* @__PURE__ */ new Float32Array(1), L = new Uint32Array(I.buffer);
105
+ function R(e) {
106
+ I[0] = e;
107
+ let t = L[0], n = t >>> 16 & 32768, r = (t >>> 23 & 255) - 112, i = t & 8388607;
101
108
  return r <= 0 ? r < -10 ? n : (i = (i | 8388608) >> 1 - r, n | i + 4096 >> 13) : n | (r << 10) + (i + 4096 >> 13);
102
109
  }
103
- function N(e, t) {
104
- return (M(t) << 16 | M(e)) >>> 0;
110
+ function z(e, t) {
111
+ return (R(t) << 16 | R(e)) >>> 0;
105
112
  }
106
- var P = (e, t, n) => {
113
+ var B = (e, t, n) => {
107
114
  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
115
  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
116
  return [i, a];
110
- }, F = [
117
+ }, V = [
111
118
  "ribbons",
112
119
  "mesh",
113
120
  "events",
@@ -122,12 +129,12 @@ var P = (e, t, n) => {
122
129
  "space",
123
130
  "overLife",
124
131
  "schedule"
125
- ], I = 120, L = (e) => ({
132
+ ], H = 120, U = (e) => ({
126
133
  ...e.position && { position: Array.from(e.position) },
127
134
  ...e.velocity && { velocity: Array.from(e.velocity) },
128
135
  ...e.spread !== void 0 && { spread: e.spread },
129
136
  ...e.emissionExtent && { emissionExtent: Array.from(e.emissionExtent) }
130
- }), R = 0, z = class t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
137
+ }), W = 0, G = class t {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
131
138
  constructor(e = {}, t = {}) {
132
139
  this.options = e, this.features = t, this.attachment = {
133
140
  view: void 0,
@@ -139,7 +146,10 @@ var P = (e, t, n) => {
139
146
  }, this.presentation = {
140
147
  colorAttachments: [this.attachment],
141
148
  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 = {
149
+ }, this.reactiveAttachments = [], this.veiled = {}, this.ambientVeil = { veil: (e, t) => this.veil(e, t) }, this.reactivePass = {
150
+ colorAttachments: this.reactiveAttachments,
151
+ depthStencilAttachment: this.depthAttachment
152
+ }, this.renderFormat = "", this.renderDepth = "", this.renderKey = "", this.name = "vfx:" + W++, this.renderGroups = /* @__PURE__ */ new Map(), this.renders = /* @__PURE__ */ new Map(), this.billboard = "", this.extraValues = /* @__PURE__ */ new Float32Array(524), this.spriteEntries = [], this.transparency = g(), 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
153
  delta: 0,
144
154
  time: 0,
145
155
  budget: 0,
@@ -149,8 +159,8 @@ var P = (e, t, n) => {
149
159
  time: 0,
150
160
  budget: 0,
151
161
  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);
162
+ }, this.ticked = !1, this.clocked = !1, this.warm = [], this.held = [], this.routeLoading = !1, this.routeReady = Promise.resolve(), this.disposed = !1;
163
+ let n = m("vfx", e);
154
164
  this.options = (n.capacity ?? 0) < (e.initialCount ?? 0) ? e : n, this.capacity = this.options.capacity ?? 1e6, this.validate();
155
165
  let r = e.texture;
156
166
  if (r) {
@@ -158,34 +168,35 @@ var P = (e, t, n) => {
158
168
  this.sprite = t.texture.copy(r);
159
169
  }
160
170
  }
161
- static attach(e, n = {}, r = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
171
+ static attach(e, n = {}, r = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
162
172
  let i = new t(n, r);
163
- return o(e).use(i), i;
173
+ return d(e).use(i), i;
164
174
  }
165
175
  validate() {
166
176
  let e = this.options;
167
177
  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
178
  if (e.emissionExtent) {
169
- s(e.emissionExtent, 3, "Emission extent");
179
+ f(e.emissionExtent, 3, "Emission extent");
170
180
  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
181
  }
172
182
  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.");
183
+ if (!Number.isFinite(e.intensity ?? 1) || (e.intensity ?? 1) < 0 || (e.intensity ?? 1) > k) throw RangeError("Particle intensity must be between 0 and 65,504; pass a value in range.");
184
+ if (!Number.isInteger(this.capacity) || this.capacity < 1 || this.capacity > O || 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
185
  for (let t = 0; t < 3; t++) {
176
186
  let n = t === 0 ? e.spread ?? 1 : t === 1 ? e.turbulence ?? .5 : e.frequency ?? 1;
177
187
  if (!Number.isFinite(Math.fround(n)) || n < 0) throw RangeError("VFX spread, turbulence and frequency must be 0 or more; check the options.");
178
188
  }
179
189
  if (e.wind !== void 0) {
180
190
  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);
191
+ "sample" in e.wind || B(e.wind, j, 0);
182
192
  }
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;
193
+ f(e.position ?? j, 3, "Emitter position"), f(e.velocity ?? M, 3, "Emitter velocity"), f(e.gravity ?? N, 3, "Particle gravity"), f(e.color ?? P, 4, "Particle color");
194
+ let t = e.color ?? P;
185
195
  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.");
196
+ let n = e.lifetime ?? F;
197
+ if (f(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
198
  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.");
199
+ if (e.reactive !== void 0 && typeof e.reactive != "boolean") throw TypeError("VFX reactive must be true or false; pass a boolean");
189
200
  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
201
  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
202
  if (e.softness) {
@@ -204,7 +215,7 @@ var P = (e, t, n) => {
204
215
  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
216
  } else if (this.emitterShape) throw TypeError("VFX emitter was set at attach and cannot be removed; attach a new VFX to drop it");
206
217
  e.obstacles && this.features.obstacles.write(e.obstacles, this.extraValues);
207
- for (let t of F) {
218
+ for (let t of V) {
208
219
  let n = e[t], r = this.features[t];
209
220
  if (n !== void 0) {
210
221
  if (!r) throw TypeError(`VFX ${t} needs ${t} from @margoengine/vfx/${t.replace(/[A-Z]/g, (e) => "-" + e.toLowerCase())}: pass {${t}}`);
@@ -219,15 +230,15 @@ var P = (e, t, n) => {
219
230
  return this.fogSource = r(e), this;
220
231
  }
221
232
  burst(e, t) {
222
- if (this.disposed) throw new c("disposed", "VFX is disposed; attach a new VFX to burst it");
233
+ if (this.disposed) throw new p("disposed", "VFX is disposed; attach a new VFX to burst it");
223
234
  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
235
  return t ? e > 0 && this.spawnQueue.push({
225
236
  count: e,
226
- spawn: L(t)
237
+ spawn: U(t)
227
238
  }) : this.burstCount = Math.min(this.capacity, this.burstCount + e), this;
228
239
  }
229
240
  reset() {
230
- if (this.disposed) throw new c("disposed", "VFX is disposed; attach a new VFX to reset it");
241
+ if (this.disposed) throw new p("disposed", "VFX is disposed; attach a new VFX to reset it");
231
242
  this.seconds = this.remainder = this.frames = this.burstCount = this.done = 0, this.spawnQueue.length = 0;
232
243
  for (let e of [this.tick, this.still]) e.delta = e.time = e.budget = e.frame = 0;
233
244
  if (this.ticked = this.clocked = !1, this.warm = [], this.held.length = 0, !this.device) return this;
@@ -257,10 +268,10 @@ var P = (e, t, n) => {
257
268
  return this;
258
269
  }
259
270
  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;
271
+ if (this.disposed || !e.gpu) throw new p(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");
272
+ this.engine = e, this.device = e.gpu, this.leaveVeils = D(this.device, this.ambientVeil);
262
273
  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.`);
274
+ 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 ${A(t)} here); reduce capacity.`);
264
275
  let n = (e, t) => this.device.createBuffer({
265
276
  size: e,
266
277
  usage: t | GPUBufferUsage.COPY_DST
@@ -268,9 +279,9 @@ var P = (e, t, n) => {
268
279
  this.uniform = n(224, GPUBufferUsage.UNIFORM), this.particles = n(this.capacity * 64, GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC);
269
280
  let a = r.sort ? 2 ** Math.ceil(Math.log2(this.capacity)) : this.capacity;
270
281
  (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]]]);
282
+ let o = v;
283
+ 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(y, this.sprite) : y, r.curves && (this.billboard = i.curves.patch(this.billboard, r.curves), this.curveRuntime = i.curves.create(this.device, this.owned));
284
+ let s = V.flatMap((e) => r[e] === void 0 ? [] : [[i[e], r[e]]]);
274
285
  for (let [e, t] of s) e.simulation && (o = e.simulation(o, t)), e.billboard && (this.billboard = e.billboard(this.billboard, t));
275
286
  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
287
  for (let e of [this.indirect, this.visible]) this.device.queue.writeBuffer(e, 0, new Uint32Array([
@@ -280,10 +291,10 @@ var P = (e, t, n) => {
280
291
  0,
281
292
  0
282
293
  ]));
283
- let l = Math.ceil(this.capacity / 256), u = (e) => {
294
+ let c = Math.ceil(this.capacity / 256), d = (e) => {
284
295
  let t = n(e, GPUBufferUsage.STORAGE);
285
296
  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 = []) => {
297
+ }, f = d(c * 4), m = d(c * 4), h = d(c * 1024), g = this.device.createShaderModule({ code: o }), _ = this.uniform, b = (e, t, n = []) => {
287
298
  let r = this.device.createComputePipeline({
288
299
  layout: "auto",
289
300
  compute: {
@@ -298,7 +309,7 @@ var P = (e, t, n) => {
298
309
  resource: { buffer: e }
299
310
  }] : []), ...n]
300
311
  })];
301
- }, y = {
312
+ }, x = {
302
313
  device: this.device,
303
314
  capacity: this.capacity,
304
315
  uniform: _,
@@ -311,15 +322,15 @@ var P = (e, t, n) => {
311
322
  stats: this.engine.stats,
312
323
  engine: this.engine
313
324
  };
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", [
325
+ this.runtimes = s.flatMap(([e, t]) => e.create ? [e.create(x, t, this.owned)] : []);
326
+ let S = this.runtimes.flatMap((e) => e.compute ?? []);
327
+ [this.simulation, this.computeGroup] = b("main", [
317
328
  _,
318
329
  this.particles,
319
- f,
330
+ m,
320
331
  0,
321
332
  this.indirect,
322
- d,
333
+ f,
323
334
  0,
324
335
  0,
325
336
  0,
@@ -330,15 +341,15 @@ var P = (e, t, n) => {
330
341
  resource: { buffer: this.extra }
331
342
  }] : [],
332
343
  ...this.emitterRuntime?.entries ?? [],
333
- ...b
334
- ]), this.births = [v("deaths", [
344
+ ...S
345
+ ]), this.births = [b("deaths", [
335
346
  _,
336
347
  this.particles,
337
- d
338
- ]), v("scan", [
348
+ f
349
+ ]), b("scan", [
339
350
  _,
340
351
  0,
341
- d,
352
+ f,
342
353
  0,
343
354
  0,
344
355
  0,
@@ -347,10 +358,10 @@ var P = (e, t, n) => {
347
358
  0,
348
359
  0,
349
360
  this.respawn
350
- ])], this.listing = [v("scan", [
361
+ ])], this.listing = [b("scan", [
351
362
  _,
352
363
  0,
353
- f,
364
+ m,
354
365
  0,
355
366
  0,
356
367
  0,
@@ -359,10 +370,10 @@ var P = (e, t, n) => {
359
370
  0,
360
371
  0,
361
372
  this.visible
362
- ]), v("compact", [
373
+ ]), b("compact", [
363
374
  _,
364
375
  0,
365
- f,
376
+ m,
366
377
  this.alive,
367
378
  0,
368
379
  0,
@@ -372,12 +383,12 @@ var P = (e, t, n) => {
372
383
  h,
373
384
  this.visible
374
385
  ])], 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 = {
386
+ let C = this.particles, w = u(this.device, () => import("./compat-CVSEj1Bp.js"));
387
+ w && (this.routeLoading = !0), w?.then((e) => {
388
+ this.particles === C && (this.route = {
378
389
  kernels: new e.SimulationRoute(this.device, o, this.capacity, {
379
390
  uniform: _,
380
- particles: S,
391
+ particles: C,
381
392
  alive: this.alive,
382
393
  indirect: this.indirect,
383
394
  visible: this.visible,
@@ -388,14 +399,17 @@ var P = (e, t, n) => {
388
399
  resource: { buffer: this.extra }
389
400
  }] : [],
390
401
  ...this.emitterRuntime?.entries ?? [],
391
- ...b
402
+ ...S
392
403
  ], this.owned),
393
404
  billboard: e.countedBillboard,
394
405
  binding: e.COUNT_BINDING
395
406
  }, this.renders.clear(), this.renderGroups.clear());
396
407
  }).finally(() => {
397
- this.particles === S && (this.routeLoading = !1);
398
- });
408
+ this.particles === C && (this.routeLoading = !1);
409
+ }), this.routeReady = l(w);
410
+ }
411
+ get ready() {
412
+ return this.routeReady;
399
413
  }
400
414
  registerPasses(e) {
401
415
  e.add({
@@ -486,24 +500,35 @@ var P = (e, t, n) => {
486
500
  }
487
501
  }
488
502
  countTick(e) {
489
- return this.done++, this.countStep(1 / 120, e, !1, this.done / 120);
503
+ this.done++;
504
+ let t = this.options, n = this.done / 120;
505
+ return t.tick ? (t.tick(n), this.countStep(1 / 120, e, !1, n), e.spawn = U({
506
+ position: t.position ?? j,
507
+ velocity: t.velocity ?? M,
508
+ spread: t.spread ?? 1,
509
+ emissionExtent: t.emissionExtent ?? [
510
+ 0,
511
+ 0,
512
+ 0
513
+ ]
514
+ }), e) : (e.spawn = void 0, this.countStep(1 / 120, e, !1, n));
490
515
  }
491
516
  simulateStep(t, n) {
492
517
  let r = this.options, i = n.budget;
493
518
  this.values.set(t.camera.matrix), e(this.view, t.camera);
494
- let a = n.spawn, o = a?.position ?? r.position ?? T;
519
+ let a = n.spawn, o = a?.position ?? r.position ?? j;
495
520
  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
521
  this.values[19] = this.transparency.hook ? this.view[14] : 0;
497
522
  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;
523
+ s[23] = Math.sqrt(c * c + l * l) * t.height * .5, this.values.set(r.gravity ?? N, 24), this.values[27] = n.delta, this.values.set(o, 28), this.values[31] = n.time, this.values.set(a?.velocity ?? r.velocity ?? M, 32), this.values[35] = a?.spread ?? r.spread ?? 1, this.values.set(r.color ?? P, 36);
524
+ let u = r.lifetime ?? F;
500
525
  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, [
526
+ let [e, t] = B(r.wind, [
502
527
  o[0],
503
528
  o[1],
504
529
  o[2]
505
530
  ], n.time);
506
- this.ints[55] = N(e, t);
531
+ this.ints[55] = z(e, t);
507
532
  } else this.ints[55] = 0;
508
533
  if (t.device.queue.writeBuffer(this.uniform, 0, this.values), this.extra) {
509
534
  let e = this.extraValues;
@@ -521,37 +546,41 @@ var P = (e, t, n) => {
521
546
  for (let e of this.runtimes) this.route && e.eventList || e.run?.(d);
522
547
  d.end();
523
548
  }
524
- prepare(e, t) {
549
+ prepare(e, t, r = !1, i) {
525
550
  (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({
551
+ let a = this.fogSource;
552
+ a && (n(a, e.camera.position, this.fogData, !e.format.includes("float") && !e.format.endsWith("-srgb")), this.fogBuffer ??= e.device.createBuffer({
528
553
  size: 48,
529
554
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
530
555
  }), 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({
556
+ let o = this.options.softness ?? 0, s = 0;
557
+ o > 0 && (this.softRuntime ??= this.features.soft.create(e.device, this.owned), s = this.softRuntime.write(e, this.options.depth(), this.view, o), this.softRuntime.changed && this.renderGroups.clear());
558
+ let l = t?.surface(1), u = t ? 2 : 1, d = this.renderKey + ":" + e.descriptor.multisample?.count + (a ? ":fog" : "") + (s ? ":soft" + s : "") + (l ?? "") + (r ? ":reactive" : "") + (i ? ":veil:" + i : "");
559
+ for (let e of this.runtimes) e.key && (d += e.key(u));
560
+ let f = this.renders.get(d);
561
+ if (!f) {
562
+ let n = s ? this.features.soft.patch(this.billboard, s) : this.billboard, o = a ? T(n) : n, p = this.route ? this.route.billboard(o) : o, m = r ? p : l ? C(p, l) : (e.descriptor.multisample?.count ?? 1) > 1 ? b(p) : p;
563
+ for (let e of this.runtimes) e.shade && (m = e.shade(m, u));
564
+ r && (m = x(m));
565
+ let h = e.device.createShaderModule({ code: m });
566
+ f = e.device.createRenderPipeline({
541
567
  layout: "auto",
542
568
  vertex: {
543
- module: f,
569
+ module: h,
544
570
  entryPoint: "vertex"
545
571
  },
546
572
  fragment: {
547
- module: f,
548
- entryPoint: t ? "transparent" : "fragment",
573
+ module: h,
574
+ entryPoint: r ? "reactive" : t ? "transparent" : "fragment",
549
575
  ...t?.blends ? { constants: { margoKind: 0 } } : {},
550
- targets: t ? [...t.targets] : [{
551
- format: e.format,
576
+ targets: r ? [{
577
+ format: "r8unorm",
578
+ blend: c
579
+ }] : t ? [...t.targets] : [{
580
+ format: i ?? e.format,
552
581
  blend: {
553
582
  color: {
554
- srcFactor: "src-alpha",
583
+ srcFactor: i ? "zero" : "src-alpha",
555
584
  dstFactor: "one-minus-src-alpha"
556
585
  },
557
586
  alpha: {
@@ -567,11 +596,11 @@ var P = (e, t, n) => {
567
596
  depthWriteEnabled: !1,
568
597
  depthCompare: "greater-equal"
569
598
  }
570
- }), this.renders.set(c, l);
599
+ }), this.renders.set(d, f);
571
600
  }
572
- let u = this.renderGroups.get(l);
573
- return u || (u = e.device.createBindGroup({
574
- layout: l.getBindGroupLayout(0),
601
+ let p = this.renderGroups.get(f);
602
+ return p || (p = e.device.createBindGroup({
603
+ layout: f.getBindGroupLayout(0),
575
604
  entries: [
576
605
  ...[
577
606
  this.uniform,
@@ -584,20 +613,20 @@ var P = (e, t, n) => {
584
613
  ...this.spriteEntries,
585
614
  ...this.curveRuntime?.entries ?? [],
586
615
  ...this.runtimes.flatMap((e) => e.render ?? []),
587
- ...r ? [{
616
+ ...a ? [{
588
617
  binding: 5,
589
618
  resource: { buffer: this.fogBuffer }
590
619
  }] : [],
591
- ...a ? this.softRuntime.entries : [],
620
+ ...s ? this.softRuntime.entries : [],
592
621
  ...this.route ? [{
593
622
  binding: this.route.binding,
594
623
  resource: { buffer: this.visible }
595
624
  }] : []
596
625
  ]
597
- }), this.renderGroups.set(l, u)), [l, u];
626
+ }), this.renderGroups.set(f, p)), [f, p];
598
627
  }
599
628
  draw(e) {
600
- !this.transparency.hook && !this.runtimes.some((e) => e.hides?.()) && this.billboards(e);
629
+ this.runtimes.some((e) => e.hides?.()) || (this.transparency.hook ? this.visible && this.drawReactive(e) : this.billboards(e));
601
630
  for (let t of this.runtimes) t.draw?.(e);
602
631
  }
603
632
  billboards(e) {
@@ -607,18 +636,39 @@ var P = (e, t, n) => {
607
636
  r.setPipeline(t), r.setBindGroup(0, n);
608
637
  for (let e of this.runtimes) e.bind?.(r, t, 1);
609
638
  a(r, e), this.route ? r.draw(3, this.capacity) : r.drawIndirect(this.visible, 0), r.end(), this.engine.stats.drawCalls++;
639
+ let i = this.veiled;
640
+ i.encoder = e.encoder, i.depth = e.depth, i.view = e.view, this.drawReactive(e);
641
+ }
642
+ veil(e, t) {
643
+ let n = this.veiled;
644
+ if (!this.visible || e.encoder !== n.encoder || e.depth !== n.depth || e.view !== n.view) return !1;
645
+ let [r, i] = this.prepare(e, void 0, !1, t);
646
+ this.attachment.view = e.color, this.depthAttachment.view = e.depth, this.depthAttachment.stencilReadOnly = e.descriptor.depthStencil.format.includes("stencil") ? !0 : void 0;
647
+ let o = e.encoder.beginRenderPass(this.presentation);
648
+ o.setPipeline(r), o.setBindGroup(0, i);
649
+ for (let e of this.runtimes) e.bind?.(o, r, 1);
650
+ return a(o, e), this.route ? o.draw(3, this.capacity) : o.drawIndirect(this.visible, 0), o.end(), !0;
651
+ }
652
+ drawReactive(e) {
653
+ if (!(this.options.reactive ?? o(e, this))) return;
654
+ let [t, n] = this.prepare(e, void 0, !0);
655
+ this.reactiveAttachments[0] = s(e), this.depthAttachment.view = e.depth, this.depthAttachment.stencilReadOnly = e.descriptor.depthStencil.format.includes("stencil") ? !0 : void 0;
656
+ let r = e.encoder.beginRenderPass(this.reactivePass);
657
+ r.setPipeline(t), r.setBindGroup(0, n);
658
+ for (let e of this.runtimes) e.bind?.(r, t, 1);
659
+ a(r, e), this.route ? r.draw(3, this.capacity) : r.drawIndirect(this.visible, 0), r.end(), this.engine.stats.drawCalls++;
610
660
  }
611
661
  setTransparency(e, t) {
612
662
  return this.transparency.set(e, t);
613
663
  }
614
664
  drawTransparent(e, t) {
615
665
  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);
666
+ let [n, r] = this.prepare(e, t), i = _(e.device, t, n, r);
617
667
  for (let e of this.runtimes) e.bind?.(i, n, 2);
618
668
  this.route ? i.draw(3, this.capacity) : i.drawIndirect(this.visible, 0), this.engine.stats.drawCalls++;
619
669
  }
620
670
  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");
671
+ if (!this.indirect || !this.particles || !this.alive || !this.visible) throw new p("state", "VFX is not attached; attach it to an engine first");
622
672
  return {
623
673
  particles: this.particles,
624
674
  indirect: this.indirect,
@@ -627,6 +677,7 @@ var P = (e, t, n) => {
627
677
  };
628
678
  }
629
679
  release() {
680
+ this.leaveVeils?.(), this.leaveVeils = this.veiled.encoder = this.veiled.depth = this.veiled.view = void 0;
630
681
  for (let e of this.runtimes) e.dispose?.();
631
682
  for (let e of [
632
683
  this.uniform,
@@ -655,4 +706,4 @@ var P = (e, t, n) => {
655
706
  }
656
707
  };
657
708
  //#endregion
658
- export { I as n, z as t };
709
+ export { H as n, G as t };