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/// (`shadows_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#[derive(Clone, Component, Debug, Reflect)]73#[reflect(Component, Default, Debug, Clone)]74#[require(Transform, Visibility)]75pub struct FogVolume {76/// The color of the fog.77///78/// Note that the fog must be lit by a [`VolumetricLight`] or ambient light79/// in order for this color to appear.80///81/// Defaults to white.82pub fog_color: Color,8384/// The density of fog, which measures how dark the fog is.85///86/// The default value is 0.1.87pub density_factor: f32,8889/// Optional 3D voxel density texture for the fog.90pub density_texture: Option<Handle<Image>>,9192/// Configurable offset of the density texture in UVW coordinates.93///94/// This can be used to scroll a repeating density texture in a direction over time95/// to create effects like fog moving in the wind. Make sure to configure the texture96/// to use `ImageAddressMode::Repeat` if this is your intention.97///98/// Has no effect when no density texture is present.99///100/// The default value is (0, 0, 0).101pub density_texture_offset: Vec3,102103/// The absorption coefficient, which measures what fraction of light is104/// absorbed by the fog at each step.105///106/// Increasing this value makes the fog darker.107///108/// The default value is 0.3.109pub absorption: f32,110111/// The scattering coefficient, which measures the fraction of light that's112/// scattered toward, and away from, the viewer.113///114/// The default value is 0.3.115pub scattering: f32,116117/// Measures the fraction of light that's scattered *toward* the camera, as118/// opposed to *away* from the camera.119///120/// Increasing this value makes light shafts become more prominent when the121/// camera is facing toward their source and less prominent when the camera122/// is facing away. Essentially, a high value here means the light shafts123/// will fade into view as the camera focuses on them and fade away when the124/// camera is pointing away.125///126/// The default value is 0.8.127pub scattering_asymmetry: f32,128129/// Applies a nonphysical color to the light.130///131/// This can be useful for artistic purposes but is nonphysical.132///133/// The default value is white.134pub light_tint: Color,135136/// Scales the light by a fixed fraction.137///138/// This can be useful for artistic purposes but is nonphysical.139///140/// The default value is 1.0, which results in no adjustment.141pub light_intensity: f32,142}143144impl Default for FogVolume {145fn default() -> Self {146Self {147absorption: 0.3,148scattering: 0.3,149density_factor: 0.1,150density_texture: None,151density_texture_offset: Vec3::ZERO,152scattering_asymmetry: 0.5,153fog_color: Color::WHITE,154light_tint: Color::WHITE,155light_intensity: 1.0,156}157}158}159160161