@@ -27,7 +27,7 @@ fn main() {
27
27
..default ( )
28
28
} )
29
29
. add_systems ( Startup , setup)
30
- . add_systems ( Update , ( rotate, toggle_prepass_view) )
30
+ . add_systems ( Update , ( rotate, toggle_prepass_view, toggle_multisampling ) )
31
31
// Disabling MSAA for maximum compatibility. Shader prepass with MSAA needs GPU capability MULTISAMPLED_SHADING
32
32
. insert_resource ( Msaa :: Off )
33
33
. run ( ) ;
@@ -140,10 +140,12 @@ fn setup(
140
140
commands. spawn (
141
141
TextBundle :: from_sections ( vec ! [
142
142
TextSection :: new( "Prepass Output: transparent\n " , style. clone( ) ) ,
143
+ TextSection :: new( "MSAA: Off\n " , style. clone( ) ) ,
143
144
TextSection :: new( "\n \n " , style. clone( ) ) ,
144
145
TextSection :: new( "Controls\n " , style. clone( ) ) ,
145
146
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) ,
147
149
] )
148
150
. with_style ( Style {
149
151
position_type : PositionType :: Absolute ,
@@ -240,17 +242,9 @@ fn toggle_prepass_view(
240
242
3 => "motion vectors" ,
241
243
_ => unreachable ! ( ) ,
242
244
} ;
243
- let text_color = if * prepass_view == 3 {
244
- Color :: BLACK
245
- } else {
246
- Color :: WHITE
247
- } ;
248
245
249
246
let mut text = text. single_mut ( ) ;
250
247
text. sections [ 0 ] . value = format ! ( "Prepass Output: {label}\n " ) ;
251
- for section in & mut text. sections {
252
- section. style . color = text_color;
253
- }
254
248
255
249
let handle = material_handle. single ( ) ;
256
250
let mat = materials. get_mut ( handle) . unwrap ( ) ;
@@ -259,3 +253,20 @@ fn toggle_prepass_view(
259
253
mat. settings . show_motion_vectors = ( * prepass_view == 3 ) as u32 ;
260
254
}
261
255
}
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