Skip to content

Commit f767e19

Browse files
atlv24alice-i-cecilejanhohenheim
authored
allow toggling projection in antialias example (#20950)
# Objective - test ortho in aa ## Solution - add option ## Testing - run it --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Jan Hohenheim <[email protected]>
1 parent ee29a43 commit f767e19

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

examples/3d/anti_aliasing.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ fn main() {
3636

3737
app.add_plugins(DefaultPlugins)
3838
.add_systems(Startup, setup)
39-
.add_systems(Update, (modify_aa, modify_sharpening, update_ui));
39+
.add_systems(
40+
Update,
41+
(modify_aa, modify_sharpening, modify_projection, update_ui),
42+
);
4043

4144
app.run();
4245
}
@@ -257,9 +260,28 @@ fn modify_sharpening(
257260
}
258261
}
259262

263+
fn modify_projection(keys: Res<ButtonInput<KeyCode>>, mut query: Query<&mut Projection>) {
264+
for mut projection in &mut query {
265+
if keys.just_pressed(KeyCode::KeyO) {
266+
match *projection {
267+
Projection::Perspective(_) => {
268+
*projection = Projection::Orthographic(OrthographicProjection {
269+
scale: 0.002,
270+
..OrthographicProjection::default_3d()
271+
});
272+
}
273+
_ => {
274+
*projection = Projection::Perspective(PerspectiveProjection::default());
275+
}
276+
}
277+
}
278+
}
279+
}
280+
260281
fn update_ui(
261282
#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))] camera: Single<
262283
(
284+
&Projection,
263285
Option<&Fxaa>,
264286
Option<&Smaa>,
265287
Option<&TemporalAntiAliasing>,
@@ -271,6 +293,7 @@ fn update_ui(
271293
>,
272294
#[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))] camera: Single<
273295
(
296+
&Projection,
274297
Option<&Fxaa>,
275298
Option<&Smaa>,
276299
Option<&TemporalAntiAliasing>,
@@ -285,9 +308,9 @@ fn update_ui(
285308
>,
286309
) {
287310
#[cfg(all(feature = "dlss", not(feature = "force_disable_dlss")))]
288-
let (fxaa, smaa, taa, cas, msaa, dlss) = *camera;
311+
let (projection, fxaa, smaa, taa, cas, msaa, dlss) = *camera;
289312
#[cfg(any(not(feature = "dlss"), feature = "force_disable_dlss"))]
290-
let (fxaa, smaa, taa, cas, msaa) = *camera;
313+
let (projection, fxaa, smaa, taa, cas, msaa) = *camera;
291314

292315
let ui = &mut ui.0;
293316
*ui = "Antialias Method\n".to_string();
@@ -375,6 +398,14 @@ fn update_ui(
375398
ui.push_str(&format!("(-/+) Strength: {:.1}\n", cas.sharpening_strength));
376399
draw_selectable_menu_item(ui, "Denoising", 'D', cas.denoise);
377400
}
401+
402+
ui.push_str("\n----------\n\n");
403+
draw_selectable_menu_item(
404+
ui,
405+
"Orthographic",
406+
'O',
407+
matches!(projection, Projection::Orthographic(_)),
408+
);
378409
}
379410

380411
/// Set up a simple 3D scene

0 commit comments

Comments
 (0)