Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tonemapping switch to bloom 2d example #17789

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions examples/2d/bloom_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
}
}