Skip to content

Commit fc98664

Browse files
authored
Add tonemapping switch to bloom 2d example (#17789)
# Objective Allow switching through available Tonemapping algorithms on `bloom_2d` example to compare between them ## Solution Add a resource to `bloom_2d` that holds current tonemapping algorithm, a method to get the next one, and a check of key press to make the switch ## Testing Ran `bloom_2d` example with modified code ## Showcase https://github.com/user-attachments/assets/920b2d6a-b237-4b19-be9d-9b651b4dc913 Note: Sprite flashing is already described in #17763
1 parent fe7a29e commit fc98664

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

examples/2d/bloom_2d.rs

+28-7
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ fn setup(
7373
// ------------------------------------------------------------------------------------------------
7474

7575
fn update_bloom_settings(
76-
camera: Single<(Entity, Option<&mut Bloom>), With<Camera>>,
76+
camera: Single<(Entity, &Tonemapping, Option<&mut Bloom>), With<Camera>>,
7777
mut text: Single<&mut Text>,
7878
mut commands: Commands,
7979
keycode: Res<ButtonInput<KeyCode>>,
8080
time: Res<Time>,
8181
) {
82-
let bloom = camera.into_inner();
82+
let (camera_entity, tonemapping, bloom) = camera.into_inner();
8383

8484
match bloom {
85-
(entity, Some(mut bloom)) => {
85+
Some(mut bloom) => {
8686
text.0 = "Bloom (Toggle: Space)\n".to_string();
8787
text.push_str(&format!("(Q/A) Intensity: {}\n", bloom.intensity));
8888
text.push_str(&format!(
@@ -112,7 +112,7 @@ fn update_bloom_settings(
112112
text.push_str(&format!("(I/K) Horizontal Scale: {}\n", bloom.scale.x));
113113

114114
if keycode.just_pressed(KeyCode::Space) {
115-
commands.entity(entity).remove::<Bloom>();
115+
commands.entity(camera_entity).remove::<Bloom>();
116116
}
117117

118118
let dt = time.delta_secs();
@@ -182,12 +182,33 @@ fn update_bloom_settings(
182182
bloom.scale.x = bloom.scale.x.clamp(0.0, 16.0);
183183
}
184184

185-
(entity, None) => {
186-
text.0 = "Bloom: Off (Toggle: Space)".to_string();
185+
None => {
186+
text.0 = "Bloom: Off (Toggle: Space)\n".to_string();
187187

188188
if keycode.just_pressed(KeyCode::Space) {
189-
commands.entity(entity).insert(Bloom::default());
189+
commands.entity(camera_entity).insert(Bloom::default());
190190
}
191191
}
192192
}
193+
194+
text.push_str(&format!("(O) Tonemapping: {:?}\n", tonemapping));
195+
if keycode.just_pressed(KeyCode::KeyO) {
196+
commands
197+
.entity(camera_entity)
198+
.insert(next_tonemap(tonemapping));
199+
}
200+
}
201+
202+
/// Get the next Tonemapping algorithm
203+
fn next_tonemap(tonemapping: &Tonemapping) -> Tonemapping {
204+
match tonemapping {
205+
Tonemapping::None => Tonemapping::AcesFitted,
206+
Tonemapping::AcesFitted => Tonemapping::AgX,
207+
Tonemapping::AgX => Tonemapping::BlenderFilmic,
208+
Tonemapping::BlenderFilmic => Tonemapping::Reinhard,
209+
Tonemapping::Reinhard => Tonemapping::ReinhardLuminance,
210+
Tonemapping::ReinhardLuminance => Tonemapping::SomewhatBoringDisplayTransform,
211+
Tonemapping::SomewhatBoringDisplayTransform => Tonemapping::TonyMcMapface,
212+
Tonemapping::TonyMcMapface => Tonemapping::None,
213+
}
193214
}

0 commit comments

Comments
 (0)