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
This commit is contained in:
parent
fe7a29e12b
commit
fc98664d3d
@ -73,16 +73,16 @@ fn setup(
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
fn update_bloom_settings(
|
||||
camera: Single<(Entity, Option<&mut Bloom>), With<Camera>>,
|
||||
camera: Single<(Entity, &Tonemapping, Option<&mut Bloom>), With<Camera>>,
|
||||
mut text: Single<&mut Text>,
|
||||
mut commands: Commands,
|
||||
keycode: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let bloom = camera.into_inner();
|
||||
let (camera_entity, tonemapping, bloom) = camera.into_inner();
|
||||
|
||||
match bloom {
|
||||
(entity, Some(mut bloom)) => {
|
||||
Some(mut bloom) => {
|
||||
text.0 = "Bloom (Toggle: Space)\n".to_string();
|
||||
text.push_str(&format!("(Q/A) Intensity: {}\n", bloom.intensity));
|
||||
text.push_str(&format!(
|
||||
@ -112,7 +112,7 @@ fn update_bloom_settings(
|
||||
text.push_str(&format!("(I/K) Horizontal Scale: {}\n", bloom.scale.x));
|
||||
|
||||
if keycode.just_pressed(KeyCode::Space) {
|
||||
commands.entity(entity).remove::<Bloom>();
|
||||
commands.entity(camera_entity).remove::<Bloom>();
|
||||
}
|
||||
|
||||
let dt = time.delta_secs();
|
||||
@ -182,12 +182,33 @@ fn update_bloom_settings(
|
||||
bloom.scale.x = bloom.scale.x.clamp(0.0, 16.0);
|
||||
}
|
||||
|
||||
(entity, None) => {
|
||||
text.0 = "Bloom: Off (Toggle: Space)".to_string();
|
||||
None => {
|
||||
text.0 = "Bloom: Off (Toggle: Space)\n".to_string();
|
||||
|
||||
if keycode.just_pressed(KeyCode::Space) {
|
||||
commands.entity(entity).insert(Bloom::default());
|
||||
commands.entity(camera_entity).insert(Bloom::default());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text.push_str(&format!("(O) Tonemapping: {:?}\n", tonemapping));
|
||||
if keycode.just_pressed(KeyCode::KeyO) {
|
||||
commands
|
||||
.entity(camera_entity)
|
||||
.insert(next_tonemap(tonemapping));
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the next Tonemapping algorithm
|
||||
fn next_tonemap(tonemapping: &Tonemapping) -> Tonemapping {
|
||||
match tonemapping {
|
||||
Tonemapping::None => Tonemapping::AcesFitted,
|
||||
Tonemapping::AcesFitted => Tonemapping::AgX,
|
||||
Tonemapping::AgX => Tonemapping::BlenderFilmic,
|
||||
Tonemapping::BlenderFilmic => Tonemapping::Reinhard,
|
||||
Tonemapping::Reinhard => Tonemapping::ReinhardLuminance,
|
||||
Tonemapping::ReinhardLuminance => Tonemapping::SomewhatBoringDisplayTransform,
|
||||
Tonemapping::SomewhatBoringDisplayTransform => Tonemapping::TonyMcMapface,
|
||||
Tonemapping::TonyMcMapface => Tonemapping::None,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user