Skip to content

Commit

Permalink
Improve Bloom 3D lighting (bevyengine#11981)
Browse files Browse the repository at this point in the history
# Objective

- With the recent lighting changes, the default configuration in the
`bloom_3d` example is less clear what bloom actually does
- See [this
screenshot](https://github.com/bevyengine/bevy-website/pull/1023/files/4fdb1455d5a3371d69db32b036e38731342b48de#r1494648414)
for a comparison.
- `bloom_3d` additionally uses a for-loop to spawn the spheres, which
can be turned into `commands::spawn_batch` call.
- The text is black, which is difficult to see on the gray background.

## Solution

- Increase emmisive values of materials.
- Set text to white.

## Showcase

Before:

<img width="1392" alt="before"
src="https://github.com/bevyengine/bevy/assets/59022059/757057ad-ed9f-4eed-b135-8e2032fcdeb5">

After:

<img width="1392" alt="image"
src="https://github.com/bevyengine/bevy/assets/59022059/3f9dc7a8-94b2-44b9-8ac3-deef1905221b">

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
  • Loading branch information
2 people authored and spectria-limina committed Mar 9, 2024
1 parent 5f34a9b commit 6c72e7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions crates/bevy_core_pipeline/src/bloom/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub struct BloomSettings {

impl BloomSettings {
/// The default bloom preset.
///
/// This uses the [`EnergyConserving`](BloomCompositeMode::EnergyConserving) composite mode.
pub const NATURAL: Self = Self {
intensity: 0.15,
low_frequency_boost: 0.7,
Expand Down
15 changes: 9 additions & 6 deletions examples/3d/bloom_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ fn setup_scene(
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
BloomSettings::default(), // 3. Enable bloom for the camera
// 3. Enable bloom for the camera
BloomSettings::NATURAL,
));

let material_emissive1 = materials.add(StandardMaterial {
emissive: Color::linear_rgb(2300.0, 900.0, 300.0), // 4. Put something bright in a dark environment to see the effect
emissive: Color::linear_rgb(23000.0, 9000.0, 3000.0), // 4. Put something bright in a dark environment to see the effect
..default()
});
let material_emissive2 = materials.add(StandardMaterial {
emissive: Color::linear_rgb(300.0, 2300.0, 900.0),
emissive: Color::linear_rgb(3000.0, 23000.0, 9000.0),
..default()
});
let material_emissive3 = materials.add(StandardMaterial {
emissive: Color::linear_rgb(900.0, 300.0, 2300.0),
emissive: Color::linear_rgb(9000.0, 3000.0, 23000.0),
..default()
});
let material_non_emissive = materials.add(StandardMaterial {
Expand All @@ -60,6 +61,8 @@ fn setup_scene(

for x in -5..5 {
for z in -5..5 {
// This generates a pseudo-random integer between `[0, 6)`, but deterministically so
// the same spheres are always the same colors.
let mut hasher = DefaultHasher::new();
(x, z).hash(&mut hasher);
let rand = (hasher.finish() - 2) % 6;
Expand Down Expand Up @@ -90,7 +93,7 @@ fn setup_scene(
"",
TextStyle {
font_size: 20.0,
color: Color::BLACK,
color: Color::WHITE,
..default()
},
)
Expand Down Expand Up @@ -219,7 +222,7 @@ fn update_bloom_settings(
*text = "Bloom: Off (Toggle: Space)".to_string();

if keycode.just_pressed(KeyCode::Space) {
commands.entity(entity).insert(BloomSettings::default());
commands.entity(entity).insert(BloomSettings::NATURAL);
}
}
}
Expand Down

0 comments on commit 6c72e7f

Please sign in to comment.