diff --git a/crates/bevy_pbr/src/light.rs b/crates/bevy_pbr/src/light.rs index 502b22047de4f..7316604ad3f5c 100644 --- a/crates/bevy_pbr/src/light.rs +++ b/crates/bevy_pbr/src/light.rs @@ -1081,20 +1081,12 @@ fn compute_aabb_for_cluster( // Convert to view space at the cluster near and far planes // NOTE: 1.0 is the near plane due to using reverse z projections - let p_min = screen_to_view( - screen_size, - inverse_projection, - p_min, - 1.0 - (ijk.z / cluster_dimensions.z as f32), - ) - .xyz(); - let p_max = screen_to_view( - screen_size, - inverse_projection, - p_max, - 1.0 - ((ijk.z + 1.0) / cluster_dimensions.z as f32), - ) - .xyz(); + let mut p_min = screen_to_view(screen_size, inverse_projection, p_min, 0.0).xyz(); + let mut p_max = screen_to_view(screen_size, inverse_projection, p_max, 0.0).xyz(); + + // calculate cluster depth using z_near and z_far + p_min.z = -z_near + (z_near - z_far) * ijk.z / cluster_dimensions.z as f32; + p_max.z = -z_near + (z_near - z_far) * (ijk.z + 1.0) / cluster_dimensions.z as f32; cluster_min = p_min.min(p_max); cluster_max = p_min.max(p_max);