@@ -22,6 +22,12 @@ use crate::*;
22
22
23
23
mod ambient_light;
24
24
pub use ambient_light:: AmbientLight ;
25
+ mod point_light;
26
+ pub use point_light:: PointLight ;
27
+ mod spot_light;
28
+ pub use spot_light:: SpotLight ;
29
+ mod directional_light;
30
+ pub use directional_light:: DirectionalLight ;
25
31
26
32
/// Constants for operating with the light units: lumens, and lux.
27
33
pub mod light_consts {
@@ -80,61 +86,6 @@ pub mod light_consts {
80
86
}
81
87
}
82
88
83
- /// A light that emits light in all directions from a central point.
84
- ///
85
- /// Real-world values for `intensity` (luminous power in lumens) based on the electrical power
86
- /// consumption of the type of real-world light are:
87
- ///
88
- /// | Luminous Power (lumen) (i.e. the intensity member) | Incandescent non-halogen (Watts) | Incandescent halogen (Watts) | Compact fluorescent (Watts) | LED (Watts |
89
- /// |------|-----|----|--------|-------|
90
- /// | 200 | 25 | | 3-5 | 3 |
91
- /// | 450 | 40 | 29 | 9-11 | 5-8 |
92
- /// | 800 | 60 | | 13-15 | 8-12 |
93
- /// | 1100 | 75 | 53 | 18-20 | 10-16 |
94
- /// | 1600 | 100 | 72 | 24-28 | 14-17 |
95
- /// | 2400 | 150 | | 30-52 | 24-30 |
96
- /// | 3100 | 200 | | 49-75 | 32 |
97
- /// | 4000 | 300 | | 75-100 | 40.5 |
98
- ///
99
- /// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting)
100
- #[ derive( Component , Debug , Clone , Copy , Reflect ) ]
101
- #[ reflect( Component , Default ) ]
102
- pub struct PointLight {
103
- pub color : Color ,
104
- /// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
105
- pub intensity : f32 ,
106
- pub range : f32 ,
107
- pub radius : f32 ,
108
- pub shadows_enabled : bool ,
109
- pub shadow_depth_bias : f32 ,
110
- /// A bias applied along the direction of the fragment's surface normal. It is scaled to the
111
- /// shadow map's texel size so that it can be small close to the camera and gets larger further
112
- /// away.
113
- pub shadow_normal_bias : f32 ,
114
- }
115
-
116
- impl Default for PointLight {
117
- fn default ( ) -> Self {
118
- PointLight {
119
- color : Color :: WHITE ,
120
- // 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's
121
- // default "very overcast day" exposure level. For "indoor lighting" with a lower exposure,
122
- // this would be way too bright.
123
- intensity : 1_000_000.0 ,
124
- range : 20.0 ,
125
- radius : 0.0 ,
126
- shadows_enabled : false ,
127
- shadow_depth_bias : Self :: DEFAULT_SHADOW_DEPTH_BIAS ,
128
- shadow_normal_bias : Self :: DEFAULT_SHADOW_NORMAL_BIAS ,
129
- }
130
- }
131
- }
132
-
133
- impl PointLight {
134
- pub const DEFAULT_SHADOW_DEPTH_BIAS : f32 = 0.02 ;
135
- pub const DEFAULT_SHADOW_NORMAL_BIAS : f32 = 0.6 ;
136
- }
137
-
138
89
#[ derive( Resource , Clone , Debug , Reflect ) ]
139
90
#[ reflect( Resource ) ]
140
91
pub struct PointLightShadowMap {
@@ -147,144 +98,6 @@ impl Default for PointLightShadowMap {
147
98
}
148
99
}
149
100
150
- /// A light that emits light in a given direction from a central point.
151
- /// Behaves like a point light in a perfectly absorbent housing that
152
- /// shines light only in a given direction. The direction is taken from
153
- /// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at).
154
- #[ derive( Component , Debug , Clone , Copy , Reflect ) ]
155
- #[ reflect( Component , Default ) ]
156
- pub struct SpotLight {
157
- pub color : Color ,
158
- /// Luminous power in lumens, representing the amount of light emitted by this source in all directions.
159
- pub intensity : f32 ,
160
- pub range : f32 ,
161
- pub radius : f32 ,
162
- pub shadows_enabled : bool ,
163
- pub shadow_depth_bias : f32 ,
164
- /// A bias applied along the direction of the fragment's surface normal. It is scaled to the
165
- /// shadow map's texel size so that it can be small close to the camera and gets larger further
166
- /// away.
167
- pub shadow_normal_bias : f32 ,
168
- /// Angle defining the distance from the spot light direction to the outer limit
169
- /// of the light's cone of effect.
170
- /// `outer_angle` should be < `PI / 2.0`.
171
- /// `PI / 2.0` defines a hemispherical spot light, but shadows become very blocky as the angle
172
- /// approaches this limit.
173
- pub outer_angle : f32 ,
174
- /// Angle defining the distance from the spot light direction to the inner limit
175
- /// of the light's cone of effect.
176
- /// Light is attenuated from `inner_angle` to `outer_angle` to give a smooth falloff.
177
- /// `inner_angle` should be <= `outer_angle`
178
- pub inner_angle : f32 ,
179
- }
180
-
181
- impl SpotLight {
182
- pub const DEFAULT_SHADOW_DEPTH_BIAS : f32 = 0.02 ;
183
- pub const DEFAULT_SHADOW_NORMAL_BIAS : f32 = 1.8 ;
184
- }
185
-
186
- impl Default for SpotLight {
187
- fn default ( ) -> Self {
188
- // a quarter arc attenuating from the center
189
- Self {
190
- color : Color :: WHITE ,
191
- // 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's
192
- // default "very overcast day" exposure level. For "indoor lighting" with a lower exposure,
193
- // this would be way too bright.
194
- intensity : 1_000_000.0 ,
195
- range : 20.0 ,
196
- radius : 0.0 ,
197
- shadows_enabled : false ,
198
- shadow_depth_bias : Self :: DEFAULT_SHADOW_DEPTH_BIAS ,
199
- shadow_normal_bias : Self :: DEFAULT_SHADOW_NORMAL_BIAS ,
200
- inner_angle : 0.0 ,
201
- outer_angle : std:: f32:: consts:: FRAC_PI_4 ,
202
- }
203
- }
204
- }
205
-
206
- /// A Directional light.
207
- ///
208
- /// Directional lights don't exist in reality but they are a good
209
- /// approximation for light sources VERY far away, like the sun or
210
- /// the moon.
211
- ///
212
- /// The light shines along the forward direction of the entity's transform. With a default transform
213
- /// this would be along the negative-Z axis.
214
- ///
215
- /// Valid values for `illuminance` are:
216
- ///
217
- /// | Illuminance (lux) | Surfaces illuminated by |
218
- /// |-------------------|------------------------------------------------|
219
- /// | 0.0001 | Moonless, overcast night sky (starlight) |
220
- /// | 0.002 | Moonless clear night sky with airglow |
221
- /// | 0.05–0.3 | Full moon on a clear night |
222
- /// | 3.4 | Dark limit of civil twilight under a clear sky |
223
- /// | 20–50 | Public areas with dark surroundings |
224
- /// | 50 | Family living room lights |
225
- /// | 80 | Office building hallway/toilet lighting |
226
- /// | 100 | Very dark overcast day |
227
- /// | 150 | Train station platforms |
228
- /// | 320–500 | Office lighting |
229
- /// | 400 | Sunrise or sunset on a clear day. |
230
- /// | 1000 | Overcast day; typical TV studio lighting |
231
- /// | 10,000–25,000 | Full daylight (not direct sun) |
232
- /// | 32,000–100,000 | Direct sunlight |
233
- ///
234
- /// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lux)
235
- ///
236
- /// ## Shadows
237
- ///
238
- /// To enable shadows, set the `shadows_enabled` property to `true`.
239
- ///
240
- /// Shadows are produced via [cascaded shadow maps](https://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps.pdf).
241
- ///
242
- /// To modify the cascade set up, such as the number of cascades or the maximum shadow distance,
243
- /// change the [`CascadeShadowConfig`] component of the [`DirectionalLightBundle`].
244
- ///
245
- /// To control the resolution of the shadow maps, use the [`DirectionalLightShadowMap`] resource:
246
- ///
247
- /// ```
248
- /// # use bevy_app::prelude::*;
249
- /// # use bevy_pbr::DirectionalLightShadowMap;
250
- /// App::new()
251
- /// .insert_resource(DirectionalLightShadowMap { size: 2048 });
252
- /// ```
253
- #[ derive( Component , Debug , Clone , Reflect ) ]
254
- #[ reflect( Component , Default ) ]
255
- pub struct DirectionalLight {
256
- pub color : Color ,
257
- /// Illuminance in lux (lumens per square meter), representing the amount of
258
- /// light projected onto surfaces by this light source. Lux is used here
259
- /// instead of lumens because a directional light illuminates all surfaces
260
- /// more-or-less the same way (depending on the angle of incidence). Lumens
261
- /// can only be specified for light sources which emit light from a specific
262
- /// area.
263
- pub illuminance : f32 ,
264
- pub shadows_enabled : bool ,
265
- pub shadow_depth_bias : f32 ,
266
- /// A bias applied along the direction of the fragment's surface normal. It is scaled to the
267
- /// shadow map's texel size so that it is automatically adjusted to the orthographic projection.
268
- pub shadow_normal_bias : f32 ,
269
- }
270
-
271
- impl Default for DirectionalLight {
272
- fn default ( ) -> Self {
273
- DirectionalLight {
274
- color : Color :: WHITE ,
275
- illuminance : light_consts:: lux:: AMBIENT_DAYLIGHT ,
276
- shadows_enabled : false ,
277
- shadow_depth_bias : Self :: DEFAULT_SHADOW_DEPTH_BIAS ,
278
- shadow_normal_bias : Self :: DEFAULT_SHADOW_NORMAL_BIAS ,
279
- }
280
- }
281
- }
282
-
283
- impl DirectionalLight {
284
- pub const DEFAULT_SHADOW_DEPTH_BIAS : f32 = 0.02 ;
285
- pub const DEFAULT_SHADOW_NORMAL_BIAS : f32 = 1.8 ;
286
- }
287
-
288
101
/// Controls the resolution of [`DirectionalLight`] shadow maps.
289
102
#[ derive( Resource , Clone , Debug , Reflect ) ]
290
103
#[ reflect( Resource ) ]
0 commit comments