Skip to content

Commit 2ab9126

Browse files
authored
Fix bloom luma calc in sRGB (#22565)
# Objective - Luminance is a physical value that should be calculated in linear, not logarithmic (perceptual) space. ## Solution - Don't convert from linear to srgb to do a luma calc.
1 parent d6ad9e9 commit 2ab9126

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

crates/bevy_post_process/src/bloom/bloom.wgsl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ fn tonemapping_luminance(v: vec3<f32>) -> f32 {
3737
return dot(v, vec3<f32>(0.2126, 0.7152, 0.0722));
3838
}
3939

40-
fn rgb_to_srgb_simple(color: vec3<f32>) -> vec3<f32> {
41-
return pow(color, vec3<f32>(1.0 / 2.2));
42-
}
43-
4440
// http://graphicrants.blogspot.com/2013/12/tone-mapping.html
4541
fn karis_average(color: vec3<f32>) -> f32 {
46-
// Luminance calculated by gamma-correcting linear RGB to non-linear sRGB using pow(color, 1.0 / 2.2)
47-
// and then calculating luminance based on Rec. 709 color primaries.
48-
let luma = tonemapping_luminance(rgb_to_srgb_simple(color)) / 4.0;
42+
// Luminance calculated based on Rec. 709 color primaries.
43+
// This must be done in *linear* color space.
44+
let luma = tonemapping_luminance(color) / 4.0;
4945
return 1.0 / (1.0 + luma);
5046
}
5147

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "Bloom luma calculation now in linear space"
3+
pull_requests: [22561]
4+
---
5+
6+
The luma calculation for bloom's Karis average (used for downsampling) has been corrected to use linear color space instead of non-linear sRGB space.
7+
8+
As a result, the intensity of the bloom effect may appear reduced, especially for colors with high saturation or those that were significantly affected by the previous non-linear calculation.
9+
10+
If your scene's bloom now appears too dim, you can:
11+
12+
- Increase the `intensity` field on the `Bloom` component.
13+
- Increase the `emissive` strength of your materials.
14+
- Adjust the `prefilter` settings in the `Bloom` component.

0 commit comments

Comments
 (0)