use bevy::prelude::*;
#[derive(Component)]
pub struct CameraFollowLight {
pub offset: Vec3,
}
fn set_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
ambient_light.brightness = 100.0;
ambient_light.color = Color::srgb(0.9, 0.95, 1.0); }
fn spawn_lights(mut commands: Commands) {
commands.spawn((
DirectionalLight {
shadows_enabled: true,
illuminance: 2000.0,
color: Color::srgb(1.0, 0.98, 0.95), ..default()
},
Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
CameraFollowLight {
offset: Vec3::new(5.0, 10.0, 10.0),
},
));
commands.spawn((
DirectionalLight {
shadows_enabled: false,
illuminance: 800.0,
color: Color::srgb(0.95, 0.97, 1.0), ..default()
},
Transform::from_xyz(-5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
CameraFollowLight {
offset: Vec3::new(-5.0, 5.0, 5.0),
},
));
commands.spawn((
DirectionalLight {
shadows_enabled: false,
illuminance: 500.0,
color: Color::srgb(1.0, 0.94, 0.80), ..default()
},
Transform::from_xyz(0.0, 3.0, -10.0).looking_at(Vec3::ZERO, Vec3::Y),
));
}
pub struct LightPlugin;
impl Plugin for LightPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(ClearColor(Color::srgb_u8(20, 20, 25))); app.add_systems(Startup, (set_ambient_light, spawn_lights));
}
}