Perf improvement

This commit is contained in:
Danny McGee
2023-09-27 23:41:50 -04:00
parent a60d86f2d2
commit 3dba0ee868
+23 -2
View File
@@ -5,6 +5,8 @@ use bevy::{
render::render_resource::{AsBindGroup, ShaderRef}, render::render_resource::{AsBindGroup, ShaderRef},
}; };
use crate::orbit_cam::{self, OrbitCam};
pub struct TestScenePlugin; pub struct TestScenePlugin;
impl Plugin for TestScenePlugin { impl Plugin for TestScenePlugin {
@@ -14,10 +16,17 @@ impl Plugin for TestScenePlugin {
prepass_enabled: true, prepass_enabled: true,
..default() ..default()
}) })
.add_systems(Startup, spawn_scene); .add_systems(Startup, spawn_scene)
.add_systems(
Update,
move_plane_with_camera.after(orbit_cam::pan_orbit_camera),
);
} }
} }
#[derive(Component)]
struct WorldGridPlane;
fn spawn_scene( fn spawn_scene(
mut cmd: Commands, mut cmd: Commands,
mut meshes: ResMut<Assets<Mesh>>, mut meshes: ResMut<Assets<Mesh>>,
@@ -53,16 +62,28 @@ fn spawn_scene(
cmd.spawn(( cmd.spawn((
MaterialMeshBundle { MaterialMeshBundle {
mesh: meshes.add(Mesh::from(shape::Plane { mesh: meshes.add(Mesh::from(shape::Plane {
size: 10_000.0, size: 200.0,
subdivisions: 0, subdivisions: 0,
})), })),
material: mat_proc_grid.add(ProceduralGridMaterial {}), material: mat_proc_grid.add(ProceduralGridMaterial {}),
..default() ..default()
}, },
NotShadowCaster, NotShadowCaster,
WorldGridPlane,
)); ));
} }
fn move_plane_with_camera(
mut plane: Query<(&WorldGridPlane, &mut Transform)>,
camera: Query<&OrbitCam>,
) {
let &OrbitCam { focus, .. } = camera.single();
let (_, mut xform) = plane.single_mut();
xform.translation.x = focus.x;
xform.translation.z = focus.z;
}
#[derive(AsBindGroup, Clone, TypePath, TypeUuid)] #[derive(AsBindGroup, Clone, TypePath, TypeUuid)]
#[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"] #[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"]
struct ProceduralGridMaterial {} struct ProceduralGridMaterial {}