@margoengine/vfx 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2240 -2
  4. package/dist/base-LGs65K7K.js +709 -0
  5. package/dist/base.d.ts +869 -0
  6. package/dist/base.js +1 -0
  7. package/dist/blown-sand.d.ts +218 -0
  8. package/dist/blown-sand.js +700 -0
  9. package/dist/clouds.d.ts +237 -0
  10. package/dist/clouds.js +583 -0
  11. package/dist/compat-BFjXAQuu.js +14 -0
  12. package/dist/compat-CVSEj1Bp.js +217 -0
  13. package/dist/compat.d.ts +59 -0
  14. package/dist/curves.d.ts +11 -0
  15. package/dist/curves.js +59 -0
  16. package/dist/debris.d.ts +154 -0
  17. package/dist/debris.js +290 -0
  18. package/dist/depth-collide.d.ts +7 -0
  19. package/dist/depth-collide.js +96 -0
  20. package/dist/dust-current.d.ts +66 -0
  21. package/dist/dust-current.js +92 -0
  22. package/dist/emitter.d.ts +10 -0
  23. package/dist/emitter.js +125 -0
  24. package/dist/events.d.ts +9 -0
  25. package/dist/events.js +131 -0
  26. package/dist/extra-CgGjbojB.js +4 -0
  27. package/dist/extra.d.ts +2 -0
  28. package/dist/fields.d.ts +11 -0
  29. package/dist/fields.js +95 -0
  30. package/dist/fire-front.d.ts +610 -0
  31. package/dist/fire-front.js +1080 -0
  32. package/dist/fire.d.ts +140 -0
  33. package/dist/fire.js +194 -0
  34. package/dist/flame-ramp-VoBKpYnM.js +75 -0
  35. package/dist/flame-ramp.d.ts +61 -0
  36. package/dist/flame.d.ts +428 -0
  37. package/dist/flame.js +817 -0
  38. package/dist/flipbook.d.ts +7 -0
  39. package/dist/flipbook.js +23 -0
  40. package/dist/flocking-shaders.d.ts +48 -0
  41. package/dist/flocking-sim.d.ts +623 -0
  42. package/dist/flocking.d.ts +145 -0
  43. package/dist/flocking.js +1846 -0
  44. package/dist/fog-B-kBv7g0.js +32 -0
  45. package/dist/frame-BuvMFBPp.js +4 -0
  46. package/dist/frame.d.ts +7 -0
  47. package/dist/gunfire.d.ts +742 -0
  48. package/dist/gunfire.js +1214 -0
  49. package/dist/hash-Btsp6fGK.js +7 -0
  50. package/dist/hash.d.ts +2 -0
  51. package/dist/index.d.ts +17 -0
  52. package/dist/index.js +60 -0
  53. package/dist/json.d.ts +53 -0
  54. package/dist/json.js +239 -0
  55. package/dist/lit-Dx2tNwP-.js +152 -0
  56. package/dist/lit.d.ts +18 -0
  57. package/dist/lit.js +1 -0
  58. package/dist/mesh.d.ts +16 -0
  59. package/dist/mesh.js +248 -0
  60. package/dist/node-system.d.ts +315 -0
  61. package/dist/node-system.js +384 -0
  62. package/dist/nodes.d.ts +14 -0
  63. package/dist/nodes.js +293 -0
  64. package/dist/obstacles.d.ts +3 -0
  65. package/dist/obstacles.js +25 -0
  66. package/dist/over-life.d.ts +14 -0
  67. package/dist/over-life.js +94 -0
  68. package/dist/reactive-mask-B8xbyzlk.js +69 -0
  69. package/dist/require-webgpu--tUXPsmA.js +7 -0
  70. package/dist/ribbons.d.ts +22 -0
  71. package/dist/ribbons.js +165 -0
  72. package/dist/schedule.d.ts +29 -0
  73. package/dist/schedule.js +47 -0
  74. package/dist/settings.d.ts +362 -0
  75. package/dist/settings.js +707 -0
  76. package/dist/shader.d.ts +49 -0
  77. package/dist/shadows.d.ts +26 -0
  78. package/dist/shadows.js +182 -0
  79. package/dist/shapes.d.ts +34 -0
  80. package/dist/shapes.js +81 -0
  81. package/dist/shared/fog.d.ts +33 -0
  82. package/dist/shared/pass.d.ts +53 -0
  83. package/dist/shared/settings.d.ts +89 -0
  84. package/dist/skinned.d.ts +11 -0
  85. package/dist/skinned.js +104 -0
  86. package/dist/smoke.d.ts +283 -0
  87. package/dist/smoke.js +504 -0
  88. package/dist/soft.d.ts +17 -0
  89. package/dist/soft.js +55 -0
  90. package/dist/solid.d.ts +168 -0
  91. package/dist/solid.js +403 -0
  92. package/dist/sort.d.ts +3 -0
  93. package/dist/sort.js +58 -0
  94. package/dist/space.d.ts +14 -0
  95. package/dist/space.js +88 -0
  96. package/dist/stretch.d.ts +7 -0
  97. package/dist/stretch.js +40 -0
  98. package/dist/texture.d.ts +8 -0
  99. package/dist/texture.js +45 -0
  100. package/dist/view-RKprOPAy.js +30 -0
  101. package/dist/view-rect-DkeiiUtw.js +13 -0
  102. package/dist/wrap.d.ts +3 -0
  103. package/dist/wrap.js +5 -0
  104. package/package.json +198 -4
@@ -0,0 +1,3 @@
1
+ import type { VFXFeatures } from './base.js';
2
+ /** `obstacles` option: up to 64 spheres/boxes the flow bends around and particles bounce off. */
3
+ export declare const obstacles: NonNullable<VFXFeatures['obstacles']>;
@@ -0,0 +1,25 @@
1
+ import { n as e } from "./frame-BuvMFBPp.js";
2
+ import { t } from "./extra-CgGjbojB.js";
3
+ import { finiteVector as n } from "@margoengine/math/validate";
4
+ //#region src/obstacles.ts
5
+ var r = "\nfn obstacle(i:u32,position:vec3f)->vec4f {\n let center=extra.obstacles[i*2u];let extent=extra.obstacles[i*2u+1u].xyz;let r=position-center.xyz;\n if(center.w<0.5){let d=length(r);return vec4f(select(vec3f(0,1,0),r/max(d,0.0001),d>0.003),d-extent.x);}\n let q=abs(r)-extent;let outside=max(q,vec3f(0));let nearest=length(outside);let d=nearest+min(max(q.x,max(q.y,q.z)),0.0);\n if(nearest>0.0001){return vec4f(outside*sign(r)/nearest,d);}\n let s=select(vec3f(-1),vec3f(1),r>=vec3f(0));\n if(q.x>=q.y&&q.x>=q.z){return vec4f(s.x,0,0,d);}if(q.y>=q.z){return vec4f(0,s.y,0,d);}return vec4f(0,0,s.z,d);\n}", i = "p.velocitySize=vec4f(p.velocitySize.xyz+(f.gravityDelta.xyz+curlNoise(p.positionLife.xyz))*dt,p.velocitySize.w);", a = {
6
+ patch: (n) => n.replace("@group(0) @binding(1)", t + "@group(0) @binding(1)").replace("@compute", r + "\n@compute").replace(i, "var force=f.gravityDelta.xyz+curlNoise(p.positionLife.xyz);\n\n for(var i=0u;i<extra.count.x;i++){let o=obstacle(i,p.positionLife.xyz);if(o.w<1){force-=o.xyz*min(dot(force,o.xyz),0.0)*(1-clamp(o.w,0.0,1.0));}}\n p.velocitySize=vec4f(p.velocitySize.xyz+force*dt,p.velocitySize.w);").replace(e, "\n for(var i=0u;i<extra.count.x;i++){let o=obstacle(i,p.positionLife.xyz);let r=p.velocitySize.w*0.5;if(o.w<r){p.positionLife=vec4f(p.positionLife.xyz+o.xyz*(r-o.w),p.positionLife.w);p.velocitySize=vec4f(p.velocitySize.xyz-o.xyz*min(dot(p.velocitySize.xyz,o.xyz),0.0)*(1+f.physics.z),p.velocitySize.w);}}\n " + e),
7
+ write(e, t) {
8
+ if (e.length > 64) throw RangeError("VFX supports at most 64 obstacles; remove some from the obstacles list.");
9
+ new Uint32Array(t.buffer)[8] = e.length;
10
+ for (let r = 0; r < e.length; r++) {
11
+ let i = e[r], a = 12 + r * 8, o = i.kind === "box";
12
+ if (!o && i.kind !== "sphere") throw RangeError(`Obstacle kind is ${String(i.kind)}; use 'sphere' or 'box'.`);
13
+ n(i.center, 3, "Obstacle center");
14
+ let s = o ? i.halfSize : [
15
+ i.radius,
16
+ i.radius,
17
+ i.radius
18
+ ];
19
+ if (n(s, 3, "Obstacle extent"), !s.every((e) => e > 0)) throw RangeError("Obstacle radius or halfSize must be above 0; pass positive sizes in world units.");
20
+ t.set(i.center, a), t[a + 3] = +o, t.set(s, a + 4);
21
+ }
22
+ }
23
+ };
24
+ //#endregion
25
+ export { a as obstacles };
@@ -0,0 +1,14 @@
1
+ import type { VFXExtension } from './base.js';
2
+ /** Piecewise-linear samples over normalized life; omitted channels keep the stock behaviour. */
3
+ export interface VFXOverLife {
4
+ /** Additional angular velocity in radians/second, 2..32 samples, each -1000..1000. */
5
+ spin?: readonly number[];
6
+ /** Multiplier of the birth velocity, 2..32 samples, each 0..1000. Forces remain additive. */
7
+ speed?: readonly number[];
8
+ /** Multiplier of the birth size, 2..32 samples, each 0..1000. May grow beyond 1. */
9
+ size?: readonly number[];
10
+ /** Maximum world speed, 0..1,000,000 units/second, or 2..32 samples in that range. Default no limit. */
11
+ velocityLimit?: number | readonly number[];
12
+ }
13
+ /** GPU spin/speed/growth curves and velocity limiting, shared by billboard, mesh and ribbon consumers. */
14
+ export declare const overLife: VFXExtension<VFXOverLife>;
@@ -0,0 +1,94 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ //#region src/over-life.ts
3
+ var t = 27, n = /var p=Particle\(particles\[at\],particles\[at\+1\],[^;]*\);/, r = (t, n, r) => {
4
+ if (t.split(n).length !== 2) throw new e("unsupported", "VFX over-life needs its simulation shader; update the lifetime edits");
5
+ return t.replace(n, r);
6
+ }, i = (e) => `struct OverLife {counts:vec4u,values:array<vec4f,32>}
7
+ @group(0) @binding(${e}) var<uniform> lifeCurves:OverLife;
8
+ fn lifeValue(channel:u32,t:f32)->f32 {
9
+ let n=lifeCurves.counts[channel];if(n==0u){return select(1.0,0.0,channel==0u);}
10
+ let x=clamp(t,0.0,1.0)*f32(n-1u);let k=min(u32(x),n-2u);let base=channel*8u;
11
+ let a=lifeCurves.values[base+k/4u][k%4u];let j=k+1u;let b=lifeCurves.values[base+j/4u][j%4u];return mix(a,b,x-f32(k));
12
+ }
13
+ `, a = `@group(0) @binding(26) var<storage,read_write> lifeBirth:array<vec4f>;
14
+ ${i(27)}`, o = `${i(t)}fn spinIntegral(t:f32)->f32 {
15
+ let n=lifeCurves.counts.x;if(n<2u){return 0.0;}let end=clamp(t,0.0,1.0);var sum=0.0;
16
+ for(var k=0u;k+1u<n;k++){let a=f32(k)/f32(n-1u);let b=min(end,f32(k+1u)/f32(n-1u));if(b>a){sum+=(lifeValue(0u,a)+lifeValue(0u,b))*(b-a)*0.5;}}
17
+ return sum;
18
+ }
19
+ fn drawnSpin(life:f32,left:f32)->f32 {return select(0.0,life*spinIntegral(1-left/life),life>0);}
20
+ `, s = "let angle=p.rotation.x+p.rotation.y*(p.rotation.z-p.positionLife.w);", c = {
21
+ validate(e) {
22
+ if (!e || typeof e != "object" || !Object.keys(e).some((e) => [
23
+ "spin",
24
+ "speed",
25
+ "size",
26
+ "velocityLimit"
27
+ ].includes(e))) throw TypeError("VFX overLife needs a curve or velocityLimit; pass {size: [1, 2]}");
28
+ for (let t of [
29
+ "spin",
30
+ "speed",
31
+ "size",
32
+ "velocityLimit"
33
+ ]) {
34
+ let n = e[t];
35
+ if (n === void 0) continue;
36
+ let r = t === "spin" ? -1e3 : 0, i = t === "velocityLimit" ? 1e6 : 1e3, a = t === "velocityLimit" && typeof n == "number" ? [n, n] : n;
37
+ if (!Array.isArray(a) || a.length < 2 || a.length > 32) throw TypeError(`VFX overLife ${t} needs 2..32 samples; pass a sampled curve`);
38
+ if (!a.every((e) => typeof e == "number" && Number.isFinite(e) && e >= r && e <= i)) throw RangeError(`VFX overLife ${t} samples must be ${r}..${i}; pass finite values in range`);
39
+ }
40
+ },
41
+ simulation(e) {
42
+ let t = n.exec(e)?.[0] ?? "";
43
+ return e = r(e, t, t + "var coldLife=particles[cold+1].z;var birthNow=lifeBirth[i];"), e.includes("var<uniform> space:Space;") && (e = r(e, " p.positionLife.w-=dt;", " if(p.positionLife.w>0 && space.births.w>0){birthNow=vec4f((space.delta*vec4f(birthNow.xyz,0)).xyz,birthNow.w);lifeBirth[i]=birthNow;}\n p.positionLife.w-=dt;")), e = e.replace("fn update(", a + "fn update("), e = r(e, " particles[cold]=p.color;particles[cold+1]=p.rotation;", " lifeBirth[i]=p.velocitySize;birthNow=p.velocitySize;coldLife=p.rotation.z;\n p.velocitySize=vec4f(p.velocitySize.xyz*lifeValue(1u,0.0),p.velocitySize.w);\n particles[cold]=p.color;particles[cold+1]=p.rotation;"), r(e, " p.positionLife=vec4f(p.positionLife.xyz+p.velocitySize.xyz*dt,p.positionLife.w);", " let totalLife=coldLife;let age=clamp(1-p.positionLife.w/totalLife,0.0,1.0);\n let previousAge=max(0.0,age-dt/totalLife);let birth=birthNow;\n var velocity=p.velocitySize.xyz+birth.xyz*(lifeValue(1u,age)-lifeValue(1u,previousAge));\n let cap=lifeValue(3u,age);let speed=length(velocity);\n if(lifeCurves.counts.w>0u && speed>cap){velocity*=cap/max(speed,1e-20);}\n p.velocitySize=vec4f(velocity,birth.w*lifeValue(2u,age));\n p.positionLife=vec4f(p.positionLife.xyz+p.velocitySize.xyz*dt,p.positionLife.w);");
44
+ },
45
+ billboard(t) {
46
+ if (t.split(s).length !== 2) throw new e("unsupported", "VFX over-life spin needs the billboard angle; update the spin edit");
47
+ return t.replace(s, s.replace(";", "+drawnSpin(p.rotation.z,p.positionLife.w);")).replace("@vertex fn vertex(", o + "@vertex fn vertex(");
48
+ },
49
+ create(e, n, r) {
50
+ let i = e.device.createBuffer({
51
+ size: e.capacity * 16,
52
+ usage: 136
53
+ });
54
+ r.push(i);
55
+ let a = e.device.createBuffer({
56
+ size: 528,
57
+ usage: 72
58
+ });
59
+ r.push(a);
60
+ let s = /* @__PURE__ */ new Float32Array(132), c = new Uint32Array(s.buffer, 0, 4), l = {
61
+ binding: t,
62
+ resource: { buffer: a }
63
+ };
64
+ return e.spin = {
65
+ code: o,
66
+ entry: l
67
+ }, {
68
+ render: [l],
69
+ compute: [{
70
+ binding: 26,
71
+ resource: { buffer: i }
72
+ }, {
73
+ binding: 27,
74
+ resource: { buffer: a }
75
+ }],
76
+ write(t) {
77
+ let n = e.options.overLife ?? {};
78
+ s.fill(0);
79
+ for (let [e, t] of [
80
+ "spin",
81
+ "speed",
82
+ "size",
83
+ "velocityLimit"
84
+ ].entries()) {
85
+ let r = n[t], i = typeof r == "number" ? [r, r] : r;
86
+ i && (c[e] = i.length, s.set(i, 4 + e * 32));
87
+ }
88
+ t.device.queue.writeBuffer(a, 0, s);
89
+ }
90
+ };
91
+ }
92
+ };
93
+ //#endregion
94
+ export { c as overLife };
@@ -0,0 +1,69 @@
1
+ //#region ../shared/reactive-mask.js
2
+ var e = Symbol.for("margoengine.optional.reactive-mask"), t = Symbol.for("margoengine.optional.reactive-mask.demand"), n = Symbol.for("margoengine.optional.reactive-mask.target"), r = /* @__PURE__ */ new WeakMap();
3
+ function i(t, n) {
4
+ let r = t[e];
5
+ r && r.encoder === t.encoder && r.view === t.view ? r.textures.includes(n) || r.textures.push(n) : t[e] = {
6
+ encoder: t.encoder,
7
+ view: t.view,
8
+ textures: [n]
9
+ };
10
+ }
11
+ function a(e, n) {
12
+ let i = e[t], a = r.get(n);
13
+ return a || r.set(n, a = {
14
+ encoder: void 0,
15
+ reads: void 0,
16
+ wanted: !1
17
+ }), a.encoder !== e.encoder && (a.wanted = i !== void 0 && a.reads !== i, a.reads = i, a.encoder = e.encoder), a.wanted;
18
+ }
19
+ function o(e) {
20
+ let t = e.descriptor.multisample?.count ?? 1, r = e[n];
21
+ if (!r || r.device !== e.device || r.width !== e.width || r.height !== e.height || r.samples !== t) {
22
+ r?.mask.destroy(), r?.multi?.destroy();
23
+ let i = GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING, a = [e.width, e.height];
24
+ r = e[n] = {
25
+ device: e.device,
26
+ width: e.width,
27
+ height: e.height,
28
+ samples: t,
29
+ mask: e.device.createTexture({
30
+ label: "reactive particle mask",
31
+ size: a,
32
+ format: "r8unorm",
33
+ usage: i
34
+ }),
35
+ multi: t > 1 ? e.device.createTexture({
36
+ label: "reactive particle mask (multisampled)",
37
+ size: a,
38
+ format: "r8unorm",
39
+ sampleCount: t,
40
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
41
+ }) : void 0,
42
+ encoder: void 0,
43
+ view: void 0
44
+ }, r.maskView = r.mask.createView(), r.multiView = r.multi?.createView();
45
+ }
46
+ let a = r.encoder !== e.encoder || r.view !== e.view;
47
+ return r.encoder = e.encoder, r.view = e.view, i(e, r.mask), {
48
+ view: r.multiView ?? r.maskView,
49
+ resolveTarget: r.multi ? r.maskView : void 0,
50
+ loadOp: a ? "clear" : "load",
51
+ clearValue: [
52
+ 0,
53
+ 0,
54
+ 0,
55
+ 0
56
+ ],
57
+ storeOp: "store"
58
+ };
59
+ }
60
+ var s = {
61
+ operation: "max",
62
+ srcFactor: "one",
63
+ dstFactor: "one"
64
+ }, c = {
65
+ color: s,
66
+ alpha: s
67
+ };
68
+ //#endregion
69
+ export { a as n, o as r, c as t };
@@ -0,0 +1,7 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ //#region ../shared/require-webgpu.js
3
+ function t(t, n) {
4
+ if (t.backend === "webgl2" || !t.gpu) throw new e("unsupported", `${n} needs WebGPU; see https://margoengine.com/errors#webgpu`);
5
+ }
6
+ //#endregion
7
+ export { t };
@@ -0,0 +1,22 @@
1
+ import type { VFXExtension, VFXRibbons } from './base.js';
2
+ /** Most recorded points across all of an effect's ribbons: capacity x (points - 1), 16 bytes each (64 MB). */
3
+ export declare const MAX_RIBBON_POINTS = 4194304;
4
+ /**
5
+ * One triangle strip per slot: vertex 2k and 2k+1 are the two edges at point k (0: the particle, k >= 1: k records
6
+ * back). Records of this life are the newest ones with its stamp, a run that starts at record 1 because every record
7
+ * since its birth stored it, so a binary search finds the run's length; points past it collapse onto the oldest point,
8
+ * so a young particle's ribbon is shorter. A dead slot is moved outside the clip volume. The strip's side is
9
+ * perpendicular to the ribbon (the neighbours' difference, or the next pair's where the newest record is the particle
10
+ * itself) and to the eye, so it shows its face; where neither gives a direction the strip has no width. Alpha falls from the particle's own (with its life
11
+ * fade) at the head to 0 at the tail, and across the width as 1 - e^2 (e from -1 to 1). `reactive` writes that alpha
12
+ * as the strip's coverage of TAA's reactive mask.
13
+ */
14
+ export declare const ribbonShader: string;
15
+ /**
16
+ * The `ribbons` feature: a camera-facing ribbon behind every particle through its last positions (`points`, recorded
17
+ * every `interval` seconds), for smoke and magic trails. Pass it as `{ribbons}` to `VFX` from `@margoengine/vfx/base`;
18
+ * the root `VFX` has it. Ribbons draw after the billboards in their own pass, alpha blended and depth tested, in slot
19
+ * order; `heads: false` leaves the billboards out. Like the billboards, the strips draw their coverage into the frame's
20
+ * shared reactive mask while TAA reads masks (the effect's `reactive` option), as they have no motion vectors.
21
+ */
22
+ export declare const ribbons: VFXExtension<VFXRibbons>;
@@ -0,0 +1,165 @@
1
+ import { t as e } from "./frame-BuvMFBPp.js";
2
+ import { t } from "./view-rect-DkeiiUtw.js";
3
+ import { n, r, t as i } from "./reactive-mask-B8xbyzlk.js";
4
+ //#region src/ribbons.ts
5
+ var a = 4194304, o = "\nstruct Ribbon {control:vec4u,shape:vec4f,eye:vec4f}\n@group(0) @binding(14) var<uniform> ribbon:Ribbon;\n", s = `
6
+ @group(0) @binding(13) var<storage,read_write> ribbonHistory:array<vec4f>;
7
+ ${o}
8
+ @compute @workgroup_size(256) fn ribbonRecord(@builtin(global_invocation_id) id:vec3u){
9
+ if(id.x>=f.control.x){return;}let p=particles[id.x*2];if(p.w<=0){return;}
10
+ ribbonHistory[id.x*ribbon.control.z+(ribbon.control.x-1u)%ribbon.control.z]=vec4f(p.xyz,particles[f.control.x*2+id.x*2+1].x+1);
11
+ }`, c = e + `
12
+ @group(0) @binding(1) var<storage,read> particles:array<vec4f>;
13
+ @group(0) @binding(13) var<storage,read> ribbonHistory:array<vec4f>;
14
+ ${o}
15
+ struct Out {@builtin(position) clip:vec4f,@location(0) color:vec4f,@location(1) edge:f32}
16
+ fn ribbonPoint(slot:u32,k:u32,head:vec3f)->vec3f {
17
+ if(k==0u){return head;}return ribbonHistory[slot*ribbon.control.z+(ribbon.control.x-k)%ribbon.control.z].xyz;
18
+ }
19
+ @vertex fn vertex(@builtin(vertex_index) v:u32,@builtin(instance_index) slot:u32)->Out {
20
+ var o:Out;let at=slot*2;let cold=f.control.x*2+at;let head=particles[at];let color=particles[cold];let rotation=particles[cold+1];
21
+ if(head.w<=0){o.clip=vec4f(2,2,2,1);return o;}
22
+ let stamp=rotation.x+1;var lo=0u;var hi=ribbon.control.y;
23
+ loop{if(lo>=hi){break;}let mid=(lo+hi+1u)/2u;if(ribbonHistory[slot*ribbon.control.z+(ribbon.control.x-mid)%ribbon.control.z].w==stamp){lo=mid;}else{hi=mid-1u;}}
24
+ let k=min(v/2u,lo);let p=ribbonPoint(slot,k,head.xyz);
25
+ var t=ribbonPoint(slot,max(k,1u)-1u,head.xyz)-ribbonPoint(slot,min(k+1u,lo),head.xyz);
26
+ if(dot(t,t)<1e-12){t=ribbonPoint(slot,max(k,2u)-2u,head.xyz)-ribbonPoint(slot,min(k+2u,lo),head.xyz);}
27
+ let side=cross(t,ribbon.eye.xyz-p);let s=dot(side,side);
28
+ let e=f32(v%2u)*2-1;o.edge=e;
29
+ o.clip=f.camera*vec4f(p+side*inverseSqrt(max(s,1e-24))*select(0.0,e*ribbon.shape.x*0.5,s>1e-12),1);
30
+ o.color=vec4f(color.rgb,color.a*clamp(head.w/rotation.z,0.0,1.0)*(1-f32(v/2u)/f32(ribbon.control.w-1u)));return o;
31
+ }
32
+ @fragment fn fragment(i:Out)->@location(0) vec4f {return vec4f(i.color.rgb,i.color.a*(1-i.edge*i.edge));}
33
+ @fragment fn reactive(i:Out)->@location(0) vec4f {return vec4f(clamp(i.color.a*(1-i.edge*i.edge),0.0,1.0),0,0,1);}`, l = (e) => e.points ?? 16, u = {
34
+ validate(e, t) {
35
+ if (!e || typeof e != "object") throw TypeError("VFX ribbons must be an object; pass e.g. {points: 16, interval: 1 / 60}");
36
+ let n = l(e), r = e.interval ?? 1 / 60;
37
+ if (!Number.isInteger(n) || n < 2 || n > 64) throw RangeError(`VFX ribbons points is ${n}; pass a whole number from 2 to 64`);
38
+ if (typeof r != "number" || !(r >= 0 && r <= 1)) throw RangeError("VFX ribbons interval must be 0 to 1 seconds; pass e.g. 1 / 60, or 0 for every frame");
39
+ if (e.width !== void 0 && !(typeof e.width == "number" && Number.isFinite(Math.fround(e.width)) && e.width > 0)) throw RangeError("VFX ribbons width must be a world distance above 0; pass e.g. 0.1");
40
+ if (e.heads !== void 0 && typeof e.heads != "boolean") throw TypeError("VFX ribbons heads must be true or false; pass a boolean");
41
+ if ((t.capacity ?? 1e6) * (n - 1) > 4194304) throw RangeError(`VFX ribbons need capacity x (points - 1) at most ${a}; lower capacity or points`);
42
+ },
43
+ simulation: (e) => e + s,
44
+ create(e, a, o) {
45
+ let { device: s, capacity: u, options: d } = e, f = l(a), p = f - 1, m = s.createBuffer({
46
+ size: u * p * 16,
47
+ usage: GPUBufferUsage.STORAGE
48
+ });
49
+ o.push(m);
50
+ let h = s.createBuffer({
51
+ size: 48,
52
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
53
+ });
54
+ o.push(h);
55
+ let g = s.createComputePipeline({
56
+ layout: "auto",
57
+ compute: {
58
+ module: e.module,
59
+ entryPoint: "ribbonRecord"
60
+ }
61
+ }), _ = (t) => s.createBindGroup({
62
+ layout: t,
63
+ entries: [
64
+ {
65
+ binding: 0,
66
+ resource: { buffer: e.uniform }
67
+ },
68
+ {
69
+ binding: 1,
70
+ resource: { buffer: e.particles }
71
+ },
72
+ {
73
+ binding: 13,
74
+ resource: { buffer: m }
75
+ },
76
+ {
77
+ binding: 14,
78
+ resource: { buffer: h }
79
+ }
80
+ ]
81
+ }), v = _(g.getBindGroupLayout(0)), y = /* @__PURE__ */ new Float32Array(12), b = new Uint32Array(y.buffer), x = /* @__PURE__ */ new Map(), S = {
82
+ view: void 0,
83
+ loadOp: "load",
84
+ storeOp: "store"
85
+ }, C = {
86
+ view: void 0,
87
+ depthReadOnly: !0
88
+ }, w = {
89
+ colorAttachments: [S],
90
+ depthStencilAttachment: C
91
+ }, T = [], E = {
92
+ colorAttachments: T,
93
+ depthStencilAttachment: C
94
+ }, D = {}, O, k = 0, A = Infinity, j = !1, M = () => {
95
+ let e = d.ribbons;
96
+ if (!e || l(e) !== f) throw TypeError("VFX ribbons and their points are fixed at attach; attach a new VFX to change them");
97
+ return e;
98
+ };
99
+ return {
100
+ reset() {
101
+ s.queue.writeBuffer(m, 0, new Uint8Array(m.size)), k = 0, A = Infinity;
102
+ },
103
+ hides: () => M().heads === !1,
104
+ write(e) {
105
+ let t = M(), n = t.interval ?? 1 / 60;
106
+ A += e.delta, j = A >= n, j && (k++, A = A - n >= n ? 0 : A - n), b[0] = k, b[1] = Math.min(k, p), b[2] = p, b[3] = f, y[4] = t.width ?? d.size ?? .1, y.set(e.camera.position, 8), e.device.queue.writeBuffer(h, 0, y);
107
+ },
108
+ run(e) {
109
+ j && (e.setPipeline(g), e.setBindGroup(0, v), e.dispatchWorkgroups(Math.ceil(u / 256)));
110
+ },
111
+ draw(a) {
112
+ let o = a.descriptor.depthStencil.format, l = a.descriptor.multisample?.count ?? 1, p = a.format + ":" + o + ":" + l, m = (e) => {
113
+ let t = x.get(p + (e ? ":reactive" : ""));
114
+ if (!t) {
115
+ O ??= s.createShaderModule({ code: c });
116
+ let n = s.createRenderPipeline({
117
+ layout: "auto",
118
+ vertex: {
119
+ module: O,
120
+ entryPoint: "vertex"
121
+ },
122
+ fragment: {
123
+ module: O,
124
+ entryPoint: e ? "reactive" : "fragment",
125
+ targets: [e ? {
126
+ format: "r8unorm",
127
+ blend: i
128
+ } : {
129
+ format: a.format,
130
+ blend: {
131
+ color: {
132
+ srcFactor: "src-alpha",
133
+ dstFactor: "one-minus-src-alpha"
134
+ },
135
+ alpha: {
136
+ srcFactor: "one",
137
+ dstFactor: "one-minus-src-alpha"
138
+ }
139
+ }
140
+ }]
141
+ },
142
+ primitive: { topology: "triangle-strip" },
143
+ multisample: a.descriptor.multisample,
144
+ depthStencil: {
145
+ format: o,
146
+ depthWriteEnabled: !1,
147
+ depthCompare: "greater-equal"
148
+ }
149
+ });
150
+ t = [n, _(n.getBindGroupLayout(0))], x.set(p + (e ? ":reactive" : ""), t);
151
+ }
152
+ return t;
153
+ };
154
+ S.view = a.color, C.view = a.depth, C.stencilReadOnly = o.includes("stencil") ? !0 : void 0;
155
+ let h = (n, [r, i]) => {
156
+ let o = a.encoder.beginRenderPass(n);
157
+ o.setPipeline(r), o.setBindGroup(0, i), t(o, a), o.draw(f * 2, u), o.end(), e.stats.drawCalls++;
158
+ };
159
+ h(w, m(!1)), (d.reactive ?? n(a, D)) && (T[0] = r(a), h(E, m(!0)));
160
+ }
161
+ };
162
+ }
163
+ };
164
+ //#endregion
165
+ export { a as MAX_RIBBON_POINTS, c as ribbonShader, u as ribbons };
@@ -0,0 +1,29 @@
1
+ import type { VFXExtension } from './base.js';
2
+ /** Most expanded burst cycles in an effect; bounds authoring and replay work. */
3
+ export declare const MAX_BURST_EVENTS = 16384;
4
+ /** A repeated timed birth event. All settings are captured at attachment. */
5
+ export interface VFXScheduledBurst {
6
+ /** Seconds from effect start, 0..1,000,000. */
7
+ time: number;
8
+ /** Birth count, whole 0..capacity; total frame births are capped by capacity/dead slots. */
9
+ count: number;
10
+ /** Whole repetitions, 1..16,384. Default 1. */
11
+ cycles?: number;
12
+ /** Seconds between repetitions, 0..1,000,000. Default 0. */
13
+ interval?: number;
14
+ /** Independent chance per repetition, 0..1. Default 1. */
15
+ probability?: number;
16
+ }
17
+ /** Deterministic prewarm and burst scheduling, fixed at attachment. Reset repeats the same schedule. */
18
+ export interface VFXSchedule {
19
+ /** Seconds to simulate before the first visible frame, 0..3600. Default 0. */
20
+ prewarm?: number;
21
+ /** Warmup step in seconds, 0.001..1, with at most 10,000 steps. Default 1/60. */
22
+ step?: number;
23
+ /** Up to 1024 burst definitions and 16,384 expanded cycles. Default empty. */
24
+ bursts?: readonly VFXScheduledBurst[];
25
+ /** Unsigned 32-bit seed for burst probabilities. Default 0. */
26
+ seed?: number;
27
+ }
28
+ /** Prewarm by ordinary submitted simulation steps, plus deterministic time/cycle/probability bursts. */
29
+ export declare const schedule: VFXExtension<VFXSchedule>;
@@ -0,0 +1,47 @@
1
+ import { t as e } from "./hash-Btsp6fGK.js";
2
+ //#region src/schedule.ts
3
+ var t = 16384, n = (e, t, n, r, i = !1) => {
4
+ if (typeof e != "number" || !Number.isFinite(e) || e < n || e > r || i && !Number.isInteger(e)) throw RangeError(`VFX schedule ${t} must be ${n}..${r}${i ? " whole" : ""}; pass a finite value in range`);
5
+ }, r = e, i = {
6
+ validate(e, r) {
7
+ if (!e || typeof e != "object") throw TypeError("VFX schedule needs an object; pass {prewarm: 1}");
8
+ if (n(e.prewarm ?? 0, "prewarm", 0, 3600), n(e.step ?? 1 / 60, "step", .001, 1), n(e.seed ?? 0, "seed", 0, 4294967295, !0), Math.ceil((e.prewarm ?? 0) / (e.step ?? 1 / 60)) > 1e4) throw RangeError("VFX prewarm exceeds 10000 steps; increase step or reduce duration");
9
+ if (e.bursts !== void 0 && (!Array.isArray(e.bursts) || e.bursts.length > 1024)) throw TypeError("VFX schedule bursts need at most 1024 definitions; pass an array");
10
+ let i = 0;
11
+ for (let a of e.bursts ?? []) {
12
+ if (!a || typeof a != "object") throw TypeError("VFX schedule burst needs time and count; pass an object");
13
+ n(a.time, "time", 0, 1e6), n(a.count, "count", 0, r.capacity ?? 1e6, !0), n(a.cycles ?? 1, "cycles", 1, t, !0), n(a.interval ?? 0, "interval", 0, 1e6), n(a.probability ?? 1, "probability", 0, 1), i += a.cycles ?? 1;
14
+ }
15
+ if (i > 16384) throw RangeError("VFX schedule exceeds 16384 burst cycles; reduce its repetitions");
16
+ },
17
+ create(e, t) {
18
+ let n = [];
19
+ for (let [e, i] of (t.bursts ?? []).entries()) for (let a = 0; a < (i.cycles ?? 1); a++) r((t.seed ?? 0) ^ r(e + 1) ^ Math.imul(a + 1, 2654435769)) / 4294967296 < (i.probability ?? 1) && n.push({
20
+ time: i.time + a * (i.interval ?? 0),
21
+ count: i.count
22
+ });
23
+ n.sort((e, t) => e.time - t.time);
24
+ let i = t.prewarm ?? 0, a = t.step ?? 1 / 60, o = 0, s = 0, c = !0;
25
+ return {
26
+ warmup(e) {
27
+ if (!c) return;
28
+ c = !1;
29
+ let t = Math.floor(i / a);
30
+ for (let n = 0; n < t; n++) e(a);
31
+ let n = i - t * a;
32
+ n > 0 && e(n);
33
+ },
34
+ emission(e) {
35
+ o += e;
36
+ let t = 0;
37
+ for (; s < n.length && n[s].time <= o;) t += n[s++].count;
38
+ return t;
39
+ },
40
+ reset() {
41
+ o = 0, s = 0, c = !0;
42
+ }
43
+ };
44
+ }
45
+ };
46
+ //#endregion
47
+ export { t as MAX_BURST_EVENTS, i as schedule };