Path: blob/main/crates/bevy_post_process/src/auto_exposure/settings.rs
6596 views
use core::ops::RangeInclusive;12use super::compensation_curve::AutoExposureCompensationCurve;3use bevy_asset::Handle;4use bevy_ecs::{prelude::Component, reflect::ReflectComponent};5use bevy_image::Image;6use bevy_reflect::{std_traits::ReflectDefault, Reflect};7use bevy_render::{extract_component::ExtractComponent, view::Hdr};8use bevy_utils::default;910/// Component that enables auto exposure for an HDR-enabled 2d or 3d camera.11///12/// Auto exposure adjusts the exposure of the camera automatically to13/// simulate the human eye's ability to adapt to different lighting conditions.14///15/// Bevy's implementation builds a 64 bin histogram of the scene's luminance,16/// and then adjusts the exposure so that the average brightness of the final17/// render will be middle gray. Because it's using a histogram, some details can18/// be selectively ignored or emphasized. Outliers like shadows and specular19/// highlights can be ignored, and certain areas can be given more (or less)20/// weight based on a mask.21///22/// # Usage Notes23///24/// **Auto Exposure requires compute shaders and is not compatible with WebGL2.**25#[derive(Component, Clone, Reflect, ExtractComponent)]26#[reflect(Component, Default, Clone)]27#[require(Hdr)]28pub struct AutoExposure {29/// The range of exposure values for the histogram.30///31/// Pixel values below this range will be ignored, and pixel values above this range will be32/// clamped in the sense that they will count towards the highest bin in the histogram.33/// The default value is `-8.0..=8.0`.34pub range: RangeInclusive<f32>,3536/// The portion of the histogram to consider when metering.37///38/// By default, the darkest 10% and the brightest 10% of samples are ignored,39/// so the default value is `0.10..=0.90`.40pub filter: RangeInclusive<f32>,4142/// The speed at which the exposure adapts from dark to bright scenes, in F-stops per second.43pub speed_brighten: f32,4445/// The speed at which the exposure adapts from bright to dark scenes, in F-stops per second.46pub speed_darken: f32,4748/// The distance in F-stops from the target exposure from where to transition from animating49/// in linear fashion to animating exponentially. This helps against jittering when the50/// target exposure keeps on changing slightly from frame to frame, while still maintaining51/// a relatively slow animation for big changes in scene brightness.52///53/// ```text54/// ev55/// ➔●┐56/// | ⬈ ├ exponential section57/// │ ⬈ ┘58/// │ ⬈ ┐59/// │ ⬈ ├ linear section60/// │⬈ ┘61/// ●───────────────────────── time62/// ```63///64/// The default value is 1.5.65pub exponential_transition_distance: f32,6667/// The mask to apply when metering. The mask will cover the entire screen, where:68/// * `(0.0, 0.0)` is the top-left corner,69/// * `(1.0, 1.0)` is the bottom-right corner.70///71/// Only the red channel of the texture is used.72/// The sample at the current screen position will be used to weight the contribution73/// of each pixel to the histogram:74/// * 0.0 means the pixel will not contribute to the histogram,75/// * 1.0 means the pixel will contribute fully to the histogram.76///77/// The default value is a white image, so all pixels contribute equally.78///79/// # Usage Notes80///81/// The mask is quantized to 16 discrete levels because of limitations in the compute shader82/// implementation.83pub metering_mask: Handle<Image>,8485/// Exposure compensation curve to apply after metering.86/// The default value is a flat line at 0.0.87/// For more information, see [`AutoExposureCompensationCurve`].88pub compensation_curve: Handle<AutoExposureCompensationCurve>,89}9091impl Default for AutoExposure {92fn default() -> Self {93Self {94range: -8.0..=8.0,95filter: 0.10..=0.90,96speed_brighten: 3.0,97speed_darken: 1.0,98exponential_transition_distance: 1.5,99metering_mask: default(),100compensation_curve: default(),101}102}103}104105106