Skip to content

Commit 750afbe

Browse files
committed
Add MSAA toggling to example
1 parent 9a9dd69 commit 750afbe

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

examples/shader/shader_prepass.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
..default()
2828
})
2929
.add_systems(Startup, setup)
30-
.add_systems(Update, (rotate, toggle_prepass_view))
30+
.add_systems(Update, (rotate, toggle_prepass_view, toggle_multisampling))
3131
// Disabling MSAA for maximum compatibility. Shader prepass with MSAA needs GPU capability MULTISAMPLED_SHADING
3232
.insert_resource(Msaa::Off)
3333
.run();
@@ -140,10 +140,12 @@ fn setup(
140140
commands.spawn(
141141
TextBundle::from_sections(vec![
142142
TextSection::new("Prepass Output: transparent\n", style.clone()),
143+
TextSection::new("MSAA: Off\n", style.clone()),
143144
TextSection::new("\n\n", style.clone()),
144145
TextSection::new("Controls\n", style.clone()),
145146
TextSection::new("---------------\n", style.clone()),
146-
TextSection::new("Space - Change output\n", style),
147+
TextSection::new("Space - Change output\n", style.clone()),
148+
TextSection::new("M - Change MSAA\n", style),
147149
])
148150
.with_style(Style {
149151
position_type: PositionType::Absolute,
@@ -240,17 +242,9 @@ fn toggle_prepass_view(
240242
3 => "motion vectors",
241243
_ => unreachable!(),
242244
};
243-
let text_color = if *prepass_view == 3 {
244-
Color::BLACK
245-
} else {
246-
Color::WHITE
247-
};
248245

249246
let mut text = text.single_mut();
250247
text.sections[0].value = format!("Prepass Output: {label}\n");
251-
for section in &mut text.sections {
252-
section.style.color = text_color;
253-
}
254248

255249
let handle = material_handle.single();
256250
let mat = materials.get_mut(handle).unwrap();
@@ -259,3 +253,20 @@ fn toggle_prepass_view(
259253
mat.settings.show_motion_vectors = (*prepass_view == 3) as u32;
260254
}
261255
}
256+
257+
fn toggle_multisampling(
258+
keycode: Res<Input<KeyCode>>,
259+
mut text: Query<&mut Text>,
260+
mut msaa: ResMut<Msaa>,
261+
) {
262+
if keycode.just_pressed(KeyCode::M) {
263+
*msaa = match *msaa {
264+
Msaa::Off => Msaa::Sample2,
265+
Msaa::Sample2 => Msaa::Sample4,
266+
Msaa::Sample4 => Msaa::Sample8,
267+
Msaa::Sample8 => Msaa::Off,
268+
};
269+
let mut text = text.single_mut();
270+
text.sections[1].value = format!("MSAA: {:?}\n", *msaa);
271+
}
272+
}

0 commit comments

Comments
 (0)