pub struct SkyState {
pub sun_elevation_deg: f64,
pub dust_optical_depth: f64,
}
impl SkyState {
pub fn new(sun_elevation_deg: f64, dust_optical_depth: f64) -> Self {
Self {
sun_elevation_deg,
dust_optical_depth,
}
}
pub fn zenith_color(&self) -> [f64; 3] {
if self.sun_elevation_deg < 0.0 {
return [0.0, 0.0, 0.0];
}
let tau = self.dust_optical_depth;
let elevation_factor = (self.sun_elevation_deg / 90.0).sqrt();
[
(0.7 + 0.2 * tau.min(1.0)) * elevation_factor,
(0.4 + 0.1 * tau.min(1.0)) * elevation_factor,
(0.25 - 0.05 * tau.min(1.0)).max(0.05) * elevation_factor,
]
}
pub fn sunset_color(&self) -> [f64; 3] {
if self.sun_elevation_deg > 10.0 || self.sun_elevation_deg < -5.0 {
return self.zenith_color();
}
[0.15, 0.25, 0.55]
}
pub fn horizon_glow(&self) -> f64 {
if self.sun_elevation_deg < -18.0 {
return 0.0;
}
let factor = ((self.sun_elevation_deg + 18.0) / 28.0).clamp(0.0, 1.0);
factor * (1.0 - (-self.dust_optical_depth).exp())
}
}