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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
let n = seen.len() as u32;
|
||||
for t in &mut tiles {
|
||||
t.origin = moved(t.origin);
|
||||
}
|
||||
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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user