Skip to content

Commit

Permalink
Set the default target exposure to the minimum value, not 0 (#13562)
Browse files Browse the repository at this point in the history
# Objective

- In particularly dark scenes, auto-exposure would lead to an unexpected
darkening of the view.
- Fixes #13446.

## Solution

The average luminance should default to something else than 0.0 instead,
when there are no samples. We set it to `settings.min_log_lum`.

## Testing

I was able to reproduce the problem on the `auto_exposure` example by
setting the point light intensity to 2000 and looking into the
right-hand corner. There was a sudden darkening.

Now, the discontinuity is gone.

---------

Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: Bram Buurlage <[email protected]>
  • Loading branch information
3 people authored May 29, 2024
1 parent 4e72bf4 commit 9d74e16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions crates/bevy_core_pipeline/src/auto_exposure/auto_exposure.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,25 @@ fn compute_average(@builtin(local_invocation_index) local_index: u32) {
count += bin_count;
}

var target_exposure = 0.0;
var avg_lum = settings.min_log_lum;

if count > 0u {
// The average luminance of the included histogram samples.
let avg_lum = sum / (f32(count) * 63.0)
avg_lum = sum / (f32(count) * 63.0)
* settings.log_lum_range
+ settings.min_log_lum;
}

// The position in the compensation curve texture to sample for avg_lum.
let u = (avg_lum - compensation_curve.min_log_lum) * compensation_curve.inv_log_lum_range;
// The position in the compensation curve texture to sample for avg_lum.
let u = (avg_lum - compensation_curve.min_log_lum) * compensation_curve.inv_log_lum_range;

// The target exposure is the negative of the average log luminance.
// The compensation value is added to the target exposure to adjust the exposure for
// artistic purposes.
target_exposure = textureLoad(tex_compensation, i32(saturate(u) * 255.0), 0).r
* compensation_curve.compensation_range
+ compensation_curve.min_compensation
- avg_lum;
}
// The target exposure is the negative of the average log luminance.
// The compensation value is added to the target exposure to adjust the exposure for
// artistic purposes.
let target_exposure = textureLoad(tex_compensation, i32(saturate(u) * 255.0), 0).r
* compensation_curve.compensation_range
+ compensation_curve.min_compensation
- avg_lum;

// Smoothly adjust the `exposure` towards the `target_exposure`
let delta = target_exposure - exposure;
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/auto_exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn setup(

commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 5000.0,
intensity: 2000.0,
..default()
},
transform: Transform::from_xyz(0.0, 0.0, 0.0),
Expand Down

0 comments on commit 9d74e16

Please sign in to comment.