@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/flame.js CHANGED
@@ -1,59 +1,179 @@
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
3
 
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 "./view-rect-DkeiiUtw.js";
7
- import { soft as a, softDepthWgsl as o } from "./soft.js";
8
- import { a as s, c, i as l, n as u, o as d, r as f, s as p, t as m } from "./flame-ramp-VoBKpYnM.js";
9
- import { t as h } from "./require-webgpu--tUXPsmA.js";
10
- import { finiteVector as g } from "@margoengine/math/validate";
7
+ import { n as a, r as o, t as s } from "./reactive-mask-B8xbyzlk.js";
8
+ import { soft as c, softDepthWgsl as l } from "./soft.js";
9
+ import { a as u, c as d, i as f, n as p, o as m, r as h, s as g, t as _ } from "./flame-ramp-VoBKpYnM.js";
10
+ import { t as v } from "./require-webgpu--tUXPsmA.js";
11
+ import { finiteVector as y } from "@margoengine/math/validate";
12
+ import { MargoError as b } from "@margoengine/math/errors";
11
13
  //#region ../shared/noise-wgsl.js
12
- var _ = "fn hash1(n:u32)->f32 {var x=n*747796405u+2891336453u;x=((x>>((x>>28u)+4u))^x)*277803737u;x=(x>>22u)^x;return f32(x)/4294967295.0;}\nfn hash3(p:vec3i)->f32 {let q=bitcast<vec3u>(p);return hash1((q.x*73856093u)^(q.y*19349663u)^(q.z*83492791u));}\nfn vnoise3(p:vec3f)->f32 {\n let i=vec3i(floor(p));let f=p-floor(p);let s=f*f*(3.0-2.0*f);\n let a=mix(mix(hash3(i),hash3(i+vec3i(1,0,0)),s.x),mix(hash3(i+vec3i(0,1,0)),hash3(i+vec3i(1,1,0)),s.x),s.y);\n let b=mix(mix(hash3(i+vec3i(0,0,1)),hash3(i+vec3i(1,0,1)),s.x),mix(hash3(i+vec3i(0,1,1)),hash3(i+vec3i(1,1,1)),s.x),s.y);\n return mix(a,b,s.z);\n}", v = 9.80665, y = .5, b = .25;
13
- function x(e) {
14
+ var x = "fn hash1(n:u32)->f32 {var x=n*747796405u+2891336453u;x=((x>>((x>>28u)+4u))^x)*277803737u;x=(x>>22u)^x;return f32(x)/4294967295.0;}\nfn hash3(p:vec3i)->f32 {let q=bitcast<vec3u>(p);return hash1((q.x*73856093u)^(q.y*19349663u)^(q.z*83492791u));}\nfn vnoise3(p:vec3f)->f32 {\n let i=vec3i(floor(p));let f=p-floor(p);let s=f*f*(3.0-2.0*f);\n let a=mix(mix(hash3(i),hash3(i+vec3i(1,0,0)),s.x),mix(hash3(i+vec3i(0,1,0)),hash3(i+vec3i(1,1,0)),s.x),s.y);\n let b=mix(mix(hash3(i+vec3i(0,0,1)),hash3(i+vec3i(1,0,1)),s.x),mix(hash3(i+vec3i(0,1,1)),hash3(i+vec3i(1,1,1)),s.x),s.y);\n return mix(a,b,s.z);\n}", S = 9.80665, C = .5, w = .25;
15
+ function T(e) {
14
16
  if (!(Number.isFinite(e) && e >= 0)) throw RangeError("Fireline intensity must be a finite kW/m of 0 or more");
15
17
  return .0775 * e ** .46;
16
18
  }
17
- function S(e) {
19
+ function ee(e) {
18
20
  if (!(Number.isFinite(e) && e >= 0)) throw RangeError("Flame length must be a finite number of metres, 0 or more");
19
21
  return (e / .0775) ** (1 / .46);
20
22
  }
21
- function C(e, t) {
23
+ function E(e, t) {
22
24
  if (!(Number.isFinite(e) && e >= 0)) throw RangeError("Heat release must be a finite number of watts, 0 or more");
23
25
  if (!(Number.isFinite(t) && t >= 0)) throw RangeError("Fire diameter must be a finite number of metres, 0 or more");
24
26
  return Math.max(.235 * (e / 1e3) ** .4 - 1.02 * t, 0);
25
27
  }
26
- var w = 1.5;
27
- function T(e) {
28
+ var D = Object.freeze({
29
+ itemMass: .567,
30
+ burnTime: 600,
31
+ heatOfCombustion: 247e5,
32
+ smoke: Object.freeze([
33
+ .97,
34
+ .97,
35
+ .97
36
+ ])
37
+ });
38
+ function te(e) {
39
+ let { fuel: t, area: n, burnTime: r, heatOfCombustion: i } = e, a = e.spread ?? 0, o = (e) => Number.isFinite(e) && e > 0;
40
+ if (!o(t)) throw RangeError("burningBed fuel must be a finite number of kilograms above 0");
41
+ if (!o(n)) throw RangeError("burningBed area must be a finite number of square metres above 0");
42
+ if (!o(r)) throw RangeError("burningBed burnTime must be a finite number of seconds above 0");
43
+ if (!o(i)) throw RangeError("burningBed heatOfCombustion must be a finite number of J/kg above 0");
44
+ if (!(Number.isFinite(a) && a >= 0)) throw RangeError("burningBed spread must be a finite number of seconds, 0 or more");
45
+ let s = t * i / r, c = Math.sqrt(4 * n / Math.PI), l = (e) => a > 0 ? Math.min(Math.max(e / a, 0), 1) : +(e >= 0), u = (e) => {
46
+ if (!Number.isFinite(e)) throw RangeError("burningBed time must be a finite number of seconds");
47
+ return s * Math.max(l(e) - l(e - r), 0);
48
+ };
49
+ return Object.freeze({
50
+ duration: a + r,
51
+ diameter: c,
52
+ power: u,
53
+ flameLength: (e) => E(u(e), c)
54
+ });
55
+ }
56
+ var O = 1.5;
57
+ function k(e) {
28
58
  if (!(Number.isFinite(e) && e > 0)) throw RangeError("Fire diameter must be a finite number of metres above 0");
29
- return w / Math.sqrt(e);
59
+ return O / Math.sqrt(e);
30
60
  }
31
- function E(e) {
61
+ function A(e) {
32
62
  let [t, n] = e;
33
63
  return Math.max(Math.min(Math.sqrt(4 * t * n / Math.PI), 2 * Math.min(t, n)), .05);
34
64
  }
35
- var D = 5.95, O = 5.96, ee = .5, k = 1.35, A = 2, j = 4, M = 18, N = 64, P = 256, F = .03, te = 5.588238, I = 5e-4, L = .15, R = 3, z = 4, B = 16, V = .5, H = .3;
36
- function U(e, t, n = H) {
65
+ var j = 5.95, ne = 5.96, re = .5, M = 1.35, N = 2, ie = 18, P = 64, F = 256, ae = .03, oe = 5.588238, I = 5e-4, se = .15, L = 3, ce = 4, R = 16, z = .5, B = .3;
66
+ function V(e, t, n = B) {
37
67
  if (!(Number.isFinite(e) && e >= 0)) throw RangeError("Heat release must be a finite number of watts, 0 or more");
38
68
  if (!(Number.isFinite(n) && n >= 0 && n <= 1)) throw RangeError("Radiant fraction must be a number from 0 to 1");
39
- return n * e * s(t);
69
+ return n * e * u(t);
40
70
  }
41
- function W(e, t) {
71
+ function H(e, t) {
42
72
  if (!(Number.isFinite(e) && e >= 0)) throw RangeError("Flame length must be a finite number of metres, 0 or more");
43
73
  if (!(Number.isFinite(t) && t >= 0)) throw RangeError("Fire diameter must be a finite number of metres, 0 or more");
44
74
  return 1e3 * ((e + 1.02 * t) / .235) ** 2.5;
45
75
  }
46
- var G = (e) => {
76
+ var U = 5.670374419e-8, W = 1e3, le = u(5772);
77
+ function G(e) {
78
+ let { heat: t, area: n, kelvin: r } = e, i = e.noon ?? Math.PI, a = e.radiantFraction ?? .3;
79
+ if (!(Number.isFinite(t) && t >= 0)) throw RangeError("Flame heat must be a finite number of watts, 0 or more");
80
+ if (!(Number.isFinite(n) && n > 0)) throw RangeError("Flame area must be a finite number of square metres above 0");
81
+ if (d(r, "core", 800, 3e3), !(Number.isFinite(i) && i > 0 && i <= 1e7)) throw RangeError("Flame noon must be the noon sun's engine intensity, above 0 and at most 1e7; pass e.g. Math.PI");
82
+ if (!(Number.isFinite(a) && a >= 0 && a <= 1)) throw RangeError("Radiant fraction must be a number from 0 to 1");
83
+ let o = Math.min(a * t / n, U * r ** 4) * u(r) / Math.PI, [s, c, l] = h(r);
84
+ return o * i / (W * le) / (.2126 * s + .7152 * c + .0722 * l);
85
+ }
86
+ function K(e, t) {
87
+ return 2 * Math.max(t[0], t[1]) * e + t[0] * t[1];
88
+ }
89
+ var q = (e) => {
47
90
  let t = Math.imul(e >>> 0, 747796405) + 2891336453 >>> 0;
48
91
  return t = Math.imul((t >>> (t >>> 28) + 4 ^ t) >>> 0, 277803737) >>> 0, t = (t >>> 22 ^ t) >>> 0, t / 4294967295;
49
- }, K = (e) => {
92
+ }, J = (e) => {
50
93
  let t = Math.floor(e), n = e - t, r = n * n * (3 - 2 * n);
51
- return G(t | 0) + (G(t + 1 | 0) - G(t | 0)) * r;
52
- }, q = (e) => Math.min(Math.max(e, 0), 1), J = 128, Y = 112, X = 116, Z = 120, ne = 124, Q = /* @__PURE__ */ new WeakMap(), re = 0, $ = /* @__PURE__ */ new WeakMap(), ie = (e, n, r, i) => `
53
- struct F {camera:mat4x4f,eye:vec4f,base:vec4f,shape:vec4f,turn:vec4f,motion:vec4f,look:vec4f,box:vec4f,forward:vec4f,ramp:array<vec4f,${B}>,extra:vec4f,ground:vec4f,glow:vec4f,outer:vec4f}
94
+ return q(t | 0) + (q(t + 1 | 0) - q(t | 0)) * r;
95
+ }, ue = (e) => Math.min(Math.max(e, 0), 1), de = 8;
96
+ function fe(e) {
97
+ if (typeof e != "object" || !e || e.length !== 64) throw RangeError("Flame relief must hold 64 heights (8 x 8 over the footprint)");
98
+ for (let t = 0; t < e.length; t++) d(e[t], "relief", -1e3, 1e3);
99
+ }
100
+ function Y(e, t, n) {
101
+ if (!e) return 0;
102
+ let r = Math.min(Math.max((t * .5 + .5) * 7, 0), 7), i = Math.min(Math.max((n * .5 + .5) * 7, 0), 7), a = Math.min(Math.floor(r), 6), o = Math.min(Math.floor(i), 6), s = r - a, c = i - o, l = (t, n) => e[n * 8 + t];
103
+ return (1 - c) * ((1 - s) * l(a, o) + s * l(a + 1, o)) + c * ((1 - s) * l(a, o + 1) + s * l(a + 1, o + 1));
104
+ }
105
+ var pe = 196, me = 112, he = 116, ge = 120, _e = 124, ve = 128, ye = 132, X = /* @__PURE__ */ new WeakMap(), be = 0, Z = /* @__PURE__ */ new WeakMap(), Q = /* @__PURE__ */ new WeakMap();
106
+ function xe(e, t) {
107
+ let n = t.descriptor.multisample?.count ?? 1;
108
+ if (!e.mask || e.device !== t.device || e.width !== t.width || e.height !== t.height || e.samples !== n) {
109
+ e.mask?.destroy(), e.multi?.destroy();
110
+ let r = [t.width, t.height];
111
+ e.device = t.device, e.width = t.width, e.height = t.height, e.samples = n, e.mask = t.device.createTexture({
112
+ label: "flame coverage mask",
113
+ size: r,
114
+ format: "r8unorm",
115
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC
116
+ }), e.multi = n > 1 ? t.device.createTexture({
117
+ label: "flame coverage mask (multisampled)",
118
+ size: r,
119
+ format: "r8unorm",
120
+ sampleCount: n,
121
+ usage: GPUTextureUsage.RENDER_ATTACHMENT
122
+ }) : void 0, e.maskView = e.mask.createView(), e.multiView = e.multi?.createView(), e.drawn = -1;
123
+ }
124
+ let r = e.drawn !== e.frame || e.view !== t.view;
125
+ return e.drawn = e.frame, e.view = t.view, {
126
+ view: e.multiView ?? e.maskView,
127
+ resolveTarget: e.multi ? e.maskView : void 0,
128
+ loadOp: r ? "clear" : "load",
129
+ clearValue: [
130
+ 0,
131
+ 0,
132
+ 0,
133
+ 0
134
+ ],
135
+ storeOp: "store"
136
+ };
137
+ }
138
+ function Se(e) {
139
+ if (!e || typeof e.use != "function") throw TypeError("watchFlameCoverage needs an engine; pass the engine the flames are attached to");
140
+ let t = Q.get(e);
141
+ t || Q.set(e, t = {
142
+ watchers: 0,
143
+ frame: 0,
144
+ drawn: -1,
145
+ view: void 0,
146
+ width: 0,
147
+ height: 0,
148
+ samples: 0
149
+ });
150
+ let n = t;
151
+ n.watchers++ === 0 && e.use({coreRequirement:/*@__PURE__*/__margoCoreRequirement("1.0.0",import.meta.url),
152
+ name: "flame-coverage",
153
+ setup() {},
154
+ onPreUpdate() {
155
+ n.frame++;
156
+ },
157
+ dispose() {
158
+ n.mask?.destroy(), n.multi?.destroy(), n.mask = n.multi = n.maskView = n.multiView = void 0, n.watchers = 0;
159
+ }
160
+ });
161
+ let r = !0, i = () => {
162
+ r && (r = !1, --n.watchers === 0 && e.removePlugin("flame-coverage"));
163
+ };
164
+ return {
165
+ get texture() {
166
+ return r && n.mask && n.drawn === n.frame ? n.mask : void 0;
167
+ },
168
+ dispose: i,
169
+ [Symbol.dispose]: i
170
+ };
171
+ }
172
+ var $ = (e, n, r, i, a = i) => `
173
+ struct F {camera:mat4x4f,eye:vec4f,base:vec4f,shape:vec4f,turn:vec4f,motion:vec4f,look:vec4f,box:vec4f,forward:vec4f,ramp:array<vec4f,${R}>,extra:vec4f,ground:vec4f,glow:vec4f,outer:vec4f,relief:vec4f,grid:array<vec4f,16>}
54
174
  @group(0) @binding(0) var<uniform> u:F;
55
175
  ${n ? t(0, 5) : ""}
56
- ${i ? o(e) : ""}
176
+ ${a ? l(e) : ""}
57
177
  struct Out {@builtin(position) clip:vec4f,@location(0) world:vec3f}
58
178
 
59
179
 
@@ -67,17 +187,34 @@ fn toLocal(v:vec3f)->vec3f {
67
187
  r.y-=u.ground.x*r.x+u.ground.y*r.z;
68
188
  return vec3f(r.x-u.shape.z*r.y,r.y,r.z-u.shape.w*r.y);
69
189
  }
190
+
191
+
192
+ fn cell(i:u32,j:u32)->f32 {let k=j*8u+i;return u.grid[k>>2u][k&3u];}
193
+ fn reliefAt(x:f32,z:f32)->f32 {
194
+ let n=7.0;
195
+ let fu=clamp((x/max(u.relief.z,1e-6)*0.5+0.5)*n,0.0,n);let fv=clamp((z/max(u.relief.w,1e-6)*0.5+0.5)*n,0.0,n);
196
+ let i=min(u32(fu),6u);let j=min(u32(fv),6u);let a=fu-f32(i);let b=fv-f32(j);
197
+ return mix(mix(cell(i,j),cell(i+1u,j),a),mix(cell(i,j+1u),cell(i+1u,j+1u),a),b);
198
+ }
199
+
200
+
201
+
202
+ fn overGround(q:vec3f)->vec3f {let g=reliefAt(q.x+u.shape.z*q.y,q.z+u.shape.w*q.y);return vec3f(q.x+u.shape.z*g,q.y-g,q.z+u.shape.w*g);}
203
+
204
+ fn reliefPad()->f32 {return max(abs(u.shape.z),abs(u.shape.w))*max(abs(u.relief.x),abs(u.relief.y));}
70
205
  fn corner(v:u32,margin:f32,top:f32)->Out {
71
206
  var corners=array<u32,36>(0u,2u,1u,1u,2u,3u,4u,5u,6u,5u,7u,6u,0u,1u,4u,1u,5u,4u,2u,6u,3u,3u,6u,7u,0u,4u,2u,2u,4u,6u,1u,3u,5u,3u,7u,5u);
72
207
  let k=corners[v];
73
208
  let c=vec3f(f32(k&1u),f32((k>>1u)&1u),f32((k>>2u)&1u));
74
- let w=toWorld(vec3f((c.x*2.0-1.0)*(u.shape.x+margin),mix(u.box.z,top,c.y),(c.z*2.0-1.0)*(u.shape.y+margin)));
209
+
210
+ let pad=margin+reliefPad();
211
+ let w=toWorld(vec3f((c.x*2.0-1.0)*(u.shape.x+pad),mix(u.box.z+u.relief.x,top+u.relief.y,c.y),(c.z*2.0-1.0)*(u.shape.y+pad)));
75
212
  var o:Out;o.clip=u.camera*vec4f(w,1.0);o.world=w;return o;
76
213
  }
77
214
 
78
215
  @vertex fn vertex(@builtin(vertex_index) v:u32)->Out {return corner(v,u.box.x,u.box.y);}
79
216
  @vertex fn glowVertex(@builtin(vertex_index) v:u32)->Out {return corner(v,u.outer.x,u.outer.y);}
80
- ${_}
217
+ ${x}
81
218
  fn vnoise1(v:f32)->f32 {let i=floor(v);let f=v-i;let s=f*f*(3.0-2.0*f);let a=bitcast<u32>(i32(i));return mix(hash1(a),hash1(a+1u),s);}
82
219
  fn fbm(p:vec3f)->f32 {return 0.5161*vnoise3(p)+0.2581*vnoise3(p*2.03+vec3f(17.1,3.7,9.2))+0.129*vnoise3(p*4.07+vec3f(5.3,11.9,2.1))+0.0645*vnoise3(p*8.11+vec3f(9.7,1.3,13.4))+0.0323*vnoise3(p*16.3+vec3f(3.1,7.7,5.9));}
83
220
  fn table(x:f32)->vec3f {let t=clamp(x,0.0,1.0)*15.0;let i=u32(floor(t));let j=min(i+1u,15u);return mix(u.ramp[i].rgb,u.ramp[j].rgb,t-floor(t));}
@@ -90,7 +227,7 @@ fn trees(q:vec3f,h0:f32)->vec2f {
90
227
  for(var j=-1;j<=1;j++){for(var i=-1;i<=1;i++){
91
228
  let id=vec2i(c)+vec2i(i,j);let at=(vec2f(id)+0.2+0.6*vec2f(hash3(vec3i(id,7)),hash3(vec3i(id,13))))*S;
92
229
  let h=(h0+0.3*hash3(vec3i(id,29)))/(0.6+0.8*hash3(vec3i(id,41)));
93
- let r=0.34*pow(clamp(1.0-h/${k.toFixed(2)},0.0,1.0),0.7)*smoothstep(-0.08,0.12,h);
230
+ let r=0.34*pow(clamp(1.0-h/${M.toFixed(2)},0.0,1.0),0.7)*smoothstep(-0.08,0.12,h);
94
231
  let v=2.6*(r-length(q.xz-at)/S);
95
232
  if(v>best.x){best=vec2f(v,h);}
96
233
  }}
@@ -98,7 +235,7 @@ fn trees(q:vec3f,h0:f32)->vec2f {
98
235
  }
99
236
  fn zone(q:vec3f)->vec2f {
100
237
  let L=u.base.w;var h=q.y/L;
101
- if(h<u.box.z/L||h>${A.toFixed(2)}){return vec2f(0.0);}
238
+ if(h<u.box.z/L||h>${N.toFixed(2)}){return vec2f(0.0);}
102
239
  let along=select(q.z,q.x,u.shape.x>=u.shape.y);
103
240
 
104
241
 
@@ -111,7 +248,7 @@ fn zone(q:vec3f)->vec2f {
111
248
  if(column<-1.2){return vec2f(0.0);}
112
249
  }
113
250
  let puff=sin(6.2831853*(u.turn.z*u.eye.w-q.y/u.turn.w+vnoise1(along/u.look.z+u.look.w)));
114
- let taper=pow(clamp(1.0-h/${k.toFixed(2)},0.0,1.0),0.6);
251
+ let taper=pow(clamp(1.0-h/${M.toFixed(2)},0.0,1.0),0.6);
115
252
  let narrow=min(u.shape.x,u.shape.y)+0.12*L;
116
253
  let ext=max(vec2f(u.shape.x,u.shape.y)+0.12*L-narrow*(1.0-taper)-0.2*L*smoothstep(0.0,1.3,h),vec2f(0.0));
117
254
  let d=abs(q.xz)-ext;
@@ -153,19 +290,24 @@ fn rayOf(i:Out,margin:f32,top:f32,glow:bool)->Ray {
153
290
  var r:Ray;
154
291
  let ray=i.world-u.eye.xyz;let along=length(ray);r.rd=ray/along;
155
292
  r.o=toLocal(u.eye.xyz-u.base.xyz);r.d=toLocal(r.rd);
156
- let m=vec2f(u.shape.x,u.shape.y)+margin;
157
- let box=boxHit(r.o,r.d,vec3f(-m.x,u.box.z,-m.y),vec3f(m.x,top,m.y));
293
+ let m=vec2f(u.shape.x,u.shape.y)+margin+reliefPad();
294
+ let box=boxHit(r.o,r.d,vec3f(-m.x,u.box.z+u.relief.x,-m.y),vec3f(m.x,top+u.relief.y,m.y));
158
295
  let enter=box.x;let leave=box.y;
159
296
 
160
297
 
161
298
  ${i ? "let mine=!(abs(along-leave)>abs(along-max(enter,0.0))&&enter>0.0);" : "let mine=select(!(abs(along-enter)>abs(along-leave)||enter<0.0),abs(along-leave)<=abs(along-enter),glow&&enter<0.0);"}
162
299
  var end=leave;
163
- ${i ? "if(textureLoad(sceneDepth,vec2i(i.clip.xy),0)>0.0){end=min(end,softGap(i.clip,0.0)/max(dot(r.rd,u.forward.xyz),1e-4));}" : ""}
300
+ ${a ? "if(textureLoad(sceneDepth,vec2i(i.clip.xy),0)>0.0){end=min(end,softGap(i.clip,0.0)/max(dot(r.rd,u.forward.xyz),1e-4));}" : ""}
164
301
 
165
302
 
166
303
  var ground=-1.0;
167
304
  let floor=select(0.0,u.box.z+0.16*u.base.w,u.extra.y>0.0);
168
- if(r.d.y<0.0){let tg=(floor-r.o.y)/r.d.y;if(tg>max(enter,0.0)&&tg<end){end=tg;ground=tg;}}
305
+
306
+ if(r.d.y<0.0){
307
+ var tg=(floor-r.o.y)/r.d.y;
308
+ for(var k=0;k<4;k++){let p=r.o+r.d*tg;tg=(floor+reliefAt(p.x+u.shape.z*p.y,p.z+u.shape.w*p.y)-r.o.y)/r.d.y;}
309
+ if(tg>max(enter,0.0)&&tg<end){end=tg;ground=tg;}
310
+ }
169
311
  r.span=vec4f(max(enter,0.0),end,ground,select(0.0,1.0,mine&&end>max(enter,0.0)));
170
312
  return r;
171
313
  }
@@ -176,22 +318,22 @@ fn march(o:vec3f,d:vec3f,t0:f32,t1:f32,pixel:vec2f,stopAt:f32)->March {
176
318
  var m:March;m.glow=vec3f(0.0);m.trans=1.0;m.middle=t0;m.surface=-1.0;
177
319
 
178
320
 
179
- let dt=min((t1-t0)/${N}.0,${F}*u.base.w);
321
+ let dt=min((t1-t0)/${P}.0,${ae}*u.base.w);
180
322
 
181
323
 
182
- let px=pixel+${te}*u.extra.x;let dither=fract(52.9829189*fract(0.06711056*px.x+0.00583715*px.y));
324
+ let px=pixel+${oe}*u.extra.x;let dither=fract(52.9829189*fract(0.06711056*px.x+0.00583715*px.y));
183
325
  var t=t0+dt*dither;
184
326
  let k=u.box.w/u.base.w;
185
327
  var last=t;var entered=false;
186
- for(var n=0;n<${P};n++){
328
+ for(var n=0;n<${F};n++){
187
329
  if(t>t1){break;}
188
- var z=zone(o+d*t);
330
+ var z=zone(overGround(o+d*t));
189
331
 
190
332
 
191
333
  if(z.x>0.0&&!entered){
192
334
  entered=true;var a0=last;var b0=t;
193
- for(var r=0;r<5;r++){let mid=0.5*(a0+b0);if(zone(o+d*mid).x>0.0){b0=mid;}else{a0=mid;}}
194
- t=b0;z=zone(o+d*t);
335
+ for(var r=0;r<5;r++){let mid=0.5*(a0+b0);if(zone(overGround(o+d*mid)).x>0.0){b0=mid;}else{a0=mid;}}
336
+ t=b0;z=zone(overGround(o+d*t));
195
337
  }
196
338
  last=t;
197
339
  if(z.x>0.0){
@@ -215,11 +357,18 @@ fn glowAt(e:vec3f,rd:vec3f,ta:f32,tb:f32,tg:f32)->vec3f {
215
357
  if(n<=0||tb<=ta){return vec3f(0.0);}
216
358
  let L=u.base.w;let R=u.extra.z;let a2=0.0625*L*L;let kR=1.0/(R*R+a2);
217
359
  let long=u.shape.x>=u.shape.y;let span=1.6*max(u.shape.x,u.shape.y);
218
- let normal=normalize(vec3f(-u.outer.z,1.0,-u.outer.w));
360
+ var normal=normalize(vec3f(-u.outer.z,1.0,-u.outer.w));
361
+
362
+ if(tg>0.0){
363
+ let q=toLocal(e+rd*tg-u.base.xyz);let px=q.x+u.shape.z*q.y;let pz=q.z+u.shape.w*q.y;
364
+ let hx=u.relief.z/7.0+1e-3;let hz=u.relief.w/7.0+1e-3;
365
+ let du=(reliefAt(px+hx,pz)-reliefAt(px-hx,pz))/(2.0*hx);let dv=(reliefAt(px,pz+hz)-reliefAt(px,pz-hz))/(2.0*hz);
366
+ normal=normalize(vec3f(-(u.outer.z+du*u.turn.x+dv*u.turn.y),1.0,-(u.outer.w-du*u.turn.y+dv*u.turn.x)));
367
+ }
219
368
  var air=0.0;var lit=0.0;
220
369
  for(var k=0;k<n;k++){
221
370
  let a=select(0.0,(f32(k)/f32(max(n-1,1))-0.5)*span,n>1);
222
- let s=toWorld(select(vec3f(0.0,u.glow.w,a),vec3f(a,u.glow.w,0.0),long));
371
+ let s=toWorld(select(vec3f(0.0,u.glow.w+reliefAt(0.0,a),a),vec3f(a,u.glow.w+reliefAt(a,0.0),0.0),long));
223
372
  let es=s-e;let tc=dot(es,rd);let h2=max(dot(es,es)-tc*tc,0.0);
224
373
  let c2=R*R-h2;
225
374
  if(c2>0.0){
@@ -233,7 +382,7 @@ fn glowAt(e:vec3f,rd:vec3f,ta:f32,tb:f32,tg:f32)->vec3f {
233
382
  }
234
383
  return u.glow.rgb*(u.ground.w*0.07957747*air+u.ground.z*0.31830989*lit);
235
384
  }
236
- @fragment fn fragment(i:Out)->@location(0) vec4f {
385
+ fn flame(i:Out)->vec4f {
237
386
  let r=rayOf(i,u.box.x,u.box.y,false);
238
387
  if(r.span.w<=0.0){discard;}
239
388
  let m=march(r.o,r.d,r.span.x,r.span.y,i.clip.xy,0.0);
@@ -241,11 +390,18 @@ fn glowAt(e:vec3f,rd:vec3f,ta:f32,tb:f32,tg:f32)->vec3f {
241
390
  let alpha=(1.0-m.trans*m.trans)*u.motion.w;
242
391
  if(alpha<=0.0){discard;}
243
392
 
244
- var c=u.look.x*(vec3f(1.0)-exp(-u.look.y*m.glow/(max(1.0-m.trans,1e-5)*u.look.x)));
393
+
394
+ var c=u.look.x*m.glow/max(1.0-m.trans,1e-5);
245
395
  ${n ? "c=mix(c,margoFog.color.rgb,fogAmount(u.eye.xyz+r.rd*m.middle));" : ""}
246
396
  ${r ? "c=encodeSrgb(max(c,vec3f(0.0)));" : ""}
247
397
  return vec4f(c*alpha,alpha);
248
398
  }
399
+ @fragment fn fragment(i:Out)->@location(0) vec4f {return flame(i);}
400
+
401
+ @fragment fn reactiveFragment(i:Out)->@location(0) vec4f {return vec4f(clamp(flame(i).a,0.0,1.0),0,0,1);}
402
+
403
+
404
+ @fragment fn coverageFragment(i:Out)->@location(0) vec4f {return vec4f(select(0.0,1.0,flame(i).a>0.0),0,0,1);}
249
405
 
250
406
 
251
407
  struct Glow {@location(0) color:vec4f,@builtin(frag_depth) depth:f32}
@@ -266,14 +422,14 @@ struct Depth {@builtin(frag_depth) depth:f32}
266
422
  @fragment fn depthFragment(i:Out)->Depth {
267
423
  let r=rayOf(i,u.box.x,u.box.y,false);
268
424
  if(r.span.w<=0.0||u.motion.w<1.0){discard;}
269
- let m=march(r.o,r.d,r.span.x,r.span.y,i.clip.xy,${ee});
425
+ let m=march(r.o,r.d,r.span.x,r.span.y,i.clip.xy,${re});
270
426
  if(m.surface<0.0){discard;}
271
427
  let p=u.camera*vec4f(u.eye.xyz+r.rd*m.surface,1.0);
272
428
  var o:Depth;o.depth=clamp(p.z/p.w,0.0,1.0);return o;
273
429
  }
274
- `, ae = class t {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
430
+ `, Ce = class t {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
275
431
  constructor(e, t) {
276
- this.disposed = !1, this.clock = 0, this.current = 0, this.key = [], this.values = new Float32Array(J), this.view = /* @__PURE__ */ new Float32Array(16), this.heat = {
432
+ this.disposed = !1, this.clock = 0, this.current = 0, this.key = [], this.values = new Float32Array(pe), this.view = /* @__PURE__ */ new Float32Array(16), this.heat = {
277
433
  position: [
278
434
  0,
279
435
  0,
@@ -284,19 +440,21 @@ struct Depth {@builtin(frag_depth) depth:f32}
284
440
  yaw: 0,
285
441
  lean: [0, 0],
286
442
  time: 0
287
- }, this.fogData = /* @__PURE__ */ new Float32Array(12), this.steady = [], this.coreFloor = 0, this.samples = 0, this.owned = [], this.groups = /* @__PURE__ */ new Map(), this.attachment = {
443
+ }, this.fogData = /* @__PURE__ */ new Float32Array(12), this.steady = [], this.samples = 0, this.owned = [], this.groups = /* @__PURE__ */ new Map(), this.attachment = {
288
444
  view: void 0,
289
445
  loadOp: "load",
290
446
  storeOp: "store"
291
447
  }, this.depthAttachment = {
292
448
  view: void 0,
293
449
  depthReadOnly: !0
294
- }, this.name = "vfx-flame:" + re++, this.seed = t * 7.31 % 97, this.options = e, this.check();
450
+ }, this.reactiveAttachments = [], this.name = "vfx-flame:" + be++, this.seed = t * 7.31 % 97, this.options = e, this.check();
295
451
  let n = e.lights, r = n && "names" in n && "clustered" in n ? n : void 0, i = r ? r.clustered : n && "maxLights" in n ? n : void 0;
296
452
  if (n && !i) throw TypeError("Invalid Flame lights; pass a Clustered from @margoengine/clustered or its LightGroups");
297
- let a = [];
453
+ let a = e.castShadow === !0;
454
+ if (a && i && !i.shadow) throw new b("state", "A Flame that casts shadows needs LocalShadows attached to its Clustered first; attach it, or pass castShadow: false");
455
+ let o = [];
298
456
  if (i) {
299
- for (let e = 0; e < 4; e++) a.push({
457
+ for (let e = 0; e < (a ? 1 : 4); e++) o.push({
300
458
  position: [
301
459
  0,
302
460
  -1e6,
@@ -309,7 +467,8 @@ struct Depth {@builtin(frag_depth) depth:f32}
309
467
  .5,
310
468
  .2
311
469
  ],
312
- radius: 0
470
+ radius: 0,
471
+ castShadow: a
313
472
  });
314
473
  if (r) {
315
474
  let e = "flame";
@@ -317,20 +476,22 @@ struct Depth {@builtin(frag_depth) depth:f32}
317
476
  this.target = this.group = r.group(e);
318
477
  } else this.target = i;
319
478
  }
320
- this.lights = a, this.write(!0);
479
+ this.lights = o, this.write(!0);
321
480
  }
322
481
  length() {
323
482
  let e = this.options;
324
483
  if (e.length !== void 0) return e.length;
325
- if (e.intensity !== void 0) return x(e.intensity);
484
+ if (e.intensity !== void 0) return T(e.intensity);
326
485
  let [t, n] = e.footprint ?? [0, 0];
327
- return C(e.heat ?? 0, Math.sqrt(4 * t * n / Math.PI));
486
+ return E(e.heat ?? 0, Math.sqrt(4 * t * n / Math.PI));
328
487
  }
329
488
  check() {
330
489
  let e = this.options;
331
490
  if (!e || typeof e != "object") throw TypeError("Flame options must be an object with a position and a length, intensity or heat");
332
- if (g(e.position, 3, "Flame position"), e.length === void 0 && e.intensity === void 0 && e.heat === void 0) throw TypeError("Flame needs a length (m), an intensity (kW/m) or a heat (W)");
333
- c(this.length(), "length", 0, 1e3), e.footprint && (c(e.footprint[0], "footprint x", 0, 1e5), c(e.footprint[1], "footprint z", 0, 1e5)), c(e.opacity ?? 1, "opacity", 0, 1), c(e.flicker ?? 1, "flicker", 0, 3), c(e.tongues ?? 1, "tongues", .25, 4), c(e.crowns ?? 0, "crowns", 0, 1e3), e.slope !== void 0 && (g(e.slope, 2, "Flame slope"), c(e.slope[0], "slope x", -10, 10), c(e.slope[1], "slope z", -10, 10)), c(e.glow ?? 1, "glow", 0, 8), c(e.haze ?? I, "haze", 0, 1), c(e.groundAlbedo ?? 0, "groundAlbedo", 0, 1), c(e.glowRadius ?? R, "glowRadius", .5, 10), c(e.yaw ?? 0, "yaw", -1e3, 1e3), c(e.lightPower ?? 1, "lightPower", 0, 1e6);
491
+ if (y(e.position, 3, "Flame position"), e.length === void 0 && e.intensity === void 0 && e.heat === void 0) throw TypeError("Flame needs a length (m), an intensity (kW/m) or a heat (W)");
492
+ if (d(this.length(), "length", 0, 1e3), e.footprint && (d(e.footprint[0], "footprint x", 0, 1e5), d(e.footprint[1], "footprint z", 0, 1e5)), d(e.opacity ?? 1, "opacity", 0, 1), d(e.flicker ?? 1, "flicker", 0, 3), d(e.tongues ?? 1, "tongues", .25, 4), d(e.crowns ?? 0, "crowns", 0, 1e3), e.slope !== void 0 && (y(e.slope, 2, "Flame slope"), d(e.slope[0], "slope x", -10, 10), d(e.slope[1], "slope z", -10, 10)), e.relief !== void 0 && fe(e.relief), d(e.glow ?? 1, "glow", 0, 8), e.castShadow !== void 0 && typeof e.castShadow != "boolean") throw TypeError("Flame castShadow must be true or false; pass a boolean");
493
+ if (e.reactive !== void 0 && typeof e.reactive != "boolean") throw TypeError("Flame reactive must be true or false; pass a boolean");
494
+ d(e.haze ?? I, "haze", 0, 1), d(e.groundAlbedo ?? 0, "groundAlbedo", 0, 1), d(e.glowRadius ?? L, "glowRadius", .5, 10), d(e.yaw ?? 0, "yaw", -1e3, 1e3), d(e.lightPower ?? 1, "lightPower", 0, 1e6), e.keyDistance !== void 0 && d(e.keyDistance, "keyDistance", .01, 1e4), e.noon !== void 0 && d(e.noon, "noon", 1e-9, 1e7), e.heat !== void 0 && d(e.heat, "heat", 0, 0x9184e72a000);
334
495
  }
335
496
  lookOf() {
336
497
  let e = this.options, t = this.look, n = (e, n) => t && typeof t[e] == "number" ? t[e] : n, r = t?.["flames.edgeColor"] ?? [
@@ -366,17 +527,33 @@ struct Depth {@builtin(frag_depth) depth:f32}
366
527
  ];
367
528
  if (!e && r.every((e, t) => e === this.key[t])) return;
368
529
  for (let e = 0; e < r.length; e++) this.key[e] = r[e];
369
- let i = c(n.core, "core", 800, 3e3), a = c(Math.min(n.edge, i), "edge", 600, 3e3), o = c(t.cooling ?? 1.2, "cooling", .2, 5), s = c(t.exposure ?? .3, "exposure", 0, 1), l = d(i)[1], u = this.values;
370
- this.coreFloor = Math.min(...f(i));
371
- for (let e = 0; e < B; e++) {
372
- let t = e / 15, r = a + (i - a) * t ** o, c = Math.min(1, (d(r)[1] / l) ** s), p = f(r);
373
- for (let r = 0; r < 3; r++) u[48 + e * 4 + r] = p[r] * c + (n.edgeColor[r] - p[r] * c) * n.ramp * (1 - t);
374
- u[48 + e * 4 + 3] = 1;
530
+ let i = d(n.core, "core", 800, 3e3), a = d(Math.min(n.edge, i), "edge", 600, 3e3), o = d(t.cooling ?? 1.2, "cooling", .2, 5), s = d(t.exposure ?? .3, "exposure", 0, 1), c = m(i)[1], l = this.values;
531
+ for (let e = 0; e < R; e++) {
532
+ let t = e / 15, r = a + (i - a) * t ** o, u = Math.min(1, (m(r)[1] / c) ** s), d = h(r);
533
+ for (let r = 0; r < 3; r++) l[48 + e * 4 + r] = d[r] * u + (n.edgeColor[r] - d[r] * u) * n.ramp * (1 - t);
534
+ l[48 + e * 4 + 3] = 1;
375
535
  }
376
536
  }
377
537
  setFlameLook(e) {
378
538
  return this.look = { ...e }, this.write(), this;
379
539
  }
540
+ get peakRadiance() {
541
+ let e = this.lookOf();
542
+ return e.peak * e.radiance * this.coreRadiance(e);
543
+ }
544
+ get heatRelease() {
545
+ let e = this.options, [t, n] = e.footprint ?? [.5 * this.length(), .5 * this.length()];
546
+ return e.heat === void 0 ? e.intensity === void 0 ? H(this.length(), Math.sqrt(4 * t * n / Math.PI)) : e.intensity * 1e3 * t : e.heat;
547
+ }
548
+ coreRadiance(e) {
549
+ let t = this.options, n = Math.max(this.length(), .001), r = t.footprint ?? [.5 * n, .5 * n], i = [Math.max(r[0] * e.size, .001), Math.max(r[1] * e.size, .001)];
550
+ return G({
551
+ heat: this.heatRelease,
552
+ area: K(n, i),
553
+ kelvin: d(e.core, "core", 800, 3e3),
554
+ ...t.noon === void 0 ? {} : { noon: t.noon }
555
+ });
556
+ }
380
557
  get plume() {
381
558
  let e = this.options, t = this.heat, n = this.values;
382
559
  return t.position[0] = e.position[0], t.position[1] = e.position[1], t.position[2] = e.position[2], t.length = this.current, t.footprint[0] = 2 * n[24], t.footprint[1] = 2 * n[25], t.yaw = e.yaw ?? 0, t.time = this.clock, t;
@@ -389,7 +566,7 @@ struct Depth {@builtin(frag_depth) depth:f32}
389
566
  }
390
567
  get puffing() {
391
568
  let e = this.length();
392
- return T(E(this.options.footprint ?? [.5 * e, .5 * e]));
569
+ return k(A(this.options.footprint ?? [.5 * e, .5 * e]));
393
570
  }
394
571
  setup(e) {
395
572
  this.engine = e;
@@ -397,13 +574,13 @@ struct Depth {@builtin(frag_depth) depth:f32}
397
574
  registerPasses(e) {
398
575
  e.add({
399
576
  name: this.name + ":draw",
400
- order: D,
577
+ order: j,
401
578
  execute: (e) => {
402
579
  e.backend === "webgpu" && this.draw(e, !1);
403
580
  }
404
581
  }), e.add({
405
582
  name: this.name + ":depth",
406
- order: O,
583
+ order: ne,
407
584
  execute: (e) => {
408
585
  e.backend === "webgpu" && this.draw(e, !0);
409
586
  }
@@ -428,56 +605,70 @@ struct Depth {@builtin(frag_depth) depth:f32}
428
605
  if (this.disposed) return;
429
606
  this.advanceTime(e), this.check(), this.write();
430
607
  let t = this.options, n = this.length(), r = this.lookOf(), i = t.footprint ?? [.5 * n, .5 * n], a = this.values;
431
- this.current = n, c(r.peak, "peak", 1e-6, 1e3);
432
- let o = Math.max(n, .001), s = y * Math.sqrt(v * o), l = E(i), u = T(l), d = t.yaw ?? 0;
433
- a[19] = this.clock, a[20] = t.position[0], a[21] = n > 0 ? t.position[1] : -1e6, a[22] = t.position[2], a[23] = o, a[24] = i[0] / 2 * r.size, a[25] = i[1] / 2 * r.size, this.lean(s, a, 26), a[28] = Math.cos(d), a[29] = Math.sin(d), a[30] = u, a[31] = s / u, a[32] = s, a[33] = .22 * o * r.tongues, a[34] = r.flicker, a[35] = q(r.opacity), a[36] = r.peak, a[37] = Math.min(j * r.radiance, 2 / Math.max(this.coreFloor, .001)), a[38] = l, a[39] = this.seed, a[40] = .2 * o + .3 * Math.min(i[0], i[1]), a[41] = A * o, a[42] = (t.crowns ? -.46 : -.16) * o, a[43] = n > 0 ? M : 0, a[Y] = Math.floor(this.clock * 240) % 4096, a[113] = t.crowns ?? 0, this.glow(o, i, r, s, a), this.light(o, i, u, l, r.flicker, a[39]);
608
+ this.current = n, d(r.peak, "peak", 1e-6, 1e3);
609
+ let o = Math.max(n, .001), s = C * Math.sqrt(S * o), c = A(i), l = k(c), u = t.yaw ?? 0;
610
+ a[19] = this.clock, a[20] = t.position[0], a[21] = n > 0 ? t.position[1] : -1e6, a[22] = t.position[2], a[23] = o, a[24] = i[0] / 2 * r.size, a[25] = i[1] / 2 * r.size, this.lean(s, a, 26), a[28] = Math.cos(u), a[29] = Math.sin(u), a[30] = l, a[31] = s / l, a[32] = s, a[33] = .22 * o * r.tongues, a[34] = r.flicker, a[35] = ue(r.opacity), a[36] = r.peak * r.radiance * this.coreRadiance(r), a[37] = 0, a[38] = c, a[39] = this.seed, a[40] = .2 * o + .3 * Math.min(i[0], i[1]), a[41] = N * o, a[42] = (t.crowns ? -.46 : -.16) * o, a[43] = n > 0 ? ie : 0;
611
+ let f = t.relief, p = 0, m = 0;
612
+ for (let e = 0; e < 64; e++) {
613
+ let t = f ? f[e] : 0;
614
+ a[ye + e] = t, p = Math.min(p, t), m = Math.max(m, t);
615
+ }
616
+ a[ve] = p, a[129] = m, a[130] = i[0] / 2, a[131] = i[1] / 2, a[me] = Math.floor(this.clock * 240) % 4096, a[113] = t.crowns ?? 0, this.glow(o, i, r, s, a), this.light(o, i, l, c, r.flicker, a[39]);
617
+ }
618
+ lightTotal(e, t, n) {
619
+ let r = this.options, i = z * n.peak * n.radiance * this.coreRadiance(n) * e * (.5 * (t[0] + t[1]) + .24 * e);
620
+ if (r.keyDistance !== void 0) {
621
+ let [e, t, a] = h(Math.max(1e3, Math.min(n.core * .8, 3e3)));
622
+ i = Math.PI * r.keyDistance ** 2 / (.2126 * e + .7152 * t + .0722 * a);
623
+ }
624
+ return i * (r.lightPower ?? 1);
434
625
  }
435
626
  glow(e, t, n, r, i) {
436
- let a = this.options, o = Math.cos(a.yaw ?? 0), s = Math.sin(a.yaw ?? 0), c = a.slope?.[0] ?? 0, l = a.slope?.[1] ?? 0, u = c * o - l * s, d = c * s + l * o, p = Math.min(z, Math.max(1, Math.round(Math.max(t[0], t[1]) / e))), m = this.current > 0 && n.glow > 0, h = m ? V * n.peak * n.radiance * n.glow * e * (.5 * (t[0] + t[1]) + .24 * e) * (a.lightPower ?? 1) : 0, g = f(Math.max(1e3, Math.min(n.core * .8, 3e3))), _ = (a.glowRadius ?? R) * e, v = Math.max(Math.abs(i[26]), Math.abs(i[27])), y = Math.max(Math.abs(u), Math.abs(d)), b = a.groundAlbedo ?? (a.lights ? 0 : L);
437
- i[114] = _, i[115] = m ? p : 0, i[X] = u, i[117] = d, i[118] = b, i[119] = n.haze;
438
- for (let e = 0; e < 3; e++) i[Z + e] = h / p * g[e];
439
- i[123] = .35 * e, i[ne] = m ? Math.max(i[40], _ * (1 + y + v)) : i[40], i[125] = m ? Math.max(i[41], .35 * e + _ * (1 + y)) : i[41], i[126] = c, i[127] = l;
627
+ let a = this.options, o = Math.cos(a.yaw ?? 0), s = Math.sin(a.yaw ?? 0), c = a.slope?.[0] ?? 0, l = a.slope?.[1] ?? 0, u = c * o - l * s, d = c * s + l * o, f = Math.min(ce, Math.max(1, Math.round(Math.max(t[0], t[1]) / e))), p = this.current > 0 && n.glow > 0, m = p ? n.glow * this.lightTotal(e, t, n) : 0, g = h(Math.max(1e3, Math.min(n.core * .8, 3e3))), _ = (a.glowRadius ?? L) * e, v = Math.max(Math.abs(i[26]), Math.abs(i[27])), y = Math.max(Math.abs(u), Math.abs(d)), b = a.groundAlbedo ?? (a.lights ? 0 : se);
628
+ i[114] = _, i[115] = p ? f : 0, i[he] = u, i[117] = d, i[118] = b, i[119] = n.haze;
629
+ for (let e = 0; e < 3; e++) i[ge + e] = m / f * g[e];
630
+ i[123] = .35 * e, i[_e] = p ? Math.max(i[40], _ * (1 + y + v)) : i[40], i[125] = p ? Math.max(i[41], .35 * e + _ * (1 + y)) : i[41], i[126] = c, i[127] = l;
440
631
  }
441
632
  light(e, t, n, r, i, a) {
442
633
  if (!this.target || this.target.isDisposed) return;
443
- let o = this.options, s = this.lights, c = t[0] >= t[1], l = c ? t[0] : t[1], u = Math.min(4, Math.max(1, Math.round(l / Math.max(e, .001)))), d = this.current > 0, p = this.lookOf(), m = d ? V * p.peak * p.radiance * e * (.5 * (t[0] + t[1]) + .24 * e) * (o.lightPower ?? 1) : 0, h = Math.cos(o.yaw ?? 0), g = Math.sin(o.yaw ?? 0), _ = f(Math.max(1e3, Math.min(p.core * .8, 3e3)));
634
+ let o = this.options, s = this.lights, c = t[0] >= t[1], l = c ? t[0] : t[1], u = Math.min(s.length, Math.max(1, Math.round(l / Math.max(e, .001)))), d = this.current > 0, f = this.lookOf(), p = d ? this.lightTotal(e, t, f) : 0, m = Math.cos(o.yaw ?? 0), g = Math.sin(o.yaw ?? 0), _ = h(Math.max(1e3, Math.min(f.core * .8, 3e3)));
444
635
  for (let d = 0; d < s.length; d++) {
445
- let f = s[d], p = u > 1 ? (d / (u - 1) - .5) * l * .8 : 0, b = c ? p : 0, x = c ? 0 : p, S = 6.2831853 * (n * this.clock - .35 * e / (y * Math.sqrt(v * e) / n) + K(p / r + a)), C = Math.max(.15, 1 + i * (.3 * Math.sin(S) + .25 * (K(this.clock * n * 2.7 + d * 5.1 + a) - .5))), w = f.position;
446
- w[0] = o.position[0] + h * b + g * x, w[1] = o.position[1] + .35 * e, w[2] = o.position[2] - g * b + h * x, f.range = 30 * e, f.radius = .25 * Math.min(e, Math.max(t[0], t[1]) / u + .2 * e), f.intensity = d < u ? m / u * C : 0, f.color = _, this.steady[d] = d < u ? m / u : 0;
636
+ let f = s[d], h = u > 1 ? (d / (u - 1) - .5) * l * .8 : 0, v = c ? h : 0, y = c ? 0 : h, b = 6.2831853 * (n * this.clock - .35 * e / (C * Math.sqrt(S * e) / n) + J(h / r + a)), x = Math.max(.15, 1 + i * (.3 * Math.sin(b) + .25 * (J(this.clock * n * 2.7 + d * 5.1 + a) - .5))), w = f.position;
637
+ w[0] = o.position[0] + m * v + g * y, w[1] = o.position[1] + .35 * e + Y(o.relief, v / Math.max(t[0] / 2, 1e-6), y / Math.max(t[1] / 2, 1e-6)), w[2] = o.position[2] - g * v + m * y, f.range = 30 * e, f.radius = .25 * Math.min(e, Math.max(t[0], t[1]) / u + .2 * e), f.intensity = d < u ? p / u * x : 0, f.color = _, this.steady[d] = d < u ? p / u : 0;
447
638
  }
448
639
  this.target.setLights(s);
449
640
  }
450
- draw(t, o) {
641
+ draw(t, l) {
451
642
  if (this.disposed) return;
452
- let s = t.device, c = this.options, l = this.values, u = e(this.view, t.camera);
453
- if (!o) {
454
- l.set(t.camera.matrix);
455
- for (let e = 0; e < 3; e++) l[16 + e] = t.camera.position[e], l[44 + e] = -u[e * 4 + 2];
456
- this.uniform ??= s.createBuffer({
457
- size: 512,
643
+ let u = t.device, d = this.options, f = this.values, p = e(this.view, t.camera);
644
+ if (!l) {
645
+ f.set(t.camera.matrix);
646
+ for (let e = 0; e < 3; e++) f[16 + e] = t.camera.position[e], f[44 + e] = -p[e * 4 + 2];
647
+ this.uniform ??= u.createBuffer({
648
+ size: 784,
458
649
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
459
- }), s.queue.writeBuffer(this.uniform, 0, l);
650
+ }), u.queue.writeBuffer(this.uniform, 0, f);
460
651
  }
461
652
  if (!this.uniform) return;
462
- let d = r(c.fog ?? null), f = !t.format.includes("float") && !t.format.endsWith("-srgb");
463
- d && !o && (n(d, t.camera.position, this.fogData), this.fogBuffer ??= s.createBuffer({
653
+ let m = r(d.fog ?? null), h = !t.format.includes("float") && !t.format.endsWith("-srgb");
654
+ m && !l && (n(m, t.camera.position, this.fogData), this.fogBuffer ??= u.createBuffer({
464
655
  size: 48,
465
656
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
466
- }), s.queue.writeBuffer(this.fogBuffer, 0, this.fogData));
467
- let p = 0, m = c.depth;
468
- m && (this.softRuntime ??= a.create(s, this.owned), o ? p = this.samples : (p = this.samples = this.softRuntime.write(t, m(), u, 1), this.softRuntime.changed && this.groups.clear()));
469
- let h = t.descriptor.multisample?.count ?? 1, g = t.descriptor.depthStencil.format, _ = [
657
+ }), u.queue.writeBuffer(this.fogBuffer, 0, this.fogData));
658
+ let g = 0, _ = d.depth;
659
+ _ && (this.softRuntime ??= c.create(u, this.owned), l ? g = this.samples : (g = this.samples = this.softRuntime.write(t, _(), p, 1), this.softRuntime.changed && this.groups.clear()));
660
+ let v = t.descriptor.multisample?.count ?? 1, y = t.descriptor.depthStencil.format, b = [
470
661
  t.format,
662
+ y,
663
+ v,
471
664
  g,
472
- h,
473
- p,
474
- !!d,
475
- !!m
476
- ].join(":"), v = Q.get(s);
477
- v || Q.set(s, v = /* @__PURE__ */ new Map());
478
- let y = v.get(_);
479
- if (!y) {
480
- let e = s.createShaderModule({ code: ie(p, !!d, f, !!m) }), n = {
665
+ !!m,
666
+ !!_
667
+ ].join(":"), x = X.get(u);
668
+ x || X.set(u, x = /* @__PURE__ */ new Map());
669
+ let S = x.get(b);
670
+ if (!S) {
671
+ let e = u.createShaderModule({ code: $(g, !!m, h, !!_) }), n = _ ? u.createShaderModule({ code: $(g, !!m, h, !0, !1) }) : e, r = {
481
672
  color: {
482
673
  srcFactor: "one",
483
674
  dstFactor: "one-minus-src-alpha"
@@ -486,79 +677,100 @@ struct Depth {@builtin(frag_depth) depth:f32}
486
677
  srcFactor: "one",
487
678
  dstFactor: "one-minus-src-alpha"
488
679
  }
489
- }, r = (n, r, i, a) => s.createRenderPipeline({
680
+ }, i = (n, r, i, a, o = e) => u.createRenderPipeline({
490
681
  layout: "auto",
491
682
  vertex: {
492
- module: e,
683
+ module: o,
493
684
  entryPoint: n
494
685
  },
495
686
  fragment: {
496
- module: e,
687
+ module: o,
497
688
  entryPoint: r,
498
689
  targets: [i]
499
690
  },
500
691
  primitive: { topology: "triangle-list" },
501
692
  multisample: t.descriptor.multisample,
502
693
  depthStencil: {
503
- format: g,
694
+ format: y,
504
695
  ...a
505
696
  }
506
697
  });
507
- y = [
508
- r("glowVertex", "glowFragment", {
698
+ S = [
699
+ i("glowVertex", "glowFragment", {
509
700
  format: t.format,
510
- blend: n
701
+ blend: r
511
702
  }, {
512
703
  depthWriteEnabled: !1,
513
704
  depthCompare: "greater-equal"
514
705
  }),
515
- r("vertex", "fragment", {
706
+ i("vertex", "fragment", {
516
707
  format: t.format,
517
- blend: n
708
+ blend: r
518
709
  }, {
519
710
  depthWriteEnabled: !1,
520
- depthCompare: m ? "always" : "greater-equal"
711
+ depthCompare: _ ? "always" : "greater-equal"
521
712
  }),
522
- r("vertex", "depthFragment", {
713
+ i("vertex", "depthFragment", {
523
714
  format: t.format,
524
715
  writeMask: 0
525
716
  }, {
526
717
  depthWriteEnabled: !0,
527
718
  depthCompare: "greater-equal"
719
+ }, n),
720
+ i("vertex", "reactiveFragment", {
721
+ format: "r8unorm",
722
+ blend: s
723
+ }, {
724
+ depthWriteEnabled: !1,
725
+ depthCompare: _ ? "always" : "greater-equal"
726
+ }),
727
+ i("vertex", "coverageFragment", {
728
+ format: "r8unorm",
729
+ blend: s
730
+ }, {
731
+ depthWriteEnabled: !1,
732
+ depthCompare: _ ? "always" : "greater-equal"
528
733
  })
529
- ], v.set(_, y);
734
+ ], x.set(b, S);
530
735
  }
531
- let b = o ? [y[2]] : l[115] > 0 ? [y[0], y[1]] : [y[1]];
532
- for (let e of [
533
- y[0],
534
- y[1],
535
- y[2]
536
- ]) this.groups.has(e) || this.groups.set(e, s.createBindGroup({
736
+ let C = l ? [S[2]] : f[115] > 0 ? [S[0], S[1]] : [S[1]];
737
+ for (let e of S) this.groups.has(e) || this.groups.set(e, u.createBindGroup({
537
738
  layout: e.getBindGroupLayout(0),
538
739
  entries: [
539
740
  {
540
741
  binding: 0,
541
742
  resource: { buffer: this.uniform }
542
743
  },
543
- ...d ? [{
744
+ ...m && e !== S[2] ? [{
544
745
  binding: 5,
545
746
  resource: { buffer: this.fogBuffer }
546
747
  }] : [],
547
- ...p ? this.softRuntime.entries : []
748
+ ...g && e !== S[2] ? this.softRuntime.entries : []
548
749
  ]
549
750
  }));
550
- if (!(this.current > 0) || o && !((this.options.opacity ?? 1) >= 1 && this.lookOf().opacity >= 1)) return;
551
- this.attachment.view = t.color, this.depthAttachment.view = t.depth, this.depthAttachment.depthReadOnly = !o || void 0, o ? (this.depthAttachment.depthLoadOp = "load", this.depthAttachment.depthStoreOp = "store") : (delete this.depthAttachment.depthLoadOp, delete this.depthAttachment.depthStoreOp), this.depthAttachment.stencilReadOnly = g.includes("stencil") ? !0 : void 0;
552
- let x = t.encoder.beginRenderPass({
751
+ if (!(this.current > 0) || l && !((this.options.opacity ?? 1) >= 1 && this.lookOf().opacity >= 1)) return;
752
+ this.attachment.view = t.color, this.depthAttachment.view = t.depth, this.depthAttachment.depthReadOnly = !l || void 0, l ? (this.depthAttachment.depthLoadOp = "load", this.depthAttachment.depthStoreOp = "store") : (delete this.depthAttachment.depthLoadOp, delete this.depthAttachment.depthStoreOp), this.depthAttachment.stencilReadOnly = y.includes("stencil") ? !0 : void 0;
753
+ let w = t.encoder.beginRenderPass({
553
754
  colorAttachments: [this.attachment],
554
755
  depthStencilAttachment: this.depthAttachment
555
756
  });
556
- i(x, t);
557
- for (let e of b) x.setPipeline(e), x.setBindGroup(0, this.groups.get(e)), x.draw(36), this.engine && this.engine.stats.drawCalls++;
558
- x.end();
757
+ i(w, t);
758
+ for (let e of C) w.setPipeline(e), w.setBindGroup(0, this.groups.get(e)), w.draw(36), this.engine && this.engine.stats.drawCalls++;
759
+ if (w.end(), l) return;
760
+ (d.reactive ?? a(t, this)) && this.drawMask(t, S[3], o(t));
761
+ let T = this.engine && Q.get(this.engine);
762
+ T && T.watchers > 0 && this.drawMask(t, S[4], xe(T, t));
763
+ }
764
+ drawMask(e, t, n) {
765
+ this.reactiveAttachments[0] = n;
766
+ let r = e.encoder.beginRenderPass({
767
+ colorAttachments: this.reactiveAttachments,
768
+ depthStencilAttachment: this.depthAttachment
769
+ });
770
+ i(r, e), r.setPipeline(t), r.setBindGroup(0, this.groups.get(t)), r.draw(36), r.end(), this.engine && this.engine.stats.drawCalls++;
559
771
  }
560
772
  setLength(e) {
561
- return c(e, "length", 0, 1e3), this.options.length = e, this;
773
+ return d(e, "length", 0, 1e3), this.options.length = e, this;
562
774
  }
563
775
  setWind(e) {
564
776
  return this.options.wind = e, this;
@@ -566,10 +778,10 @@ struct Depth {@builtin(frag_depth) depth:f32}
566
778
  get steadyIntensities() {
567
779
  return this.steady;
568
780
  }
569
- static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
570
- h(e, "Flame");
571
- let r = $.get(e) ?? 0, i = new t(n, r);
572
- return e.use(i), $.set(e, r + 1), i;
781
+ static attach(e, n) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
782
+ v(e, "Flame");
783
+ let r = Z.get(e) ?? 0, i = new t(n, r);
784
+ return e.use(i), Z.set(e, r + 1), i;
573
785
  }
574
786
  release() {
575
787
  for (let e of [
@@ -589,8 +801,8 @@ struct Depth {@builtin(frag_depth) depth:f32}
589
801
  this.dispose();
590
802
  }
591
803
  };
592
- function oe(e, t, n) {
593
- let r = Math.sqrt(Math.max(t / b, 1)), i = structuredClone(e);
804
+ function we(e, t, n) {
805
+ let r = Math.sqrt(Math.max(t / w, 1)), i = structuredClone(e);
594
806
  return i.size *= r, i.rate *= r, i.capacity = Math.ceil(i.capacity * r), i.lifetime = [i.lifetime[0] * r, i.lifetime[1] * r], i.velocity = i.velocity.map((e) => e * r), i.gravity = i.gravity.map((e) => e * r), i.turbulence *= r, i.frequency /= r, {
595
807
  ...i,
596
808
  emissionExtent: [
@@ -602,4 +814,4 @@ function oe(e, t, n) {
602
814
  };
603
815
  }
604
816
  //#endregion
605
- export { y as FLAME_FROUDE, V as FLAME_LIGHT_FILL, m as FLAME_PEAK, H as FLAME_RADIANT_FRACTION, ae as Flame, b as HEARTH_FLAME_LENGTH, w as PUFFING_CONSTANT, u as blackbodyChromaticity, f as blackbodyColor, l as blackbodyLuminanceRatio, s as blackbodyLuminousEfficacy, x as byramFlameLength, S as byramIntensity, U as flameLuminousFlux, p as flameRamp, C as heskestadFlameLength, W as heskestadHeat, E as puffingDiameter, T as puffingFrequency, oe as scaleHearthEmbers };
817
+ export { C as FLAME_FROUDE, z as FLAME_LIGHT_FILL, _ as FLAME_PEAK, B as FLAME_RADIANT_FRACTION, de as FLAME_RELIEF, Ce as Flame, w as HEARTH_FLAME_LENGTH, D as INCENDIARY_4LB, O as PUFFING_CONSTANT, p as blackbodyChromaticity, h as blackbodyColor, f as blackbodyLuminanceRatio, u as blackbodyLuminousEfficacy, te as burningBed, T as byramFlameLength, ee as byramIntensity, K as flameArea, G as flameCoreRadiance, V as flameLuminousFlux, g as flameRamp, Y as flameReliefAt, E as heskestadFlameLength, H as heskestadHeat, A as puffingDiameter, k as puffingFrequency, we as scaleHearthEmbers, Se as watchFlameCoverage };