From 713d91b7218b2ec77cac6f35e6eda6942f41b4c5 Mon Sep 17 00:00:00 2001
From: BD103 <59022059+BD103@users.noreply.github.com>
Date: Thu, 7 Mar 2024 10:20:38 -0500
Subject: [PATCH] Improve Bloom 3D lighting (#11981)
# 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:
After:
---------
Co-authored-by: Alice Cecile
---
crates/bevy_core_pipeline/src/bloom/settings.rs | 2 ++
examples/3d/bloom_3d.rs | 15 +++++++++------
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/crates/bevy_core_pipeline/src/bloom/settings.rs b/crates/bevy_core_pipeline/src/bloom/settings.rs
index 69c789933c..d42cc412f2 100644
--- a/crates/bevy_core_pipeline/src/bloom/settings.rs
+++ b/crates/bevy_core_pipeline/src/bloom/settings.rs
@@ -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,
diff --git a/examples/3d/bloom_3d.rs b/examples/3d/bloom_3d.rs
index 34101d35ff..b2fd467942 100644
--- a/examples/3d/bloom_3d.rs
+++ b/examples/3d/bloom_3d.rs
@@ -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 {
@@ -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;
@@ -90,7 +93,7 @@ fn setup_scene(
"",
TextStyle {
font_size: 20.0,
- color: Color::BLACK,
+ color: Color::WHITE,
..default()
},
)
@@ -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);
}
}
}