Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/bevy_light/src/directional_light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use bevy_ecs::prelude::*;
use bevy_image::Image;
use bevy_reflect::prelude::*;
use bevy_transform::components::Transform;
use tracing::warn;

use super::{
cascade::CascadeShadowConfig, cluster::ClusterVisibilityClass, light_consts, Cascades,
Expand Down Expand Up @@ -182,6 +183,8 @@ pub struct DirectionalLightTexture {
pub struct DirectionalLightShadowMap {
// The width and height of each cascade.
///
/// Must be a power of two to avoid unstable cascade positioning.
///
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of documenting here, it may be better to make this a private field, and enforce the power of two requirement at construction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// Defaults to `2048`.
pub size: usize,
}
Expand All @@ -192,6 +195,14 @@ impl Default for DirectionalLightShadowMap {
}
}

pub fn validate_shadow_map_size(mut shadow_map: ResMut<DirectionalLightShadowMap>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a separate system just to warn devs? or can it not be a part of the build_directional_light_cascades system?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesnt have to be separate, but im hoping we get resource hooks and can use those instead eventually.

if shadow_map.is_changed() && !shadow_map.size.is_power_of_two() {
let new_size = shadow_map.size.next_power_of_two();
warn!("Non-power-of-two DirectionalLightShadowMap sizes are not supported, correcting {} to {new_size}", shadow_map.size);
shadow_map.size = new_size;
}
}

pub fn update_directional_light_frusta(
mut views: Query<
(
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_light/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub use directional_light::{
DirectionalLightTexture,
};

use crate::directional_light::validate_shadow_map_size;

/// Constants for operating with the light units: lumens, and lux.
pub mod light_consts {
/// Approximations for converting the wattage of lamps to lumens.
Expand Down Expand Up @@ -145,6 +147,7 @@ impl Plugin for LightPlugin {
.add_systems(
PostUpdate,
(
validate_shadow_map_size.before(build_directional_light_cascades),
add_clusters
.in_set(SimulationLightSystems::AddClusters)
.after(CameraUpdateSystems),
Expand Down
Loading