Skip to content

Commit dd57db4

Browse files
authored
prepare bevy_light for split (#19965)
# Objective - prepare bevy_light for split ## Solution - extract cascade module (this is not strictly necessary for bevy_light) - clean up imports to be less globby and tangled - move light specific stuff into light modules - move light system and type init from pbr into new LightPlugin ## Testing - 3d_scene, lighting NOTE TO REVIEWERS: it may help to review commits independently.
1 parent 0b771d9 commit dd57db4

File tree

8 files changed

+678
-624
lines changed

8 files changed

+678
-624
lines changed

crates/bevy_pbr/src/lib.rs

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub mod graph {
122122
}
123123
}
124124

125+
pub use crate::cascade::{CascadeShadowConfig, CascadeShadowConfigBuilder, Cascades};
125126
use crate::{deferred::DeferredPbrLightingPlugin, graph::NodePbr};
126127
use bevy_app::prelude::*;
127128
use bevy_asset::{AssetApp, AssetPath, Assets, Handle};
@@ -130,19 +131,16 @@ use bevy_ecs::prelude::*;
130131
use bevy_image::Image;
131132
use bevy_render::{
132133
alpha::AlphaMode,
133-
camera::{sort_cameras, CameraUpdateSystems, Projection},
134+
camera::{sort_cameras, Projection},
134135
extract_component::ExtractComponentPlugin,
135136
extract_resource::ExtractResourcePlugin,
136137
load_shader_library,
137138
render_graph::RenderGraph,
138139
render_resource::ShaderRef,
139140
sync_component::SyncComponentPlugin,
140-
view::VisibilitySystems,
141141
ExtractSchedule, Render, RenderApp, RenderDebugFlags, RenderSystems,
142142
};
143143

144-
use bevy_transform::TransformSystems;
145-
146144
use std::path::PathBuf;
147145

148146
fn shader_ref(path: PathBuf) -> ShaderRef {
@@ -205,22 +203,8 @@ impl Plugin for PbrPlugin {
205203
load_shader_library!(app, "meshlet/dummy_visibility_buffer_resolve.wgsl");
206204

207205
app.register_asset_reflect::<StandardMaterial>()
208-
.register_type::<AmbientLight>()
209-
.register_type::<CascadeShadowConfig>()
210-
.register_type::<Cascades>()
211206
.register_type::<ClusterConfig>()
212-
.register_type::<DirectionalLight>()
213-
.register_type::<DirectionalLightShadowMap>()
214-
.register_type::<NotShadowCaster>()
215-
.register_type::<NotShadowReceiver>()
216-
.register_type::<PointLight>()
217-
.register_type::<PointLightShadowMap>()
218-
.register_type::<SpotLight>()
219-
.register_type::<ShadowFilteringMethod>()
220-
.init_resource::<AmbientLight>()
221207
.init_resource::<GlobalVisibleClusterableObjects>()
222-
.init_resource::<DirectionalLightShadowMap>()
223-
.init_resource::<PointLightShadowMap>()
224208
.register_type::<DefaultOpaqueRendererMethod>()
225209
.init_resource::<DefaultOpaqueRendererMethod>()
226210
.add_plugins((
@@ -243,7 +227,7 @@ impl Plugin for PbrPlugin {
243227
ExtractComponentPlugin::<ShadowFilteringMethod>::default(),
244228
LightmapPlugin,
245229
LightProbePlugin,
246-
PbrProjectionPlugin,
230+
LightPlugin,
247231
GpuMeshPreprocessPlugin {
248232
use_gpu_instance_buffer_builder: self.use_gpu_instance_buffer_builder,
249233
},
@@ -266,64 +250,6 @@ impl Plugin for PbrPlugin {
266250
SimulationLightSystems::AssignLightsToClusters,
267251
)
268252
.chain(),
269-
)
270-
.configure_sets(
271-
PostUpdate,
272-
SimulationLightSystems::UpdateDirectionalLightCascades
273-
.ambiguous_with(SimulationLightSystems::UpdateDirectionalLightCascades),
274-
)
275-
.configure_sets(
276-
PostUpdate,
277-
SimulationLightSystems::CheckLightVisibility
278-
.ambiguous_with(SimulationLightSystems::CheckLightVisibility),
279-
)
280-
.add_systems(
281-
PostUpdate,
282-
(
283-
add_clusters
284-
.in_set(SimulationLightSystems::AddClusters)
285-
.after(CameraUpdateSystems),
286-
assign_objects_to_clusters
287-
.in_set(SimulationLightSystems::AssignLightsToClusters)
288-
.after(TransformSystems::Propagate)
289-
.after(VisibilitySystems::CheckVisibility)
290-
.after(CameraUpdateSystems),
291-
clear_directional_light_cascades
292-
.in_set(SimulationLightSystems::UpdateDirectionalLightCascades)
293-
.after(TransformSystems::Propagate)
294-
.after(CameraUpdateSystems),
295-
update_directional_light_frusta
296-
.in_set(SimulationLightSystems::UpdateLightFrusta)
297-
// This must run after CheckVisibility because it relies on `ViewVisibility`
298-
.after(VisibilitySystems::CheckVisibility)
299-
.after(TransformSystems::Propagate)
300-
.after(SimulationLightSystems::UpdateDirectionalLightCascades)
301-
// We assume that no entity will be both a directional light and a spot light,
302-
// so these systems will run independently of one another.
303-
// FIXME: Add an archetype invariant for this https://github.com/bevyengine/bevy/issues/1481.
304-
.ambiguous_with(update_spot_light_frusta),
305-
update_point_light_frusta
306-
.in_set(SimulationLightSystems::UpdateLightFrusta)
307-
.after(TransformSystems::Propagate)
308-
.after(SimulationLightSystems::AssignLightsToClusters),
309-
update_spot_light_frusta
310-
.in_set(SimulationLightSystems::UpdateLightFrusta)
311-
.after(TransformSystems::Propagate)
312-
.after(SimulationLightSystems::AssignLightsToClusters),
313-
(
314-
check_dir_light_mesh_visibility,
315-
check_point_light_mesh_visibility,
316-
)
317-
.in_set(SimulationLightSystems::CheckLightVisibility)
318-
.after(VisibilitySystems::CalculateBounds)
319-
.after(TransformSystems::Propagate)
320-
.after(SimulationLightSystems::UpdateLightFrusta)
321-
// NOTE: This MUST be scheduled AFTER the core renderer visibility check
322-
// because that resets entity `ViewVisibility` for the first view
323-
// which would override any results from this otherwise
324-
.after(VisibilitySystems::CheckVisibility)
325-
.before(VisibilitySystems::MarkNewlyHiddenEntitiesInvisible),
326-
),
327253
);
328254

329255
if self.add_default_deferred_lighting_plugin {
@@ -401,17 +327,3 @@ impl Plugin for PbrPlugin {
401327
app.insert_resource(global_cluster_settings);
402328
}
403329
}
404-
405-
/// Camera projection PBR functionality.
406-
#[derive(Default)]
407-
pub struct PbrProjectionPlugin;
408-
impl Plugin for PbrProjectionPlugin {
409-
fn build(&self, app: &mut App) {
410-
app.add_systems(
411-
PostUpdate,
412-
build_directional_light_cascades
413-
.in_set(SimulationLightSystems::UpdateDirectionalLightCascades)
414-
.after(clear_directional_light_cascades),
415-
);
416-
}
417-
}

crates/bevy_pbr/src/light/ambient_light.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
use super::*;
1+
use bevy_camera::Camera;
2+
use bevy_color::Color;
3+
use bevy_ecs::prelude::*;
4+
use bevy_reflect::prelude::*;
5+
use bevy_render::{extract_component::ExtractComponent, extract_resource::ExtractResource};
26

37
/// An ambient light, which lights the entire scene equally.
48
///
5-
/// This resource is inserted by the [`PbrPlugin`] and by default it is set to a low ambient light.
9+
/// This resource is inserted by the [`LightPlugin`] and by default it is set to a low ambient light.
610
///
711
/// It can also be added to a camera to override the resource (or default) ambient for that camera only.
812
///
@@ -17,6 +21,8 @@ use super::*;
1721
/// ambient_light.brightness = 100.0;
1822
/// }
1923
/// ```
24+
///
25+
/// [`LightPlugin`]: crate::LightPlugin
2026
#[derive(Resource, Component, Clone, Debug, ExtractResource, ExtractComponent, Reflect)]
2127
#[reflect(Resource, Component, Debug, Default, Clone)]
2228
#[require(Camera)]

0 commit comments

Comments
 (0)