-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
Labels
A-RenderingDrawing game state to the screenDrawing game state to the screenC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesS-Needs-InvestigationThis issue requires detective work to figure out what's going wrongThis issue requires detective work to figure out what's going wrong
Description
When increasing the number of RenderLayers and spawning one Camera3d per layer,
performance drops significantly, even in minimal scenes.
In the following test(based on examples/3d/3d_scene), where only one camera sees the spwaned cube (RenderLayers 0) , I measure:
Layers | Cameras | FPS
1 | 1 | ~900
2 | 2 | ~720
5 | 5 | ~425
10 | 10 | ~270
test:
//! A simple 3D scene with light shining over a cube sitting on a plane.
use bevy::{
prelude::*,
render::view::RenderLayers,
window::PresentMode,
};
#[derive(Resource)]
pub struct FpsTimer(pub Timer);
const ADDITIONAL_LAYERS:usize = 1;
fn main() {
App::new()
.add_plugins(DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
#[cfg(not(target_os = "android"))]
present_mode: PresentMode::Immediate,
#[cfg(target_os = "android")]
present_mode: PresentMode::Fifo,
..Default::default()
}),
..Default::default()
})
)
.add_systems(Startup, setup)
.add_systems(Update,
fps_counter,
)
.run();
}
/// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
Transform::from_xyz(0.0, 0.5, 0.0),
RenderLayers::layer(0),
));
// light
commands.spawn((
PointLight {
//shadows_enabled: true,
..default()
},
Transform::from_xyz(4.0, 8.0, 4.0),
));
// camera
commands.spawn((
Camera {
order: 0,
..default()
},
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
RenderLayers::layer(0),
));
for i in 0..ADDITIONAL_LAYERS {
commands.spawn((
Camera {
order: (i+1) as _,
..default()
},
Camera3d::default(),
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
RenderLayers::layer((i+1) as _),
));
}
commands.insert_resource(FpsTimer(Timer::from_seconds(1.0, TimerMode::Repeating)));
}
pub fn fps_counter(time: Res<Time>, mut timer: ResMut<FpsTimer>) {
timer.0.tick(time.delta());
if timer.0.finished() {
println!("FPS: {}", 1.0 / time.delta_secs());
}
}
janhohenheim
Metadata
Metadata
Assignees
Labels
A-RenderingDrawing game state to the screenDrawing game state to the screenC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesS-Needs-InvestigationThis issue requires detective work to figure out what's going wrongThis issue requires detective work to figure out what's going wrong