cyber_rider/src/lights.rs

98 lines
2.7 KiB
Rust
Raw Normal View History

2023-03-10 19:45:01 +00:00
use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*};
use crate::planet::PLANET_RADIUS;
2022-01-29 21:31:15 +00:00
pub const LIGHT_RANGE: f32 = 90.0;
2022-01-19 23:07:24 +00:00
fn spawn_static_lights(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let pink_light = PointLight {
intensity: 1_00.0,
range: LIGHT_RANGE,
color: Color::PINK,
radius: 1.0,
shadows_enabled: true,
..Default::default()
};
let blue_light = PointLight {
intensity: 1_000.0,
range: LIGHT_RANGE,
color: Color::BLUE,
radius: 1.0,
shadows_enabled: true,
..Default::default()
};
commands.insert_resource(AmbientLight {
color: Color::WHITE,
2022-02-21 21:08:49 +00:00
brightness: 0.2,
2022-01-19 23:07:24 +00:00
});
2022-01-19 04:08:47 +00:00
2023-03-10 19:45:01 +00:00
let _cascade_shadow_config = CascadeShadowConfigBuilder {
first_cascade_far_bound: 0.3,
maximum_distance: 3.0,
..default()
}
.build();
// up light
commands
2023-01-20 22:40:51 +00:00
.spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0),
2022-01-19 04:08:47 +00:00
point_light: pink_light,
..Default::default()
})
.with_children(|builder| {
2023-01-20 22:40:51 +00:00
builder.spawn(PbrBundle {
2023-03-10 01:50:14 +00:00
mesh: meshes.add(
Mesh::try_from(shape::Icosphere {
radius: 10.0,
subdivisions: 2,
})
.unwrap(),
),
material: materials.add(StandardMaterial {
2022-01-19 23:07:24 +00:00
base_color: Color::BLUE,
emissive: Color::PINK,
..Default::default()
}),
..Default::default()
});
});
// down light
commands
2023-01-20 22:40:51 +00:00
.spawn(PointLightBundle {
transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0),
point_light: blue_light,
..Default::default()
})
.with_children(|builder| {
2023-01-20 22:40:51 +00:00
builder.spawn(PbrBundle {
2023-03-10 01:50:14 +00:00
mesh: meshes.add(
Mesh::try_from(shape::Icosphere {
radius: 10.0,
subdivisions: 2,
})
.unwrap(),
),
material: materials.add(StandardMaterial {
2022-01-19 23:07:24 +00:00
base_color: Color::PINK,
emissive: Color::BLUE,
..Default::default()
}),
..Default::default()
});
});
}
2022-01-14 00:14:08 +00:00
pub struct CyberSpaceLightsPlugin;
impl Plugin for CyberSpaceLightsPlugin {
fn build(&self, app: &mut App) {
2024-06-13 20:00:39 +00:00
app.add_systems(Startup, spawn_static_lights);
2022-01-14 00:14:08 +00:00
}
}