Replay controls (arrows, Space, Backspace), distant terrain for cameras

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 11:15:11 +03:00
parent f0fbc397d8
commit 94170823cb
11 changed files with 349 additions and 41 deletions
+7 -1
View File
@@ -92,7 +92,13 @@ CI: `.gitea/workflows/build.yml` на каждый пуш собирает мо
- **лучшие моменты** — нарезка до 8 самых интересных событий (перехват баллистики и гиперзвука, поражения
объектов, потерянные комплексы, разделение «Орешника») с титрами и замедлением; колесо листает моменты.
Повтор идёт на весь экран с леттербоксом; звук слышен так, как его слышала бы камера. R — выход.
Повтор идёт на весь экран с леттербоксом; звук слышен так, как его слышала бы камера. Управление (подсказка
показывается в начале, после нажатия и на паузе): **← →** — перемотка на 5 с (в нарезке — соседний момент),
**↑ ↓** — скорость (×0.25–×32), **Пробел** — пауза (в конце — сначала), **колесо** — время / моменты,
**R** или **Backspace** — выход, **N** — выйти в меню. В конце повтор встаёт на паузу.
Чтобы в повторах и камерах комплексов была видна земля далеко от игрока, мод включает дальний ландшафт
(48 чанков, упрощённый); выключается в меню N → «Огонь, ремонт, эффекты…» → «Дальний ландшафт».
Клавиши N, K, J и R можно переназначить в «Настройки → Моды».
+49 -1
View File
@@ -56,6 +56,8 @@ struct AirDef {
wave: wave::WaveConfig,
/// A replay playing (it takes the screen and the mouse wheel).
replay: Option<replay::Player>,
/// The world drawn beyond the render distance (replays and cameras see far off).
far: bool,
/// The menu's page while it is open.
menu: Option<Page>,
/// Where the player is, for the sounds' delay and far variants.
@@ -109,6 +111,7 @@ const REPLAY_EVENTS: u32 = 3;
const BTN_MAP: u32 = 40;
const BTN_FULL: u32 = 41;
const BTN_REEL: u32 = 42;
const BTN_FAR: u32 = 19;
const BTN_CLASS: u32 = 100;
const BTN_ALL: u32 = 120;
const BTN_DEFAULT: u32 = 121;
@@ -355,6 +358,7 @@ impl AirDef {
text += &format!("target {} {} {} {h}\n", t.x, t.y, t.z);
}
text += &format!("damage {}\n", self.sim.damage);
text += &format!("far {}\n", self.far);
for (kind, roles) in &self.sim.roles {
text += &format!("roles {} {}\n", kind.key(), roles);
}
@@ -393,6 +397,7 @@ impl AirDef {
}
}
Some(&"damage") => self.sim.damage = w.get(1) != Some(&"false"),
Some(&"far") => self.far = w.get(1) != Some(&"false"),
Some(&"roles") => {
if let (Some(kind), Some(r)) = (w.get(1).and_then(|k| SamKind::from_key(k)), w.get(2).and_then(|v| v.parse().ok())) {
self.sim.roles.insert(kind, r);
@@ -412,6 +417,13 @@ impl AirDef {
}
impl AirDef {
/// Distant terrain (48 chunks, coarse) while `far` is on: the raid's whole area has land,
/// in the world and in the cameras.
fn apply_far(&self) {
let far = self.far.then_some(render::FarTerrain { distance: 48, reduced: true });
render::set_far_terrain(far);
}
/// Plays the last recorded raid: "map", "full", "reel" or (with `event`) a clip.
fn start_replay(&mut self, what: &str, event: Option<usize>) -> Result<(), String> {
let n = self.sim.replays.len();
@@ -565,6 +577,7 @@ impl AirDef {
widgets.push(Widget::Button(ButtonWidget { id: BTN_REPAIR, label: format!("Ремонт всех (повреждено: {broken})") }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_SHADER, label: format!("Эффекты: {}", onoff(self.sim.shader)) }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_DAMAGE, label: format!("Разрушения: {}", onoff(self.sim.damage)) }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_FAR, label: format!("Дальний ландшафт: {}", onoff(self.far)) }));
widgets.push(Widget::Button(ButtonWidget { id: BTN_BACK, label: "← Назад".into() }));
}
Page::Wave => {
@@ -643,6 +656,7 @@ impl Mod for AirDef {
grid_ids: Vec::new(),
wave: wave::WaveConfig::default(),
replay: None,
far: true,
menu: None,
listener: DVec3::ZERO,
pending: Vec::new(),
@@ -651,10 +665,19 @@ impl Mod for AirDef {
let _ = input::register_key("monitor", "Монитор ПВО: следующий комплекс", "key.keyboard.k");
let _ = input::register_key("grid", "Командный пункт: все комплексы", "key.keyboard.j");
let _ = input::register_key("replay", "Повтор налёта: карта / выход", "key.keyboard.r");
// The replay's own keys (they do nothing outside a replay).
let _ = input::register_key("rp_back", "Повтор: назад", "key.keyboard.left");
let _ = input::register_key("rp_forward", "Повтор: вперёд", "key.keyboard.right");
let _ = input::register_key("rp_faster", "Повтор: быстрее", "key.keyboard.up");
let _ = input::register_key("rp_slower", "Повтор: медленнее", "key.keyboard.down");
// Not Enter: it opens the chat.
let _ = input::register_key("rp_pause", "Повтор: пауза", "key.keyboard.space");
let _ = input::register_key("rp_exit", "Повтор: выход", "key.keyboard.backspace");
me.load();
input::claim_items(&ITEMS.map(String::from));
render::set_post(include_str!("../shaders/effects.wgsl"));
me.sim.shader = true;
me.apply_far();
Ok((me, Registration::new().command("airdef").on_tick()))
}
@@ -663,7 +686,27 @@ impl Mod for AirDef {
for event in input::poll() {
match event {
Event::UseStart(u) => self.use_item(&u.item.id),
Event::KeyDown(k) if k == "menu" => self.open_menu(Page::Main),
Event::KeyDown(k) if k == "menu" => {
if self.replay.is_some() {
self.stop_replay();
}
self.open_menu(Page::Main)
}
Event::KeyDown(k) if k == "rp_exit" && self.replay.is_some() => self.stop_replay(),
Event::KeyDown(k) if k.starts_with("rp_") => {
let c = match k.as_str() {
"rp_back" => replay::Control::Back,
"rp_forward" => replay::Control::Forward,
"rp_faster" => replay::Control::Faster,
"rp_slower" => replay::Control::Slower,
_ => replay::Control::Pause,
};
if let Some(r) = &mut self.replay
&& let Some(rec) = self.sim.replays.get(r.rec)
{
r.control(c, rec);
}
}
Event::KeyDown(k) if k == "monitor" => self.cycle_monitor(),
Event::KeyDown(k) if k == "grid" => self.grid = !self.grid,
Event::KeyDown(k) if k == "replay" => {
@@ -850,6 +893,11 @@ impl Mod for AirDef {
render::clear_post();
}
}
(Page::More, BTN_FAR) => {
self.far = !self.far;
self.apply_far();
self.dirty = true;
}
(Page::More, BTN_DAMAGE) => {
self.sim.damage = !self.sim.damage;
self.dirty = true;
+128 -32
View File
@@ -50,9 +50,29 @@ pub struct Player {
fov: f32,
/// The last tick whose events made their sounds.
heard: f64,
/// Time stands still (Space, or the end reached).
paused: bool,
/// Ticks the controls stay on screen.
help: u32,
pub done: bool,
}
/// What the replay's keys do.
#[derive(Clone, Copy, PartialEq)]
pub enum Control {
Back,
Forward,
Faster,
Slower,
Pause,
}
/// The speeds ↑ and ↓ step through.
const SPEEDS: [f64; 8] = [0.25, 0.5, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0];
/// The keys, for the screen.
const KEYS_HELP: &str = "← → перемотка · ↑ ↓ скорость · Пробел пауза · R / Backspace выход";
fn fill(x: f32, y: f32, w: f32, h: f32, color: u32) -> Shape {
Shape::Fill(FillShape { rect: Rect { x, y, w, h }, color })
}
@@ -194,33 +214,81 @@ impl Player {
look: DVec3::NEG_Z,
fov: 50.0,
heard: start,
paused: false,
help: 100,
done: false,
}
}
/// The wheel: scrubs the map, sets the full replay's speed, skips clips.
/// The wheel: scrubs the map and the full replay, skips clips.
pub fn wheel(&mut self, steps: f32, rec: &Recording) {
match &mut self.mode {
Mode::Map => self.t = (self.t - steps as f64 * 60.0).clamp(0.0, rec.len as f64),
Mode::Full => {
const SPEEDS: [f64; 6] = [0.5, 1.0, 2.0, 4.0, 8.0, 16.0];
let c = if steps > 0.0 { Control::Back } else { Control::Forward };
for _ in 0..(steps.abs().round() as u32).max(1) {
self.control(c, rec);
}
}
/// A key: steps back or forward (5 s, or a moment of the reel), faster, slower, pause.
pub fn control(&mut self, c: Control, rec: &Recording) {
self.help = self.help.max(60);
match c {
Control::Faster | Control::Slower => {
let i = SPEEDS.iter().position(|s| *s >= self.speed).unwrap_or(2) as i32;
let j = (i - steps.signum() as i32).clamp(0, SPEEDS.len() as i32 - 1);
let j = (i + if c == Control::Faster { 1 } else { -1 }).clamp(0, SPEEDS.len() as i32 - 1);
self.speed = SPEEDS[j as usize];
self.paused = false;
}
Mode::Clips { list, at, reel } => {
let next = (*at as i32 - steps.signum() as i32).clamp(0, list.len() as i32 - 1) as usize;
if next != *at {
*at = next;
self.t = list[next].from;
self.heard = self.t;
self.fade = 6;
self.card = if *reel { 50 } else { 0 };
Control::Pause => {
// At the end, Space plays it again.
if self.paused && self.at_end(rec) {
self.restart();
}
self.paused = !self.paused;
}
Control::Back | Control::Forward => {
let dir = if c == Control::Forward { 1 } else { -1 };
match &mut self.mode {
Mode::Map | Mode::Full => {
self.t = (self.t + dir as f64 * 100.0).clamp(0.0, rec.len as f64);
self.heard = self.t;
self.shot = (usize::MAX, 0);
}
Mode::Clips { list, at, reel } => {
let next = (*at as i32 + dir).clamp(0, list.len() as i32 - 1) as usize;
// Back on the first moment: from its start again.
*at = next;
self.t = list[next].from;
self.heard = self.t;
self.fade = 6;
self.card = if *reel { 50 } else { 0 };
self.paused = false;
}
}
}
}
}
fn at_end(&self, rec: &Recording) -> bool {
match &self.mode {
Mode::Map | Mode::Full => self.t >= rec.len as f64,
Mode::Clips { list, at, .. } => *at + 1 >= list.len() && self.t >= list[*at].to,
}
}
fn restart(&mut self) {
let reel = matches!(self.mode, Mode::Clips { reel: true, .. });
self.t = match &mut self.mode {
Mode::Clips { list, at, .. } => {
*at = 0;
list[0].from
}
_ => 0.0,
};
self.heard = self.t;
self.card = if reel { 50 } else { 0 };
self.fade = 6;
}
/// One tick: time runs, the ghosts fly, the director films. Models and sounds go to `out`.
pub fn tick(&mut self, sim: &Sim, listener: DVec3, out: &mut Out) {
let Some(rec) = sim.replays.get(self.rec) else {
@@ -231,25 +299,28 @@ impl Player {
if self.card > 0 {
self.card -= 1;
}
// Time: slowed round the moment in clips, held still while a title card shows.
self.help = self.help.saturating_sub(1);
// Time: slowed round the moment in clips (the chosen speed scales it), held still while a
// title card shows or paused.
let mut speed = self.speed;
if let Mode::Clips { list, at, .. } = &self.mode {
let te = rec.events[list[*at].event].at as f64;
if (te - 14.0..te + 18.0).contains(&self.t) {
speed = 0.3;
speed *= 0.3;
}
if self.card > 25 {
speed = 0.0;
}
}
self.t += speed;
if !self.paused {
self.t += speed;
}
// The end: it stops there, paused (Space plays it again, R leaves).
match &mut self.mode {
Mode::Map | Mode::Full => {
if self.t >= rec.len as f64 {
self.t = rec.len as f64;
if matches!(self.mode, Mode::Full) {
self.done = true;
}
self.paused = true;
}
}
Mode::Clips { list, at, reel } => {
@@ -261,7 +332,8 @@ impl Player {
self.fade = 6;
self.card = if *reel { 50 } else { 0 };
} else {
self.done = true;
self.t = list[*at].to;
self.paused = true;
}
}
}
@@ -441,20 +513,15 @@ impl Player {
s.push(text(head, 18.0, bar / 2.0 - 4.0, 0xFFFFFFFF, false));
let speed = if let Mode::Clips { list, at, .. } = &self.mode {
let te = rec.events[list[*at].event].at as f64;
if (te - 14.0..te + 18.0).contains(&self.t) { 0.3 } else { 1.0 }
if (te - 14.0..te + 18.0).contains(&self.t) { self.speed * 0.3 } else { self.speed }
} else {
self.speed
};
let time = format!("{} / {} ×{}", clock(self.t), clock(rec.len as f64), speed);
let state = if self.paused { "ПАУЗА".to_string() } else { format!("×{speed}") };
let time = format!("{} / {} {state}", clock(self.t), clock(rec.len as f64));
let tw = horizon_mod_sdk::render::text_width(&time);
s.push(text(time, gw - 8.0 - tw, bar / 2.0 - 4.0, 0xFFC0C0C0, false));
// The controls between them, where they fit.
let hint = "колесо: ".to_string() + match self.mode { Mode::Full => "скорость", _ => "дальше / назад" } + " · R: выход";
let hw = horizon_mod_sdk::render::text_width(&hint);
let (left, right) = (18.0 + head_w + 12.0, gw - 8.0 - tw - 12.0);
if right - left >= hw {
s.push(text(hint, left + (right - left - hw) / 2.0, bar / 2.0 - 4.0, 0x80FFFFFF, false));
}
let _ = head_w;
// Caption: what is happening.
let caption = match &self.mode {
Mode::Clips { list, at, .. } => Some(list[*at].event),
@@ -484,9 +551,31 @@ impl Player {
let a = (self.fade.min(6) * 42) as u32;
s.push(fill(0.0, 0.0, gw, gh, a << 24));
}
self.controls(&mut s, gw, gh, bar);
s
}
/// The keys, shown at the start, after a key and while paused; a big pause mark.
fn controls(&self, s: &mut Vec<Shape>, gw: f32, gh: f32, bar: f32) {
if self.paused {
let (cx, cy) = (gw / 2.0, gh / 2.0);
s.push(fill(cx - 14.0, cy - 14.0, 10.0, 28.0, 0xC0FFFFFF));
s.push(fill(cx + 4.0, cy - 14.0, 10.0, 28.0, 0xC0FFFFFF));
}
if self.help > 0 || self.paused {
let line = match self.mode {
Mode::Clips { reel: true, .. } => KEYS_HELP.replace("перемотка", "моменты"),
Mode::Clips { .. } => KEYS_HELP.replace("← → перемотка · ", ""),
_ => KEYS_HELP.to_string(),
};
let w = horizon_mod_sdk::render::text_width(&line) + 12.0;
let a = if self.paused { 0xFF } else { (self.help.min(20) * 12) as u32 };
let y = gh - bar - 18.0;
s.push(fill(gw / 2.0 - w / 2.0, y, w, 13.0, (a.min(0xB0) << 24) | 0x000000));
s.push(text(line, gw / 2.0, y + 3.0, (a << 24) | 0xFFFFFF, true));
}
}
/// The raid from above: systems and their reach, objects, every track up to now, the events
/// so far, and a time line.
fn map(&self, rec: &Recording, gw: f32, gh: f32) -> Vec<Shape> {
@@ -601,8 +690,15 @@ impl Player {
// Header, legend, time line.
let kills = rec.events.iter().filter(|e| (e.at as f64) <= self.t && matches!(e.kind, EventKind::Kill { .. })).count();
let hits = rec.events.iter().filter(|e| (e.at as f64) <= self.t && matches!(e.kind, EventKind::Hit { .. })).count();
s.push(text(format!("КАРТА НАЛЁТА №{} · {} · сбито {kills} · прилётов {hits}", rec.number, clock(self.t)), 8.0, 6.0, 0xFF9FE0FF, false));
s.push(text("красный: цели · серый: ложные · жёлтый: перехватчики · x сбит · ■ прилёт · колесо: время · R выход", 8.0, gh - 12.0, 0x90FFFFFF, false));
let state = if self.paused { "ПАУЗА".to_string() } else { format!("×{}", self.speed) };
s.push(text(format!("КАРТА НАЛЁТА №{} · {} / {} {state} · сбито {kills} · прилётов {hits}", rec.number, clock(self.t), clock(rec.len as f64)), 8.0, 6.0, 0xFF9FE0FF, false));
let legend = "красный: цели · серый: ложные · жёлтый: перехватчики · x сбит · квадрат: прилёт";
let lw = horizon_mod_sdk::render::text_width(legend);
if lw < gw - 16.0 {
s.push(text(legend, gw - 8.0 - lw, 6.0 + 11.0, 0x70FFFFFF, false));
}
let keys = format!("{KEYS_HELP} · колесо: время");
s.push(text(keys, gw / 2.0, gh - 12.0, 0xC0FFFFFF, true));
let (tx, ty, tw) = (8.0, gh - bottom + 6.0, gw - 16.0);
s.push(fill(tx, ty, tw, 3.0, 0x60FFFFFF));
let len = rec.len.max(1) as f32;
@@ -1,7 +1,7 @@
From 3de7a6875140a107e28563cc44489b55f5794517 Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 12:37:45 +0300
Subject: [PATCH 1/7] Mod API (AirDef fork): world models, client particles,
Subject: [PATCH 1/8] Mod API (AirDef fork): world models, client particles,
sounds, ground heights
render.set-models draws block models with an interpolated pose per id;
@@ -1,7 +1,7 @@
From a6d64e6415bf618539af464e521091e72b72d72f Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 12:39:45 +0300
Subject: [PATCH 2/7] cargo-horizon-mod: report particles and sounds
Subject: [PATCH 2/8] cargo-horizon-mod: report particles and sounds
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
@@ -1,7 +1,7 @@
From ee79b3562feebe51959a01f1585a9e85bd53ccb5 Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 13:33:10 +0300
Subject: [PATCH 3/7] Mod API (AirDef fork): full-screen post pass for mods
Subject: [PATCH 3/8] Mod API (AirDef fork): full-screen post pass for mods
render.set-post compiles a mod's WGSL after a prelude (camera matrices,
time, 256 vec4 of params, the world's colour and depth) and runs it after
@@ -1,7 +1,7 @@
From 2b137dbbedd540daeebc7f5e387847aeb56a1355 Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 22:09:30 +0300
Subject: [PATCH 4/7] Mod models: draw far models as scaled impostors past the
Subject: [PATCH 4/8] Mod models: draw far models as scaled impostors past the
far plane, cull at 4096
---
@@ -1,7 +1,7 @@
From c8ebca6e0af68630e65211844b34d25c5b985c03 Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 22:31:00 +0300
Subject: [PATCH 5/7] Mod cameras: render.set-views draws the world from other
Subject: [PATCH 5/8] Mod cameras: render.set-views draws the world from other
points into pictures that HUD view shapes show (API level 9)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,7 +1,7 @@
From 8d2261fc4f8072c32e454139cfea7a8c0cd9d664 Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 23:08:21 +0300
Subject: [PATCH 6/7] Mods: more fuel per tick and per event (AirDef plans
Subject: [PATCH 6/8] Mods: more fuel per tick and per event (AirDef plans
raids)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,7 +1,7 @@
From 6c548de34def8e4a624d734243418090798bd16a Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Wed, 28 Oct 2026 23:25:29 +0300
Subject: [PATCH 7/7] Mod cameras up to 1920x1080 (full-screen replays)
Subject: [PATCH 7/8] Mod cameras up to 1920x1080 (full-screen replays)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
@@ -0,0 +1,158 @@
From 9b9e93269d67401cc620567a884d5ce97f68d76e Mon Sep 17 00:00:00 2001
From: chexit <chexit@duck.com>
Date: Thu, 29 Oct 2026 11:15:11 +0300
Subject: [PATCH 8/8] Mod cameras: distant terrain tiles, fog measured from the
camera, no impostors while one is shown
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
crates/horizon-client/src/game/mod_models.rs | 4 +-
crates/horizon-client/src/gfx.rs | 53 +++++++++++++++++---
crates/horizon-client/src/gfx/mod_views.rs | 4 ++
3 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/crates/horizon-client/src/game/mod_models.rs b/crates/horizon-client/src/game/mod_models.rs
index 7ae58f664..87d46c843 100644
--- a/crates/horizon-client/src/game/mod_models.rs
+++ b/crates/horizon-client/src/game/mod_models.rs
@@ -164,6 +164,8 @@ impl Game<'_> {
self.settings.cloud_range,
));
let reach = depth_far * 0.85;
+ // A mod camera (a replay's, a system's) must see them where they are: no impostors then.
+ let impostors = self.mods.models.views.is_empty();
for p in self.mods.models.poses.values() {
let mut at = p.previous.lerp(p.position, t);
let d = at.distance(camera);
@@ -171,7 +173,7 @@ impl Game<'_> {
continue;
}
let mut shrink = 1.0f32;
- if d > reach {
+ if d > reach && impostors {
shrink = (reach / d) as f32;
at = camera + (at - camera) * (reach / d);
}
diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs
index 3ad257728..9772e3a83 100644
--- a/crates/horizon-client/src/gfx.rs
+++ b/crates/horizon-client/src/gfx.rs
@@ -3078,6 +3078,9 @@ impl Renderer {
d.aspect,
(d.fov.to_radians() / 2.0).tan(),
],
+ // Fog goes by the distance from the player's camera: pushed out by how far this
+ // camera is from it, so what is near this one stays clear.
+ fog: globals.fog.map(|f| f + d.away),
..*globals
};
self.uploads
@@ -3138,6 +3141,19 @@ impl Renderer {
let instance = d.first + k as u32;
pass.draw_indexed(0..s.solid * 6, s.start as i32, instance..instance + 1);
}
+ for (k, v) in d.lods.iter().enumerate() {
+ let Some(tile) = self.lods.get(&v.key) else { continue };
+ let s = &tile.mesh;
+ if s.solid == 0 {
+ continue;
+ }
+ if page != Some(s.page) {
+ pass.set_vertex_buffer(0, self.arena.buffer(s.page).slice(..));
+ page = Some(s.page);
+ }
+ let instance = d.first + (d.visible.len() + k) as u32;
+ pass.draw_indexed(0..s.solid * 6, s.start as i32, instance..instance + 1);
+ }
if entity_quads > 0 {
pass.set_pipeline(&self.entity_pipeline);
pass.set_bind_group(0, &self.entity_group, &[]);
@@ -3971,14 +3987,30 @@ impl Renderer {
let own = world_projection(v.fov, aspect, frame.depth_far) * view;
let planes = Frustum { planes: frustum(own) };
let mut seen = Vec::new();
- self.sections
- .visible(v.camera, radius, &planes, |_| true, |_, _| false, &mut seen);
+ // Where distant terrain covers a column, its tile draws instead, as in the world pass.
+ self.sections.visible(
+ v.camera,
+ radius,
+ &planes,
+ |_| true,
+ |x, z| !cutout.is_empty() && cutout.contains(&(x, z)),
+ &mut seen,
+ );
+ let mut tiles: Vec<lod::Visible> = self
+ .lods
+ .iter()
+ .filter_map(|(&key, tile)| tile.visible(key, v.camera, frame.distance, &planes))
+ .collect();
// Relative to the player's camera, as the rest of the frame.
let shift = (v.camera - camera).as_vec3();
+ let moved = |o: [f32; 3]| [o[0] + shift.x, o[1] + shift.y, o[2] + shift.z];
for s in &mut seen {
- s.origin = [s.origin[0] + shift.x, s.origin[1] + shift.y, s.origin[2] + shift.z];
+ s.origin = moved(s.origin);
+ }
+ for t in &mut tiles {
+ t.origin = moved(t.origin);
}
- let n = seen.len() as u32;
+ let n = (seen.len() + tiles.len()) as u32;
views_due.push(mod_views::Due {
id: v.id,
view_proj,
@@ -3986,14 +4018,16 @@ impl Renderer {
aspect,
fov: v.fov,
visible: seen,
+ lods: tiles,
first,
+ away: shift.length(),
});
first += n;
}
} else if frame.mod_views.is_empty() {
self.mod_views = None;
}
- let view_sections: usize = views_due.iter().map(|d| d.visible.len()).sum();
+ let view_sections: usize = views_due.iter().map(|d| d.visible.len() + d.lods.len()).sum();
let instances = self.drawn_sections + shadow_visible.len() + view_sections;
if instances as u64 > self.instance_capacity {
self.instance_capacity = (instances as u64).next_power_of_two();
@@ -4014,9 +4048,12 @@ impl Renderer {
.chain(visible_lods.iter().map(|v| lod::instance(v.origin)))
.chain(shadow_visible.iter().map(|v| section_instance(v.origin)))
.chain(
- views_due
- .iter()
- .flat_map(|d| d.visible.iter().map(|v| section_instance(v.origin))),
+ views_due.iter().flat_map(|d| {
+ d.visible
+ .iter()
+ .map(|v| section_instance(v.origin))
+ .chain(d.lods.iter().map(|v| lod::instance(v.origin)))
+ }),
),
);
if !self.origins.is_empty() {
diff --git a/crates/horizon-client/src/gfx/mod_views.rs b/crates/horizon-client/src/gfx/mod_views.rs
index 91ae103a8..c0d886afd 100644
--- a/crates/horizon-client/src/gfx/mod_views.rs
+++ b/crates/horizon-client/src/gfx/mod_views.rs
@@ -45,8 +45,12 @@ pub(super) struct Due {
pub aspect: f32,
pub fov: f32,
pub visible: Vec<super::resident::Visible>,
+ /// Distant terrain tiles in its view, after the sections.
+ pub lods: Vec<super::lod::Visible>,
/// The instance of `visible[0]` in the section origins.
pub first: u32,
+ /// How far it is from the player's camera: fog is measured from there.
+ pub away: f32,
}
pub(super) struct Views {
--
2.54.0 (Apple Git-157)