Skip to content

Commit

Permalink
bevy_pbr: Rename MAX_POINT_LIGHTS to MAX_UNIFORM_BUFFER_POINT_LIGHTS
Browse files Browse the repository at this point in the history
  • Loading branch information
superdump committed Apr 5, 2022
1 parent 3b13f86 commit 9da6d5d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use bevy_window::Windows;

use crate::{
calculate_cluster_factors, CubeMapFace, CubemapVisibleEntities, ViewClusterBindings,
CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT, CUBE_MAP_FACES, MAX_POINT_LIGHTS, POINT_LIGHT_NEAR_Z,
CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT, CUBE_MAP_FACES, MAX_UNIFORM_BUFFER_POINT_LIGHTS,
POINT_LIGHT_NEAR_Z,
};

/// A light that emits light in all directions from a central point.
Expand Down Expand Up @@ -736,7 +737,7 @@ pub(crate) fn assign_lights_to_clusters(
clustered_forward_buffer_binding_type,
BufferBindingType::Storage { .. }
);
if lights.len() > MAX_POINT_LIGHTS && !supports_storage_buffers {
if lights.len() > MAX_UNIFORM_BUFFER_POINT_LIGHTS && !supports_storage_buffers {
lights.sort_by(|light_1, light_2| {
point_light_order(
(&light_1.entity, &light_1.shadows_enabled),
Expand All @@ -752,7 +753,7 @@ pub(crate) fn assign_lights_to_clusters(
let mut lights_in_view_count = 0;
lights.retain(|light| {
// take one extra light to check if we should emit the warning
if lights_in_view_count == MAX_POINT_LIGHTS + 1 {
if lights_in_view_count == MAX_UNIFORM_BUFFER_POINT_LIGHTS + 1 {
false
} else {
let light_sphere = Sphere {
Expand All @@ -772,12 +773,15 @@ pub(crate) fn assign_lights_to_clusters(
}
});

if lights.len() > MAX_POINT_LIGHTS && !*max_point_lights_warning_emitted {
warn!("MAX_POINT_LIGHTS ({}) exceeded", MAX_POINT_LIGHTS);
if lights.len() > MAX_UNIFORM_BUFFER_POINT_LIGHTS && !*max_point_lights_warning_emitted {
warn!(
"MAX_UNIFORM_BUFFER_POINT_LIGHTS ({}) exceeded",
MAX_UNIFORM_BUFFER_POINT_LIGHTS
);
*max_point_lights_warning_emitted = true;
}

lights.truncate(MAX_POINT_LIGHTS);
lights.truncate(MAX_UNIFORM_BUFFER_POINT_LIGHTS);
}

for (view_entity, camera_transform, camera, frustum, config, clusters, mut visible_lights) in
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_pbr/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct GpuPointLight {

pub enum GpuPointLights {
Uniform {
buffer: UniformVec<[GpuPointLight; MAX_POINT_LIGHTS]>,
buffer: UniformVec<[GpuPointLight; MAX_UNIFORM_BUFFER_POINT_LIGHTS]>,
},
Storage {
buffer: StorageBuffer<GpuPointLight>,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl GpuPointLights {
let gpu_point_lights = lights
.drain(..)
.chain(std::iter::repeat_with(GpuPointLight::default))
.take(MAX_POINT_LIGHTS)
.take(MAX_UNIFORM_BUFFER_POINT_LIGHTS)
.collect::<Vec<_>>();
buffer.push(gpu_point_lights.try_into().unwrap());
}
Expand Down Expand Up @@ -219,7 +219,7 @@ pub struct GpuLights {
}

// NOTE: this must be kept in sync with the same constants in pbr.frag
pub const MAX_POINT_LIGHTS: usize = 256;
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")]
Expand Down Expand Up @@ -1008,7 +1008,7 @@ pub fn prepare_lights(
}

// this must match CLUSTER_COUNT_SIZE in pbr.wgsl
// and must be large enough to contain MAX_POINT_LIGHTS
// and must be large enough to contain MAX_UNIFORM_BUFFER_POINT_LIGHTS
const CLUSTER_COUNT_SIZE: u32 = 13;

const CLUSTER_OFFSET_MASK: u32 = (1 << (32 - CLUSTER_COUNT_SIZE)) - 1;
Expand Down

0 comments on commit 9da6d5d

Please sign in to comment.