bevyengine / bevyengine/bevy

Low fps with 100 objects and shadows

Open
#10,747 3 comments 0 reactions 0 assignees View on GitHub
C-Bug C-Performance
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

Bevy 0.12

## Relevant system information
`AdapterInfo { name: "NVIDIA GeForce GTX 1060 3GB", vendor: 4318, device: 7170, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "546.17", backend: Vulkan }`

## What you did

I have a simple scene with 100 thin slices of cuboids on top of each other with a gap. When I am at the bottom of this tower and look in the direction of the directional light with shadows enabled, I get suprisingly low fps.

Code to reproduce this problem:
```rust
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
};

fn main() {
App::new()
.add_plugins((
DefaultPlugins,
LogDiagnosticsPlugin::default(),
FrameTimeDiagnosticsPlugin,
))
.insert_resource(AmbientLight {
brightness: 0.4,
..default()
})
.add_systems(Startup, setup)
.run();
}

fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn(DirectionalLightBundle {
directional_light: DirectionalLight {
shadows_enabled: true,
..default()
},
transform: Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_3)),
..default()
});
commands.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(6.849407, -6.858866, -80.42553))
.with_rotation(Quat::from_xyzw(
0.006013192,
0.9359487,
-0.3517212,
0.016001422,
)),
..default()
});

let mesh = meshes.add(shape::Cube::default().into());
let material = materials.add(StandardMaterial::default());
for i in 0..100 {
let transform = Transform::IDENTITY
.with_scale(Vec3::new(100.0, 0.15, 100.0))
.with_translation(Vec3::new(0.0, i as f32, 0.0));
commands.spawn(PbrBundle {
material: material.clone(),
mesh: mesh.clone(),
transform,
..default()
});
}
}
```

## Additional information
- screenshots
This is an image of what it looks like from the side, as the reproducible example isn't really visually useful.
![image](https://github.com/bevyengine/bevy/assets/52673876/17baf746-e2d3-4776-a464-d679a2db37c6)
- theories about what might be going wrong
The techniques for sorting the rendering order so that fragment shaders are run for the objects that are closer to the camera are not used/misused for directional light shadowing.
- workarounds that you used
`Msaa::off`, changing the shadow filtering to hardware 2x2
- links to related bugs, PRs or discussions
https://discord.com/channels/691052431525675048/1178024759779401728

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Bevy 0.12 reproduction with 100 stacked cuboids, directional-light shadows, and the reported camera position. Compare performance with MSAA disabled and hardware 2x2 shadow filtering, then inspect the shadow-rendering path to determine what causes the frame-rate drop. Done means the reproduction no longer exhibits the reported low FPS without relying on those workarounds.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.