Replays in full HD with shader effects driven by the recording (#56), recorded clock survives gaps (#57), cinematic intercepts: layered sound with travel delay, big flash, light burst, exposure punch, shock ring (#51) (fork patch 31)
build / mod (push) Successful in 3m21s
build / mod (push) Successful in 3m21s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+128
-16
@@ -12,6 +12,7 @@ use horizon_mod_sdk::{
|
||||
ui::{self, ButtonWidget, ItemWidget, ListWidget, Screen, Widget},
|
||||
};
|
||||
|
||||
mod cinema;
|
||||
mod monitor;
|
||||
mod panel;
|
||||
mod radar;
|
||||
@@ -88,6 +89,8 @@ struct AirDef {
|
||||
menu: Option<Page>,
|
||||
/// Where the player is, for the sounds' delay and far variants.
|
||||
listener: DVec3,
|
||||
/// The picture punch (#51) the HD exposure and bloom were last set for.
|
||||
punch: f32,
|
||||
/// Sounds on their way to the player at the speed of sound.
|
||||
pending: Vec<PendingSound>,
|
||||
/// The handles `render.model-id` gave the model names (valid under `model_generation`); none:
|
||||
@@ -163,6 +166,16 @@ fn say(text: &str) {
|
||||
chat::show(text);
|
||||
}
|
||||
|
||||
/// What the effects draw this tick (`Mod::shown`).
|
||||
struct Shown {
|
||||
blasts: Vec<sim::Blast>,
|
||||
/// The clock the blasts' `start` is on: the simulation's ticks, or the recording's.
|
||||
now: f32,
|
||||
/// 1 minus the share of the frame's partial tick the effects advance with.
|
||||
hold: f32,
|
||||
replay: bool,
|
||||
}
|
||||
|
||||
fn player() -> Option<game::Player> {
|
||||
game::get_player()
|
||||
}
|
||||
@@ -303,14 +316,37 @@ impl AirDef {
|
||||
/// blasts (a flash, then the fireball's glow dying down), burning wrecks and the
|
||||
/// searchlights' spots.
|
||||
fn lights(&self, out: &Out) -> Vec<PointLight> {
|
||||
let shown = self.shown();
|
||||
let mut lights: Vec<PointLight> = Vec::new();
|
||||
let mut add = |id: u32, at: DVec3, rgb: (f32, f32, f32), intensity: f32, radius: f32| {
|
||||
if lights.len() < 500 && intensity > 0.05 {
|
||||
lights.push(PointLight { id, x: at.x, y: at.y, z: at.z, color: rgb, intensity, radius: radius.clamp(1.0, 256.0) });
|
||||
}
|
||||
};
|
||||
let tick = self.sim.tick;
|
||||
let tick = shown.now as u64;
|
||||
let flicker = |id: u32| 0.85 + 0.15 * (((tick as u32).wrapping_mul(2654435761) ^ id.wrapping_mul(97)) % 100) as f32 / 100.0;
|
||||
// Blasts first, the nearest first: a crowded sky never costs the key intercept its light.
|
||||
let viewer = self.viewer(&shown);
|
||||
let mut near: Vec<&sim::Blast> = shown.blasts.iter().collect();
|
||||
if let Some(e) = viewer {
|
||||
near.sort_by(|a, b| a.at.distance_squared(e).total_cmp(&b.at.distance_squared(e)));
|
||||
}
|
||||
for (rank, b) in near.into_iter().enumerate() {
|
||||
let age = (shown.now - b.start as f32).max(0.0);
|
||||
let size = b.size;
|
||||
let glow = (-age / (b.life as f32 * 0.15).max(1.0)).exp();
|
||||
let flash = (-age * 0.35).exp() * 4.0;
|
||||
// Its own id range: the models' and the systems' ids are small numbers.
|
||||
let id = 0x6100_0000 | (b.id & 0x00ff_ffff);
|
||||
let centre = b.at + DVec3::Y * size as f64 * 0.5;
|
||||
add(id, centre, (1.0, 0.58, 0.25), size * size * 18.0 * (glow + flash), size * 14.0);
|
||||
// The punch (#51): a white burst that lights the land, the smoke and the wrecks far round
|
||||
// for a moment; for the nearest few, scaled by the blast.
|
||||
if rank < 6 {
|
||||
let burst = (-age / 2.0).exp();
|
||||
add(0x6300_0000 | (b.id & 0x00ff_ffff), centre, (1.0, 0.9, 0.74), size * size * 95.0 * burst, (size * 30.0).min(256.0));
|
||||
}
|
||||
}
|
||||
for m in out.models.iter().filter(|m| m.glow) {
|
||||
let s = m.scale.max(0.1);
|
||||
match m.name {
|
||||
@@ -323,14 +359,9 @@ impl AirDef {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
for b in &self.sim.blasts {
|
||||
let age = tick.saturating_sub(b.start) as f32;
|
||||
let size = b.size;
|
||||
let glow = (-age / (b.life as f32 * 0.15).max(1.0)).exp();
|
||||
let flash = (-age * 0.35).exp() * 4.0;
|
||||
// Its own id range: the models' and the systems' ids are small numbers.
|
||||
let id = 0x6100_0000 | (b.id & 0x00ff_ffff);
|
||||
add(id, b.at + DVec3::Y * size as f64 * 0.5, (1.0, 0.58, 0.25), size * size * 18.0 * (glow + flash), size * 14.0);
|
||||
// A replay shows its own flames (the models of the ghosts) and none of the live world's.
|
||||
if shown.replay {
|
||||
return lights;
|
||||
}
|
||||
// Fires burn on for minutes: a flickering, wide glow that dies down with the flames.
|
||||
for f in self.sim.fires.list.iter().filter(|f| f.shown) {
|
||||
@@ -373,6 +404,7 @@ impl AirDef {
|
||||
/// Switches the HD lighting.
|
||||
fn apply_hd(&self) {
|
||||
render::set_lighting(Lighting { hd: self.hd, exposure: 1.0, bloom: 0.55 });
|
||||
// (The punch of the next blast sets its own.)
|
||||
if !self.hd {
|
||||
render::set_lights(&[]);
|
||||
}
|
||||
@@ -381,15 +413,15 @@ impl AirDef {
|
||||
/// Hands the simulation's output to the game.
|
||||
/// The post pass's parameters: blasts and glowing parts (shaders/effects.wgsl).
|
||||
fn shader_params(&self, out: &Out) -> Vec<f32> {
|
||||
let shown = self.shown();
|
||||
let mut p = vec![0.0f32; 4];
|
||||
p[0] = self.sim.tick as f32;
|
||||
p[0] = shown.now;
|
||||
p[3] = if self.smoke.hd { 2.0 } else if self.hd { 1.0 } else { 0.0 };
|
||||
let mut blasts: Vec<&sim::Blast> = self.sim.blasts.iter().rev().take(48).collect();
|
||||
let mut blasts: Vec<&sim::Blast> = shown.blasts.iter().rev().take(48).collect();
|
||||
// The shader composites the volumes front to back with one shared transmittance, so
|
||||
// the nearest to the player goes first. This is exact for volumes that do not
|
||||
// overlap; where two intersect, no order by centre is right along every ray.
|
||||
if let Some(pl) = player() {
|
||||
let e = eye(&pl);
|
||||
if let Some(e) = self.viewer(&shown) {
|
||||
blasts.sort_by(|a, b| a.at.distance_squared(e).total_cmp(&b.at.distance_squared(e)));
|
||||
}
|
||||
p[1] = blasts.len() as f32;
|
||||
@@ -420,9 +452,52 @@ impl AirDef {
|
||||
lights += 1;
|
||||
}
|
||||
p[2] = lights as f32;
|
||||
// The last vec4: how much of the frame's partial tick the effects run on (0 live; a
|
||||
// slowed or paused replay runs on its own time, not the frame's).
|
||||
p.resize(1024, 0.0);
|
||||
p[1020] = shown.hold;
|
||||
p
|
||||
}
|
||||
|
||||
/// The smoke volumes the renderer draws and the clock they are aged by: the live ones, or (in a
|
||||
/// replay) the blasts' billows at the replay's moment, never the live raid's trails and fires.
|
||||
/// The billows are the live ones' own function (`Smoke::segments`), run on the recording's
|
||||
/// blasts and time with the live state set aside for the call.
|
||||
fn shown_smoke(&mut self) -> (f64, Vec<render::SmokeSegment>) {
|
||||
let shown = self.shown();
|
||||
if !shown.replay {
|
||||
return (self.sim.tick as f64, self.smoke.segments(&self.sim));
|
||||
}
|
||||
let blasts = std::mem::replace(&mut self.sim.blasts, shown.blasts);
|
||||
let fires = std::mem::take(&mut self.sim.fires.list);
|
||||
let tick = std::mem::replace(&mut self.sim.tick, shown.now as u64);
|
||||
let segments = smoke::Smoke::default().segments(&self.sim);
|
||||
self.sim.blasts = blasts;
|
||||
self.sim.fires.list = fires;
|
||||
self.sim.tick = tick;
|
||||
(f64::from(shown.now), segments)
|
||||
}
|
||||
|
||||
/// Where the picture is seen from: the replay's camera, or the player's eyes.
|
||||
fn viewer(&self, shown: &Shown) -> Option<DVec3> {
|
||||
match &self.replay {
|
||||
Some(r) if shown.replay => Some(r.eye()),
|
||||
_ => player().map(|pl| eye(&pl)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The blasts the effects show and the clock they run on: the live ones, or (in a replay) the
|
||||
/// recording's at the replay's moment, never the live world's.
|
||||
fn shown(&self) -> Shown {
|
||||
if let Some(r) = &self.replay
|
||||
&& r.filming()
|
||||
&& let Some(rec) = self.sim.replay(r.rec)
|
||||
{
|
||||
return Shown { blasts: sim::record::replay_blasts(rec, r.time()), now: r.time() as f32, hold: 1.0 - r.rate().clamp(0.0, 1.0), replay: true };
|
||||
}
|
||||
Shown { blasts: self.sim.blasts.clone(), now: self.sim.tick as f32, hold: 0.0, replay: false }
|
||||
}
|
||||
|
||||
/// The models to the game by handle: each name crosses once, the buffer stays allocated.
|
||||
fn send_models(&mut self, models: &[sim::Model]) {
|
||||
let generation = render::model_generation();
|
||||
@@ -460,8 +535,18 @@ impl AirDef {
|
||||
render::set_params(&self.shader_params(&out));
|
||||
}
|
||||
if self.hd {
|
||||
// The camera's reaction to a near blast: a brief exposure and bloom punch.
|
||||
let shown = self.shown();
|
||||
let p = self.viewer(&shown).map_or(0.0, |e| {
|
||||
shown.blasts.iter().map(|b| cinema::punch(b.size, shown.now - b.start as f32, b.at.distance(e))).fold(0.0, f32::max)
|
||||
});
|
||||
if (p - self.punch).abs() > 0.01 || (p == 0.0 && self.punch != 0.0) {
|
||||
self.punch = p;
|
||||
render::set_lighting(Lighting { hd: true, exposure: 1.0 + 0.4 * p, bloom: 0.55 + 0.9 * p });
|
||||
}
|
||||
render::set_lights(&self.lights(&out));
|
||||
self.smoke.hd = render::set_smoke(self.sim.tick as f64, &self.smoke.segments(&self.sim));
|
||||
let (clock, segments) = self.shown_smoke();
|
||||
self.smoke.hd = render::set_smoke(clock, &segments);
|
||||
} else {
|
||||
self.smoke.hd = false;
|
||||
}
|
||||
@@ -469,7 +554,7 @@ impl AirDef {
|
||||
self.send_models(&out.models);
|
||||
}
|
||||
if !out.particles.is_empty() {
|
||||
let hd_smoke = self.smoke.hd;
|
||||
let hd_smoke = self.smoke.hd && !self.replay.as_ref().is_some_and(|r| r.filming());
|
||||
let spawns: Vec<ParticleSpawn> = out
|
||||
.particles
|
||||
.into_iter()
|
||||
@@ -492,9 +577,13 @@ impl AirDef {
|
||||
render::spawn_particles(&spawns);
|
||||
}
|
||||
let now = self.sim.tick;
|
||||
// Blasts play layered (cinema.rs), the nearest ones in full.
|
||||
let mut booms: Vec<(f64, usize, DVec3, f32, f32)> = Vec::new();
|
||||
for (event, at, volume, pitch) in out.sounds {
|
||||
let dist = at.distance(self.listener);
|
||||
if travels(event) {
|
||||
if let Some(power) = cinema::blast_power(event) {
|
||||
booms.push((dist, power, at, volume, pitch));
|
||||
} else if travels(event) {
|
||||
// Seen first, heard later; from afar muffled.
|
||||
let name = if dist > FAR { format!("{event}_far") } else { event.to_string() };
|
||||
let delay = (dist / SOUND_SPEED) as u64;
|
||||
@@ -507,6 +596,18 @@ impl AirDef {
|
||||
render::play_sound(event, at.x, at.y, at.z, volume, pitch);
|
||||
}
|
||||
}
|
||||
booms.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
for (rank, (dist, power, at, volume, pitch)) in booms.into_iter().enumerate() {
|
||||
for l in cinema::layers(power, dist, FAR, volume, pitch, rank) {
|
||||
// Seen first, heard later: each voice after the sound has travelled.
|
||||
let delay = (dist / SOUND_SPEED) as u64 + l.delay;
|
||||
if delay == 0 {
|
||||
render::play_sound(&l.name, at.x, at.y, at.z, l.volume, l.pitch);
|
||||
} else if self.pending.len() < 256 {
|
||||
self.pending.push(PendingSound { due: now + delay, name: l.name, at, volume: l.volume, pitch: l.pitch });
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut i = 0;
|
||||
while i < self.pending.len() {
|
||||
if self.pending[i].due <= now {
|
||||
@@ -794,6 +895,7 @@ impl AirDef {
|
||||
fn stop_replay(&mut self) {
|
||||
self.replay = None;
|
||||
render::set_time_override(None);
|
||||
render::set_main_view(None);
|
||||
input::claim_wheel(false);
|
||||
render::set_hud(&[]);
|
||||
render::set_views(&[]);
|
||||
@@ -1013,6 +1115,7 @@ impl Mod for AirDef {
|
||||
health_mark: 0,
|
||||
menu: None,
|
||||
listener: DVec3::ZERO,
|
||||
punch: 0.0,
|
||||
pending: Vec::new(),
|
||||
model_ids: std::collections::HashMap::new(),
|
||||
model_generation: u32::MAX,
|
||||
@@ -1148,6 +1251,13 @@ impl Mod for AirDef {
|
||||
render::query_sections(render::Policy::Collision, §ions);
|
||||
}
|
||||
if let Some(mut r) = self.replay.take() {
|
||||
// A replay shows the recording alone: not the live raid's models, particles, sounds or jolts.
|
||||
if r.filming() {
|
||||
out.models.clear();
|
||||
out.particles.clear();
|
||||
out.sounds.clear();
|
||||
out.shake = None;
|
||||
}
|
||||
r.tick(&self.sim, self.listener, &mut out);
|
||||
if r.done {
|
||||
self.replay = Some(r);
|
||||
@@ -1163,6 +1273,8 @@ impl Mod for AirDef {
|
||||
let size = render::gui_size();
|
||||
render::set_hud(&r.hud(&self.sim, size));
|
||||
render::set_views(&r.views(size));
|
||||
// The world through the director's camera, with the full pipeline (HD, the post pass).
|
||||
render::set_main_view(r.filming().then(|| r.view_id()));
|
||||
// The sky of the raid, not of now (None for a raid whose clock was unknown).
|
||||
render::set_time_override(r.day_time(&self.sim));
|
||||
self.monitor_shown = true;
|
||||
|
||||
Reference in New Issue
Block a user