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::{RenderApp, extract_resource::ExtractResource, render_graph::RenderGraphExt as _},
};
use crate::{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, Light2dPlugin));
let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};
render_app.add_render_graph_edges(
Core2d,
(
Node2d::MainOpaquePass,
SpriteDepthLabel,
OccluderLabel,
Node2d::MainTransparentPass,
Light2dLabel,
Node2d::EndMainPass,
Node2d::Tonemapping,
Light2dCompositeLabel,
Node2d::EndMainPassPostProcessing,
),
);
}
}
#[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,
}
}
}