use bevy_asset::Handle;1use bevy_camera::visibility::Visibility;2use bevy_color::Color;3use bevy_ecs::prelude::*;4use bevy_image::Image;5use bevy_math::Vec3;6use bevy_reflect::prelude::*;7use bevy_transform::components::Transform;89/// Add this component to a [`DirectionalLight`](crate::DirectionalLight) with a shadow map10/// (`shadow_maps_enabled: true`) to make volumetric fog interact with it.11///12/// This allows the light to generate light shafts/god rays.13#[derive(Clone, Copy, Component, Default, Debug, Reflect)]14#[reflect(Component, Default, Debug, Clone)]15pub struct VolumetricLight;1617/// When placed on a [`bevy_camera::Camera3d`], enables18/// volumetric fog and volumetric lighting, also known as light shafts or god19/// rays.20///21/// Requires using WebGPU on Wasm builds.22#[derive(Clone, Copy, Component, Debug, Reflect)]23#[reflect(Component, Default, Debug, Clone)]24pub struct VolumetricFog {25/// Color of the ambient light.26///27/// This is separate from Bevy's [`AmbientLight`](crate::AmbientLight) because an28/// [`EnvironmentMapLight`](crate::EnvironmentMapLight) is29/// still considered an ambient light for the purposes of volumetric fog. If you're using a30/// [`EnvironmentMapLight`](crate::EnvironmentMapLight), for best results,31/// this should be a good approximation of the average color of the environment map.32///33/// Defaults to white.34pub ambient_color: Color,3536/// The brightness of the ambient light.37///38/// If there's no [`EnvironmentMapLight`](crate::EnvironmentMapLight),39/// set this to 0.40///41/// Defaults to 0.1.42pub ambient_intensity: f32,4344/// The maximum distance to offset the ray origin randomly by, in meters.45///46/// This is intended for use with temporal antialiasing. It helps fog look47/// less blocky by varying the start position of the ray, using interleaved48/// gradient noise.49pub jitter: f32,5051/// The number of raymarching steps to perform.52///53/// Higher values produce higher-quality results with less banding, but54/// reduce performance.55///56/// The default value is 64.57pub step_count: u32,58}5960impl Default for VolumetricFog {61fn default() -> Self {62Self {63step_count: 64,64// Matches `AmbientLight` defaults.65ambient_color: Color::WHITE,66ambient_intensity: 0.1,67jitter: 0.0,68}69}70}7172/// A unit cube of fog at the origin. Can be positioned and scaled with a [`Transform`].73/// Only visible by cameras with a [`VolumetricFog`] component when lit by a directional light with [`VolumetricLight`].74#[derive(Clone, Component, Debug, Reflect)]75#[reflect(Component, Default, Debug, Clone)]76#[require(Transform, Visibility)]77pub struct FogVolume {78/// The color of the fog.79///80/// Note that the fog must be lit by a [`VolumetricLight`] or ambient light81/// in order for this color to appear.82///83/// Defaults to white.84pub fog_color: Color,8586/// The density of fog, which measures how dark the fog is.87///88/// The default value is 0.1.89pub density_factor: f32,9091/// Optional 3D voxel density texture for the fog.92pub density_texture: Option<Handle<Image>>,9394/// Configurable offset of the density texture in UVW coordinates.95///96/// This can be used to scroll a repeating density texture in a direction over time97/// to create effects like fog moving in the wind. Make sure to configure the texture98/// to use `ImageAddressMode::Repeat` if this is your intention.99///100/// Has no effect when no density texture is present.101///102/// The default value is (0, 0, 0).103pub density_texture_offset: Vec3,104105/// The absorption coefficient, which measures what fraction of light is106/// absorbed by the fog at each step.107///108/// Increasing this value makes the fog darker.109///110/// The default value is 0.3.111pub absorption: f32,112113/// The scattering coefficient, which measures the fraction of light that's114/// scattered toward, and away from, the viewer.115///116/// The default value is 0.3.117pub scattering: f32,118119/// Measures the fraction of light that's scattered *toward* the camera, as120/// opposed to *away* from the camera.121///122/// Increasing this value makes light shafts become more prominent when the123/// camera is facing toward their source and less prominent when the camera124/// is facing away. Essentially, a high value here means the light shafts125/// will fade into view as the camera focuses on them and fade away when the126/// camera is pointing away.127///128/// The default value is 0.8.129pub scattering_asymmetry: f32,130131/// Applies a nonphysical color to the light.132///133/// This can be useful for artistic purposes but is nonphysical.134///135/// The default value is white.136pub light_tint: Color,137138/// Scales the light by a fixed fraction.139///140/// This can be useful for artistic purposes but is nonphysical.141///142/// The default value is 1.0, which results in no adjustment.143pub light_intensity: f32,144}145146impl Default for FogVolume {147fn default() -> Self {148Self {149absorption: 0.3,150scattering: 0.3,151density_factor: 0.1,152density_texture: None,153density_texture_offset: Vec3::ZERO,154scattering_asymmetry: 0.5,155fog_color: Color::WHITE,156light_tint: Color::WHITE,157light_intensity: 1.0,158}159}160}161162163