Path: blob/main/crates/bevy_post_process/src/auto_exposure/settings.rs
9371 views
use core::ops::RangeInclusive;12use super::compensation_curve::AutoExposureCompensationCurve;3use bevy_asset::Handle;4use bevy_camera::Hdr;5use bevy_ecs::{prelude::Component, reflect::ReflectComponent};6use bevy_image::Image;7use bevy_reflect::{std_traits::ReflectDefault, Reflect};8use bevy_render::extract_component::ExtractComponent;9use bevy_utils::default;1011/// Component that enables auto exposure for an HDR-enabled 2d or 3d camera.12///13/// Auto exposure adjusts the exposure of the camera automatically to14/// simulate the human eye's ability to adapt to different lighting conditions.15///16/// Bevy's implementation builds a 64 bin histogram of the scene's luminance,17/// and then adjusts the exposure so that the average brightness of the final18/// render will be middle gray. Because it's using a histogram, some details can19/// be selectively ignored or emphasized. Outliers like shadows and specular20/// highlights can be ignored, and certain areas can be given more (or less)21/// weight based on a mask.22///23/// # Usage Notes24///25/// **Auto Exposure requires compute shaders and is not compatible with WebGL2.**26#[derive(Component, Clone, Reflect, ExtractComponent)]27#[reflect(Component, Default, Clone)]28#[require(Hdr)]29pub struct AutoExposure {30/// The range of exposure values for the histogram.31///32/// Pixel values below this range will be ignored, and pixel values above this range will be33/// clamped in the sense that they will count towards the highest bin in the histogram.34/// The default value is `-8.0..=8.0`.35pub range: RangeInclusive<f32>,3637/// The portion of the histogram to consider when metering.38///39/// By default, the darkest 10% and the brightest 10% of samples are ignored,40/// so the default value is `0.10..=0.90`.41pub filter: RangeInclusive<f32>,4243/// The speed at which the exposure adapts from dark to bright scenes, in F-stops per second.44pub speed_brighten: f32,4546/// The speed at which the exposure adapts from bright to dark scenes, in F-stops per second.47pub speed_darken: f32,4849/// The distance in F-stops from the target exposure from where to transition from animating50/// in linear fashion to animating exponentially. This helps against jittering when the51/// target exposure keeps on changing slightly from frame to frame, while still maintaining52/// a relatively slow animation for big changes in scene brightness.53///54/// ```text55/// ev56/// ➔●┐57/// | ⬈ ├ exponential section58/// │ ⬈ ┘59/// │ ⬈ ┐60/// │ ⬈ ├ linear section61/// │⬈ ┘62/// ●───────────────────────── time63/// ```64///65/// The default value is 1.5.66pub exponential_transition_distance: f32,6768/// The mask to apply when metering. The mask will cover the entire screen, where:69/// * `(0.0, 0.0)` is the top-left corner,70/// * `(1.0, 1.0)` is the bottom-right corner.71///72/// Only the red channel of the texture is used.73/// The sample at the current screen position will be used to weight the contribution74/// of each pixel to the histogram:75/// * 0.0 means the pixel will not contribute to the histogram,76/// * 1.0 means the pixel will contribute fully to the histogram.77///78/// The default value is a white image, so all pixels contribute equally.79///80/// # Usage Notes81///82/// The mask is quantized to 16 discrete levels because of limitations in the compute shader83/// implementation.84pub metering_mask: Handle<Image>,8586/// Exposure compensation curve to apply after metering.87/// The default value is a flat line at 0.0.88/// For more information, see [`AutoExposureCompensationCurve`].89pub compensation_curve: Handle<AutoExposureCompensationCurve>,90}9192impl Default for AutoExposure {93fn default() -> Self {94Self {95range: -8.0..=8.0,96filter: 0.10..=0.90,97speed_brighten: 3.0,98speed_darken: 1.0,99exponential_transition_distance: 1.5,100metering_mask: default(),101compensation_curve: default(),102}103}104}105106107