Skip to content

Commit

Permalink
remove const
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Apr 7, 2022
1 parent 2af5d3c commit d39b81f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,6 @@ pub struct GpuLights {

// NOTE: this must be kept in sync with the same constants in pbr.frag
pub const MAX_UNIFORM_BUFFER_POINT_LIGHTS: usize = 256;
// FIXME: How should we handle shadows for clustered forward? Limiting to maximum 10
// point light shadow maps for now
#[cfg(feature = "webgl")]
pub const MAX_POINT_LIGHT_SHADOW_MAPS: usize = 1;
#[cfg(not(feature = "webgl"))]
pub const MAX_POINT_LIGHT_SHADOW_MAPS: usize = 256;
pub const MAX_DIRECTIONAL_LIGHTS: usize = 1;
pub const DIRECTIONAL_SHADOW_LAYERS: u32 = MAX_DIRECTIONAL_LIGHTS as u32;
pub const SHADOW_FORMAT: TextureFormat = TextureFormat::Depth32Float;
Expand Down Expand Up @@ -703,12 +697,14 @@ pub fn prepare_lights(

let mut point_lights: Vec<_> = point_lights.iter().collect::<Vec<_>>();

let nb_shadow_lights = point_lights
#[cfg(not(feature = "webgl"))]
let max_point_light_shadow_maps = point_lights
.iter()
.filter(|light| light.1.shadows_enabled)
.count()
.min(MAX_POINT_LIGHT_SHADOW_MAPS)
.min((render_device.limits().max_texture_array_layers / 6) as usize);
#[cfg(feature = "webgl")]
let max_point_light_shadow_maps = 1;

// Sort point lights with shadows enabled first, then by a stable key so that the index can be used
// to render at most `MAX_POINT_LIGHT_SHADOW_MAPS` point light shadows.
Expand All @@ -729,7 +725,7 @@ pub fn prepare_lights(
for (index, &(entity, light)) in point_lights.iter().enumerate() {
let mut flags = PointLightFlags::NONE;
// Lights are sorted, shadow enabled lights are first
if light.shadows_enabled && index < nb_shadow_lights {
if light.shadows_enabled && index < max_point_light_shadow_maps {
flags |= PointLightFlags::SHADOWS_ENABLED;
}
gpu_point_lights.push(GpuPointLight {
Expand Down Expand Up @@ -765,7 +761,7 @@ pub fn prepare_lights(
size: Extent3d {
width: point_light_shadow_map.size as u32,
height: point_light_shadow_map.size as u32,
depth_or_array_layers: nb_shadow_lights.max(1) as u32 * 6,
depth_or_array_layers: max_point_light_shadow_maps.max(1) as u32 * 6,
},
mip_level_count: 1,
sample_count: 1,
Expand Down Expand Up @@ -822,7 +818,7 @@ pub fn prepare_lights(
for &(light_entity, light) in point_lights
.iter()
// Lights are sorted, shadow enabled lights are first
.take(nb_shadow_lights)
.take(max_point_light_shadow_maps)
.filter(|(_, light)| light.shadows_enabled)
{
let light_index = *global_light_meta
Expand Down

0 comments on commit d39b81f

Please sign in to comment.