Fixed crash when CSM near and far values are superimposed

This commit is contained in:
Adrien GIVRY
2025-04-28 17:22:49 -04:00
parent 64c9caf76a
commit 7ff1908aad
2 changed files with 7 additions and 2 deletions
+1
View File
@@ -48,6 +48,7 @@ lightmap = "0.2"
libloading = "0.8.1"
gltf = { version = "1.4.0", default-features = false, features = ["names", "utils", "extras"] }
bytemuck = { version = "1.16.1", features = ["derive"] }
approx = "0.5.1"
# These dependencies aren't used by the engine, but it is necessary to prevent cargo from rebuilding
# the engine lib on different packages. This is especially important for hot reloading feature.
+6 -2
View File
@@ -48,6 +48,7 @@ use crate::{
light::directional::{FrustumSplitOptions, CSM_NUM_CASCADES},
},
};
use approx::relative_eq;
use fyrox_graphics::framebuffer::GpuFrameBuffer;
use fyrox_graphics::gpu_texture::GpuTexture;
@@ -194,8 +195,11 @@ impl CsmRenderer {
let z_near = z_values[i];
let mut z_far = z_values[i + 1];
if z_far.eq(&z_near) {
z_far += 10.0 * f32::EPSILON;
// Prevents z_near and z_far from being relatively equal, which would result in an invalid perspective matrix.
if relative_eq!(z_far, z_near) {
// Needs to be at least greater than f32::EPSILON to break the relative equality.
const MIN_DEPTH_DELTA: f32 = f32::EPSILON * 2.0;
z_far += MIN_DEPTH_DELTA * z_near;
}
let projection_matrix = camera