use crate::math::Color;
#[derive(Debug, Clone, Copy)]
pub struct AtmosphereMaterial {
pub color: Color,
pub sunset_color: Color,
pub planet_radius: f32,
pub atmosphere_radius: f32,
pub intensity: f32,
pub falloff: f32,
pub opacity: f32,
pub airglow: f32,
pub airglow_color: Color,
pub ozone: f32,
pub aurora: f32,
pub aurora_color: Color,
pub aurora_colatitude: f32,
pub render_state: super::RenderState,
}
impl Default for AtmosphereMaterial {
fn default() -> Self {
Self::new(1.0, 1.025)
}
}
impl AtmosphereMaterial {
pub fn new(planet_radius: f32, atmosphere_radius: f32) -> Self {
Self {
color: Color::new(0.30, 0.55, 1.0),
sunset_color: Color::new(1.0, 0.48, 0.20),
planet_radius: planet_radius.max(1e-4),
atmosphere_radius: atmosphere_radius.max(planet_radius * 1.0001),
intensity: 1.5,
falloff: 3.0,
opacity: 1.0,
airglow: 0.0,
airglow_color: Color::new(0.35, 1.0, 0.55),
ozone: 0.0,
aurora: 0.0,
aurora_color: Color::new(0.25, 1.0, 0.45),
render_state: super::RenderState::DEFAULT,
aurora_colatitude: 23.0,
}
}
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self
}
pub fn sunset_color(mut self, color: Color) -> Self {
self.sunset_color = color;
self
}
pub fn intensity(mut self, intensity: f32) -> Self {
self.intensity = intensity.max(0.0);
self
}
pub fn falloff(mut self, falloff: f32) -> Self {
self.falloff = falloff.clamp(0.1, 32.0);
self
}
pub fn ozone(mut self, ozone: f32) -> Self {
self.ozone = ozone.max(0.0);
self
}
pub fn aurora(mut self, strength: f32, color: Color, colatitude: f32) -> Self {
self.aurora = strength.max(0.0);
self.aurora_color = color;
self.aurora_colatitude = colatitude.clamp(1.0, 89.0);
self
}
pub fn opacity(mut self, opacity: f32) -> Self {
self.opacity = opacity.clamp(0.0, 1.0);
self
}
pub fn airglow(mut self, strength: f32) -> Self {
self.airglow = strength.max(0.0);
self
}
pub fn airglow_color(mut self, color: Color) -> Self {
self.airglow_color = color;
self
}
pub fn thickness(&self) -> f32 {
(self.atmosphere_radius - self.planet_radius).max(1e-5)
}
}