use bevy::prelude::*;
#[derive(Resource, Debug, Default, Clone, Copy)]
pub struct ViewPos(pub Vec2);
#[derive(Resource, Debug, Default, Clone, Copy)]
pub struct ViewDetail(pub f32);
#[derive(Resource, Debug, Default, Clone, Copy)]
pub struct ViewSeaLevel(pub f32);
#[derive(Resource, Debug, Default, Clone, Copy)]
pub struct ViewOrder(pub isize);
#[derive(Component, Debug, Clone, Copy, bevy::render::extract_component::ExtractComponent)]
pub struct OceanView;
const MIN_SCREEN_SAMPLES_PER_WAVE: f32 = 4.0;
const BASE_MIN_WAVELENGTH: f32 = 0.75;
pub fn projected_detail_lod(altitude: f32, projection: &Projection, viewport_height: f32) -> f32 {
let world_height = match projection {
Projection::Perspective(projection) => 2.0 * altitude * (0.5 * projection.fov).tan(),
Projection::Orthographic(projection) => projection.area.height(),
Projection::Custom(_) => return 0.0,
};
let minimum_wavelength = MIN_SCREEN_SAMPLES_PER_WAVE * world_height / viewport_height;
(minimum_wavelength / BASE_MIN_WAVELENGTH)
.log2()
.clamp(0.0, (crate::cascade::LOD_COUNT - 1) as f32)
}