Skip the fireball raymarch when its fade is zero (#126 point 4)

In the HD smoke path fade = 1 - smoothstep(0.08, 0.28, k) is exactly 0
from k = 0.28: every step's density is zero, absorb is 0, so the march
adds no light and leaves transmittance alone while still sampling fbm
and shading the volume. Wrap the loop in an `if fade > 0.0` guard; the
glow after it is untouched (heat is still live there) and is itself
skipped once its heat is spent. Density, steps, sampling and lighting
are unchanged.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
This commit is contained in:
2026-11-21 13:50:03 +03:00
parent 1a82742744
commit 8fb849f195
+26 -19
View File
@@ -209,26 +209,33 @@ fn post(uv: vec2<f32>, pixel: vec2<f32>) -> vec4<f32> {
let on_screen = radius / max(length(centre), 1.0);
let steps = i32(clamp(on_screen * 40.0, 6.0, 14.0));
let ds = (t1 - t0) / f32(steps);
for (var s = 0; s < steps; s++) {
if trans < 0.02 { break; }
let p = dir * (t0 + (f32(s) + 0.5) * ds);
let local = (p - centre) / radius;
let r = length(local);
let n = fbm(local * 2.4 + seed + vec3<f32>(0.0, -age * 0.06, age * 0.02));
let shape = smoothstep(1.0, 0.25, r + (n - 0.5) * 1.1);
if shape <= 0.0 { continue; }
let density = shape * (1.2 + n * 2.0) * fade;
let absorb = 1.0 - exp(-density * ds * 1.4 / max(radius * 0.25, 0.5));
// Hot inside, soot outside; smoke lit from above by the sky.
let core = heat * (1.0 - r) * (0.6 + n);
let smoke = vec3<f32>(0.10, 0.095, 0.09) * (0.5 + 0.8 * sun * (0.5 + local.y * 0.5));
let c = mix(smoke, fire(core * 1.6), clamp(core * 2.2, 0.0, 1.0));
lit += trans * absorb * c;
trans *= 1.0 - absorb;
// At zero fade every step's density is zero: absorb is 0, so the march adds no light and
// leaves the transmittance alone. Skip it (the HD smoke path fades out by k = 0.28) instead
// of sampling the noise and shading a volume that cannot be seen.
if fade > 0.0 {
for (var s = 0; s < steps; s++) {
if trans < 0.02 { break; }
let p = dir * (t0 + (f32(s) + 0.5) * ds);
let local = (p - centre) / radius;
let r = length(local);
let n = fbm(local * 2.4 + seed + vec3<f32>(0.0, -age * 0.06, age * 0.02));
let shape = smoothstep(1.0, 0.25, r + (n - 0.5) * 1.1);
if shape <= 0.0 { continue; }
let density = shape * (1.2 + n * 2.0) * fade;
let absorb = 1.0 - exp(-density * ds * 1.4 / max(radius * 0.25, 0.5));
// Hot inside, soot outside; smoke lit from above by the sky.
let core = heat * (1.0 - r) * (0.6 + n);
let smoke = vec3<f32>(0.10, 0.095, 0.09) * (0.5 + 0.8 * sun * (0.5 + local.y * 0.5));
let c = mix(smoke, fire(core * 1.6), clamp(core * 2.2, 0.0, 1.0));
lit += trans * absorb * c;
trans *= 1.0 - absorb;
}
}
// Light thrown round by the fire (zero once its heat is spent).
if heat > 0.0 {
let d = length(centre);
glow += vec3<f32>(1.0, 0.5, 0.15) * heat * heat * size * 0.05 / (1.0 + d * 0.03);
}
// Light thrown round by the fire.
let d = length(centre);
glow += vec3<f32>(1.0, 0.5, 0.15) * heat * heat * size * 0.05 / (1.0 + d * 0.03);
}
color = color * trans + lit;