This commit is contained in:
Matthew Deville 2025-08-31 11:46:51 +02:00
parent abff3f5434
commit 68763ea15c

View file

@ -17,6 +17,7 @@ fn main() {
Material2dPlugin::<CustomMaterial>::default(),
))
.add_systems(Startup, setup)
.add_systems(Update, resize_fullscreen_quad)
.run();
}
@ -40,9 +41,26 @@ fn setup(
Mesh2d(meshes.add(Rectangle::default())),
MeshMaterial2d(materials.add(CustomMaterial {})),
Transform::from_scale(Vec3::new(size.x, size.y, 1.0)),
FullscreenQuad,
));
}
/// Marker component for the fullscreen quad so we can update it on window resize
#[derive(Component)]
struct FullscreenQuad;
/// Update fullscreen quad transforms when the primary window is resized.
fn resize_fullscreen_quad(
primary_window: Single<&Window, With<PrimaryWindow>>,
mut transform: Single<&mut Transform, With<FullscreenQuad>>,
) {
let size = Vec2::new(
primary_window.resolution.width(),
primary_window.resolution.height(),
);
transform.scale = Vec3::new(size.x, size.y, 1.0);
}
// This is the struct that will be passed to your shader
#[derive(Asset, TypePath, AsBindGroup, Clone)]
struct CustomMaterial {}