Advance M0 scene and rendering foundations
CI / Format, lint, test, build (push) Waiting to run

This commit is contained in:
Rbanh committed 2026-06-06 03:50:03 -04:00
1 parent 2fa64106c8
commit 2054fa2558
21 files changed
+711 -159

No files matched your search

+71 -17
View File
@@ -2,7 +2,7 @@
use bevy::light::{CascadeShadowConfig, CascadeShadowConfigBuilder};
use bevy::prelude::*;
use settings::RenderingSettings;
use settings::{ActiveCameraRenderProfile, GiPath, RenderingCapabilities, RenderingSettings};
use crate::{
inspector_component_active, AuthoringLightKind, InspectorOrder, LevelObject, LightDesc,
@@ -29,26 +29,29 @@ pub fn cascade_config_from_rendering(rendering: &RenderingSettings) -> CascadeSh
pub fn hydrate_lights(
mut commands: Commands,
settings: Res<settings::ProjectSettings>,
lights: Query<
(Entity, &LightDesc, Option<&InspectorOrder>),
(
With<LevelObject>,
Or<(
Added<LightDesc>,
Changed<LightDesc>,
Changed<InspectorOrder>,
)>,
),
>,
profile: Option<Res<ActiveCameraRenderProfile>>,
caps: Option<Res<RenderingCapabilities>>,
lights: Query<(Entity, Ref<LightDesc>, Option<Ref<InspectorOrder>>), With<LevelObject>>,
) {
let rendering = &settings.rendering;
let render_stack_changed = profile.as_ref().is_some_and(|profile| profile.is_changed())
|| caps.as_ref().is_some_and(|caps| caps.is_changed());
let profile = profile.as_deref();
let caps = caps.as_deref();
for (entity, light, order) in &lights {
let mut entity_commands = commands.entity(entity);
strip_light_components(&mut entity_commands);
if !inspector_component_active(order, COMPONENT_LIGHT_DESC) {
let order_changed = order.as_ref().is_some_and(|order| order.is_changed());
if !light.is_changed() && !order_changed && !render_stack_changed {
continue;
}
insert_light_from_desc(&mut entity_commands, light, rendering);
let mut entity_commands = commands.entity(entity);
strip_light_components(&mut entity_commands);
if !inspector_component_active(order.as_deref(), COMPONENT_LIGHT_DESC) {
continue;
}
if local_light_disabled_in_solari(&light, profile, caps) {
continue;
}
insert_light_from_desc(&mut entity_commands, &light, rendering);
}
}
@@ -77,16 +80,27 @@ pub(crate) fn normalized_directional_lux(intensity: f32) -> f32 {
pub fn reconcile_missing_runtime_lights(
mut commands: Commands,
settings: Res<settings::ProjectSettings>,
profile: Option<Res<ActiveCameraRenderProfile>>,
caps: Option<Res<RenderingCapabilities>>,
lights: Query<(Entity, &LightDesc, Option<&InspectorOrder>), With<LevelObject>>,
points: Query<(), With<PointLight>>,
spots: Query<(), With<SpotLight>>,
directionals: Query<(), With<DirectionalLight>>,
) {
let rendering = &settings.rendering;
let profile = profile.as_deref();
let caps = caps.as_deref();
for (entity, light, order) in &lights {
if !inspector_component_active(order, COMPONENT_LIGHT_DESC) {
continue;
}
if local_light_disabled_in_solari(light, profile, caps) {
if points.contains(entity) || spots.contains(entity) || directionals.contains(entity) {
let mut entity_commands = commands.entity(entity);
strip_light_components(&mut entity_commands);
}
continue;
}
let missing = match light.kind {
AuthoringLightKind::Point => !points.contains(entity),
AuthoringLightKind::Spot => !spots.contains(entity),
@@ -101,6 +115,18 @@ pub fn reconcile_missing_runtime_lights(
}
}
pub(crate) fn local_light_disabled_in_solari(
light: &LightDesc,
profile: Option<&ActiveCameraRenderProfile>,
caps: Option<&RenderingCapabilities>,
) -> bool {
matches!(
light.kind,
AuthoringLightKind::Point | AuthoringLightKind::Spot
) && profile.is_some_and(|profile| profile.gi_path == GiPath::SolariDeferred)
&& caps.is_some_and(|caps| caps.rt_supported)
}
pub(crate) fn insert_light_from_desc(
entity: &mut EntityCommands<'_>,
light: &LightDesc,
@@ -156,7 +182,7 @@ mod tests {
use super::*;
use crate::{AuthoringLightKind, ColorDesc, LevelObject, LightDesc};
use bevy::ecs::world::CommandQueue;
use settings::RenderingSettings;
use settings::{ActiveCameraRenderProfile, GiPath, RenderingCapabilities, RenderingSettings};
#[test]
fn light_kind_swap_replaces_runtime_types() {
@@ -251,6 +277,34 @@ mod tests {
assert!(world.get::<Visibility>(spot_entity).is_some());
}
#[test]
fn solari_disables_point_and_spot_light_hydration() {
let profile = ActiveCameraRenderProfile {
gi_path: GiPath::SolariDeferred,
..Default::default()
};
let caps = RenderingCapabilities {
rt_supported: true,
..Default::default()
};
assert!(local_light_disabled_in_solari(
&LightDesc::for_kind(AuthoringLightKind::Point),
Some(&profile),
Some(&caps)
));
assert!(local_light_disabled_in_solari(
&LightDesc::for_kind(AuthoringLightKind::Spot),
Some(&profile),
Some(&caps)
));
assert!(!local_light_disabled_in_solari(
&LightDesc::for_kind(AuthoringLightKind::Directional),
Some(&profile),
Some(&caps)
));
}
#[test]
fn point_light_default_casts_shadows() {
let light = LightDesc::for_kind(AuthoringLightKind::Point);
+75 -7
View File
@@ -138,13 +138,6 @@ pub fn flush_level_object_hydration(world: &mut World) {
}
}
let lights: Vec<(Entity, crate::LightDesc)> = world
.query_filtered::<(Entity, &crate::LightDesc, Option<&InspectorOrder>), With<LevelObject>>()
.iter(world)
.filter(|(_, _, order)| inspector_component_active(*order, COMPONENT_LIGHT_DESC))
.map(|(entity, light, _)| (entity, light.clone()))
.collect();
let visibility_targets: Vec<(Entity, EditorVisibility)> = world
.query_filtered::<(Entity, &EditorVisibility), With<LevelObject>>()
.iter(world)
@@ -155,6 +148,22 @@ pub fn flush_level_object_hydration(world: &mut World) {
.get_resource::<settings::ProjectSettings>()
.map(|s| s.rendering.clone())
.unwrap_or_default();
let profile = world
.get_resource::<settings::ActiveCameraRenderProfile>()
.cloned();
let caps = world
.get_resource::<settings::RenderingCapabilities>()
.cloned();
let lights: Vec<(Entity, crate::LightDesc)> = world
.query_filtered::<(Entity, &crate::LightDesc, Option<&InspectorOrder>), With<LevelObject>>()
.iter(world)
.filter(|(_, light, order)| {
inspector_component_active(*order, COMPONENT_LIGHT_DESC)
&& !lights::local_light_disabled_in_solari(light, profile.as_ref(), caps.as_ref())
})
.map(|(entity, light, _)| (entity, light.clone()))
.collect();
let mut state: SystemState<(
Commands,
@@ -245,6 +254,65 @@ mod tests {
assert!(app.world().get::<PointLight>(entity).is_some());
}
#[test]
fn flush_hydration_skips_point_light_when_solari_is_active() {
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.add_plugins(AssetPlugin::default());
app.add_plugins(bevy::pbr::MaterialPlugin::<StandardMaterial>::default());
app.init_asset::<Mesh>();
app.world_mut()
.insert_resource(settings::ActiveCameraRenderProfile {
gi_path: settings::GiPath::SolariDeferred,
..Default::default()
});
app.world_mut()
.insert_resource(settings::RenderingCapabilities {
rt_supported: true,
..Default::default()
});
let entity = app
.world_mut()
.spawn((LevelObject, LightDesc::for_kind(AuthoringLightKind::Point)))
.id();
flush_level_object_hydration(app.world_mut());
assert!(app.world().get::<PointLight>(entity).is_none());
}
#[test]
fn flush_hydration_keeps_directional_light_when_solari_is_active() {
let mut app = App::new();
app.add_plugins(MinimalPlugins);
app.add_plugins(AssetPlugin::default());
app.add_plugins(bevy::pbr::MaterialPlugin::<StandardMaterial>::default());
app.init_asset::<Mesh>();
app.world_mut()
.insert_resource(settings::ActiveCameraRenderProfile {
gi_path: settings::GiPath::SolariDeferred,
..Default::default()
});
app.world_mut()
.insert_resource(settings::RenderingCapabilities {
rt_supported: true,
..Default::default()
});
let entity = app
.world_mut()
.spawn((
LevelObject,
LightDesc::for_kind(AuthoringLightKind::Directional),
))
.id();
flush_level_object_hydration(app.world_mut());
assert!(app.world().get::<DirectionalLight>(entity).is_some());
}
#[test]
fn flush_hydration_skips_inactive_light_desc() {
let mut app = App::new();