The fixed 500-block far plane clipped geometry before fog saturated, making the clip plane itself the visible boundary at large view distances.
38 lines
1.3 KiB
Rust
38 lines
1.3 KiB
Rust
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
//! Unit tests for the pure helpers in [`crate::renderer`].
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn far_plane_floors_at_the_minimum_for_near_fog() {
|
|
// Fog that saturates well inside the minimum leaves the far plane at the floor; shrinking it to match would clip geometry for no gain.
|
|
assert!((far_plane_for(128.0, 64.0) - MIN_FAR_PLANE).abs() < f32::EPSILON);
|
|
}
|
|
|
|
#[test]
|
|
fn far_plane_covers_the_diagonal_of_the_two_extents() {
|
|
// 768 horizontal and 384 vertical (a radius-24 cylinder) reach 858.6 at the corner, past the 500-block floor.
|
|
let far = far_plane_for(768.0, 384.0);
|
|
assert!(far > MIN_FAR_PLANE);
|
|
assert!(
|
|
(far - 858.65_f32).abs() < 0.01,
|
|
"unexpected far plane {far}"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn far_plane_reaches_past_each_extent_taken_alone() {
|
|
// The corner of the box is further than either edge, so covering only the larger extent would still clip partially-visible fragments near the diagonal.
|
|
let (horizontal, vertical) = (768.0_f32, 384.0_f32);
|
|
let far = far_plane_for(horizontal, vertical);
|
|
assert!(far > horizontal);
|
|
assert!(far > vertical);
|
|
}
|
|
|
|
#[test]
|
|
fn far_plane_is_well_formed_without_fog() {
|
|
// A caller that supplies no fog distance must still receive a usable projection rather than a degenerate zero-depth one.
|
|
assert!(far_plane_for(0.0, 0.0) > 0.0);
|
|
}
|