diff --git a/crates/bevy_core_pipeline/Cargo.toml b/crates/bevy_core_pipeline/Cargo.toml index 248895e03a542..e6846d0ec161d 100644 --- a/crates/bevy_core_pipeline/Cargo.toml +++ b/crates/bevy_core_pipeline/Cargo.toml @@ -29,7 +29,6 @@ bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" } bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev" } bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev" } bevy_render = { path = "../bevy_render", version = "0.14.0-dev" } -bevy_time = { path = "../bevy_time", version = "0.14.0-dev" } bevy_transform = { path = "../bevy_transform", version = "0.14.0-dev" } bevy_math = { path = "../bevy_math", version = "0.14.0-dev" } bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" } diff --git a/crates/bevy_core_pipeline/src/auto_exposure/auto_exposure.wgsl b/crates/bevy_core_pipeline/src/auto_exposure/auto_exposure.wgsl index fc4a5ff6907ef..aa3e50f417592 100644 --- a/crates/bevy_core_pipeline/src/auto_exposure/auto_exposure.wgsl +++ b/crates/bevy_core_pipeline/src/auto_exposure/auto_exposure.wgsl @@ -1,4 +1,5 @@ #import bevy_render::view::View +#import bevy_render::globals::Globals // Constant to convert RGB to luminance, taken from RTR vol 4 pg. 278 const RGB_TO_LUM = vec3(0.2125, 0.7154, 0.0721); @@ -11,8 +12,7 @@ struct AutoExposure { high_percent: f32, speed_up: f32, speed_down: f32, - exp_up: f32, - exp_down: f32, + exponential_transition_distance: f32, } struct CompensationCurve { @@ -22,21 +22,23 @@ struct CompensationCurve { compensation_range: f32, } -@group(0) @binding(0) var settings: AutoExposure; +@group(0) @binding(0) var globals: Globals; -@group(0) @binding(1) var tex_color: texture_2d; +@group(0) @binding(1) var settings: AutoExposure; -@group(0) @binding(2) var tex_mask: texture_2d; +@group(0) @binding(2) var tex_color: texture_2d; -@group(0) @binding(3) var tex_compensation: texture_1d; +@group(0) @binding(3) var tex_mask: texture_2d; -@group(0) @binding(4) var compensation_curve: CompensationCurve; +@group(0) @binding(4) var tex_compensation: texture_1d; -@group(0) @binding(5) var histogram: array, 64>; +@group(0) @binding(5) var compensation_curve: CompensationCurve; -@group(0) @binding(6) var exposure: f32; +@group(0) @binding(6) var histogram: array, 64>; -@group(0) @binding(7) var view: View; +@group(0) @binding(7) var exposure: f32; + +@group(0) @binding(8) var view: View; var histogram_shared: array, 64>; @@ -155,9 +157,13 @@ fn compute_average(@builtin(local_invocation_index) local_index: u32) { // Smoothly adjust the `exposure` towards the `target_exposure` let delta = target_exposure - exposure; if target_exposure > exposure { - exposure = exposure + min(settings.speed_down, delta * settings.exp_down); + let speed_down = settings.speed_down * globals.delta_time; + let exp_down = speed_down / settings.exponential_transition_distance; + exposure = exposure + min(speed_down, delta * exp_down); } else { - exposure = exposure + max(-settings.speed_up, delta * settings.exp_up); + let speed_up = settings.speed_up * globals.delta_time; + let exp_up = speed_up / settings.exponential_transition_distance; + exposure = exposure + max(-speed_up, delta * exp_up); } // Apply the exposure to the color grading settings, from where it will be used for the color diff --git a/crates/bevy_core_pipeline/src/auto_exposure/compensation_curve.rs b/crates/bevy_core_pipeline/src/auto_exposure/compensation_curve.rs index dc6604b6f868e..e51753fce7d9f 100644 --- a/crates/bevy_core_pipeline/src/auto_exposure/compensation_curve.rs +++ b/crates/bevy_core_pipeline/src/auto_exposure/compensation_curve.rs @@ -121,7 +121,6 @@ const MAX_ERROR: f32 = 1e-5; const MAX_ITERS: u8 = 8; /// Find the `y` value of the curve at the given `x` value using the Newton-Raphson method. -#[inline] fn find_y_given_x(segment: &CubicSegment, x: f32) -> f32 { let mut t_guess = x; let mut pos_guess = Vec2::ZERO; diff --git a/crates/bevy_core_pipeline/src/auto_exposure/mod.rs b/crates/bevy_core_pipeline/src/auto_exposure/mod.rs index 6e270adbb24c3..0b79eeed14fd5 100644 --- a/crates/bevy_core_pipeline/src/auto_exposure/mod.rs +++ b/crates/bevy_core_pipeline/src/auto_exposure/mod.rs @@ -13,7 +13,6 @@ use bevy_render::{ renderer::RenderDevice, Render, RenderApp, RenderSet, }; -use bevy_time::Time; mod compensation_curve; mod node; @@ -23,10 +22,7 @@ mod state; pub use compensation_curve::AutoExposureCompensationCurve; use node::AutoExposureNode; -use pipeline::{ - AutoExposurePipeline, AutoExposureUniform, Pass, ViewAutoExposurePipeline, - METERING_SHADER_HANDLE, -}; +use pipeline::{AutoExposurePipeline, Pass, ViewAutoExposurePipeline, METERING_SHADER_HANDLE}; pub use settings::AutoExposureSettings; use state::{extract_state_buffers, prepare_state_buffers, AutoExposureStateBuffers}; @@ -115,7 +111,6 @@ fn queue_view_auto_exposure_pipelines( mut compute_pipelines: ResMut>, pipeline: Res, buffers: Res, - time: Res