@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
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
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 C=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
- import { n as e, t } from "./base-C9upJytz.js";
3
+ const C=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
4
+ import { n as e, t } from "./base-LGs65K7K.js";
5
5
  import { obstacles as n } from "./obstacles.js";
6
6
  import { wrap as r } from "./wrap.js";
7
7
  import { sort as i } from "./sort.js";
@@ -12,7 +12,7 @@ import { soft as c } from "./soft.js";
12
12
  import { ribbons as l } from "./ribbons.js";
13
13
  import { mesh as u } from "./mesh.js";
14
14
  import { events as d } from "./events.js";
15
- import { lit as f } from "./lit.js";
15
+ import { r as f } from "./lit-Dx2tNwP-.js";
16
16
  import { depthCollide as p } from "./depth-collide.js";
17
17
  import { stretch as m } from "./stretch.js";
18
18
  import { fields as h } from "./fields.js";
@@ -51,7 +51,7 @@ var w = {
51
51
  constructor(e = {}) {
52
52
  super(e, w);
53
53
  }
54
- static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("0.1.0",import.meta.url));
54
+ static attach(t, n = {}) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
55
55
  let r = new e(n);
56
56
  return C(t).use(r), r;
57
57
  }
package/dist/json.js CHANGED
@@ -21,10 +21,12 @@ var n = 1, r = {
21
21
  emissionExtent: !0,
22
22
  intensity: !0,
23
23
  clock: !0,
24
+ tick: !0,
24
25
  obstacles: !0,
25
26
  wrap: !0,
26
27
  sort: !0,
27
28
  softness: !0,
29
+ reactive: !0,
28
30
  depth: !0,
29
31
  texture: !0,
30
32
  curves: !0,
@@ -0,0 +1,152 @@
1
+ import { MargoError as e } from "@margoengine/math/errors";
2
+ Object.freeze({
3
+ forward: .85,
4
+ back: -.3,
5
+ backWeight: .15
6
+ });
7
+ var t = Object.freeze({
8
+ forward: .9,
9
+ back: -.3,
10
+ backWeight: .1
11
+ }), n = 21;
12
+ function r(t, n, r) {
13
+ if (t.split(n).length !== 2) throw new e("unsupported", "VFX lit needs the billboard shader it was written for; update the lit edits");
14
+ return t.replace(n, r);
15
+ }
16
+ var i = (e, t) => {
17
+ let i = !!t.lamps, a = r(e, "@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(8) litWorld:vec3f,@location(9) litSide:vec4f,");
18
+ a = r(a, "o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);let litHalf=p.velocitySize.w*0.5*grow;o.litWorld=position;o.litSide=vec4f((position-p.positionLife.xyz)/litHalf,litHalf);"), a = r(a, "@fragment fn fragment(i:Out)->@location(0) vec4f {", "@fragment fn fragment(i:Out)->@location(0) vec4f {return lit(i,unlit(i));}\nfn unlit(i:Out)->vec4f {");
19
+ let o = "base*litFrame.sunColor.rgb*(max(0.0,dot(n,litFrame.sun.xyz)+wrap)/(1.0+wrap)*0.31830989)";
20
+ return a + `
21
+ struct LitFrame {sun:vec4f,sunColor:vec4f,ambient:vec4f,eye:vec4f,glow:vec4f,glowColor:vec4f,air:vec4f,airBack:vec4f${i ? ",lamp:vec4f" : ""}}
22
+ @group(0) @binding(${n}) var<uniform> litFrame:LitFrame;
23
+ fn lit(i:Out,c:vec4f)->vec4f {
24
+ let toward=cross(f.right.xyz,f.up.xyz);let z=sqrt(max(0.0,1.0-dot(i.uv,i.uv)));
25
+ let n=normalize(i.litSide.xyz+toward*z);let p=i.litWorld+toward*(z*i.litSide.w);let base=c.rgb;let wrap=litFrame.sunColor.w;
26
+ let up=n.y;let g=litFrame.ambient.w;let r=litFrame.airBack.rgb;
27
+ let sky=litFrame.ambient.rgb*((1.0+up)+g*(1.0-up))/(1.0+g);
28
+ let air=litFrame.air.rgb*((1.0-up)+r*(1.0+up))/(1.0+r);
29
+ var light=base*(sky+air)+${t.shadows ? `shadowLit(${o},p,n)` : o};
30
+ ${t.lights ? "light+=clusterLighting(i.clip.xy,p,n,litFrame.eye.xyz,base,1.0,0.0,vec3f(0.04),1.0);" : ""}
31
+ ${i ? "light+=base*lampScatter(i.clip.xy,p,normalize(litFrame.eye.xyz-p),litFrame.lamp);" : ""}
32
+
33
+
34
+
35
+ let toGlow=litFrame.glow.xyz-p;let d2=dot(toGlow,toGlow);
36
+ let e=litFrame.glowColor.w/(12566.37*(d2+litFrame.glow.w*litFrame.glow.w));
37
+ light+=base*litFrame.glowColor.rgb*(e*max(0.0,dot(n,toGlow*inverseSqrt(max(d2,1e-6)))+wrap)/(1.0+wrap));
38
+ return vec4f(light,c.a);
39
+ }
40
+ `;
41
+ };
42
+ function a(e, t) {
43
+ if (e !== void 0 && (!e || typeof e.pbr != "function" || typeof e.bindings != "function")) throw TypeError(`VFX lit ${t} must be ${t === "lights" ? "Clustered" : "Shadows"} or have pbr and bindings`);
44
+ }
45
+ var o = 0, s = [
46
+ 1,
47
+ .42,
48
+ .12
49
+ ];
50
+ function c(e) {
51
+ if (e === void 0) return;
52
+ let t = (e, t, n) => typeof e == "number" && Number.isFinite(e) && e >= t && e <= n;
53
+ if (!e || typeof e != "object" || !Array.isArray(e.position) || e.position.length !== 3 || !e.position.every((e) => t(e, -1e7, 1e7)) || !t(e.power, 0, 0x9184e72a000) || e.radius !== void 0 && !t(e.radius, .01, 1e5) || e.color !== void 0 && (!Array.isArray(e.color) || e.color.length !== 3 || !e.color.every((e) => t(e, 0, 16)))) throw RangeError("VFX lit glow needs {position: [x, y, z], power: watts 0 to 1e13, radius?: 0.01 to 1e5 m, color?: linear [r, g, b] 0 to 16}");
54
+ }
55
+ function l(e) {
56
+ if (e !== void 0 && (!Array.isArray(e) || e.length !== 3 || !e.every((e) => typeof e == "number" && Number.isFinite(e) && e >= 0 && e <= 1e3))) throw RangeError("VFX lit air must be [r, g, b] shares of the noon sun's light, each 0 to 1000; pass e.g. [0.002, 0.0008, 0.0002]");
57
+ }
58
+ var u = [
59
+ .337,
60
+ .306,
61
+ .268
62
+ ];
63
+ function d(e) {
64
+ if (e.ground !== void 0 && !(typeof e.ground == "number" && e.ground >= 0 && e.ground <= 1)) throw RangeError("VFX lit ground must be the ground's albedo, 0 to 1; pass e.g. 0.2");
65
+ let t = e.airReflectance;
66
+ if (t !== void 0 && (!Array.isArray(t) || t.length !== 3 || !t.every((e) => typeof e == "number" && e >= 0 && e <= 1))) throw RangeError("VFX lit airReflectance must be [r, g, b] reflectances of the layer over the particles, each 0 to 1; pass e.g. [0.34, 0.31, 0.27]");
67
+ }
68
+ function f(e) {
69
+ let t = (e, t, n) => e === void 0 || typeof e == "number" && Number.isFinite(e) && e >= t && e <= n;
70
+ if (!t(e.lampAlbedo, 0, 1)) throw RangeError("VFX lit lampAlbedo must be 0 to 1; pass e.g. 1");
71
+ let n = e.lampPhase;
72
+ if (n !== void 0 && (!n || typeof n != "object" || !t(n.forward, -.99, .99) || !t(n.back, -.99, .99) || !t(n.backWeight, 0, 1))) throw RangeError("VFX lit lampPhase must be {forward, back: g -0.99 to 0.99, backWeight: 0 to 1}; pass e.g. {forward: 0.9}");
73
+ }
74
+ function p(e) {
75
+ if (e !== void 0 && !(typeof e == "number" && Number.isFinite(e) && e > 0 && e <= 1e7)) throw RangeError("VFX lit noon must be the noon sun's engine intensity, above 0 and at most 1e7; pass e.g. 1");
76
+ }
77
+ var m = {
78
+ validate(e) {
79
+ if (!e || typeof e != "object") throw TypeError("VFX lit must be an object; pass {} for the sun, or {lights, shadows}");
80
+ if (a(e.lights, "lights"), a(e.shadows, "shadows"), e.lamps !== void 0) {
81
+ if (!e.lamps || typeof e.lamps.lamps != "function") throw TypeError("VFX lit lamps must be a Clustered (@margoengine/clustered); pass the lamps the scene uses");
82
+ if (e.lights) throw TypeError("VFX lit takes its clustered lights as lights (shaded as balls) or lamps (scattered), not both");
83
+ }
84
+ if (f(e), e.wrap !== void 0 && !(typeof e.wrap == "number" && e.wrap >= 0 && e.wrap <= 1)) throw RangeError("VFX lit wrap must be 0 to 1; pass e.g. 0.5");
85
+ let t = e.ambient;
86
+ if (t !== void 0 && (!Array.isArray(t) || t.length !== 3 || !t.every((e) => typeof e == "number" && e >= 0 && e <= 16))) throw RangeError("VFX lit ambient must be linear [r, g, b], each 0 to 16");
87
+ c(e.glow), p(e.noon), l(e.air), d(e);
88
+ },
89
+ billboard: (e, t) => i(e, t),
90
+ create(e, r, i) {
91
+ let { device: a, options: m } = e, h = r.lamps ? 144 : 128, g = a.createBuffer({
92
+ size: h,
93
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
94
+ });
95
+ i.push(g);
96
+ let _ = new Float32Array(h / 4), v = !!(r.lights || r.shadows || r.lamps), y = /* @__PURE__ */ new Map(), b = /* @__PURE__ */ new WeakMap(), x = (e) => {
97
+ let t = (r.lights?.pbr(e) ?? r.lamps?.lamps(e))?.declarations ?? "", n = r.shadows?.pbr(e).declarations ?? "", i = y.get(e);
98
+ return (!i || i.lights !== t || i.shadows !== n) && y.set(e, i = {
99
+ lights: t,
100
+ shadows: n,
101
+ key: ":lit" + ++o
102
+ }), i;
103
+ };
104
+ return {
105
+ render: [{
106
+ binding: n,
107
+ resource: { buffer: g }
108
+ }],
109
+ write(n) {
110
+ if (m.lit !== r) throw TypeError("VFX lit is fixed at attach; change its wrap or ambient in place or attach a new VFX");
111
+ let { direction: i, radiance: a, ambient: o } = e.engine.lighting, h = Math.hypot(i[0], i[1], i[2]), v = h > 0 ? Math.max(0, i[3]) : 0;
112
+ for (let e = 0; e < 3; e++) _[e] = v ? i[e] / h : 0, _[4 + e] = a[e] * v, _[8 + e] = r.ambient ? r.ambient[e] : a[3] * o[e], _[12 + e] = n.camera.position[e];
113
+ l(r.air), d(r), _.fill(0, 24, 32);
114
+ let y = r.airReflectance ?? u;
115
+ for (let e = 0; e < 3; e++) r.air && (_[24 + e] = r.air[e] * (r.noon ?? Math.PI) / Math.PI), _[28 + e] = y[e];
116
+ _[11] = r.ground ?? .2, _[7] = r.wrap ?? .5;
117
+ let b = r.glow;
118
+ if (c(b), p(r.noon), _.fill(0, 16, 24), b && b.power > 0) {
119
+ let e = b.color ?? s;
120
+ for (let t = 0; t < 3; t++) _[16 + t] = b.position[t], _[20 + t] = e[t];
121
+ _[19] = b.radius ?? 1, _[23] = b.power * (r.noon ?? Math.PI) / Math.PI;
122
+ }
123
+ if (r.lamps) {
124
+ f(r);
125
+ let e = r.lampPhase;
126
+ _[32] = e?.forward ?? t.forward, _[33] = e?.back ?? t.back, _[34] = e?.backWeight ?? t.backWeight, _[35] = r.lampAlbedo ?? 1;
127
+ }
128
+ n.device.queue.writeBuffer(g, 0, _);
129
+ },
130
+ ...v ? {
131
+ key: (e) => x(e).key,
132
+ shade(e, t) {
133
+ let n = x(t);
134
+ return n.lights + n.shadows + e;
135
+ },
136
+ bind(e, t, n) {
137
+ let i = r.lights?.bindings() ?? r.lamps?.lamps(n).bindings(), o = r.shadows?.bindings(), s = b.get(t);
138
+ (!s || s.lights !== i || s.shadows !== o) && b.set(t, s = {
139
+ lights: i,
140
+ shadows: o,
141
+ group: a.createBindGroup({
142
+ layout: t.getBindGroupLayout(n),
143
+ entries: [...i ?? [], ...o ?? []]
144
+ })
145
+ }), e.setBindGroup(n, s.group);
146
+ }
147
+ } : {}
148
+ };
149
+ }
150
+ };
151
+ //#endregion
152
+ export { u as n, m as r, s as t };
package/dist/lit.d.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  import type { VFXExtension, VFXLit } from './base.js';
2
2
  /** A flame's colour as light, linear RGB (a 1,300 K blackbody's hue, as the flame ramp's edge). */
3
3
  export declare const GLOW_COLOR: readonly [number, number, number];
4
+ /**
5
+ * The reflectance of a thick smoke pall, red, green and blue (670, 550 and 440 nm): the two-stream slab reflection of
6
+ * Meador and Weaver (1980) for wildfire smoke, as `hazeReflectance({smoke: 1})` of `@margoengine/weather` gives it.
7
+ * The share of the air's light that the pall over a column sends back down onto its puffs when none is given.
8
+ */
9
+ export declare const PALL_REFLECTANCE: readonly [number, number, number];
4
10
  /**
5
11
  * The `lit` feature: billboards lit by the engine's sun (with wrap lighting), its ambient light, `Clustered` point and
6
- * spot lights and `Shadows` sun shadows, shaded as balls so smoke and dust take light from the side it comes from.
12
+ * spot lights and `Shadows` sun shadows, shaded as balls so smoke and dust take light from the side it comes from, or
13
+ * the `Clustered` lamps scattered with a phase function (`lamps`) so spray glows round the lamps it flies past.
7
14
  * Pass it as `{lit}` to `VFX` from `@margoengine/vfx/base`; the root `VFX` has it. `lights` and `shadows` are read at
8
15
  * attach; `wrap` and `ambient` every frame. Under an order-independent pass (`addEffect` from `@margoengine/oit/vfx`)
9
16
  * the particles are lit the same: the pass's declarations take bind group 1 and the lights and shadows group 2.
package/dist/lit.js CHANGED
@@ -1,105 +1 @@
1
- import { MargoError as e } from "@margoengine/math/errors";
2
- //#region src/lit.ts
3
- var t = 21;
4
- function n(t, n, r) {
5
- if (t.split(n).length !== 2) throw new e("unsupported", "VFX lit needs the billboard shader it was written for; update the lit edits");
6
- return t.replace(n, r);
7
- }
8
- var r = (e, r) => {
9
- let i = n(e, "@location(0) uv:vec2f,", "@location(0) uv:vec2f,@location(8) litWorld:vec3f,@location(9) litSide:vec4f,");
10
- i = n(i, "o.clip=f.camera*vec4f(position,1);", "o.clip=f.camera*vec4f(position,1);let litHalf=p.velocitySize.w*0.5*grow;o.litWorld=position;o.litSide=vec4f((position-p.positionLife.xyz)/litHalf,litHalf);"), i = n(i, "@fragment fn fragment(i:Out)->@location(0) vec4f {", "@fragment fn fragment(i:Out)->@location(0) vec4f {return lit(i,unlit(i));}\nfn unlit(i:Out)->vec4f {");
11
- let a = "base*litFrame.sunColor.rgb*(max(0.0,dot(n,litFrame.sun.xyz)+wrap)/(1.0+wrap)*0.31830989)";
12
- return i + `
13
- struct LitFrame {sun:vec4f,sunColor:vec4f,ambient:vec4f,eye:vec4f,glow:vec4f,glowColor:vec4f}
14
- @group(0) @binding(${t}) var<uniform> litFrame:LitFrame;
15
- fn lit(i:Out,c:vec4f)->vec4f {
16
- let toward=cross(f.right.xyz,f.up.xyz);let z=sqrt(max(0.0,1.0-dot(i.uv,i.uv)));
17
- let n=normalize(i.litSide.xyz+toward*z);let p=i.litWorld+toward*(z*i.litSide.w);let base=c.rgb;let wrap=litFrame.sunColor.w;
18
- var light=base*litFrame.ambient.rgb+${r.shadows ? `shadowLit(${a},p,n)` : a};
19
- ${r.lights ? "light+=clusterLighting(i.clip.xy,p,n,litFrame.eye.xyz,base,1.0,0.0,vec3f(0.04),1.0);" : ""}
20
-
21
-
22
- let toGlow=litFrame.glow.xyz-p;let d2=dot(toGlow,toGlow);
23
- let e=litFrame.glowColor.w/(12566.37*(d2+litFrame.glow.w*litFrame.glow.w));
24
- light+=base*litFrame.glowColor.rgb*(e*max(0.0,dot(n,toGlow*inverseSqrt(max(d2,1e-6)))+wrap)/(1.0+wrap));
25
- return vec4f(light,c.a);
26
- }
27
- `;
28
- };
29
- function i(e, t) {
30
- if (e !== void 0 && (!e || typeof e.pbr != "function" || typeof e.bindings != "function")) throw TypeError(`VFX lit ${t} must be ${t === "lights" ? "Clustered" : "Shadows"} or have pbr and bindings`);
31
- }
32
- var a = 0, o = [
33
- 1,
34
- .42,
35
- .12
36
- ];
37
- function s(e) {
38
- if (e === void 0) return;
39
- let t = (e, t, n) => typeof e == "number" && Number.isFinite(e) && e >= t && e <= n;
40
- if (!e || typeof e != "object" || !Array.isArray(e.position) || e.position.length !== 3 || !e.position.every((e) => t(e, -1e7, 1e7)) || !t(e.power, 0, 0x9184e72a000) || e.radius !== void 0 && !t(e.radius, .01, 1e5) || e.color !== void 0 && (!Array.isArray(e.color) || e.color.length !== 3 || !e.color.every((e) => t(e, 0, 16)))) throw RangeError("VFX lit glow needs {position: [x, y, z], power: watts 0 to 1e13, radius?: 0.01 to 1e5 m, color?: linear [r, g, b] 0 to 16}");
41
- }
42
- var c = {
43
- validate(e) {
44
- if (!e || typeof e != "object") throw TypeError("VFX lit must be an object; pass {} for the sun, or {lights, shadows}");
45
- if (i(e.lights, "lights"), i(e.shadows, "shadows"), e.wrap !== void 0 && !(typeof e.wrap == "number" && e.wrap >= 0 && e.wrap <= 1)) throw RangeError("VFX lit wrap must be 0 to 1; pass e.g. 0.5");
46
- let t = e.ambient;
47
- if (t !== void 0 && (!Array.isArray(t) || t.length !== 3 || !t.every((e) => typeof e == "number" && e >= 0 && e <= 16))) throw RangeError("VFX lit ambient must be linear [r, g, b], each 0 to 16");
48
- s(e.glow);
49
- },
50
- billboard: (e, t) => r(e, t),
51
- create(e, n, r) {
52
- let { device: i, options: c } = e, l = i.createBuffer({
53
- size: 96,
54
- usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
55
- });
56
- r.push(l);
57
- let u = /* @__PURE__ */ new Float32Array(24), d = !!(n.lights || n.shadows), f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new WeakMap(), m = (e) => {
58
- let t = n.lights?.pbr(e).declarations ?? "", r = n.shadows?.pbr(e).declarations ?? "", i = f.get(e);
59
- return (!i || i.lights !== t || i.shadows !== r) && f.set(e, i = {
60
- lights: t,
61
- shadows: r,
62
- key: ":lit" + ++a
63
- }), i;
64
- };
65
- return {
66
- render: [{
67
- binding: t,
68
- resource: { buffer: l }
69
- }],
70
- write(t) {
71
- if (c.lit !== n) throw TypeError("VFX lit is fixed at attach; change its wrap or ambient in place or attach a new VFX");
72
- let { direction: r, radiance: i, ambient: a } = e.engine.lighting, d = Math.hypot(r[0], r[1], r[2]), f = d > 0 ? Math.max(0, r[3]) : 0;
73
- for (let e = 0; e < 3; e++) u[e] = f ? r[e] / d : 0, u[4 + e] = i[e] * f, u[8 + e] = n.ambient ? n.ambient[e] : i[3] * a[e], u[12 + e] = t.camera.position[e];
74
- u[7] = n.wrap ?? .5;
75
- let p = n.glow;
76
- if (s(p), u.fill(0, 16, 24), p && p.power > 0) {
77
- let e = p.color ?? o;
78
- for (let t = 0; t < 3; t++) u[16 + t] = p.position[t], u[20 + t] = e[t];
79
- u[19] = p.radius ?? 1, u[23] = p.power;
80
- }
81
- t.device.queue.writeBuffer(l, 0, u);
82
- },
83
- ...d ? {
84
- key: (e) => m(e).key,
85
- shade(e, t) {
86
- let n = m(t);
87
- return n.lights + n.shadows + e;
88
- },
89
- bind(e, t, r) {
90
- let a = n.lights?.bindings(), o = n.shadows?.bindings(), s = p.get(t);
91
- (!s || s.lights !== a || s.shadows !== o) && p.set(t, s = {
92
- lights: a,
93
- shadows: o,
94
- group: i.createBindGroup({
95
- layout: t.getBindGroupLayout(r),
96
- entries: [...a ?? [], ...o ?? []]
97
- })
98
- }), e.setBindGroup(r, s.group);
99
- }
100
- } : {}
101
- };
102
- }
103
- };
104
- //#endregion
105
- export { o as GLOW_COLOR, c as lit };
1
+ export { t as GLOW_COLOR, n as PALL_REFLECTANCE, r as lit } from "./lit-Dx2tNwP-.js";
package/dist/mesh.d.ts CHANGED
@@ -10,5 +10,7 @@ export declare function meshCorners(m: VFXMeshParticles): Float32Array;
10
10
  * The `mesh` feature: draws each particle as an instance of a small triangle mesh instead of a billboard, tumbling by
11
11
  * its spin or following its velocity, lit by one directional light. Pass it as `{mesh}` to `VFX` from
12
12
  * `@margoengine/vfx/base`; the root `VFX` has it. The mesh is read at attach; `light`, `color` and `ambient` every frame.
13
+ * The pieces cover the frame's shared reactive mask while TAA reads masks (the effect's `reactive` option), as they
14
+ * have no motion vectors.
13
15
  */
14
16
  export declare const mesh: VFXExtension<VFXMeshParticles>;
package/dist/mesh.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { t as e } from "./frame-BuvMFBPp.js";
2
2
  import { t } from "./view-rect-DkeiiUtw.js";
3
+ import { n, r, t as i } from "./reactive-mask-B8xbyzlk.js";
3
4
  //#region src/mesh.ts
4
- var n = 65536, r = [
5
+ var a = 65536, o = [
5
6
  .4,
6
7
  1,
7
8
  .3
8
9
  ];
9
- function i(e) {
10
+ function s(e) {
10
11
  let t = e.positions, n = t.length / 3, r = e.indices ?? Array.from({ length: n }, (e, t) => t), i = 0;
11
12
  for (let e = 0; e < n; e++) i = Math.max(i, Math.hypot(t[e * 3], t[e * 3 + 1], t[e * 3 + 2]));
12
13
  let a = new Float32Array(r.length * 8);
@@ -52,7 +53,7 @@ function i(e) {
52
53
  }
53
54
  return a;
54
55
  }
55
- var a = (t, n = "") => e + n + `
56
+ var c = (t, n = "") => e + n + `
56
57
  @group(0) @binding(1) var<storage,read> particles:array<vec4f>;
57
58
  @group(0) @binding(2) var<storage,read> alive:array<u32>;
58
59
  @group(0) @binding(15) var<storage,read> meshCorners:array<vec4f>;
@@ -70,31 +71,32 @@ fn meshHash(v:u32)->u32 {var x=v;x=(x^(x>>16u))*0x7feb352du;x=(x^(x>>15u))*0x846
70
71
  @fragment fn fragment(i:Out)->@location(0) vec4f {
71
72
  let lit=meshLight.direction.w+(1-meshLight.direction.w)*max(dot(normalize(i.normal),meshLight.direction.xyz),0.0);
72
73
  return vec4f(i.color*meshLight.color.rgb*lit,1);
73
- }`, o = (e, t) => {
74
+ }
75
+ @fragment fn reactive(i:Out)->@location(0) vec4f {return vec4f(1,0,0,1);}`, l = (e, t) => {
74
76
  let n = e;
75
77
  if (!n || typeof n != "object" || typeof n.length != "number") throw TypeError(`VFX mesh ${t} must be an array of numbers; pass a Float32Array or number[]`);
76
78
  for (let e = 0; e < n.length; e++) if (typeof n[e] != "number" || !Number.isFinite(n[e])) throw RangeError(`VFX mesh ${t}[${e}] is not a finite number; pass finite values`);
77
79
  return n;
78
- }, s = /* @__PURE__ */ new WeakSet();
79
- function c(e) {
80
- let t = o(e.positions, "positions");
80
+ }, u = /* @__PURE__ */ new WeakSet();
81
+ function d(e) {
82
+ let t = l(e.positions, "positions");
81
83
  if (t.length % 3 || t.length < 9) throw RangeError("VFX mesh positions must be xyz triples, at least one triangle; pass 3 numbers a vertex");
82
- let r = t.length / 3, i = e.indices === void 0 ? void 0 : o(e.indices, "indices"), a = i ? i.length : r;
83
- if (a % 3 || !a || a / 3 > 65536) throw RangeError(`VFX mesh needs 1 to ${n} whole triangles; pass indices (or positions) a multiple of 3`);
84
- if (i) {
85
- for (let e = 0; e < i.length; e++) if (!Number.isInteger(i[e]) || i[e] < 0 || i[e] >= r) throw RangeError(`VFX mesh indices[${e}] is ${i[e]}; pass whole numbers below ${r}`);
84
+ let n = t.length / 3, r = e.indices === void 0 ? void 0 : l(e.indices, "indices"), i = r ? r.length : n;
85
+ if (i % 3 || !i || i / 3 > 65536) throw RangeError(`VFX mesh needs 1 to ${a} whole triangles; pass indices (or positions) a multiple of 3`);
86
+ if (r) {
87
+ for (let e = 0; e < r.length; e++) if (!Number.isInteger(r[e]) || r[e] < 0 || r[e] >= n) throw RangeError(`VFX mesh indices[${e}] is ${r[e]}; pass whole numbers below ${n}`);
86
88
  }
87
- if (e.normals !== void 0 && o(e.normals, "normals").length !== t.length) throw RangeError("VFX mesh normals must have one xyz normal per vertex, as many numbers as positions");
88
- let c = 0;
89
- for (let e = 0; e < t.length; e++) c = Math.max(c, Math.abs(t[e]));
90
- if (!c) throw RangeError("VFX mesh positions are all at the origin; pass a mesh with some size");
91
- s.add(e);
89
+ if (e.normals !== void 0 && l(e.normals, "normals").length !== t.length) throw RangeError("VFX mesh normals must have one xyz normal per vertex, as many numbers as positions");
90
+ let o = 0;
91
+ for (let e = 0; e < t.length; e++) o = Math.max(o, Math.abs(t[e]));
92
+ if (!o) throw RangeError("VFX mesh positions are all at the origin; pass a mesh with some size");
93
+ u.add(e);
92
94
  }
93
- var l = {
95
+ var f = {
94
96
  validate(e) {
95
97
  if (!e || typeof e != "object") throw TypeError("VFX mesh must be an object with positions; pass e.g. {positions, indices}");
96
- if (s.has(e) || c(e), e.align !== void 0 && e.align !== "random" && e.align !== "velocity") throw TypeError(`VFX mesh align is ${String(e.align)}; pass 'random' or 'velocity'`);
97
- let t = e.light ?? r;
98
+ if (u.has(e) || d(e), e.align !== void 0 && e.align !== "random" && e.align !== "velocity") throw TypeError(`VFX mesh align is ${String(e.align)}; pass 'random' or 'velocity'`);
99
+ let t = e.light ?? o;
98
100
  if (!Array.isArray(t) || t.length !== 3 || !t.every(Number.isFinite) || !Math.hypot(...t)) throw RangeError("VFX mesh light must be a nonzero direction [x, y, z] towards the light");
99
101
  let n = e.lightColor ?? [
100
102
  1,
@@ -104,51 +106,57 @@ var l = {
104
106
  if (!Array.isArray(n) || n.length !== 3 || !n.every((e) => Number.isFinite(e) && e >= 0 && e <= 16)) throw RangeError("VFX mesh lightColor must be linear [r, g, b], each 0 to 16");
105
107
  if (e.ambient !== void 0 && !(typeof e.ambient == "number" && e.ambient >= 0 && e.ambient <= 1)) throw RangeError("VFX mesh ambient must be 0 to 1; pass e.g. 0.35");
106
108
  },
107
- create(e, n, o) {
108
- c(n);
109
- let { device: s, options: l } = e, u = i(n), d = u.length / 8, f = n.align ?? "random", p = s.createBuffer({
110
- size: u.byteLength,
109
+ create(e, a, l) {
110
+ d(a);
111
+ let { device: u, options: f } = e, p = s(a), m = p.length / 8, h = a.align ?? "random", g = u.createBuffer({
112
+ size: p.byteLength,
111
113
  usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
112
114
  });
113
- o.push(p), s.queue.writeBuffer(p, 0, u);
114
- let m = s.createBuffer({
115
+ l.push(g), u.queue.writeBuffer(g, 0, p);
116
+ let _ = u.createBuffer({
115
117
  size: 32,
116
118
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
117
119
  });
118
- o.push(m);
119
- let h = s.createBuffer({
120
+ l.push(_);
121
+ let v = u.createBuffer({
120
122
  size: 16,
121
123
  usage: GPUBufferUsage.INDIRECT | GPUBufferUsage.COPY_DST
122
124
  });
123
- o.push(h), s.queue.writeBuffer(h, 0, new Uint32Array([
124
- d,
125
+ l.push(v), u.queue.writeBuffer(v, 0, new Uint32Array([
126
+ m,
125
127
  0,
126
128
  0,
127
129
  0
128
130
  ]));
129
- let g = /* @__PURE__ */ new Float32Array(8), _ = /* @__PURE__ */ new Map(), v = {
131
+ let y = /* @__PURE__ */ new Float32Array(8), b = /* @__PURE__ */ new Map(), x = {
130
132
  view: void 0,
131
133
  loadOp: "load",
132
134
  storeOp: "store"
133
- }, y = {
135
+ }, S = {
134
136
  view: void 0,
135
137
  depthLoadOp: "load",
136
138
  depthStoreOp: "store"
137
- }, b = {
138
- colorAttachments: [v],
139
- depthStencilAttachment: y
140
- }, x, S = () => {
141
- if (l.mesh !== n) throw TypeError("VFX mesh is fixed at attach; change its light in place or attach a new VFX");
142
- return n;
139
+ }, C = {
140
+ colorAttachments: [x],
141
+ depthStencilAttachment: S
142
+ }, w = {
143
+ view: void 0,
144
+ depthReadOnly: !0
145
+ }, T = [], E = {
146
+ colorAttachments: T,
147
+ depthStencilAttachment: w
148
+ }, D = {}, O, k = () => {
149
+ if (f.mesh !== a) throw TypeError("VFX mesh is fixed at attach; change its light in place or attach a new VFX");
150
+ return a;
143
151
  };
144
152
  return {
145
153
  hides: () => !0,
146
154
  write(e) {
147
- let t = S(), n = t.light ?? r, i = Math.hypot(n[0], n[1], n[2]);
148
- g.set([
149
- n[0] / i,
150
- n[1] / i,
151
- n[2] / i,
155
+ let t = k(), n = t.light ?? o, r = Math.hypot(n[0], n[1], n[2]);
156
+ y.set([
157
+ n[0] / r,
158
+ n[1] / r,
159
+ n[2] / r,
152
160
  t.ambient ?? .35,
153
161
  ...t.lightColor ?? [
154
162
  1,
@@ -156,37 +164,49 @@ var l = {
156
164
  1
157
165
  ],
158
166
  0
159
- ]), e.device.queue.writeBuffer(m, 0, g);
167
+ ]), e.device.queue.writeBuffer(_, 0, y);
160
168
  },
161
- draw(n) {
162
- let r = n.descriptor.depthStencil.format, i = n.descriptor.multisample?.count ?? 1, o = n.format + ":" + r + ":" + i, c = _.get(o);
163
- if (!c) {
164
- x ??= s.createShaderModule({ code: a(f, e.spin?.code) });
165
- let t = s.createRenderPipeline({
169
+ draw(a) {
170
+ let o = a.descriptor.depthStencil.format, s = a.descriptor.multisample?.count ?? 1, l = a.format + ":" + o + ":" + s, d = (t) => {
171
+ let n = b.get(l + (t ? ":reactive" : ""));
172
+ if (n) return n;
173
+ O ??= u.createShaderModule({ code: c(h, e.spin?.code) });
174
+ let r = u.createRenderPipeline({
166
175
  layout: "auto",
167
176
  vertex: {
168
- module: x,
177
+ module: O,
169
178
  entryPoint: "vertex"
170
179
  },
171
- fragment: {
172
- module: x,
180
+ fragment: t ? {
181
+ module: O,
182
+ entryPoint: "reactive",
183
+ targets: [{
184
+ format: "r8unorm",
185
+ blend: i
186
+ }]
187
+ } : {
188
+ module: O,
173
189
  entryPoint: "fragment",
174
- targets: [{ format: n.format }]
190
+ targets: [{ format: a.format }]
175
191
  },
176
192
  primitive: {
177
193
  topology: "triangle-list",
178
194
  cullMode: "back",
179
195
  frontFace: "ccw"
180
196
  },
181
- multisample: n.descriptor.multisample,
182
- depthStencil: {
183
- format: r,
197
+ multisample: a.descriptor.multisample,
198
+ depthStencil: t ? {
199
+ format: o,
200
+ depthWriteEnabled: !1,
201
+ depthCompare: "greater-equal"
202
+ } : {
203
+ format: o,
184
204
  depthWriteEnabled: !0,
185
205
  depthCompare: "greater"
186
206
  }
187
207
  });
188
- c = [t, s.createBindGroup({
189
- layout: t.getBindGroupLayout(0),
208
+ return n = [r, u.createBindGroup({
209
+ layout: r.getBindGroupLayout(0),
190
210
  entries: [
191
211
  {
192
212
  binding: 0,
@@ -202,24 +222,27 @@ var l = {
202
222
  },
203
223
  {
204
224
  binding: 15,
205
- resource: { buffer: p }
225
+ resource: { buffer: g }
206
226
  },
207
- {
227
+ ...t ? [] : [{
208
228
  binding: 16,
209
- resource: { buffer: m }
210
- },
229
+ resource: { buffer: _ }
230
+ }],
211
231
  ...e.spin ? [e.spin.entry] : []
212
232
  ]
213
- })], _.set(o, c);
214
- }
215
- n.encoder.copyBufferToBuffer(e.visible, 4, h, 4, 4), v.view = n.color, y.view = n.depth;
216
- let l = r.includes("stencil");
217
- y.stencilLoadOp = l ? "load" : void 0, y.stencilStoreOp = l ? "store" : void 0;
218
- let u = n.encoder.beginRenderPass(b);
219
- u.setPipeline(c[0]), u.setBindGroup(0, c[1]), t(u, n), u.drawIndirect(h, 0), u.end(), e.stats.drawCalls++;
233
+ })], b.set(l + (t ? ":reactive" : ""), n), n;
234
+ };
235
+ a.encoder.copyBufferToBuffer(e.visible, 4, v, 4, 4), x.view = a.color, S.view = w.view = a.depth;
236
+ let p = o.includes("stencil");
237
+ S.stencilLoadOp = p ? "load" : void 0, S.stencilStoreOp = p ? "store" : void 0, w.stencilReadOnly = p ? !0 : void 0;
238
+ let m = (n, [r, i]) => {
239
+ let o = a.encoder.beginRenderPass(n);
240
+ o.setPipeline(r), o.setBindGroup(0, i), t(o, a), o.drawIndirect(v, 0), o.end(), e.stats.drawCalls++;
241
+ };
242
+ m(C, d(!1)), (f.reactive ?? n(a, D)) && (T[0] = r(a), m(E, d(!0)));
220
243
  }
221
244
  };
222
245
  }
223
246
  };
224
247
  //#endregion
225
- export { n as MAX_PARTICLE_MESH_TRIANGLES, l as mesh, i as meshCorners };
248
+ export { a as MAX_PARTICLE_MESH_TRIANGLES, f as mesh, s as meshCorners };