You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Odd behaviour as some clusters get more light than expected, and some get less / none.
Additional information
Example code to see the issue (most noticeable after ~10 seconds when the CLUSTER_COUNT_MASK limit is exceeded for the middle cluster):
use bevy::{prelude::*, diagnostic::{FrameTimeDiagnosticsPlugin,LogDiagnosticsPlugin}, window::{WindowMode,PresentMode}};fnmain(){App::new().insert_resource(WindowDescriptor{width:1280.0,height:720.0,mode:WindowMode::Windowed,present_mode:PresentMode::Immediate,
..Default::default()}).add_plugins(DefaultPlugins).add_plugin(FrameTimeDiagnosticsPlugin).add_plugin(LogDiagnosticsPlugin::default()).add_startup_system(setup).add_system(move_camera).run()}fnsetup(mutcommands:Commands,mutmeshes:ResMut<Assets<Mesh>>,mutmaterials:ResMut<Assets<StandardMaterial>>,){// some quad
commands.spawn_bundle(PbrBundle{mesh: meshes.add(shape::Quad{size:Vec2::splat(100.0),flip:false}.into()),material: materials.add(Color::WHITE.into()),transform:Transform::from_translation(Vec3::new(0.0,0.0, -5.0)),
..Default::default()});// some bright offscreen lightsfor x in0..25{for y in0..10{
commands.spawn_bundle(PointLightBundle{point_light:PointLight{color:Color::RED,intensity:10.0,range: f32::sqrt(10.0*10.0 / (4.0* std::f32::consts::PI)),
..Default::default()},transform:Transform::from_translation(Vec3::new(20.0 + 10.0* x asf32, y asf32*10.0 - 50.0, -4.9)),
..Default::default()});}}// grid of lightsfor x in1..=18{for y in1..=18{
commands.spawn_bundle(PointLightBundle{point_light:PointLight{color:Color::BLUE,intensity: x asf32* y asf32*0.01,range: f32::sqrt(x asf32* y asf32*0.01*10.0 / (4.0* std::f32::consts::PI)),
..Default::default()},transform:Transform::from_translation(Vec3::new(x asf32*0.2 - 2.0, y asf32*0.2 - 2.0, -4.9)),
..Default::default()});}}//camera
commands.spawn_bundle(PerspectiveCameraBundle::new_3d());//action}fnmove_camera(mutq:Query<&mutTransform,With<Camera>>,time:Res<Time>,){formut t in q.iter_mut(){
t.translation.z += time.delta_seconds();}}
The text was updated successfully, but these errors were encountered:
# Objective
fixbevyengine#3915
## Solution
the issues are caused by
- lights are assigned to clusters before being filtered down to MAX_POINT_LIGHTS, leading to cluster counts potentially being too high
- after fixing the above, packing the count into 8 bits still causes overflow with exactly 256 lights affecting a cluster
to fix:
```assign_lights_to_clusters```
- limit extracted lights to MAX_POINT_LIGHTS, selecting based on shadow-caster & intensity (if required)
- warn if MAX_POINT_LIGHT count is exceeded
```prepare_lights```
- limit the lights assigned to a cluster to CLUSTER_COUNT_MASK (which is 1 less than MAX_POINT_LIGHTS) to avoid overflowing into the offset bits
notes:
- a better solution to the overflow may be to use more than 8 bits for cluster_count (the comment states only 14 of the remaining 24 bits are used for the offset). this would touch more of the code base but i'm happy to try if it has some benefit.
- intensity is only one way to select lights. it may be worth allowing user configuration of the light filtering, but i can't see a clean way to do that
Bevy version
main
Operating system & version
Windows 10
What you did
Create a scene with more than 256 point lights.
What you expected to happen
Rational degradation of the lights in the scene.
What actually happened
Odd behaviour as some clusters get more light than expected, and some get less / none.
Additional information
Example code to see the issue (most noticeable after ~10 seconds when the CLUSTER_COUNT_MASK limit is exceeded for the middle cluster):
The text was updated successfully, but these errors were encountered: