mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
Fixed crash when CSM near and far values are superimposed
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user