| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
use bevy::{ |
| 9 |
camera::Hdr, |
| 10 |
light::{FogVolume, VolumetricFog, VolumetricLight}, |
| 11 |
math::vec3, |
| 12 |
prelude::*, |
| 13 |
}; |
| 14 |
|
| 15 |
|
| 16 |
fn main() { |
| 17 |
App::new() |
| 18 |
.add_plugins(DefaultPlugins.set(WindowPlugin { |
| 19 |
primary_window: Some(Window { |
| 20 |
title: "Bevy Fog Volumes Example".into(), |
| 21 |
..default() |
| 22 |
}), |
| 23 |
..default() |
| 24 |
})) |
| 25 |
.insert_resource(GlobalAmbientLight::NONE) |
| 26 |
.add_systems(Startup, setup) |
| 27 |
.add_systems(Update, rotate_camera) |
| 28 |
.run(); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { |
| 33 |
|
| 34 |
commands.spawn(( |
| 35 |
Transform::from_xyz(0.0, 0.5, 0.0), |
| 36 |
FogVolume { |
| 37 |
density_texture: Some(asset_server.load("volumes/bunny.ktx2")), |
| 38 |
density_factor: 1.0, |
| 39 |
|
| 40 |
|
| 41 |
scattering: 1.0, |
| 42 |
..default() |
| 43 |
}, |
| 44 |
)); |
| 45 |
|
| 46 |
|
| 47 |
commands.spawn(( |
| 48 |
Transform::from_xyz(1.0, 1.0, -0.3).looking_at(vec3(0.0, 0.5, 0.0), Vec3::Y), |
| 49 |
DirectionalLight { |
| 50 |
shadow_maps_enabled: true, |
| 51 |
illuminance: 32000.0, |
| 52 |
..default() |
| 53 |
}, |
| 54 |
|
| 55 |
VolumetricLight, |
| 56 |
)); |
| 57 |
|
| 58 |
|
| 59 |
commands.spawn(( |
| 60 |
Camera3d::default(), |
| 61 |
Transform::from_xyz(-0.75, 1.0, 2.0).looking_at(vec3(0.0, 0.0, 0.0), Vec3::Y), |
| 62 |
Hdr, |
| 63 |
VolumetricFog { |
| 64 |
|
| 65 |
step_count: 64, |
| 66 |
|
| 67 |
ambient_intensity: 0.0, |
| 68 |
..default() |
| 69 |
}, |
| 70 |
)); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
fn rotate_camera(mut cameras: Query<&mut Transform, With<Camera3d>>) { |
| 75 |
for mut camera_transform in cameras.iter_mut() { |
| 76 |
*camera_transform = |
| 77 |
Transform::from_translation(Quat::from_rotation_y(0.01) * camera_transform.translation) |
| 78 |
.looking_at(vec3(0.0, 0.5, 0.0), Vec3::Y); |
| 79 |
} |
| 80 |
} |