From 727d8d2493f8e720b7fe9cac2b444a7d51134eb2 Mon Sep 17 00:00:00 2001 From: yuni Date: Fri, 29 Nov 2024 19:19:58 +0100 Subject: [PATCH] atmosphere: add volumetric fog (WIP) --- src/camera.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/camera.rs b/src/camera.rs index 66e6a81..2df37d2 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -32,6 +32,7 @@ impl Plugin for CameraPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup_camera); app.add_systems(Update, handle_input.run_if(in_control).run_if(game_running)); + app.add_systems(Update, tweak_scene); app.add_systems( Update, update_map_only_object_visibility @@ -147,6 +148,14 @@ pub fn setup_camera( transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y), ..default() }, + bevy::pbr::VolumetricFogSettings { + // This value is explicitly set to 0 since we have no environment map light + ambient_intensity: 0.0, + absorption: 0.1, + density: 0.01, + step_count: 16, + ..default() + }, bevy::core_pipeline::fxaa::Fxaa { edge_threshold: bevy::core_pipeline::fxaa::Sensitivity::Extreme, ..default() @@ -793,3 +802,14 @@ pub fn position_to_transform( transform.rotation = rot.as_quat(); } } + +fn tweak_scene( + mut commands: Commands, + mut lights: Query<(Entity, &mut DirectionalLight), Changed>, +) { + for (light, mut directional_light) in lights.iter_mut() { + // Shadows are needed for volumetric lights to work. + directional_light.shadows_enabled = true; + commands.entity(light).insert(bevy::pbr::VolumetricLight); + } +}