Skip to content

The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.

Explosions: idle fireballs are hidden, idle lights black (#168)

Yujia9d25339101ec
diff --git a/docs/VOXEL.md b/docs/VOXEL.md
index 9a2f7e2..e283df2 100644
--- a/docs/VOXEL.md
+++ b/docs/VOXEL.md
@@ -568,7 +568,7 @@ const boom = new Explosions();
scene.add(boom);
// frame(f):
boom.explode(x, y, z, 4, f.time); // voxelExplode, then fire([x, y, z], 4, f.time)
-boom.step(f.time); // once a frame: lights follow their fireballs, burnt-out ones parked
+boom.step(f.time); // once a frame: lights follow their fireballs, burnt-out ones hidden
```
Positions are the world's: the group stays at the origin, unrotated, unscaled (a fire throws otherwise). `dispose()`
@@ -589,8 +589,9 @@ takes the pool out of the scene for good.
and wall agree within about 10 %). It is not one curve scaled by size²: a larger fireball's hot core lies under more
of its own smoke, so its light falls sooner (at half its life 0.0090 cd per m² of size² per nit at 2.2 m, 0.0020 at
8.8 m). `voxel/fire-light` checks it in the renderer: the fire light alone gives a floor 0.987 of what the fireball's
- own emission gives it. The light, the parking of idle objects and the rest are temporary ways round the shared live renderer (the table
- below, "Temporary ways round on the engine's shared paths").
+ own emission gives it. The light and the missing smoke grid are temporary ways round the shared live renderer (the table
+ below, "Temporary ways round on the engine's shared paths"). An idle fireball is hidden, an idle light black: neither
+ costs a pixel anything.
Caps, and what happens past them (node tests in `packages/voxel/test/explosions.test.ts`):
@@ -606,9 +607,8 @@ finite numbers, a radius not finite or not above 0, a time outside ±1e9 s, or t
throws a `RangeError` from `fire`, `explode` (before its voxel call) and `step`; a huge radius (1e30) gives the largest
fireball, a tiny one (1e-46) the smallest; the constructor checks every option (ranges in the code; `intensity: 1e308`, `life: 61`, a
smoke grid are refused). 1,000 fires in one frame, at one time or 1 µs apart, make no object (the pool cycles; the
-last 8 burn). An idle light has a reach of 1 mm where
-it is parked (a distance of 0 is unbounded reach: the sphere of its group of 16 lights held every pixel, 0.9 ms of GPU
-with nothing burning).
+last 8 burn). An idle light is black where it last burnt
+(the kernel passes a black light before its group's sphere is tested).
**Offline, the fire's light counts twice unless the game passes `lights: 0`**: an offline path reaches the
fire's emission, and the stand-in light is there as well. The bench's references are made with `lights: 0`
@@ -762,18 +762,15 @@ wild).
### Temporary ways round on the engine's shared paths
-`Explosions` (step 10 b) works round five faults of the shared renderer, in its own code, until they are fixed
+`Explosions` (step 10 b) works round two faults of the shared renderer, in its own code, until they are fixed
there (the user, 2026-11-12: these are temporary; the shared paths are fixed in their own PRs, then these go, in a PR
-of their own). Each place in `packages/voxel/src/explosions.ts` points here. (A sixth is closed at its source: the
-fireball's ghosting, once held down by its light's change cutting the whole frame's history; "Where it falls short"
-above.)
+of their own). Each place in `packages/voxel/src/explosions.ts` points here. (Four are closed at their source and gone from
+here: the fireball's ghosting; idle fireballs parked far away, now hidden; idle lights reaching 1 mm, now black; the
+smoke kept by never rebuilding, which a rebuild now carries over.)
| What | Now | The fault at its source | Known side effects | It can go when | How to tell |
| --- | --- | --- | --- | --- | --- |
| The stand-in light | a point light at each burning fire, its intensity and colour from `FIRE_LIGHT`, measured against offline | live secondary and shadow rays have no media code: `pathtrace.wgsl` `media_shadows()` is false live (line 796), GI and reflection rays never meet a medium | offline the fire's light counts twice unless the game passes `lights: 0` (`level-destruction-fire` rendered offline has both); live, `media_train` adds the light to the radiance cache's voxels (`point_direct`, `point_sphere`): the fireball (and its smoke) is lit by it a second time; the table holds for the defaults (density, life scaled; measured by day over a floor and a wall, the fireball 0.6 of its size above it; past 8.8 m the 8.8 m values) | live rays see media: a medium's emission lights surfaces and shadows pass through it | `lights: 0`, then `tools/bench-voxel-fire.ts --only quality`: the street and the fireball's regions at least as close to offline as with the light; `voxel/fire-light` replaced by a live test of the fire's own light |
-| Idle fireballs parked | at y = −10,000, scale 1e-3, instead of hidden | `World::set_visible` (`world.rs` line 750): hiding anything but particles rebuilds the live scene | parked fireballs keep their slots among the kernel's 32 volumes, and every pixel's march still tests their boxes | **now** (2026-11-13: a volume or a light hidden by its own `visible` keeps its place in the build, in place; no media pass runs while every medium is hidden; `volume/hidden-in-place-live`, `light/hidden-in-place-live` and the two `shown`). What is left is `Explosions`' own | `visible = false` instead of parking; the bench's cost runs report no rebuild after an explosion |
-| Idle lights reach 1 mm | an idle light's `distance` is 1 mm where it is parked | `light_reach` (`lib.rs` line 211): a black light without a range reaches without limit, and the kernel does not skip black lights before the group test (`pathtrace.wgsl` line 1578) | parked lights 10 km away share a group of 16 with lit ones, and groups are not sorted again when lights move (`lib.rs` line 277): the group's sphere is about 5 km wide while any fire burns (the per-light range test still works) | **now** (2026-11-13: black lights are in no group's sphere and are skipped first; a hidden light's entry is black; the groups are sorted again when a local light moves or goes dark or lit). What is left is `Explosions`' own | distance 0 on idle lights; the fire route's GPU time before any explosion within 0.1 ms of the smoke route's |
-| The smoke kept by never rebuilding | the pool's objects movable from the start; idle ones parked, not hidden (`Explosions` has no grid now: this keeps a game's own `SimulatedSmoke`) | `LiveCore::rebuild` (`live/mod.rs`) → `load_scene` → `Gpu::upload` makes new grid textures (`gpu.rs` line 1664): the simulated state is not carried over | any other structural change in the game (an object added, a texture, an edit's fallback) wipes the smoke and the fire burning in it | **now** (2026-11-13: a rebuild copies fields A and B of every simulated grid that is the same grid still into the new scene's textures, `Gpu::carry_grids`; `volume/grid-rebuild-live`). What is left is `Explosions`' own | the bench's smoke check with a rebuild forced at 1 s (an object added): the smoke at 3 s as without it |
| Volumes must not overlap | `Explosions` has no smoke grid (it refuses one); the smoke is each fireball's own. Two fires close together still make two fireballs that overlap: nothing keeps them apart (no distance rule) | `media_track` (offline) and `media_march` (live) in `pathtrace.wgsl` take the media whole, in the order a ray enters them (at most 32, a 32-bit mask), not their coefficients summed along the ray; hence the rule (`core.ts` `VolumeMesh`, MATERIAL_FUNCTIONS.md) | a fire inside smoke is drawn behind all of it (measured: not seen at all at 0.2 and 0.5 s, "Why volumes must not overlap"); neighbouring fireballs hide each other in the same way; no smoke grid around explosions | **now** (2026-11-13: the kernel takes the ray a stretch at a time and sums the coefficients of the media it is in, offline and live; `volume/overlap-emission`, `-live`). What is left is `Explosions`' own: taking a grid again, in a PR of the voxel line's | puff a `SimulatedSmoke` around fireballs again (`Explosions` taking a grid) and run the comparison that found it (`bench-voxel-fire` at d7b4e4a, `--only smoke --ages 0.2,0.5`): the fire seen in its smoke offline and live; two overlapping fireballs both seen |
### Where the engine works round its dependencies
diff --git a/packages/voxel/src/explosions.ts b/packages/voxel/src/explosions.ts
index 88dc2ba..c9d0fb3 100644
--- a/packages/voxel/src/explosions.ts
+++ b/packages/voxel/src/explosions.ts
@@ -25,12 +25,6 @@ export const MAX_TIME = 1e9;
export const FIREBALL_SIZE = 2.2;
export const MAX_FIREBALL = 40;
export const MIN_FIREBALL = 0.05;
-/** Where idle fireballs wait: tiny, far below any level (moving a volume is done in place; hiding one is not
- * promised to be). */
-const PARK: [number, number, number] = [0, -10000, 0];
-const PARKED = 1e-3;
-/** An idle light's reach (m): its light group's sphere, parked with it, then holds no pixel. */
-const IDLE_REACH = 1e-3;
/** The fireball sizes (full size, m) the fire light was measured at. */
export const FIRE_LIGHT_SIZES = [1.1, 2.2, 4.4, 8.8] as const;
@@ -152,7 +146,7 @@ export class Explosions extends Group {
readonly life: number;
readonly intensity: number;
readonly stats: ExplosionStats = { fired: 0, reused: 0, unlit: 0, most: 0, burning: 0, lit: 0 };
- /** Per fireball: when it started (scene time; NaN = parked), its full size, its centre, the order it was fired in. */
+ /** Per fireball: when it started (scene time; NaN = idle), its full size, its centre, the order it was fired in. */
private started: number[] = [];
private sizes: number[] = [];
private centers: [number, number, number][] = [];
@@ -176,27 +170,24 @@ export class Explosions extends Group {
for (let k = 0; k < n; k++) {
const f = new Fireball({ life: this.life, intensity: this.intensity, density });
f.name = `fireball-${k}`;
- // Moved at every fire: movable from the start (a fixed object's first move rebuilds the live scene once).
+ // Moved at every fire: movable from the start (a volume's first move would rebuild the live scene once).
f.movable = true;
- // Parked while idle: a temporary way round (docs/VOXEL.md, "Temporary ways round on the engine's shared paths").
- f.position.set(...PARK);
- f.scale.setScalar(PARKED);
+ // Hidden while idle: it keeps its place among the scene's volumes, and costs no pixel anything.
+ f.visible = false;
f.customData = [-1e6, 0, 0, 0];
this.add(f);
this.fireballs.push(f);
this.started.push(NaN);
this.sizes.push(0);
- this.centers.push([...PARK]);
+ this.centers.push([0, 0, 0]);
this.order.push(-1);
}
for (let k = 0; k < nl; k++) {
- // The stand-in light, and its idle reach of 1 mm where it is parked: temporary ways round (docs/VOXEL.md,
- // "Temporary ways round on the engine's shared paths").
+ // The stand-in light: a temporary way round (docs/VOXEL.md, "Temporary ways round on the engine's shared
+ // paths"). Black while idle: the kernel passes a black light before anything else.
const l = new PointLight(0xffffff, 0);
l.name = `fire-light-${k}`;
- l.distance = IDLE_REACH;
l.movable = true;
- l.position.set(...PARK);
this.add(l);
this.lights.push(l);
}
@@ -224,6 +215,7 @@ export class Explosions extends Group {
const s = this.started[k];
if (!Number.isNaN(s) && time - s < this.life) this.stats.reused++;
const f = this.fireballs[k];
+ f.visible = true;
f.position.set(...c);
f.scale.setScalar(size);
f.customData = [time, 0, 0, 0];
@@ -246,16 +238,16 @@ export class Explosions extends Group {
}
/** Once a frame (scene time): each light set from its fireball's age (the youngest that give light have them);
- * burnt-out fireballs parked. Time going back (a restart) ends every fire. */
+ * burnt-out fireballs hidden. Time going back (a restart) ends every fire. */
step(time: number): void {
within("Explosions.step: the time (the frame's f.time)", time, -MAX_TIME, MAX_TIME);
if (this.disposed) return;
- if (time < this.now) for (let k = 0; k < this.fireballs.length; k++) this.park(k);
+ if (time < this.now) for (let k = 0; k < this.fireballs.length; k++) this.rest(k);
this.now = time;
const alive: number[] = [];
for (let k = 0; k < this.fireballs.length; k++) {
if (this.burning(k, time)) alive.push(k);
- else if (!Number.isNaN(this.started[k]) && time - this.started[k] >= this.life) this.park(k);
+ else if (!Number.isNaN(this.started[k]) && time - this.started[k] >= this.life) this.rest(k);
}
this.stats.burning = alive.length;
this.stats.most = Math.max(this.stats.most, alive.length);
@@ -268,8 +260,6 @@ export class Explosions extends Group {
const g = glowing[j];
if (g === undefined) {
l.intensity = 0;
- l.distance = IDLE_REACH;
- l.position.set(...PARK);
continue;
}
lit++;
@@ -298,10 +288,10 @@ export class Explosions extends Group {
return !Number.isNaN(s) && time - s >= 0 && time - s < this.life;
}
- private park(k: number): void {
+ /** Fireball `k` burns no more: hidden where it is. */
+ private rest(k: number): void {
this.started[k] = NaN;
- this.fireballs[k].position.set(...PARK);
- this.fireballs[k].scale.setScalar(PARKED);
+ this.fireballs[k].visible = false;
}
/** The pool's positions are the world's: it and every parent at the origin, unrotated, unscaled. */
diff --git a/packages/voxel/test/explosions.test.ts b/packages/voxel/test/explosions.test.ts
index 1cb605b..b1f4572 100644
--- a/packages/voxel/test/explosions.test.ts
+++ b/packages/voxel/test/explosions.test.ts
@@ -33,8 +33,8 @@ function bound(x: Explosions) {
binding.sync();
return { scene, e, binding, made: e.take() };
}
-/** Placed fireballs (not parked). */
-const placed = (x: Explosions) => x.fireballs.filter((f) => f.position.y > -1000);
+/** Fireballs that show (not idle). */
+const placed = (x: Explosions) => x.fireballs.filter((f) => f.visible);
test("the pool: the next fireball each fire, the oldest taken over, lights for the youngest that give light", () => {
const x = new Explosions({ fireballs: 3, lights: 2 });
@@ -66,12 +66,14 @@ test("the pool: the next fireball each fire, the oldest taken over, lights for t
assert.deepEqual(x.lights.map((q) => q.position.x).sort((a, b) => a - b), [20, 30]);
x.step(10.45);
assert.deepEqual(x.lights.map((q) => q.position.x).sort((a, b) => a - b), [30, 40], "a frame on, it has one");
- // Burnt out: parked, the lights off.
+ // Burnt out: hidden where they burnt, the lights black where they were.
x.step(20);
assert.equal(x.stats.burning, 0);
assert.equal(x.stats.lit, 0);
- assert.ok(x.lights.every((q) => q.intensity === 0 && q.distance > 0 && q.distance < 0.01), "off, and reaching nothing (distance 0 would be unbounded)");
+ assert.ok(x.lights.every((q) => q.intensity === 0), "off: a black light is passed over whatever its reach");
+ assert.deepEqual(x.lights.map((q) => q.position.x).sort((a, b) => a - b), [30, 40], "and not moved away");
assert.equal(placed(x).length, 0);
+ assert.equal(x.fireballs[0].position.x, 30, "not moved away");
assert.equal(x.stats.most, 3);
});