-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Validate directional light shadow map size is power of two #20375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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. | ||
/// | ||
/// Defaults to `2048`. | ||
pub size: usize, | ||
} | ||
|
@@ -192,6 +195,14 @@ impl Default for DirectionalLightShadowMap { | |
} | ||
} | ||
|
||
pub fn validate_shadow_map_size(mut shadow_map: ResMut<DirectionalLightShadowMap>) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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< | ||
( | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was considered: https://discord.com/channels/691052431525675048/743663924229963868/1400667437829066754