use std::usize;
use bevy::{
camera::visibility::RenderLayers,
color::palettes::css::WHITE,
prelude::*,
render::{extract_component::ExtractComponent, render_resource::ShaderType},
};
#[derive(Component, Default, Clone, ExtractComponent, Reflect)]
pub(crate) struct ExtractedWorldData {
pub camera_pos: Vec2,
}
#[derive(Debug, Component, ExtractComponent, Clone, Reflect)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[require(Transform, RenderLayers)]
pub struct FireflyConfig {
pub ambient_color: Color,
pub ambient_brightness: f32,
pub light_bands: Option<f32>,
pub soft_shadows: bool,
pub z_sorting: bool,
pub z_sorting_error_margin: f32,
pub normal_mode: NormalMode,
pub normal_attenuation: f32,
pub combination_mode: CombinationMode,
pub lightmap_size: LightmapSize,
pub lightmap_filtering: bool,
pub enable_32bit_stencils: bool,
}
#[derive(Clone, Copy, Reflect, Default, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CombinationMode {
#[default]
Multiply,
Max,
Min,
Add,
None,
}
#[derive(Clone, Copy, Reflect, Default, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum LightmapSize {
#[default]
Window,
Fixed(UVec2),
Scaled(f32),
}
#[derive(Debug, Clone, Reflect)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum NormalMode {
None,
Simple,
TopDownY,
TopDownZ,
}
impl Default for FireflyConfig {
fn default() -> Self {
Self {
ambient_color: Color::Srgba(WHITE),
ambient_brightness: 0.0,
light_bands: None,
soft_shadows: true,
z_sorting: true,
z_sorting_error_margin: 0.0,
normal_mode: NormalMode::None,
normal_attenuation: 0.5,
combination_mode: CombinationMode::Multiply,
lightmap_size: LightmapSize::Window,
lightmap_filtering: true,
enable_32bit_stencils: false,
}
}
}
#[derive(ShaderType, Clone)]
pub struct UniformFireflyConfig {
pub ambient_color: Vec3,
pub ambient_brightness: f32,
pub light_bands: f32,
pub soft_shadows: u32,
pub z_sorting: u32,
pub z_sorting_error_margin: f32,
pub normal_mode: u32,
pub normal_attenuation: f32,
pub n_combined_lightmaps: u32,
pub combination_mode: u32,
pub texture_scale: Vec2,
}
#[derive(Component)]
#[relationship(relationship_target = CombinedLightmaps)]
pub struct CombineLightmapTo(pub Entity);
#[derive(Component)]
#[relationship_target(relationship = CombineLightmapTo, linked_spawn)]
pub struct CombinedLightmaps(Vec<Entity>);
#[derive(Component)]
pub struct ExtractedCombinedLightmaps(pub Vec<Entity>);
#[derive(Component)]
pub struct ExtractedCombineLightmapTo(pub Entity, pub u32);