1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Optional lighting plugins: a fixed scene sun with a fill light, a headlamp
//! carried by an entity the game marks, and lights placed in the world.
//!
//! The three plugins are independent Default Implementation plugins. None of
//! them is part of [`VoxelCorePlugin`](crate::VoxelCorePlugin) or
//! [`VoxelPlugin`](crate::VoxelPlugin); a game adds the ones it wants. Every
//! color, intensity, angle and budget is supplied by the game.
//!
//! | Plugin | What it manages |
//! |---|---|
//! | [`SceneLightingPlugin`] | A fixed directional sun, a shadowless fill light and the global ambient light, from [`SceneLightingConfig`] |
//! | [`HeadlampPlugin`] | A spot light child for every entity that carries a [`Headlamp`] component |
//! | [`PlacedLightsPlugin`] | Point lights recorded by voxel position in [`PlacedLights`], with a nearest-N budget ([`PlacedLightBudget`]) |
//!
//! # Relationship with the day cycle
//!
//! [`DayCyclePlugin`](crate::world::DayCyclePlugin) animates its own sun
//! (tagged [`SunLight`](crate::world::SunLight)) and writes the global ambient
//! brightness every frame. [`SceneLightingPlugin`] uses different marker
//! components ([`SceneSunLight`], [`SceneFillLight`]), so the two never edit
//! each other's entities. A game normally picks one of them for the sun. To
//! add a fill light to an animated day cycle, leave
//! [`SceneLightingConfig::sun`] and [`SceneLightingConfig::ambient`] as `None`
//! and set only [`SceneLightingConfig::fill`] with an explicit direction.
//!
//! # Example
//!
//! ```no_run
//! use bevy::prelude::*;
//! use voxel_framework::lighting::{
//! FillLightConfig, Headlamp, HeadlampPlugin, PlacedLight, PlacedLights,
//! PlacedLightsPlugin, SceneLightingConfig, SceneLightingPlugin, SunConfig,
//! };
//!
//! fn setup(mut commands: Commands, mut lights: ResMut<PlacedLights>) {
//! // The game decides which entity carries the headlamp.
//! commands.spawn((Camera3d::default(), Headlamp::default()));
//! // A light recorded at a voxel position.
//! lights.insert(IVec3::new(4, 10, -3), PlacedLight::default());
//! }
//!
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .insert_resource(SceneLightingConfig {
//! sun: Some(SunConfig {
//! direction: Vec3::new(-0.4, -1.0, -0.3),
//! shadows_enabled: true,
//! ..default()
//! }),
//! fill: Some(FillLightConfig::default()),
//! ambient: None,
//! })
//! .add_plugins((SceneLightingPlugin, HeadlampPlugin, PlacedLightsPlugin))
//! .add_systems(Startup, setup)
//! .run();
//! ```
use *;
pub use ;
pub use ;
pub use ;
/// System sets of the lighting plugins, all in the `Update` schedule.
///
/// Each plugin puts its systems in its own set, so a game can order its
/// systems around them or gate them with a run condition.
///
/// ```no_run
/// use bevy::prelude::*;
/// use voxel_framework::lighting::{Headlamp, HeadlampPlugin, LightingSystems};
///
/// fn toggle_headlamp(keys: Res<ButtonInput<KeyCode>>, mut lamps: Query<&mut Headlamp>) {
/// if keys.just_pressed(KeyCode::KeyF) {
/// for mut lamp in &mut lamps {
/// lamp.toggle();
/// }
/// }
/// }
///
/// App::new()
/// .add_plugins(DefaultPlugins)
/// .add_plugins(HeadlampPlugin)
/// // The change is applied to the spot light in the same frame.
/// .add_systems(Update, toggle_headlamp.before(LightingSystems::Headlamp))
/// .run();
/// ```