pub(crate) mod prelude {
pub(crate) use super::FastLightSettings;
}
use bevy::{
app::{App, Plugin},
core_pipeline::core_2d::graph::{Core2d, Node2d},
ecs::resource::Resource,
render::{
ExtractSchedule, RenderApp, extract_resource::ExtractResource,
render_graph::RenderGraphExt as _,
},
};
use crate::{
composite::prelude::*, light::prelude::*, occluder::prelude::*, sprite_depth::prelude::*,
};
pub struct FastLightPlugin {
pub texture_scale: f32,
}
impl Default for FastLightPlugin {
fn default() -> Self {
Self { texture_scale: 1. }
}
}
impl Plugin for FastLightPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(FastLightSettings::from(self));
app.add_plugins((
SpriteDepthPlugin,
OccluderPlugin,
MeshLightPlugin,
CompositePlugin,
));
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};
render_app.add_systems(
ExtractSchedule,
(
super::extract::extract_ambient_light,
super::extract::extract_mesh_lights,
super::extract::extract_view_entities,
),
);
render_app.add_render_graph_edges(
Core2d,
(
Node2d::MainOpaquePass,
SpriteDepthLabel,
OccluderLabel,
Node2d::MainTransparentPass,
MeshLightLabel,
CompositeLabel,
Node2d::EndMainPass,
),
);
}
}
#[derive(Resource, Clone, Copy, ExtractResource)]
pub(crate) struct FastLightSettings {
pub(crate) texture_scale: f32,
}
impl From<&FastLightPlugin> for FastLightSettings {
fn from(plugin: &FastLightPlugin) -> Self {
Self {
texture_scale: plugin.texture_scale,
}
}
}