diff --git a/crates/bevy_pbr/src/cluster/assign.rs b/crates/bevy_pbr/src/cluster/assign.rs index c2526bc2ff..84b2eb702e 100644 --- a/crates/bevy_pbr/src/cluster/assign.rs +++ b/crates/bevy_pbr/src/cluster/assign.rs @@ -381,7 +381,7 @@ pub(crate) fn assign_objects_to_clusters( // NOTE: Ensure the far_z is at least as far as the first_depth_slice to avoid clustering problems. let far_z = far_z.max(first_slice_depth); - let cluster_factors = crate::calculate_cluster_factors( + let cluster_factors = calculate_cluster_factors( first_slice_depth, far_z, requested_cluster_dimensions.z as f32, @@ -871,6 +871,23 @@ pub(crate) fn assign_objects_to_clusters( } } +pub fn calculate_cluster_factors( + near: f32, + far: f32, + z_slices: f32, + is_orthographic: bool, +) -> Vec2 { + if is_orthographic { + Vec2::new(-near, z_slices / (-far - -near)) + } else { + let z_slices_of_ln_zfar_over_znear = (z_slices - 1.0) / ops::ln(far / near); + Vec2::new( + z_slices_of_ln_zfar_over_znear, + ops::ln(near) * z_slices_of_ln_zfar_over_znear, + ) + } +} + fn compute_aabb_for_cluster( z_near: f32, z_far: f32, diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index cee3d76e14..c7d9efbab7 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -1,4 +1,5 @@ use self::assign::ClusterableObjectType; +use crate::assign::calculate_cluster_factors; use crate::*; use bevy_asset::UntypedAssetId; use bevy_color::ColorToComponents; @@ -11,7 +12,7 @@ use bevy_ecs::{ prelude::*, system::lifetimeless::Read, }; -use bevy_math::{ops, Mat4, UVec4, Vec2, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; +use bevy_math::{ops, Mat4, UVec4, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles}; use bevy_platform::collections::{HashMap, HashSet}; use bevy_platform::hash::FixedHasher; use bevy_render::erased_render_asset::ErasedRenderAssets; @@ -694,22 +695,6 @@ pub enum LightEntity { light_entity: Entity, }, } -pub fn calculate_cluster_factors( - near: f32, - far: f32, - z_slices: f32, - is_orthographic: bool, -) -> Vec2 { - if is_orthographic { - Vec2::new(-near, z_slices / (-far - -near)) - } else { - let z_slices_of_ln_zfar_over_znear = (z_slices - 1.0) / ops::ln(far / near); - Vec2::new( - z_slices_of_ln_zfar_over_znear, - ops::ln(near) * z_slices_of_ln_zfar_over_znear, - ) - } -} pub fn prepare_lights( mut commands: Commands,