move calculate_cluster_factors to cluster assign (#19958)
# Objective - Make bevy_light possible by making it possible to split out clusterable into bevy_camera ## Solution - Move some stuff so i can split it out cleanly. ## Testing - 3d_scene runs
This commit is contained in:
parent
f987920bbd
commit
59e8702a65
@ -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.
|
// 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 far_z = far_z.max(first_slice_depth);
|
||||||
let cluster_factors = crate::calculate_cluster_factors(
|
let cluster_factors = calculate_cluster_factors(
|
||||||
first_slice_depth,
|
first_slice_depth,
|
||||||
far_z,
|
far_z,
|
||||||
requested_cluster_dimensions.z as f32,
|
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(
|
fn compute_aabb_for_cluster(
|
||||||
z_near: f32,
|
z_near: f32,
|
||||||
z_far: f32,
|
z_far: f32,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use self::assign::ClusterableObjectType;
|
use self::assign::ClusterableObjectType;
|
||||||
|
use crate::assign::calculate_cluster_factors;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use bevy_asset::UntypedAssetId;
|
use bevy_asset::UntypedAssetId;
|
||||||
use bevy_color::ColorToComponents;
|
use bevy_color::ColorToComponents;
|
||||||
@ -11,7 +12,7 @@ use bevy_ecs::{
|
|||||||
prelude::*,
|
prelude::*,
|
||||||
system::lifetimeless::Read,
|
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::collections::{HashMap, HashSet};
|
||||||
use bevy_platform::hash::FixedHasher;
|
use bevy_platform::hash::FixedHasher;
|
||||||
use bevy_render::erased_render_asset::ErasedRenderAssets;
|
use bevy_render::erased_render_asset::ErasedRenderAssets;
|
||||||
@ -694,22 +695,6 @@ pub enum LightEntity {
|
|||||||
light_entity: Entity,
|
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(
|
pub fn prepare_lights(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
Loading…
Reference in New Issue
Block a user