@threenative/core 0.3.11 → 0.3.12

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 (157) hide show
  1. package/capabilities.json +1096 -26
  2. package/dist/camera-shake-CZKOfGn4.d.ts +46 -0
  3. package/dist/{canvas-layer-vCtanIeB.d.ts → canvas-layer-CWuFRT7G.d.ts} +1 -1
  4. package/dist/chunk-2Z44XSI2.js +35 -0
  5. package/dist/chunk-5O73CDMR.js +1849 -0
  6. package/dist/chunk-6KLNISRJ.js +153 -0
  7. package/dist/chunk-7UUT3TY5.js +133 -0
  8. package/dist/chunk-CFGTPFUH.js +231 -0
  9. package/dist/chunk-DBELTTTM.js +615 -0
  10. package/dist/chunk-GMHATRPW.js +7701 -0
  11. package/dist/chunk-GXY7B3JG.js +46 -0
  12. package/dist/chunk-KIRUKTBQ.js +187 -0
  13. package/dist/chunk-N5LRP4BR.js +220 -0
  14. package/dist/chunk-OKXUCASC.js +2238 -0
  15. package/dist/chunk-QWJEMUUT.js +94 -0
  16. package/dist/chunk-VAZM36TV.js +497 -0
  17. package/dist/{game-DzMcitDO.d.ts → game-D7pAzZUY.d.ts} +15 -3
  18. package/dist/hot.d.ts +3 -3
  19. package/dist/hot.js +2 -46
  20. package/dist/index.d.ts +329 -302
  21. package/dist/index.js +10566 -22552
  22. package/dist/{model-lod-CTpZ6imz.d.ts → model-lod-B6BMqS1r.d.ts} +33 -3
  23. package/dist/playtest.d.ts +3 -3
  24. package/dist/playtest.js +24 -75
  25. package/dist/react-css.js +1 -215
  26. package/dist/react.d.ts +2 -2
  27. package/dist/{renderer-rZm0hVqq.d.ts → renderer-DvFVoAgj.d.ts} +13 -4
  28. package/dist/spells/index.d.ts +643 -0
  29. package/dist/spells/index.js +1558 -0
  30. package/dist/spells/ultra/index.d.ts +1600 -0
  31. package/dist/spells/ultra/index.js +6804 -0
  32. package/dist/terrain-jobs-worker.js +1 -123
  33. package/dist/two-sided-foliage-W523J3UM.js +1 -0
  34. package/dist/ui-layer.js +5 -384
  35. package/dist/worker.js +4 -41
  36. package/dist/world.d.ts +725 -259
  37. package/dist/world.js +16714 -18284
  38. package/mcp/animation-server.mjs +1 -1
  39. package/mcp/animation.mjs +2 -3
  40. package/mcp/engine-server.mjs +142 -47
  41. package/mcp/servers.mjs +9 -2
  42. package/mcp/terrain.mjs +8 -0
  43. package/package.json +14 -6
  44. package/patches/three@0.187.0-prd269-upgrade.patch +2102 -0
  45. package/patches/three@0.187.0.patch +2004 -407
  46. package/src/assets.ts +9 -2
  47. package/src/card-lod.ts +152 -0
  48. package/src/compressed-texture-preparation.ts +1008 -0
  49. package/src/frame-budget.ts +31 -20
  50. package/src/game-dev-tools.ts +93 -0
  51. package/src/game-frame-loop.ts +995 -0
  52. package/src/game-renderer-metrics.ts +77 -0
  53. package/src/game-startup.ts +1001 -0
  54. package/src/game-validate.ts +70 -0
  55. package/src/game.ts +253 -1935
  56. package/src/index.ts +27 -2
  57. package/src/launch-diagnostics.ts +22 -12
  58. package/src/look/ao-admission.ts +24 -0
  59. package/src/look/filmic-tone-mapping.ts +15 -13
  60. package/src/look/look-diagnostics.ts +3 -3
  61. package/src/look/quality.ts +10 -5
  62. package/src/look/world-environment.ts +76 -9
  63. package/src/loop.ts +29 -0
  64. package/src/model-lod.ts +42 -3
  65. package/src/particle-kinds.ts +515 -0
  66. package/src/picking.ts +17 -3
  67. package/src/playtest.ts +27 -1
  68. package/src/projection-apply.ts +4 -1
  69. package/src/projection-plan.ts +9 -6
  70. package/src/render/mesh-pool.ts +1 -1
  71. package/src/render/resolution-subrect.ts +2 -0
  72. package/src/render/rough-diffuse.ts +46 -12
  73. package/src/render/soft-shadow.ts +27 -12
  74. package/src/render/virtual-shadow-adaptive.ts +55 -0
  75. package/src/render/virtual-shadow-casters.ts +175 -0
  76. package/src/render/virtual-shadow-layers.ts +76 -0
  77. package/src/render/virtual-shadow-level.ts +224 -0
  78. package/src/render/virtual-shadow-markers.ts +193 -0
  79. package/src/render/virtual-shadow-options.ts +370 -0
  80. package/src/render/virtual-shadow-pages.ts +5 -0
  81. package/src/render/virtual-shadow.ts +213 -992
  82. package/src/render/world-impostor-surface.ts +293 -34
  83. package/src/render-pass-budget.ts +34 -7
  84. package/src/renderProjection.ts +22 -0
  85. package/src/renderer.ts +92 -37
  86. package/src/snow-field.ts +1 -1
  87. package/src/spells/cast-pool.ts +361 -0
  88. package/src/spells/index.ts +177 -0
  89. package/src/spells/mechanisms.ts +295 -0
  90. package/src/spells/reaction-field.ts +415 -0
  91. package/src/spells/spell-lights.ts +139 -0
  92. package/src/spells/spell-world.ts +187 -0
  93. package/src/spells/spell.ts +397 -0
  94. package/src/spells/spells.ts +283 -0
  95. package/src/spells/ultra/engine/camera.ts +184 -0
  96. package/src/spells/ultra/engine/quality.ts +96 -0
  97. package/src/spells/ultra/index.ts +52 -0
  98. package/src/spells/ultra/main.ts +305 -0
  99. package/src/spells/ultra/scene/arenaMaterial.ts +325 -0
  100. package/src/spells/ultra/spells/cast.ts +233 -0
  101. package/src/spells/ultra/spells/fire.ts +1267 -0
  102. package/src/spells/ultra/vfx/FluidVolume.ts +816 -0
  103. package/src/spells/ultra/vfx/FluidVolume.tsl.ts +855 -0
  104. package/src/spells/ultra/vfx/FxTarget.ts +61 -0
  105. package/src/spells/ultra/vfx/GroundField.ts +1399 -0
  106. package/src/spells/ultra/vfx/Particles.ts +1475 -0
  107. package/src/spells/ultra/vfx/Ribbons.ts +645 -0
  108. package/src/spells/ultra/vfx/Shockwaves.ts +286 -0
  109. package/src/spells/ultra/vfx/Volumes.ts +489 -0
  110. package/src/spells/ultra/vfx/common.ts +1195 -0
  111. package/src/spells/ultra/vfx/noise.ts +441 -0
  112. package/src/startup-readiness.ts +128 -34
  113. package/src/version.ts +1 -1
  114. package/src/warmup.ts +56 -8
  115. package/src/water-surface.ts +9 -3
  116. package/src/world-bundle-safety.ts +401 -0
  117. package/src/world-cell-batches.ts +1216 -0
  118. package/src/world-cell-chunks.ts +1132 -0
  119. package/src/world-cell-data.ts +995 -0
  120. package/src/world-cell-impostors.ts +1449 -0
  121. package/src/world-cell-lod-bias.ts +151 -0
  122. package/src/world-cell-models.ts +1074 -0
  123. package/src/world-cell-options.ts +189 -0
  124. package/src/world-cell-placements.ts +694 -0
  125. package/src/world-cell-prewarm.ts +557 -0
  126. package/src/world-cell-readiness.ts +357 -0
  127. package/src/world-cell-render-bundles.ts +459 -0
  128. package/src/world-cell-render-gpu-dress.ts +714 -0
  129. package/src/world-cell-render-main-cull.ts +484 -0
  130. package/src/world-cell-render-shadow-claims.ts +198 -0
  131. package/src/world-cell-render-util.ts +246 -0
  132. package/src/world-cell-render.ts +1493 -0
  133. package/src/world-cell-residency.ts +745 -0
  134. package/src/world-cells.ts +1318 -10418
  135. package/src/world-chunk-shadow.ts +308 -0
  136. package/src/world-collar.ts +315 -0
  137. package/src/world-gpu-flags.ts +163 -0
  138. package/src/world-gpu-readback.ts +881 -0
  139. package/src/world-gpu-reference.ts +510 -0
  140. package/src/world-gpu-scene.ts +214 -2264
  141. package/src/world-gpu-shadow.ts +190 -0
  142. package/src/world-gpu-types.ts +381 -0
  143. package/src/world-gpu-validation.ts +518 -0
  144. package/src/world-heightfield.ts +802 -0
  145. package/src/world-load-limiter.ts +106 -0
  146. package/src/world-noise.ts +241 -0
  147. package/src/world-package.ts +42 -0
  148. package/src/world-region.ts +1 -1
  149. package/src/world-terrain-splat.ts +365 -149
  150. package/src/world-tile-budget.ts +256 -0
  151. package/src/world-tile-geometry.ts +469 -0
  152. package/src/world-tile-lod.ts +408 -0
  153. package/src/world-tile-observation.ts +566 -0
  154. package/src/world-tile-stitch.ts +166 -0
  155. package/src/world-tiles.ts +170 -1745
  156. package/src/world-water-bodies.ts +359 -0
  157. package/src/world.ts +35 -741
@@ -0,0 +1,1267 @@
1
+ // Ported from Ultra Elements src/spells/fire.js @698b720 (MIT, Copyright (c) 2026 Humpalumps). JavaScript copied verbatim; GLSL transliterated to TSL.
2
+ //
3
+ // Slice 1 runs the Fireball's charge, release and flight (the raymarched ball and its light). The
4
+ // impact, explosion and Inferno JS is here verbatim and calls the fx services; until Particles,
5
+ // FluidVolume, GroundField, Ribbons and Shockwaves are ported they are main.ts's inert seams, so an
6
+ // impact draws nothing yet. HAZE_VERT/HAZE_FRAG (a distortion-only billboard) wait on the distortion
7
+ // composite (FxTarget.ts), so `hazes` is empty and every haze path is the upstream null path.
8
+ import { Color, MathUtils, Vector3, Vector4 } from "three";
9
+ import {
10
+ Fn,
11
+ If,
12
+ clamp,
13
+ float,
14
+ length,
15
+ max,
16
+ mix,
17
+ pow,
18
+ smoothstep,
19
+ sqrt,
20
+ uniform,
21
+ vec3,
22
+ } from "three/tsl";
23
+ import type { Node } from "three/webgpu";
24
+ import type { Fx, IFluidDomain } from "../main.js";
25
+ import type { IVolumeHandle, IVolumeScope } from "../vfx/Volumes.js";
26
+ import {
27
+ arenaSDFJS as arenaSDF,
28
+ blackbody,
29
+ curl3,
30
+ mulMat3Rows,
31
+ noise3,
32
+ noise3v,
33
+ } from "../vfx/common.js";
34
+ import { blackbodyRGB } from "../vfx/noise.js";
35
+ import type { ICast, Phase } from "./cast.js";
36
+
37
+ type F = Node<"float">;
38
+ type V3 = Node<"vec3">;
39
+ type V4 = Node<"vec4">;
40
+
41
+ // Fire (PLAN 3). Fireball: a raymarched teardrop whose noise streams backwards past the ball and
42
+ // is stretched into licking tongues down the tail; fire is emission = sigma * L(T) (hot soot glows,
43
+ // cold soot is smoke), so a white-yellow core shows through a thinner orange body, with a dark
44
+ // sooty fringe heaviest on the tail. Small fast-cooling flame licks, curling dark smoke, embers
45
+ // and a short hot core ribbon trail it. Impact: a pyroclastic volume (billows, vortex-ring roll,
46
+ // cools outside-in from white to orange to rolling dark smoke), sparks, glowing debris, a dust
47
+ // ring, a shockwave, heat into the ground field (which then grows ground flames by itself).
48
+ // Inferno: a roaring column volume swirled by a vortex force, a line light, heat-haze billboard,
49
+ // embers and a scorched ring.
50
+
51
+ // fire radiance at T: blackbody chromaticity, brightness ~ (T / Tref)^4 (Stefan-Boltzmann), and no
52
+ // visible glow below ~700 K (Draper point ~800 K): T^4 alone leaves cooled soot glowing dull red, which
53
+ // the night exposure (10x dusk) turns into a red veil over the smoke
54
+ export const fireL = Fn(([T, Tref]: [F, F]) => {
55
+ const k0 = T.div(Tref);
56
+ const k = k0.mul(k0);
57
+ return blackbody(T).mul(k.mul(k).mul(smoothstep(700.0, 1000.0, T)));
58
+ });
59
+
60
+ // FIREBALL_GLSL
61
+ // uBall radius m, core temperature K, intensity, time s
62
+ // uBall2 tail length m, flow m/s, soot, seed
63
+ // uBallPos ball centre (the proxy capsule also covers the tail behind it)
64
+ // uTint
65
+ export function FIREBALL(
66
+ pw: V3,
67
+ _pl: V3,
68
+ sigma: F,
69
+ albedo: V3,
70
+ emission: V3,
71
+ V: IVolumeScope,
72
+ ): void {
73
+ const uBall = V.uBall as V4;
74
+ const uBall2 = V.uBall2 as V4;
75
+ const uBallPos = V.uBallPos as V3;
76
+ const uTint = V.uTint as V3;
77
+ sigma.assign(0.0);
78
+ albedo.assign(vec3(0.0));
79
+ emission.assign(vec3(0.0));
80
+ const R = uBall.x;
81
+ const time = uBall.w;
82
+ const L = uBall2.x;
83
+ const q = mulMat3Rows(V.uVolRot, pw.sub(uBallPos)); // y = flight direction, metres
84
+ const u = q.y.negate().div(L);
85
+ const uc = clamp(u, 0.0, 1.0); // 0 at the centre .. 1 at the tail tip
86
+ // teardrop: a sphere ahead, a tapering tail behind
87
+ const d0 = R.mul(sqrt(max(float(1.0).sub(uc.mul(0.9)), 0.0))).sub(
88
+ length(vec3(q.x, max(q.y, 0.0), q.z)),
89
+ );
90
+ const amp = R.mul(uc.mul(0.7).add(0.32));
91
+ // if (d0 < -amp || u > 1.3) return;
92
+ If(d0.greaterThanEqual(amp.negate()).and(u.lessThanEqual(1.3)), () => {
93
+ // flames stream backwards past the ball (noise scrolls along -y), stretched a little into
94
+ // tongues down the tail. Band-limited on purpose: the baked noise's finest octaves sit far below
95
+ // the march step and would only alias into grain, so the frequency stays low and the detail
96
+ // octave fades out as the step grows (gVolDt).
97
+ const s = float(0.34).div(R);
98
+ const np0 = vec3(q.x, q.y.mul(mix(1.0, 0.6, uc)).add(uBall2.y.mul(time)), q.z).mul(s);
99
+ const np = np0
100
+ .add(curl3(np0.mul(0.4).add(vec3(0.0, time.mul(0.1), uBall2.w))).mul(0.3))
101
+ .add(uBall2.w);
102
+ const n1 = noise3(np);
103
+ const n2 = noise3(np.mul(1.9).add(vec3(0.37, s.mul(time).mul(0.5), 0.11)));
104
+ const detail = float(1.0).sub(smoothstep(0.35, 0.9, V.gVolDt.div(R)));
105
+ const d = d0
106
+ .add(n1.sub(0.5).mul(2.0).mul(amp))
107
+ .add(n2.sub(0.5).mul(0.7).mul(amp).mul(detail))
108
+ .sub(R.mul(uc).mul(0.3));
109
+ const tail = float(1.0).sub(smoothstep(0.8, 1.25, u));
110
+ const body = smoothstep(0.0, R.mul(0.5), d).mul(tail);
111
+ // boiling cells (Worley, riding the flow): the burning surface breaks into dense, hot cells with
112
+ // thin, cooler, sooty folds between them, so the white core shows through in pockets
113
+ const cell = mix(
114
+ 0.5,
115
+ noise3v(np.mul(1.5).add(vec3(0.0, s.mul(time).mul(0.35), 0.0))).b,
116
+ detail,
117
+ );
118
+ const fold = float(1.0).sub(cell);
119
+ const heat = clamp(
120
+ pow(clamp(d.div(R), 0.0, 1.0), 1.15)
121
+ .mul(1.9)
122
+ .mul(float(1.0).sub(uc.mul(0.55)))
123
+ .add(n2.sub(0.5).mul(0.2))
124
+ .add(cell.sub(0.5).mul(0.45)),
125
+ 0.0,
126
+ 1.0,
127
+ );
128
+ const T = mix(760.0, uBall.y.mul(1.45), heat);
129
+ const sf = body.mul(cell.mul(cell).mul(4.0).add(1.0)).div(R);
130
+ // soot: where the tongues cool on the trailing side and in the folds, patchy, nothing ahead
131
+ const soot = smoothstep(R.mul(-0.3), R.mul(0.2), d)
132
+ .mul(float(1.0).sub(smoothstep(0.0, 0.45, heat)))
133
+ .mul(max(smoothstep(0.42, 0.75, n2), fold.mul(fold).mul(0.7)))
134
+ .mul(smoothstep(-0.25, 0.7, u))
135
+ .mul(tail);
136
+ const ss = soot.mul(uBall2.z).mul(8.0).div(R);
137
+ sigma.assign(sf.add(ss));
138
+ emission.assign(fireL(T, uBall.y).mul(sf).mul(uTint).mul(uBall.z));
139
+ albedo.assign(vec3(0.02, 0.018, 0.016).mul(ss.div(max(sigma, 1e-4))));
140
+ });
141
+ }
142
+
143
+ // flame-ish kinds: [kind, hot x T, cold x T]; recoloured when temperature or tint change
144
+ const HOT_KINDS: [string, number, number][] = [
145
+ ["flame", 1.25, 0.38],
146
+ ["ember", 1.1, 0.5],
147
+ ["spark", 1.45, 0.6],
148
+ ];
149
+
150
+ interface IFireData {
151
+ light: ReturnType<Fx["lights"]["acquire"]>;
152
+ ball: IVolumeHandle | null;
153
+ home: Vector3;
154
+ fl: IFluidDomain | null;
155
+ trail: ReturnType<Fx["trails"]["acquire"]>;
156
+ vortex: ReturnType<Fx["forces"]["acquire"]>;
157
+ haze: IHaze | null;
158
+ age: number;
159
+ nextSplat: number;
160
+ dimmed: boolean;
161
+ }
162
+ interface IHaze {
163
+ visible: boolean;
164
+ }
165
+
166
+ export default {
167
+ id: "fire",
168
+ name: "Fire",
169
+ key: "2",
170
+ hue: "#ff7a1a",
171
+ shape: "projectile",
172
+ forms: ["Fireball", "Inferno"],
173
+ radius: 0.35,
174
+ params: {
175
+ size: 1,
176
+ speed: 18,
177
+ temperature: 1900,
178
+ intensity: 1,
179
+ soot: 1,
180
+ embers: 1,
181
+ smoke: 1,
182
+ haze: 1,
183
+ scorch: 1,
184
+ height: 1,
185
+ tint: "#ffffff",
186
+ },
187
+ ranges: {
188
+ size: [0.3, 3, 0.01],
189
+ speed: [4, 40, 0.1],
190
+ temperature: [900, 6500, 10],
191
+ intensity: [0, 3, 0.01],
192
+ soot: [0, 3, 0.01],
193
+ embers: [0, 3, 0.01],
194
+ smoke: [0, 3, 0.01],
195
+ haze: [0, 3, 0.01],
196
+ scorch: [0, 2, 0.01],
197
+ height: [0.4, 2, 0.01],
198
+ },
199
+ presets: {
200
+ hellfire: { temperature: 1500, tint: "#ff6a4a", smoke: 1.6, soot: 1.6, intensity: 1.2 },
201
+ "blue flame": { temperature: 6500, tint: "#8fb8ff", smoke: 0.3, soot: 0.15 },
202
+ soulfire: { temperature: 2600, tint: "#3cff9a", smoke: 0.5, soot: 0.5 },
203
+ },
204
+ timing: { charge: 0.7, impact: 0.25, linger: 5, sustain: 2.6 },
205
+ kinds: {
206
+ // small fast-cooling licks: they ride off the ball, curl, erode away and turn to soot
207
+ flame: {
208
+ style: "media",
209
+ drag: 3.6,
210
+ buoyancy: 3.8,
211
+ curl: 3.2,
212
+ curlScale: 0.6,
213
+ life: [0.16, 0.36],
214
+ size: [0.09, 0.32],
215
+ sizePow: 0.6,
216
+ emissive: 1.3,
217
+ temp: [2375, 720],
218
+ toSmokeAt: 0.5,
219
+ smokeAlbedo: 0.04,
220
+ alpha: [0.75, 0],
221
+ density: 9,
222
+ distortion: 0.6,
223
+ erosion: 1.6,
224
+ fadeIn: 0.06,
225
+ fadeOut: 0.3,
226
+ },
227
+ ember: {
228
+ style: "glow",
229
+ drag: 0.6,
230
+ buoyancy: 1.7,
231
+ gravity: 1.2,
232
+ curl: 2.8,
233
+ curlScale: 0.5,
234
+ life: [1.0, 2.6],
235
+ size: [0.028, 0.01],
236
+ stretch: 0.025,
237
+ emissive: 4,
238
+ temp: [2090, 950],
239
+ restitution: 0.3,
240
+ friction: 0.4,
241
+ paints: "char",
242
+ paintAmount: 0.05,
243
+ },
244
+ spark: {
245
+ style: "glow",
246
+ drag: 0.35,
247
+ gravity: 9.8,
248
+ restitution: 0.4,
249
+ friction: 0.3,
250
+ life: [0.4, 1.3],
251
+ size: [0.03, 0.01],
252
+ stretch: 0.035,
253
+ emissive: 6,
254
+ temp: [2750, 1140],
255
+ paints: "heat",
256
+ paintAmount: 0.04,
257
+ },
258
+ smoke: {
259
+ style: "media",
260
+ emissive: 0,
261
+ drag: 1.3,
262
+ buoyancy: 1.6,
263
+ curl: 1.7,
264
+ curlScale: 0.32,
265
+ life: [2.2, 4.5],
266
+ size: [0.35, 2.0],
267
+ sizePow: 0.55,
268
+ color: ["#15120f", "#2e2b28"],
269
+ alpha: [0.62, 0],
270
+ density: 2.6,
271
+ erosion: 0.8,
272
+ fadeIn: 0.12,
273
+ fadeOut: 0.45,
274
+ },
275
+ dust: {
276
+ style: "media",
277
+ emissive: 0,
278
+ drag: 3.2,
279
+ buoyancy: 0.15,
280
+ curl: 0.6,
281
+ life: [0.8, 1.8],
282
+ size: [0.35, 1.4],
283
+ color: ["#463c34", "#36302b"],
284
+ alpha: [0.38, 0],
285
+ density: 1.4,
286
+ erosion: 0.6,
287
+ },
288
+ debris: {
289
+ style: "debris",
290
+ mesh: "rock",
291
+ drag: 0.25,
292
+ gravity: 9.8,
293
+ restitution: 0.3,
294
+ friction: 0.6,
295
+ life: [1.6, 3.2],
296
+ size: [0.085, 0.085],
297
+ color: ["#2a2220", "#ff5a10"],
298
+ alpha: [1, 0.9],
299
+ spin: 7,
300
+ fadeOut: 0.15,
301
+ paints: "heat",
302
+ paintAmount: 0.08,
303
+ },
304
+ },
305
+
306
+ create(fx: Fx) {
307
+ const S = this;
308
+ const P = fx.particles;
309
+ const lick = P.emitter("fire.flame", {
310
+ shape: "shell",
311
+ radius: 0.32,
312
+ spread: 0.9,
313
+ radial: 1.3,
314
+ });
315
+ const flame = P.emitter("fire.flame", { shape: "sphere", radius: 0.2, spread: 0.5 });
316
+ const muzzle = P.emitter("fire.flame", {
317
+ shape: "cone",
318
+ radius: 0.15,
319
+ spread: 0.6,
320
+ radial: 7,
321
+ cone: 0.5,
322
+ });
323
+ const pillar = P.emitter("fire.flame", {
324
+ shape: "disk",
325
+ radius: 1.0,
326
+ spread: 0.7,
327
+ radial: -0.6,
328
+ });
329
+ const blast = P.emitter("fire.flame", {
330
+ shape: "sphere",
331
+ radius: 0.6,
332
+ spread: 2.2,
333
+ radial: 5,
334
+ life: 2.6,
335
+ });
336
+ const ember = P.emitter("fire.ember", { shape: "sphere", radius: 0.25, spread: 1.2 });
337
+ const spark = P.emitter("fire.spark", { shape: "sphere", radius: 0.3, spread: 8, radial: 4 });
338
+ const smoke = P.emitter("fire.smoke", { shape: "sphere", radius: 0.5, spread: 0.6 });
339
+ const dust = P.emitter("fire.dust", { shape: "ring", radius: 0.8, spread: 0.3, radial: 7 });
340
+ const debris = P.emitter("fire.debris", { shape: "sphere", radius: 0.4, spread: 4, radial: 6 });
341
+ // ground flames wherever the field is hot (the same flame kind, a little bigger and slower)
342
+ P.fieldEmitter("fire.flame", {
343
+ slots: 1536,
344
+ a: [1, 0, 0, 0],
345
+ threshold: 0.35,
346
+ rate: 5,
347
+ up: 0.8,
348
+ lifeScale: 1.8,
349
+ sizeScale: 1.4,
350
+ });
351
+
352
+ // the shared combustion fluid: the explosion and the inferno column are simulated fire
353
+ // (upstream: FluidVolume.get(fx); here the fx service seam)
354
+ const fluid = fx.fluid;
355
+
356
+ // flight: one raymarched fireball per live cast
357
+ const tint = new Vector3(1, 1, 1);
358
+ const balls: IVolumeHandle[] = [];
359
+ for (let i = 0; i < 3; i++) {
360
+ const v = fx.volumes.add({
361
+ shape: "capsule",
362
+ tsl: FIREBALL,
363
+ maxSteps: 32,
364
+ uniforms: {
365
+ uTint: uniform(tint),
366
+ uBall: uniform(new Vector4()),
367
+ uBall2: uniform(new Vector4()),
368
+ uBallPos: uniform(new Vector3()),
369
+ },
370
+ });
371
+ v.visible = false;
372
+ v.g = 0.35;
373
+ balls.push(v);
374
+ }
375
+ const ballU = (v: IVolumeHandle) =>
376
+ v.uniforms as unknown as {
377
+ uBall: { value: Vector4 };
378
+ uBall2: { value: Vector4 };
379
+ uBallPos: { value: Vector3 };
380
+ };
381
+ // where each cast's ball forms: in front of the caster's orb, towards the target (one per cast record)
382
+ const homes = Array.from({ length: 16 }, () => new Vector3());
383
+ const isFree = (v: { visible: boolean }) => !v.visible;
384
+ const take = <T extends { visible: boolean }>(list: T[]) => list.find(isFree) ?? null;
385
+
386
+ // heat-haze billboards (inferno column, explosion): HAZE_VERT/HAZE_FRAG not ported yet (see top)
387
+ const hazes: IHaze[] = [];
388
+
389
+ const col = new Color();
390
+ const tintCol = new Color();
391
+ const lightColor = (T: number, out: Color) => {
392
+ blackbodyRGB(T, out);
393
+ return out.multiply(tintCol);
394
+ };
395
+ const _a = new Vector3();
396
+ const _b = new Vector3();
397
+ const _vd = new Vector3();
398
+ const _Y = new Vector3(0, 1, 0);
399
+ const _down = new Vector3(0, -1, 0);
400
+ const _shC = new Vector3();
401
+ // biome-ignore lint/style/useNamingConvention: upstream Ultra Elements code, copied verbatim
402
+ const SPLAT = {};
403
+ const shock: Record<string, unknown> & { pos: Vector3 } = { pos: new Vector3() };
404
+ // biome-ignore lint/style/useNamingConvention: upstream Ultra Elements code, copied verbatim
405
+ const SRC = {
406
+ pos: new Vector3(),
407
+ vel: new Vector3(),
408
+ radius: 1,
409
+ fuel: 0,
410
+ temp: 0,
411
+ soot: 0,
412
+ radial: 0,
413
+ noise: 0,
414
+ noiseScale: 1,
415
+ seed: 0,
416
+ coupling: 0,
417
+ burst: false,
418
+ };
419
+ let lastT = -1;
420
+ let lastTint = "";
421
+ // kind patches, reused (retint runs from phases)
422
+ const hot = HOT_KINDS.map(([k, a, b]) => ({
423
+ name: `fire.${k}`,
424
+ a,
425
+ b,
426
+ white: { temp: [0, 0] },
427
+ tinted: { temp: null, color: [new Color(), new Color()] },
428
+ }));
429
+ // biome-ignore lint/style/useNamingConvention: upstream Ultra Elements code, copied verbatim
430
+ const DEBRIS = { color: [new Color("#2a2220"), new Color()] };
431
+
432
+ // particle kinds follow temperature and tint: blackbody ramps when untinted, else tinted
433
+ // blackbody colours (the kind table has no tint), written as texels (no recompile)
434
+ function retint() {
435
+ const p = S.params;
436
+ if (p.temperature === lastT && p.tint === lastTint) return;
437
+ lastT = p.temperature;
438
+ lastTint = p.tint;
439
+ tintCol.set(p.tint);
440
+ tint.set(tintCol.r, tintCol.g, tintCol.b);
441
+ const white = tintCol.r > 0.97 && tintCol.g > 0.97 && tintCol.b > 0.97;
442
+ for (const h of hot) {
443
+ if (white) {
444
+ h.white.temp[0] = p.temperature * h.a;
445
+ h.white.temp[1] = p.temperature * h.b;
446
+ P.setKind(h.name, h.white);
447
+ } else {
448
+ blackbodyRGB(p.temperature * h.a, h.tinted.color[0] as Color).multiply(tintCol);
449
+ blackbodyRGB(p.temperature * h.b, h.tinted.color[1] as Color)
450
+ .multiply(tintCol)
451
+ .multiplyScalar((h.b / h.a) ** 3);
452
+ P.setKind(h.name, h.tinted);
453
+ }
454
+ }
455
+ // glowing debris: tinted blackbody at 0.8 T, normalised to a peak channel of 1 (#ff5a10 at 1900 K)
456
+ const e = blackbodyRGB(p.temperature * 0.8, DEBRIS.color[1] as Color).multiply(tintCol);
457
+ e.multiplyScalar(1 / Math.max(e.r, e.g, e.b, 1e-4));
458
+ P.setKind("fire.debris", DEBRIS);
459
+ }
460
+ retint();
461
+
462
+ function splat(
463
+ x: number,
464
+ z: number,
465
+ radius: number,
466
+ heat: number,
467
+ char: number,
468
+ pattern: string,
469
+ seed: number,
470
+ width = 0,
471
+ ) {
472
+ Object.assign(SPLAT, { x, z, radius, heat, char, pattern, seed, width });
473
+ fx.ground.splat(SPLAT);
474
+ }
475
+
476
+ // look shared by both fluid forms (spell params -> domain look)
477
+ function lookFluid(f: IFluidDomain, p: typeof S.params) {
478
+ f.temperature = p.temperature;
479
+ f.tint.copy(tintCol);
480
+ f.emission = 6.5 * p.intensity;
481
+ f.sootDensity = 3.2;
482
+ f.flameDensity = 0.9;
483
+ f.sootYield = 0.75 * p.soot;
484
+ f.sootColor.setRGB(0.09, 0.085, 0.08);
485
+ }
486
+
487
+ // one emitter record, reused
488
+ function src(
489
+ f: IFluidDomain,
490
+ x: number,
491
+ y: number,
492
+ z: number,
493
+ radius: number,
494
+ fuel: number,
495
+ temp: number,
496
+ soot: number,
497
+ burst: boolean,
498
+ noise: number,
499
+ noiseScale: number,
500
+ seed: number,
501
+ vx: number,
502
+ vy: number,
503
+ vz: number,
504
+ radial: number,
505
+ coupling: number,
506
+ ) {
507
+ SRC.pos.set(x, y, z);
508
+ SRC.radius = radius;
509
+ SRC.fuel = fuel;
510
+ SRC.temp = temp;
511
+ SRC.soot = soot;
512
+ SRC.burst = burst;
513
+ SRC.noise = noise;
514
+ SRC.noiseScale = noiseScale;
515
+ SRC.seed = seed;
516
+ SRC.vel.set(vx, vy, vz);
517
+ SRC.radial = radial;
518
+ SRC.coupling = coupling;
519
+ f.emit(SRC);
520
+ }
521
+
522
+ // capsule proxy along the flight direction: front cap around the ball, body over the tail
523
+ function placeBall(
524
+ v: IVolumeHandle,
525
+ pos: Vector3,
526
+ vel: Vector3,
527
+ R: number,
528
+ I: number,
529
+ time: number,
530
+ tail: number,
531
+ flow: number,
532
+ seed: number,
533
+ ) {
534
+ const p = S.params;
535
+ const sp = vel.length();
536
+ if (sp > 1e-4) _vd.copy(vel).divideScalar(sp);
537
+ else _vd.set(0, 1, 0);
538
+ const front = R * 1.45;
539
+ const back = tail + R * 0.35;
540
+ const ra = R * 1.5;
541
+ v.quaternion.setFromUnitVectors(_Y, _vd);
542
+ v.scale.set(ra, Math.max((front + back) * 0.5, ra), ra);
543
+ v.position.copy(pos).addScaledVector(_vd, (front - back) * 0.5);
544
+ ballU(v).uBall.value.set(R, p.temperature, I, time);
545
+ ballU(v).uBall2.value.set(tail, flow, p.soot, seed);
546
+ ballU(v).uBallPos.value.copy(pos);
547
+ }
548
+
549
+ function freeHaze() {
550
+ return hazes.find(isFree) ?? null;
551
+ }
552
+ function placeHaze(
553
+ _m: IHaze,
554
+ _x: number,
555
+ _y: number,
556
+ _z: number,
557
+ _halfWidth: number,
558
+ _height: number,
559
+ _strength: number,
560
+ ) {
561
+ // uHazeA / uHazeB: set on the haze material once HAZE_FRAG is ported
562
+ }
563
+ const data = (c: ICast) => c.data as unknown as IFireData;
564
+
565
+ return {
566
+ onParam(k: string) {
567
+ if (k === "tint" || k === "temperature") retint();
568
+ },
569
+
570
+ // Fireball flies like any projectile; Inferno erupts at the target with no flight
571
+ travel(c: ICast, dt: number) {
572
+ if (c.form === "Inferno") {
573
+ c.pos.copy(c.to);
574
+ return true;
575
+ }
576
+ c.pos.addScaledVector(c.vel, dt);
577
+ c.travelled += c.vel.length() * dt;
578
+ const passed = _a.subVectors(c.to, c.pos).dot(c.dir) <= 0;
579
+ const hit =
580
+ (c.travelled > 1 && arenaSDF(c.pos) < S.radius) || passed || c.t > c.durations.travel;
581
+ if (hit && passed && c.t <= c.durations.travel) c.pos.copy(c.to);
582
+ return hit;
583
+ },
584
+
585
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
586
+ phase(c: ICast, name: Phase) {
587
+ const p = S.params;
588
+ const d = data(c);
589
+ retint();
590
+ if (name === "charge") {
591
+ d.light = fx.lights.acquire();
592
+ if (d.light) {
593
+ d.light.range = 9;
594
+ d.light.intensity = 0;
595
+ d.light.shadow = true;
596
+ d.light.type = 0;
597
+ lightColor(p.temperature, d.light.color);
598
+ }
599
+ d.ball = c.form === "Fireball" ? take(balls) : null;
600
+ // biome-ignore lint/style/noNonNullAssertion: upstream Ultra Elements code, copied verbatim
601
+ d.home = homes[c.index % 16]!.copy(c.from)
602
+ .addScaledVector(c.dir, 0.6 * p.size)
603
+ .setY(c.from.y + 0.12 * p.size);
604
+ if (d.ball) {
605
+ d.ball.visible = true;
606
+ placeBall(d.ball, d.home, _down, 0.01, 0, 0, 0.02, 2, c.seed % 89);
607
+ }
608
+ d.fl = null;
609
+ d.trail = null;
610
+ d.vortex = null;
611
+ d.haze = null;
612
+ d.age = 0;
613
+ d.nextSplat = 0;
614
+ d.dimmed = false;
615
+ } else if (name === "release") {
616
+ fx.rig.shake(0.12, 10);
617
+ if (c.form === "Fireball") {
618
+ // it leaves from where it formed; the orb that fed it lights back up
619
+ c.pos.copy(d.home);
620
+ fx.arena.setFocus(fx.arena.focus.color, 2.5);
621
+ d.dimmed = false;
622
+ d.trail = fx.trails.acquire();
623
+ const t = d.trail;
624
+ if (t) {
625
+ t.width = 0.09 * p.size;
626
+ t.intensity = 2.5 * p.intensity;
627
+ t.glow = 3;
628
+ t.glowIntensity = 0.22;
629
+ t.fadeTime = 0.14;
630
+ t.distortion = 0.1 * p.haze;
631
+ lightColor(p.temperature * 1.15, t.color);
632
+ }
633
+ muzzle.pos.copy(c.pos);
634
+ muzzle.p.copy(c.dir);
635
+ muzzle.vel.copy(c.dir).multiplyScalar(3);
636
+ muzzle.size = p.size;
637
+ muzzle.burst(70 * p.size);
638
+ }
639
+ } else if (name === "impact") {
640
+ if (d.ball) {
641
+ d.ball.visible = false;
642
+ d.ball = null;
643
+ }
644
+ d.trail?.release();
645
+ d.trail = null;
646
+ if (c.form === "Fireball") explode(c, p, d);
647
+ else erupt(c, p, d);
648
+ } else if (name === "done") {
649
+ if (d.dimmed) {
650
+ d.dimmed = false;
651
+ fx.arena.setFocus(fx.arena.focus.color, 2.5);
652
+ } // cut short while charging
653
+ d.light?.release();
654
+ d.light = null;
655
+ d.vortex?.release();
656
+ d.vortex = null;
657
+ d.trail?.release();
658
+ d.trail = null;
659
+ d.fl?.release();
660
+ d.fl = null;
661
+ if (d.ball) d.ball.visible = false;
662
+ if (d.haze) d.haze.visible = false;
663
+ d.ball = d.haze = null;
664
+ }
665
+ },
666
+
667
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
668
+ update(c: ICast, dt: number) {
669
+ const p = S.params;
670
+ const d = data(c);
671
+ const L = d.light;
672
+ const flick =
673
+ 0.8 +
674
+ 0.2 * Math.sin(c.age * 31 + c.seed) * Math.sin(c.age * 13.7) +
675
+ 0.06 * Math.sin(c.age * 71);
676
+ if (c.phase === "charge") {
677
+ const k = c.t / c.durations.charge;
678
+ const at = c.form === "Fireball" ? d.home : c.pos;
679
+ if (d.ball) {
680
+ // the ball boils up out of nothing in front of the orb, which pours itself into it
681
+ const e = MathUtils.smoothstep(k, 0, 0.8);
682
+ placeBall(
683
+ d.ball,
684
+ at,
685
+ _down,
686
+ 0.4 * p.size * (0.15 + 0.85 * e),
687
+ 6 * p.intensity * (0.4 + 0.6 * e),
688
+ c.age,
689
+ 0.42 * p.size * (0.5 + e),
690
+ 2.8,
691
+ c.seed % 89,
692
+ );
693
+ fx.arena.setFocus(fx.arena.focus.color, 2.5 * (1 - 0.8 * e));
694
+ d.dimmed = true;
695
+ }
696
+ flame.pos.copy(at);
697
+ flame.vel.set(0, 0.6, 0);
698
+ flame.size = p.size * 0.5;
699
+ flame.rate(140 * p.size, dt);
700
+ // embers spiral in from a ring around the focus
701
+ ember.pos
702
+ .copy(at)
703
+ .addScaledVector(_a.set(Math.sin(c.age * 9), 0.3, Math.cos(c.age * 9)), 0.9);
704
+ ember.vel
705
+ .subVectors(at, ember.pos)
706
+ .multiplyScalar(2.5)
707
+ .addScaledVector(_a.set(Math.cos(c.age * 9), 0, -Math.sin(c.age * 9)), 2);
708
+ ember.rate(180 * p.embers, dt);
709
+ if (L) {
710
+ L.pos.copy(at);
711
+ L.intensity = 14 * k * flick * p.intensity;
712
+ }
713
+ if (c.form === "Inferno") {
714
+ // the ground at the target heats up in a ring before the eruption
715
+ if (c.t >= d.nextSplat) {
716
+ d.nextSplat = c.t + 0.15;
717
+ splat(
718
+ c.to.x,
719
+ c.to.z,
720
+ 1.7 * p.size * (0.6 + 0.4 * k),
721
+ 0.3 * p.scorch,
722
+ 0.2,
723
+ "ring",
724
+ c.seed + c.t,
725
+ 0.35 * p.size,
726
+ );
727
+ }
728
+ ember.pos.set(c.to.x, 0.15, c.to.z);
729
+ ember.vel.set(0, 1.5, 0);
730
+ ember.rate(90 * p.embers * k, dt);
731
+ }
732
+ } else if (c.phase === "travel") {
733
+ const R = 0.4 * p.size;
734
+ const sp = c.vel.length();
735
+ if (d.ball)
736
+ placeBall(
737
+ d.ball,
738
+ c.pos,
739
+ c.vel,
740
+ R,
741
+ 4.5 * p.intensity,
742
+ c.age,
743
+ R * 2.8,
744
+ 3 + 0.4 * sp,
745
+ c.seed % 89,
746
+ );
747
+ lick.pos.copy(c.pos);
748
+ lick.radius = 0.8 * R;
749
+ lick.vel.copy(c.vel).multiplyScalar(0.42);
750
+ lick.size = p.size;
751
+ lick.rate(1600 * p.size, dt);
752
+ smoke.pos.copy(c.pos).addScaledVector(c.dir, -1.2 * R);
753
+ smoke.radius = 0.3 * p.size;
754
+ smoke.vel.set(0, 0.7, 0).addScaledVector(c.vel, 0.04);
755
+ smoke.size = 0.6 * p.size;
756
+ smoke.rate(75 * p.smoke, dt);
757
+ ember.pos.copy(c.pos);
758
+ ember.vel.copy(c.vel).multiplyScalar(0.2);
759
+ ember.rate(200 * p.embers, dt);
760
+ d.trail?.push(c.pos);
761
+ if (L) {
762
+ L.pos.copy(c.pos);
763
+ L.intensity = 18 * flick * p.intensity;
764
+ }
765
+ } else if (c.form === "Fireball") updateExplosion(c, p, d, dt, flick);
766
+ else updateInferno(c, p, d, dt, flick);
767
+ },
768
+ };
769
+
770
+ // --- Fireball impact: a fluid fireball ------------------------------------------------
771
+ // Reference: gasoline / fuel-air fireballs (film pyro, high-speed footage): a fuel cloud
772
+ // ignites and expands violently, its surface boils into turbulent white-yellow lobes, buoyancy
773
+ // turns it into a rolling vortex ring that climbs and mushrooms, the burning shell cools to
774
+ // orange and red and is swallowed by black soot, which rises sunlit on top, dark underneath.
775
+ // the radius of a formed Aegis over the target (its centre in _shC) that the ball met from outside; 0: none
776
+ function shieldAt(c: ICast) {
777
+ const arcane = fx.spells.arcane?.inst as
778
+ | { shieldOver?(x: number, z: number, out: Vector3): number }
779
+ | undefined;
780
+ const r = arcane?.shieldOver?.(c.to.x, c.to.z, _shC) ?? 0;
781
+ return r > 0 && _shC.distanceToSquared(c.from) > r * r ? r : 0;
782
+ }
783
+
784
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
785
+ function explode(c: ICast, p: typeof S.params, d: IFireData) {
786
+ const pos = c.pos;
787
+ const s = p.size;
788
+ // an Aegis takes the blast on its shell (the ball stopped there: the dome is an occluder). It goes
789
+ // off just outside it, within the shield's 0.9 m hit reach so the shell still ripples, and the dome
790
+ // is a solid in the fire's sim: the fireball splashes on it and rolls up and over it instead of
791
+ // filling it and hiding the hit
792
+ const shR = shieldAt(c);
793
+ if (shR > 0) {
794
+ _a.subVectors(pos, _shC);
795
+ if (_a.lengthSq() < 1e-6) _a.subVectors(c.from, _shC).setY(0);
796
+ pos.copy(_shC).addScaledVector(_a.normalize(), shR + Math.min(0.8 * s, 0.85));
797
+ }
798
+ // biome-ignore lint/suspicious/noAssignInExpressions: upstream Ultra Elements code, copied verbatim
799
+ const f = (d.fl = fluid.acquire({ size: [8.5 * s, 10 * s, 8.5 * s] }));
800
+ if (f) {
801
+ if (shR > 0) f.obstacle.set(_shC.x, _shC.y, _shC.z, shR);
802
+ f.position.set(pos.x, 0.5 * f.size.y - f.h, pos.z);
803
+ lookFluid(f, p);
804
+ Object.assign(f, {
805
+ ignition: 0.25,
806
+ burnRate: 2.6,
807
+ heatPerFuel: 0.5,
808
+ expansion: 1.2,
809
+ cooling: 0.35,
810
+ radiative: 0.5,
811
+ sootYield: 0.7 * p.soot,
812
+ sootDensity: 3.6,
813
+ flameDensity: 3.5,
814
+ sootDecay: 0.06,
815
+ fuelDecay: 0.2,
816
+ buoyancy: 8,
817
+ sootWeight: 0.35,
818
+ vorticity: 7,
819
+ damping: 0.25,
820
+ forceCoupling: 0.6,
821
+ turbulence: 14,
822
+ turbulenceFreq: 0.45 / s,
823
+ sootCool: 0.9,
824
+ detailFreq: 0.4 / s,
825
+ detailErode: 0.3,
826
+ detailHeat: 0.4,
827
+ emptyBelow: 0.05, // the invisible veil round the smoke is skipped (~0.1 ms)
828
+ });
829
+ f.detailCenter.copy(pos);
830
+ } else {
831
+ // pool full: a particle fireball
832
+ blast.pos.copy(pos);
833
+ blast.radius = 0.6 * s;
834
+ blast.vel.set(0, 1.5, 0);
835
+ blast.size = 2.2 * s;
836
+ blast.burst(300 * s);
837
+ smoke.pos.copy(pos).setY(pos.y + 0.8 * s);
838
+ smoke.radius = 1.0 * s;
839
+ smoke.vel.set(0, 0.6, 0);
840
+ smoke.size = 1.25 * s;
841
+ smoke.burst(140 * p.smoke);
842
+ }
843
+ spark.pos.copy(pos);
844
+ spark.vel.set(0, 1, 0);
845
+ spark.burst(380 * p.embers);
846
+ debris.pos.copy(pos);
847
+ debris.vel.set(0, 3, 0);
848
+ debris.size = s;
849
+ debris.burst(70 * s);
850
+ ember.pos.copy(pos);
851
+ ember.vel.set(0, 2, 0);
852
+ ember.burst(160 * p.embers);
853
+ dust.pos.copy(pos).setY(0.15);
854
+ dust.size = 0.8 * s;
855
+ dust.burst(45 * s);
856
+ shock.radius0 = 0.3;
857
+ shock.radius1 = 7 * s;
858
+ shock.duration = 0.5;
859
+ shock.thickness = 0.8;
860
+ shock.distortion = 0.035 * p.haze;
861
+ shock.intensity = 0;
862
+ shock.ground = false;
863
+ shock.pos.copy(pos);
864
+ fx.shocks?.spawn(shock);
865
+ splat(pos.x, pos.z, 2.6 * s * p.scorch, 0.45, 0.9, "noise", c.seed);
866
+ fx.impacts.add("scorch", pos, 3.2 * s, 0.6, 9, lightColor(p.temperature, col));
867
+ if (d.light) {
868
+ d.light.intensity = 60 * p.intensity;
869
+ d.light.range = 16 * s;
870
+ d.light.pos.copy(pos).setY(pos.y + 0.6);
871
+ }
872
+ d.haze = freeHaze();
873
+ if (d.haze) d.haze.visible = true;
874
+ fx.flash(0.2 * p.intensity);
875
+ fx.rig.shake(0.5, 12);
876
+ if (!fx.reduced) {
877
+ fx.rig.punch(3, 0.08);
878
+ fx.rig.hitstop(0.05);
879
+ }
880
+ for (const dm of fx.dummies) {
881
+ const dist = Math.hypot(dm.pos.x - pos.x, dm.pos.z - pos.z);
882
+ if (shR > 0 && (dm.pos.x - _shC.x) ** 2 + (dm.pos.z - _shC.z) ** 2 < shR * shR) continue; // sheltered
883
+ if (dist < 3 * s) {
884
+ dm.status.burn = Math.max(dm.status.burn, 1 - dist / (3 * s) + 0.3);
885
+ dm.hit(_a.subVectors(dm.pos, pos).setY(0).normalize(), 1 - dist / (3 * s));
886
+ }
887
+ }
888
+ }
889
+
890
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
891
+ function updateExplosion(
892
+ c: ICast,
893
+ p: typeof S.params,
894
+ d: IFireData,
895
+ dt: number,
896
+ flick: number,
897
+ ) {
898
+ // biome-ignore lint/suspicious/noAssignInExpressions: upstream Ultra Elements code, copied verbatim
899
+ const a = (d.age += dt);
900
+ const s = p.size;
901
+ const f = d.fl;
902
+ const pos = c.pos;
903
+ const sd = (c.seed % 97) * 0.37;
904
+ if (f) {
905
+ const r = shieldAt(c); // the dome stays solid while it stands
906
+ f.obstacle.set(_shC.x, _shC.y, _shC.z, r);
907
+ if (a <= dt + 1e-4) {
908
+ // the fuel cloud: one lumpy core and three off-centre lobes, all igniting at once and
909
+ // thrown outwards; the noise makes the surface uneven from the first frame
910
+ src(
911
+ f,
912
+ pos.x,
913
+ pos.y,
914
+ pos.z,
915
+ 1.3 * s,
916
+ 2.0,
917
+ 1.05,
918
+ 0.05,
919
+ true,
920
+ 0.85,
921
+ 2.2 / s,
922
+ sd,
923
+ 0,
924
+ 0,
925
+ 0,
926
+ 7 * s,
927
+ 400,
928
+ );
929
+ for (let i = 0; i < 3; i++) {
930
+ const ang = sd * 3 + i * 2.1;
931
+ const r = 0.75 * s;
932
+ _b.set(Math.cos(ang) * r, (i - 1) * 0.35 * s, Math.sin(ang) * r);
933
+ src(
934
+ f,
935
+ pos.x + _b.x,
936
+ Math.max(pos.y + _b.y, 0.45 * s),
937
+ pos.z + _b.z,
938
+ 0.85 * s,
939
+ 1.8,
940
+ 1.0,
941
+ 0.05,
942
+ true,
943
+ 0.8,
944
+ 2.6 / s,
945
+ sd + i * 1.7,
946
+ _b.x * 5.5,
947
+ _b.y * 5.5 + 1.5,
948
+ _b.z * 5.5,
949
+ 3 * s,
950
+ 200,
951
+ );
952
+ // a fuel-rich, barely lit pocket outside each lobe: dark soot laced over the fire from the first frame
953
+ const r2 = 1.55 * s;
954
+ const a2 = ang + 1.05;
955
+ _b.set(Math.cos(a2) * r2, (1 - i) * 0.45 * s + 0.35 * s, Math.sin(a2) * r2);
956
+ src(
957
+ f,
958
+ pos.x + _b.x,
959
+ Math.max(pos.y + _b.y, 0.4 * s),
960
+ pos.z + _b.z,
961
+ 0.55 * s,
962
+ 0.6,
963
+ 0.45,
964
+ 0.7,
965
+ true,
966
+ 0.9,
967
+ 3 / s,
968
+ sd + 4 + i * 2.3,
969
+ _b.x * 3,
970
+ _b.y * 3 + 1,
971
+ _b.z * 3,
972
+ 1.5 * s,
973
+ 200,
974
+ );
975
+ }
976
+ } else if (a < 0.16) {
977
+ // fuel keeps pouring out of the core for a few frames: the fireball keeps growing
978
+ src(
979
+ f,
980
+ pos.x,
981
+ pos.y,
982
+ pos.z,
983
+ 0.8 * s,
984
+ 9,
985
+ 0.8,
986
+ 0,
987
+ false,
988
+ 0.5,
989
+ 1.4 / s,
990
+ sd + 5,
991
+ 0,
992
+ 1,
993
+ 0,
994
+ 5 * s,
995
+ 30,
996
+ );
997
+ }
998
+ // the soot erodes late, thin edges first, so the billows stay sharp until the cloud is gone (~5 s)
999
+ f.sootErode = 1.6 * MathUtils.smoothstep(a, 1.5, 4.4);
1000
+ // the flash: the first few frames run hotter than the settled burn
1001
+ f.emission = (3.6 + 4 * Math.exp(-a / 0.18)) * p.intensity;
1002
+ // the cell pattern rides the gas: it climbs with the fireball and grows as it expands
1003
+ const grow = 1 - Math.exp(-a / 0.45);
1004
+ f.detailCenter.set(pos.x, pos.y + 1.1 * s * Math.min(a, 3), pos.z);
1005
+ f.detailFreq = 0.4 / (s * (0.75 + 0.75 * grow));
1006
+ if (a > 5.2) {
1007
+ f.release();
1008
+ d.fl = null;
1009
+ }
1010
+ }
1011
+ // fluid heat drives the light; it climbs with the fireball
1012
+ const heat = f ? f.heat : 3 * Math.exp(-a * 1.5);
1013
+ if (d.haze) {
1014
+ d.haze.visible = a < 3.5;
1015
+ placeHaze(
1016
+ d.haze,
1017
+ pos.x,
1018
+ Math.max(0, pos.y - 0.5),
1019
+ pos.z,
1020
+ 2.6 * s,
1021
+ 6 * s,
1022
+ 0.07 * p.haze * Math.min(1, heat / 2),
1023
+ );
1024
+ }
1025
+ if (!f && c.phase === "linger" && c.t < 2) {
1026
+ smoke.pos.copy(pos).setY(pos.y + 2.4 * s + 1.2 * c.t);
1027
+ smoke.radius = 0.9 * s;
1028
+ smoke.vel.set(0, 1.2, 0);
1029
+ smoke.size = 1.4 * s;
1030
+ smoke.rate(4 * p.smoke, dt);
1031
+ }
1032
+ const L = d.light;
1033
+ if (L) {
1034
+ L.pos.set(pos.x, pos.y + 0.6 + Math.min(2.5 * s, a * 1.4 * s), pos.z);
1035
+ L.intensity = Math.min(70, 16 * heat) * p.intensity * (0.85 + 0.15 * flick);
1036
+ L.range = 16 * s;
1037
+ }
1038
+ }
1039
+
1040
+ // --- Inferno: a fluid fire column --------------------------------------------------------
1041
+ // Reference: a large pool / gasoline fire: a white-yellow base hugging the ground, flames
1042
+ // necking in and tearing into licking tongues with clear gaps, orange-red tips, and black
1043
+ // smoke rolling off the top.
1044
+ function erupt(c: ICast, p: typeof S.params, d: IFireData) {
1045
+ const x = c.to.x;
1046
+ const z = c.to.z;
1047
+ const s = p.size;
1048
+ const H = 8.5 * s * p.height;
1049
+ // biome-ignore lint/suspicious/noAssignInExpressions: upstream Ultra Elements code, copied verbatim
1050
+ const f = (d.fl = fluid.acquire({
1051
+ size: [4.2 * s, H, 4.2 * s],
1052
+ res: Math.round(fluid.res * 1.25),
1053
+ }));
1054
+ if (f) {
1055
+ f.position.set(x, 0.5 * f.size.y - f.h, z);
1056
+ lookFluid(f, p);
1057
+ Object.assign(f, {
1058
+ ignition: 0.2,
1059
+ burnRate: 4.5,
1060
+ heatPerFuel: 0.85,
1061
+ expansion: 0.15,
1062
+ cooling: 1.0,
1063
+ radiative: 0.6,
1064
+ sootDecay: 0.18,
1065
+ fuelDecay: 0.6,
1066
+ buoyancy: 6.5,
1067
+ sootWeight: 0.25,
1068
+ vorticity: 9,
1069
+ damping: 0.2,
1070
+ forceCoupling: 0.15,
1071
+ // resolved turbulence and boiling cells: tongues with gaps, mottled burning surfaces
1072
+ turbulence: 9,
1073
+ turbulenceFreq: 0.6 / s,
1074
+ sootCool: 1,
1075
+ detailFreq: 0.55 / s,
1076
+ detailErode: 0.25,
1077
+ detailHeat: 0.35,
1078
+ });
1079
+ f.sootYield = 0.45 * p.soot;
1080
+ f.detailCenter.set(x, 0, z);
1081
+ // the eruption: a lumpy slug of burning fuel thrown straight up out of the ground
1082
+ src(
1083
+ f,
1084
+ x,
1085
+ 0.6 * s,
1086
+ z,
1087
+ 0.8 * s,
1088
+ 2.0,
1089
+ 1.0,
1090
+ 0.05,
1091
+ true,
1092
+ 0.85,
1093
+ 2.4 / s,
1094
+ (c.seed % 83) * 0.41 + 7,
1095
+ 0,
1096
+ 11 * s,
1097
+ 0,
1098
+ 0,
1099
+ 300,
1100
+ );
1101
+ } else {
1102
+ pillar.pos.set(x, 0.1, z);
1103
+ pillar.radius = 0.95 * s;
1104
+ pillar.vel.set(0, 3.5, 0);
1105
+ pillar.size = 1.3 * s;
1106
+ pillar.burst(300 * s);
1107
+ }
1108
+ d.haze = freeHaze();
1109
+ if (d.haze) d.haze.visible = true;
1110
+ d.vortex = fx.forces.acquire();
1111
+ if (d.vortex) {
1112
+ const v = d.vortex;
1113
+ v.type = 1;
1114
+ v.p[0] = 0.9 * s;
1115
+ v.p[1] = 9 * s;
1116
+ v.p[2] = 5;
1117
+ v.p[3] = 1.2;
1118
+ v.w = 7 * s * p.height;
1119
+ v.pos.set(x, 0, z);
1120
+ v.dir.set(0, 1, 0);
1121
+ }
1122
+ splat(x, z, 2.4 * s, 0.5 * p.scorch, 0.7, "noise", c.seed);
1123
+ splat(x, z, 2.1 * s, 0.25 * p.scorch, 1.1 * p.scorch, "ring", c.seed + 1, 0.45 * s); // the scorched ring
1124
+ fx.impacts.add("scorch", _a.set(x, 0.8, z), 2.6 * s, 0.6, 8, lightColor(p.temperature, col));
1125
+ spark.pos.set(x, 0.4, z);
1126
+ spark.vel.set(0, 4, 0);
1127
+ spark.burst(260 * p.embers);
1128
+ dust.pos.set(x, 0.15, z);
1129
+ dust.size = s;
1130
+ dust.burst(70 * s);
1131
+ shock.radius0 = 0.5;
1132
+ shock.radius1 = 6 * s;
1133
+ shock.duration = 0.6;
1134
+ shock.thickness = 0.7;
1135
+ shock.distortion = 0.03 * p.haze;
1136
+ shock.intensity = 0;
1137
+ shock.ground = true;
1138
+ shock.pos.set(x, 0, z);
1139
+ fx.shocks?.spawn(shock);
1140
+ if (d.light) {
1141
+ d.light.type = 1;
1142
+ d.light.range = 12 * s;
1143
+ d.light.shadow = true;
1144
+ }
1145
+ fx.flash(0.12 * p.intensity);
1146
+ fx.rig.shake(0.35, 9);
1147
+ }
1148
+
1149
+ // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: upstream Ultra Elements code, copied verbatim
1150
+ function updateInferno(c: ICast, p: typeof S.params, d: IFireData, dt: number, flick: number) {
1151
+ // biome-ignore lint/suspicious/noAssignInExpressions: upstream Ultra Elements code, copied verbatim
1152
+ const a = (d.age += dt);
1153
+ const x = c.to.x;
1154
+ const z = c.to.z;
1155
+ const s = p.size;
1156
+ const f = d.fl;
1157
+ const sd = (c.seed % 83) * 0.41;
1158
+ const burn = S.timing.sustain;
1159
+ const die = MathUtils.smoothstep(a, burn, burn + 1.3);
1160
+ const on = 1 - die;
1161
+ const R = 0.95 * s;
1162
+ if (f) {
1163
+ if (a < 0.3) {
1164
+ // the jet keeps feeding the eruption for a moment
1165
+ const k = 1 - a / 0.3;
1166
+ src(
1167
+ f,
1168
+ x,
1169
+ 0.4,
1170
+ z,
1171
+ 0.75 * R,
1172
+ 10 * k,
1173
+ 1.0 * k,
1174
+ 0,
1175
+ false,
1176
+ 0.8,
1177
+ 2 / s,
1178
+ sd + 5 + a,
1179
+ 0,
1180
+ 11 * s,
1181
+ 0,
1182
+ 0,
1183
+ 25,
1184
+ );
1185
+ }
1186
+ // the boiling cells climb with the gas
1187
+ f.detailCenter.set(x, 2.2 * s * a, z);
1188
+ if (on > 0.02) {
1189
+ // the jet first; the pool of burning fuel spreads in under it from the centre
1190
+ const ramp = MathUtils.smoothstep(a, 0.05, 0.75) * on;
1191
+ // a flickering pool of burning fuel at the base, its patches drifting up through it
1192
+ src(
1193
+ f,
1194
+ x,
1195
+ 0.2,
1196
+ z,
1197
+ 1.25 * R * (0.45 + 0.55 * ramp),
1198
+ 1.3 * ramp,
1199
+ 0.55 * ramp,
1200
+ 0,
1201
+ true,
1202
+ 0.85,
1203
+ 1.6 / s,
1204
+ sd,
1205
+ 0,
1206
+ 2.2,
1207
+ 0,
1208
+ -0.6,
1209
+ 6,
1210
+ );
1211
+ // a hot core feeding the column
1212
+ src(
1213
+ f,
1214
+ x,
1215
+ 0.35,
1216
+ z,
1217
+ 0.65 * R,
1218
+ 1.6 * ramp,
1219
+ 0.8 * ramp,
1220
+ 0,
1221
+ true,
1222
+ 0.5,
1223
+ 2.2 / s,
1224
+ sd + 3,
1225
+ 0,
1226
+ 4.5,
1227
+ 0,
1228
+ 0,
1229
+ 10,
1230
+ );
1231
+ }
1232
+ f.sootDecay = 0.18 + 0.6 * MathUtils.smoothstep(a, burn + 1.5, burn + 4);
1233
+ f.emission = 6.5 * p.intensity;
1234
+ if (a > burn + 4.6) {
1235
+ f.release();
1236
+ d.fl = null;
1237
+ }
1238
+ }
1239
+ const heat = f ? f.heat : 4 * on;
1240
+ const H = Math.max(0.6, 6 * s * p.height * Math.min(1, heat / 6));
1241
+ if (d.haze) {
1242
+ d.haze.visible = a < burn + 2.2;
1243
+ placeHaze(d.haze, x, 0, z, 2.2 * s, H * 1.6 + 2, 0.09 * p.haze * (1 - 0.7 * die));
1244
+ }
1245
+ if (on > 0.01) {
1246
+ ember.pos.set(x, 0.5, z);
1247
+ ember.radius = R;
1248
+ ember.vel.set(0, 2, 0);
1249
+ ember.rate(260 * p.embers * on, dt);
1250
+ if (Math.floor(a * 4) !== Math.floor((a - dt) * 4))
1251
+ splat(x, z, 2 * s, 0.25 * p.scorch, 0.15, "noise", c.seed + a);
1252
+ for (const dm of fx.dummies)
1253
+ if (Math.hypot(dm.pos.x - x, dm.pos.z - z) < 1.6 * s)
1254
+ dm.status.burn = Math.max(dm.status.burn, 0.9);
1255
+ }
1256
+ if (d.vortex) d.vortex.w = 7 * s * p.height * on;
1257
+ const L = d.light;
1258
+ if (L) {
1259
+ L.pos.set(x, 0.3, z);
1260
+ L.end.set(x, Math.max(0.6, H * 0.6), z);
1261
+ L.intensity =
1262
+ Math.min(40, 5 * heat) * p.intensity * (0.8 + 0.2 * flick) +
1263
+ 3 * p.intensity * Math.max(0, 1 - c.t / c.durations.linger) * die;
1264
+ }
1265
+ }
1266
+ },
1267
+ };