
As a prerequisite for decals and clustering of light probes, we want clustering to operate on objects other than lights. (Currently, it only operates on point and spot lights.) This necessitates a large refactoring, so I'm splitting it up into small steps. The first such step is to separate clustering from lighting by moving clustering-related types and functions out of lighting and into their own module subtree within the `bevy_pbr` crate. (Ultimately, we may want to move it to `bevy_render`, but that requires more work and can be a followup.) No code changes have been made other than adjusting import lists and moving code. This is to make this code easy to review. Ultimately, I want to rename "light" to "clusterable object" in most cases, but doing that at the same time as moving the code would make reviewing harder. So instead I'm moving the code first and will follow this up with renaming. ## Migration Guide * Clustering-related types and functions (e.g. `assign_lights_to_clusters`) have moved under `bevy_pbr::cluster`, in preparation for the ability to cluster objects other than lights.
55 lines
2.1 KiB
Rust
55 lines
2.1 KiB
Rust
use bevy_math::UVec2;
|
|
|
|
use crate::{ClusterConfig, Clusters};
|
|
|
|
fn test_cluster_tiling(config: ClusterConfig, screen_size: UVec2) -> Clusters {
|
|
let dims = config.dimensions_for_screen_size(screen_size);
|
|
|
|
// note: near & far do not affect tiling
|
|
let mut clusters = Clusters::default();
|
|
clusters.update(screen_size, dims);
|
|
|
|
// check we cover the screen
|
|
assert!(clusters.tile_size.x * clusters.dimensions.x >= screen_size.x);
|
|
assert!(clusters.tile_size.y * clusters.dimensions.y >= screen_size.y);
|
|
// check a smaller number of clusters would not cover the screen
|
|
assert!(clusters.tile_size.x * (clusters.dimensions.x - 1) < screen_size.x);
|
|
assert!(clusters.tile_size.y * (clusters.dimensions.y - 1) < screen_size.y);
|
|
// check a smaller tile size would not cover the screen
|
|
assert!((clusters.tile_size.x - 1) * clusters.dimensions.x < screen_size.x);
|
|
assert!((clusters.tile_size.y - 1) * clusters.dimensions.y < screen_size.y);
|
|
// check we don't have more clusters than pixels
|
|
assert!(clusters.dimensions.x <= screen_size.x);
|
|
assert!(clusters.dimensions.y <= screen_size.y);
|
|
|
|
clusters
|
|
}
|
|
|
|
#[test]
|
|
// check tiling for small screen sizes
|
|
fn test_default_cluster_setup_small_screensizes() {
|
|
for x in 1..100 {
|
|
for y in 1..100 {
|
|
let screen_size = UVec2::new(x, y);
|
|
let clusters = test_cluster_tiling(ClusterConfig::default(), screen_size);
|
|
assert!(clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z <= 4096);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
// check tiling for long thin screen sizes
|
|
fn test_default_cluster_setup_small_x() {
|
|
for x in 1..10 {
|
|
for y in 1..5000 {
|
|
let screen_size = UVec2::new(x, y);
|
|
let clusters = test_cluster_tiling(ClusterConfig::default(), screen_size);
|
|
assert!(clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z <= 4096);
|
|
|
|
let screen_size = UVec2::new(y, x);
|
|
let clusters = test_cluster_tiling(ClusterConfig::default(), screen_size);
|
|
assert!(clusters.dimensions.x * clusters.dimensions.y * clusters.dimensions.z <= 4096);
|
|
}
|
|
}
|
|
}
|