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

[Merged by Bors] - Revamp Bloom #6677

Closed
wants to merge 136 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
425c7ae
Fix bloom transparency
JMS55 Nov 15, 2022
1dd39be
Default to ACES tonemapping
JMS55 Nov 17, 2022
7704e12
WIP: Fix bloom
JMS55 Nov 18, 2022
bb465b5
Revamp bloom
JMS55 Nov 18, 2022
82e0f2f
Appease clippy
JMS55 Nov 18, 2022
fa4fccb
Doc fixes
JMS55 Nov 18, 2022
d7a1ae7
Improve bloom docs
JMS55 Nov 18, 2022
9a94a40
Bloom add karis average
JMS55 Nov 18, 2022
bb06589
Reword bloom docs
JMS55 Nov 18, 2022
892fb5e
Add soft threshold
JMS55 Nov 18, 2022
eb27945
Fix shader error
JMS55 Nov 18, 2022
2e3f428
Misc changes
JMS55 Nov 18, 2022
dabf32a
Cleanup
JMS55 Nov 20, 2022
5fd4116
Clamp bloom threshold
JMS55 Nov 20, 2022
38df5ad
Clamp in shader
JMS55 Nov 20, 2022
7de822b
Misc rename
JMS55 Nov 20, 2022
cff860e
Rename threshold setting
JMS55 Nov 20, 2022
e58aeac
Rename uniform struct in shader
JMS55 Nov 20, 2022
af760a7
Slightly lower filter radius
JMS55 Nov 20, 2022
1719571
Small doc change
JMS55 Nov 20, 2022
d6b642a
Change example colors to more saturated ones
StarLederer Nov 22, 2022
3f4ecb8
Make example colors brighter
StarLederer Nov 22, 2022
4398515
Switch to energy conserving blending
StarLederer Nov 22, 2022
d172215
Revert default intensity to 0.3
StarLederer Nov 22, 2022
5fbdc01
Fix possible crash
StarLederer Nov 22, 2022
4b63ea3
Fix outdated comment
StarLederer Nov 22, 2022
aea919a
Fix unnecessary conversions
StarLederer Nov 29, 2022
0e481ff
Remove the use of view_target.post_process_write()
StarLederer Dec 2, 2022
47f2e3d
Clean redundant parts of "upsample final" up
StarLederer Dec 2, 2022
d4f491c
Add comments for future generations
StarLederer Dec 2, 2022
e64900e
Use WGPU native blending constants to control bloom intensity (instea…
StarLederer Dec 2, 2022
193932f
Add a comment about blend factors
StarLederer Dec 2, 2022
8972fd3
Remove unused uniform value
StarLederer Dec 2, 2022
ec53b37
Clean an unnecessary bind group up
StarLederer Dec 2, 2022
4daff1b
Remove rouge line
StarLederer Dec 2, 2022
5fb4806
Mark unideal code with TODOs
StarLederer Dec 2, 2022
2ab6225
Move BloomSettings to its own module
StarLederer Dec 2, 2022
bf8e301
Implement parametric bloom blending curve
StarLederer Dec 14, 2022
a574388
Convert builder functions to constants
StarLederer Dec 16, 2022
85af8f9
Implement additive bloom mode
StarLederer Dec 16, 2022
1dc0d41
Clean up bloom blending
StarLederer Dec 16, 2022
774f008
Add a sugestion for future improvement
StarLederer Dec 16, 2022
2f35c92
Revamp bloom blend function
StarLederer Dec 22, 2022
896ee46
Change order to BloomSettings -> PrefilterSettings -> BloomMode
StarLederer Dec 22, 2022
9f1c6cc
Rename BloomMode to BloomCompositeMode
StarLederer Dec 22, 2022
79bc5b9
Fix outdated names
StarLederer Dec 22, 2022
ec3c569
Rename OLDSCHOOL to OLD_SCHOOL
StarLederer Dec 22, 2022
9bef787
Change decate format in comment
StarLederer Dec 22, 2022
f849c4e
Update doc comment
StarLederer Dec 22, 2022
9298bc6
Rename PrefilterSettings to BloomPrefilterSettings
StarLederer Dec 22, 2022
3452b32
Register new Reflect types with the app
StarLederer Dec 22, 2022
c74f301
Remove unused use
StarLederer Dec 22, 2022
3d0a912
Add a doc comment to compute_blend_factor and move it higher
StarLederer Dec 28, 2022
9d5c544
Add a link to desmos
StarLederer Dec 28, 2022
dc257d4
Fix an outdated comment
StarLederer Dec 28, 2022
df53631
Update example comments
StarLederer Dec 28, 2022
ad1f11c
Fix bad/outdated comments
StarLederer Dec 28, 2022
3f51432
Implement SDR bloom
StarLederer Dec 28, 2022
8971a88
Remove unused uniforms from upsampling stage
StarLederer Jan 2, 2023
8a0d1d1
Specialize downsampling pipeline
StarLederer Jan 2, 2023
dac7680
Remove outdated line
StarLederer Jan 2, 2023
82a553d
Update example
StarLederer Jan 2, 2023
4ff46bf
Fix incorrect operator
StarLederer Jan 2, 2023
0214e39
Speed up threshold controls
StarLederer Jan 2, 2023
1cbe98a
Add descriptions to bloom parameters
StarLederer Jan 2, 2023
ebe2cff
Improve bloom calculation in additive mode
StarLederer Jan 2, 2023
3e8d9fa
Link to my parametric curve visualizer
StarLederer Jan 2, 2023
c0a7f2f
Partly implement the fix from #6802
StarLederer Jan 3, 2023
cc57711
Merge remote-tracking branch 'upstream/main' into bloom-transparent-f…
StarLederer Jan 3, 2023
9377e14
Remove error print
StarLederer Jan 3, 2023
12e4b10
Slighly limit bloom texture count
StarLederer Jan 3, 2023
75f59f8
Implement fix from #6802
StarLederer Jan 3, 2023
a495344
Fix transparency
StarLederer Jan 3, 2023
38d7c45
Merge pull request #4 from StarLederer/bloom-transparent-fix
StarLederer Jan 3, 2023
4a2587b
Update examples/3d/bloom.rs
StarLederer Jan 5, 2023
c515fc5
Update crates/bevy_core_pipeline/src/bloom/mod.rs
StarLederer Jan 5, 2023
c7faf67
Update crates/bevy_core_pipeline/src/bloom/mod.rs
StarLederer Jan 5, 2023
f87bf01
Update crates/bevy_core_pipeline/src/bloom/mod.rs
StarLederer Jan 5, 2023
895d626
Update crates/bevy_core_pipeline/src/bloom/mod.rs
StarLederer Jan 9, 2023
b2dba3a
Update crates/bevy_core_pipeline/src/bloom/mod.rs
StarLederer Jan 9, 2023
1536709
Update crates/bevy_core_pipeline/src/bloom/settings.rs
StarLederer Jan 9, 2023
8ae71e6
Update crates/bevy_core_pipeline/src/bloom/settings.rs
StarLederer Jan 9, 2023
7a321f3
Update crates/bevy_core_pipeline/src/bloom/upsampling_pipeline.rs
StarLederer Jan 9, 2023
677b758
BloomSettings doc tweaks
JMS55 Jan 9, 2023
d4b61ac
Note WebGL2 incompabillity
JMS55 Jan 9, 2023
f315d78
Update crates/bevy_core_pipeline/src/bloom/mod.rs
StarLederer Jan 9, 2023
aa2a597
Add 2d bloom example
JMS55 Jan 10, 2023
a297ce9
Merge commit '0af8e1c2117fa5b36e084848edf0a173207d6f4e' into bloom-tr…
JMS55 Jan 13, 2023
c2955b3
Update crates/bevy_core_pipeline/src/bloom/mod.rs
JMS55 Jan 13, 2023
09ae245
Cleanup bloom
JMS55 Jan 30, 2023
a96ad6e
Merge commit 'a61bf35c9769eb35d993ec34e927015fe78f085d' into bloom-tr…
JMS55 Jan 30, 2023
870435c
Fix comment
JMS55 Feb 2, 2023
a187c4b
Misc fix
JMS55 Feb 2, 2023
95ad4d7
Add bloom_2d example controls
JMS55 Feb 2, 2023
c041374
Merge commit 'e03982583da83e6559c6a8fee75be59b95c607af' into bloom-tr…
JMS55 Feb 2, 2023
6dd011b
Fix pipeline cache mut
JMS55 Feb 2, 2023
e1485f1
Update crates/bevy_core_pipeline/src/bloom/settings.rs
StarLederer Feb 3, 2023
48fedbf
Rename BloomDownsamplingUniform to BloomDownsamplingUniforms
StarLederer Feb 3, 2023
1c11c9d
Update crates/bevy_core_pipeline/src/bloom/bloom.wgsl
StarLederer Feb 3, 2023
c296a45
Update crates/bevy_core_pipeline/src/bloom/settings.rs
StarLederer Feb 3, 2023
860effc
Update crates/bevy_core_pipeline/src/bloom/settings.rs
StarLederer Feb 3, 2023
f99a027
Fix comment
StarLederer Feb 3, 2023
6d4ee2b
Fix comment
StarLederer Feb 3, 2023
e8fb506
Fix comment
StarLederer Feb 3, 2023
3339655
Finish renaming BloomDownsamplingUniforms
StarLederer Feb 3, 2023
fe5aa43
Simplify id names
StarLederer Feb 3, 2023
70b398e
Stageless rebase: Merge commit 'ea2ecd4f75da476849e9cdcd9f77c8696d009…
JMS55 Feb 7, 2023
62c885c
Change default bloom intensity
JMS55 Feb 9, 2023
7b7db8a
Fix docs
JMS55 Feb 9, 2023
ddfe45e
More doc fixes
JMS55 Feb 9, 2023
6cb8b0c
Fix clippy ignore
JMS55 Feb 9, 2023
adedc79
Try fixing docs again
JMS55 Feb 9, 2023
8981638
Doc attribute fixes... again...
JMS55 Feb 9, 2023
13d131c
Actual attribute fixes, finally
JMS55 Feb 9, 2023
93d9042
Address some PR feedback
JMS55 Feb 9, 2023
86372b1
Only create one sampler
JMS55 Feb 9, 2023
80b7ce2
Misc refactor
JMS55 Feb 9, 2023
b7e0951
Add bloom present descriptions.
JMS55 Feb 9, 2023
9b1cdad
Misc doc fix
JMS55 Feb 9, 2023
98060e8
Update crates/bevy_core_pipeline/src/bloom/bloom.wgsl
JMS55 Feb 12, 2023
24af9c6
Update crates/bevy_core_pipeline/src/bloom/bloom.wgsl
JMS55 Feb 12, 2023
26a503b
Apply PR feedback
JMS55 Feb 13, 2023
63630e8
Update crates/bevy_core_pipeline/src/bloom/bloom.wgsl
JMS55 Feb 14, 2023
c624b06
Remove ACES tonemapping
JMS55 Feb 16, 2023
61391d4
Merge commit 'b24ed8bb0cf5567fd2467751d673754d102b47e4' into bloom-tr…
JMS55 Feb 17, 2023
129f334
Update crates/bevy_core_pipeline/src/bloom/settings.rs
JMS55 Feb 18, 2023
7a02aae
Merge commit 'e2c77fee039f72e1230c5d2083a26d5f4e0f13df' into bloom-tr…
JMS55 Feb 20, 2023
e047f41
Rebase
JMS55 Feb 20, 2023
0e2d92f
Fixes
JMS55 Feb 20, 2023
f480488
Simplify shader
JMS55 Feb 20, 2023
c7d722a
Update examples/2d/bloom_2d.rs
JMS55 Feb 22, 2023
c28ad59
Update examples/3d/bloom_3d.rs
JMS55 Feb 22, 2023
5c40029
Add bloom render debug group
JMS55 Feb 27, 2023
bcc6994
Reduce bloom artifacts
robtfm Mar 3, 2023
6cb4c99
Merge commit '73c1ab1d42965e84a1748af24de61eb768d98848' into bloom-tr…
JMS55 Mar 3, 2023
e72f201
Update crates/bevy_core_pipeline/src/bloom/mod.rs
JMS55 Mar 3, 2023
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ default = [
"x11",
"filesystem_watcher",
"android_shared_stdcxx",
"tonemapping_luts"
"tonemapping_luts",
]

# Force dynamic linking, which improves iterative compile times
Expand Down Expand Up @@ -166,6 +166,7 @@ hidden = true
[[example]]
name = "bloom_2d"
path = "examples/2d/bloom_2d.rs"
required-features = ["tonemapping_luts"]

[package.metadata.example.bloom_2d]
name = "2D Bloom"
Expand Down Expand Up @@ -387,6 +388,7 @@ wasm = true
[[example]]
name = "bloom_3d"
path = "examples/3d/bloom_3d.rs"
required-features = ["tonemapping_luts"]

[package.metadata.example.bloom_3d]
name = "3D Bloom"
Expand Down
44 changes: 23 additions & 21 deletions crates/bevy_core_pipeline/src/bloom/bloom.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// * [PBB] - Physically Based Bloom - https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom

#import bevy_core_pipeline::fullscreen_vertex_shader
#import bevy_core_pipeline::tonemapping

struct BloomDownsamplingUniforms {
threshold_precomputations: vec4<f32>,
Expand Down Expand Up @@ -35,6 +34,16 @@ fn soft_threshold(color: vec3<f32>) -> vec3<f32> {
}
#endif

// luminance coefficients from Rec. 709.
// https://en.wikipedia.org/wiki/Rec._709
fn tonemapping_luminance(v: vec3<f32>) -> f32 {
return dot(v, vec3<f32>(0.2126, 0.7152, 0.0722));
}

fn rgb_to_srgb_simple(color: vec3<f32>) -> vec3<f32> {
return pow(color, vec3<f32>(1.0 / 2.2));
}

// http://graphicrants.blogspot.com/2013/12/tone-mapping.html
fn karis_average(color: vec3<f32>) -> f32 {
// Luminance calculated by gamma-correcting linear RGB to non-linear sRGB using pow(color, 1.0 / 2.2)
Expand All @@ -45,26 +54,19 @@ fn karis_average(color: vec3<f32>) -> f32 {

// [COD] slide 153
fn sample_input_13_tap(uv: vec2<f32>) -> vec3<f32> {
let texel_size = 1.0 / vec2<f32>(textureDimensions(input_texture));
let x = texel_size.x;
let y = texel_size.y;

let a = textureSample(input_texture, s, vec2<f32>(uv.x - 2.0 * x, uv.y + 2.0 * y)).rgb;
let b = textureSample(input_texture, s, vec2<f32>(uv.x, uv.y + 2.0 * y)).rgb;
let c = textureSample(input_texture, s, vec2<f32>(uv.x + 2.0 * x, uv.y + 2.0 * y)).rgb;

let d = textureSample(input_texture, s, vec2<f32>(uv.x - 2.0 * x, uv.y)).rgb;
let e = textureSample(input_texture, s, vec2<f32>(uv.x, uv.y)).rgb;
let f = textureSample(input_texture, s, vec2<f32>(uv.x + 2.0 * x, uv.y)).rgb;

let g = textureSample(input_texture, s, vec2<f32>(uv.x - 2.0 * x, uv.y - 2.0 * y)).rgb;
let h = textureSample(input_texture, s, vec2<f32>(uv.x, uv.y - 2.0 * y)).rgb;
let i = textureSample(input_texture, s, vec2<f32>(uv.x + 2.0 * x, uv.y - 2.0 * y)).rgb;

let j = textureSample(input_texture, s, vec2<f32>(uv.x - x, uv.y + y)).rgb;
let k = textureSample(input_texture, s, vec2<f32>(uv.x + x, uv.y + y)).rgb;
let l = textureSample(input_texture, s, vec2<f32>(uv.x - x, uv.y - y)).rgb;
let m = textureSample(input_texture, s, vec2<f32>(uv.x + x, uv.y - y)).rgb;
let a = textureSample(input_texture, s, uv, vec2<i32>(-2, 2)).rgb;
let b = textureSample(input_texture, s, uv, vec2<i32>(0, 2)).rgb;
let c = textureSample(input_texture, s, uv, vec2<i32>(2, 2)).rgb;
let d = textureSample(input_texture, s, uv, vec2<i32>(-2, 0)).rgb;
let e = textureSample(input_texture, s, uv).rgb;
let f = textureSample(input_texture, s, uv, vec2<i32>(2, 0)).rgb;
let g = textureSample(input_texture, s, uv, vec2<i32>(-2, -2)).rgb;
let h = textureSample(input_texture, s, uv, vec2<i32>(0, -2)).rgb;
let i = textureSample(input_texture, s, uv, vec2<i32>(2, -2)).rgb;
let j = textureSample(input_texture, s, uv, vec2<i32>(-1, 1)).rgb;
let k = textureSample(input_texture, s, uv, vec2<i32>(1, 1)).rgb;
let l = textureSample(input_texture, s, uv, vec2<i32>(-1, -1)).rgb;
let m = textureSample(input_texture, s, uv, vec2<i32>(1, -1)).rgb;

#ifdef FIRST_DOWNSAMPLE
// [COD] slide 168
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_core_pipeline/src/bloom/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
/// for 3d meshes or [`bevy_render::color::Color::Hsla`]`::lightness` for 2d sprites.
///
/// Bloom is best used alongside a tonemapping function that desaturates bright colors,
/// such as TODO - fix in tonemapping PR.
/// such as [`crate::tonemapping::Tonemapping::TonyMcMapface`].
///
/// Bevy's implementation uses a parametric curve to blend between a set of
/// blurred (lower frequency) images generated from the camera's view.
Expand All @@ -28,7 +28,7 @@ use bevy_render::{extract_component::ExtractComponent, prelude::Camera};
#[allow(clippy::doc_markdown)]
#[derive(Component, Reflect, Clone)]
pub struct BloomSettings {
/// Controls the baseline of how much the image is scattered (default: 0.3).
/// Controls the baseline of how much the image is scattered (default: 0.15).
///
/// # In energy-conserving mode
/// The value represents how likely the light is to scatter.
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_core_pipeline/src/tonemapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ impl Tonemapping {
*self != Tonemapping::None
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct TonemappingPipelineKey {
deband_dither: DebandDither,
Expand Down
18 changes: 11 additions & 7 deletions examples/2d/bloom_2d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Illustrates bloom post-processing in 2d.

use bevy::{
core_pipeline::bloom::{BloomCompositeMode, BloomSettings},
core_pipeline::{
bloom::{BloomCompositeMode, BloomSettings},
tonemapping::Tonemapping,
},
prelude::*,
sprite::MaterialMesh2dBundle,
};
Expand All @@ -27,16 +30,17 @@ fn setup(
hdr: true, // 1. HDR is required for bloom
..default()
},
tonemapping: Tonemapping::TonyMcMapface, // 2. Using a tonemapper that saturates to white is recommended
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
..default()
},
BloomSettings::default(), // 2. Enable bloom for the camera
BloomSettings::default(), // 3. Enable bloom for the camera
));

// Sprite
commands.spawn(SpriteBundle {
texture: asset_server.load("branding/icon.png"),
sprite: Sprite {
color: Color::hsl(0.0, 0.0, 2.5), // 3. Put something bright in a dark environment to see the effect
color: Color::rgb(5.0, 5.0, 5.0), // 4. Put something bright in a dark environment to see the effect
custom_size: Some(Vec2::splat(160.0)),
..default()
},
Expand All @@ -46,8 +50,8 @@ fn setup(
// Circle mesh
commands.spawn(MaterialMesh2dBundle {
mesh: meshes.add(shape::Circle::new(100.).into()).into(),
// 3. Put something bright in a dark environment to see the effect
material: materials.add(ColorMaterial::from(Color::rgb(1.5, 0.0, 1.5))),
// 4. Put something bright in a dark environment to see the effect
material: materials.add(ColorMaterial::from(Color::rgb(7.5, 0.0, 7.5))),
transform: Transform::from_translation(Vec3::new(-200., 0., 0.)),
..default()
});
Expand All @@ -57,8 +61,8 @@ fn setup(
mesh: meshes
.add(shape::RegularPolygon::new(100., 6).into())
.into(),
// 3. Put something bright in a dark environment to see the effect
material: materials.add(ColorMaterial::from(Color::rgb(1.25, 1.88, 1.82))),
// 4. Put something bright in a dark environment to see the effect
material: materials.add(ColorMaterial::from(Color::rgb(6.25, 9.4, 9.1))),
transform: Transform::from_translation(Vec3::new(200., 0., 0.)),
..default()
});
Expand Down
14 changes: 9 additions & 5 deletions examples/3d/bloom_3d.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Illustrates bloom post-processing using HDR and emissive materials.

use bevy::{
core_pipeline::bloom::{BloomCompositeMode, BloomSettings},
core_pipeline::{
bloom::{BloomCompositeMode, BloomSettings},
tonemapping::Tonemapping,
},
prelude::*,
};
use std::{
Expand Down Expand Up @@ -31,22 +34,23 @@ fn setup_scene(
hdr: true, // 1. HDR is required for bloom
..default()
},
tonemapping: Tonemapping::TonyMcMapface, // 2. Using a tonemapper that saturates to white is recommended
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
BloomSettings::default(), // 2. Enable bloom for the camera
BloomSettings::default(), // 3. Enable bloom for the camera
));

let material_emissive1 = materials.add(StandardMaterial {
emissive: Color::rgb_linear(500.0, 50.0, 5.0), // 3. Put something bright in a dark environment to see the effect
emissive: Color::rgb_linear(5000.0, 500.0, 50.0), // 4. Put something bright in a dark environment to see the effect
..default()
});
let material_emissive2 = materials.add(StandardMaterial {
emissive: Color::rgb_linear(5.0, 500.0, 50.0),
emissive: Color::rgb_linear(50.0, 5000.0, 500.0),
..default()
});
let material_emissive3 = materials.add(StandardMaterial {
emissive: Color::rgb_linear(50.0, 5.0, 500.0),
emissive: Color::rgb_linear(500.0, 50.0, 5000.0),
..default()
});
let material_non_emissive = materials.add(StandardMaterial {
Expand Down