use crate::core::{reflect::prelude::*, type_traits::prelude::*};
use serde::{Deserialize, Serialize};
use strum_macros::{AsRefStr, EnumString, VariantNames};
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Reflect)]
pub struct BloomSettings {
pub use_bloom: bool,
pub threshold: f32,
}
impl Default for BloomSettings {
fn default() -> Self {
Self {
use_bloom: true,
threshold: 1.01,
}
}
}
#[derive(
Debug,
Copy,
Clone,
PartialEq,
Default,
Serialize,
Deserialize,
Reflect,
AsRefStr,
EnumString,
VariantNames,
TypeUuidProvider,
)]
#[type_uuid(id = "b1994c1c-bc2f-497c-a05d-062a02b69ff1")]
pub enum LuminanceCalculationMethod {
#[default]
DownSampling,
Histogram,
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Reflect)]
pub struct HdrSettings {
pub use_hdr: bool,
pub luminance_calculation_method: LuminanceCalculationMethod,
#[serde(default)]
pub bloom_settings: BloomSettings,
}
impl Default for HdrSettings {
fn default() -> Self {
Self {
use_hdr: true,
luminance_calculation_method: LuminanceCalculationMethod::DownSampling,
bloom_settings: BloomSettings::default(),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Reflect)]
pub struct QualitySettings {
pub point_shadow_map_size: usize,
pub point_soft_shadows: bool,
pub point_shadows_enabled: bool,
pub point_shadows_distance: f32,
pub point_shadow_map_precision: ShadowMapPrecision,
pub point_shadows_fade_out_range: f32,
pub spot_shadow_map_size: usize,
pub spot_soft_shadows: bool,
pub spot_shadows_enabled: bool,
pub spot_shadows_distance: f32,
pub spot_shadow_map_precision: ShadowMapPrecision,
pub spot_shadows_fade_out_range: f32,
pub csm_settings: CsmSettings,
pub use_ssao: bool,
pub ssao_radius: f32,
pub light_scatter_enabled: bool,
pub fxaa: bool,
pub use_parallax_mapping: bool,
#[serde(default)]
pub use_occlusion_culling: bool,
#[serde(default)]
pub use_light_occlusion_culling: bool,
#[serde(default)]
pub hdr_settings: HdrSettings,
}
impl Default for QualitySettings {
fn default() -> Self {
Self::high()
}
}
impl QualitySettings {
pub fn ultra() -> Self {
Self {
point_shadow_map_size: 2048,
point_shadows_distance: 20.0,
point_shadows_enabled: true,
point_soft_shadows: true,
point_shadows_fade_out_range: 1.0,
spot_shadow_map_size: 2048,
spot_shadows_distance: 20.0,
spot_shadows_enabled: true,
spot_soft_shadows: true,
spot_shadows_fade_out_range: 1.0,
use_ssao: true,
ssao_radius: 0.5,
light_scatter_enabled: true,
point_shadow_map_precision: ShadowMapPrecision::Full,
spot_shadow_map_precision: ShadowMapPrecision::Full,
fxaa: true,
hdr_settings: Default::default(),
use_parallax_mapping: true,
csm_settings: Default::default(),
use_occlusion_culling: false,
use_light_occlusion_culling: false,
}
}
pub fn high() -> Self {
Self {
point_shadow_map_size: 1024,
point_shadows_distance: 15.0,
point_shadows_enabled: true,
point_soft_shadows: true,
point_shadows_fade_out_range: 1.0,
spot_shadow_map_size: 1024,
spot_shadows_distance: 15.0,
spot_shadows_enabled: true,
spot_soft_shadows: true,
spot_shadows_fade_out_range: 1.0,
use_ssao: true,
ssao_radius: 0.5,
light_scatter_enabled: true,
point_shadow_map_precision: ShadowMapPrecision::Full,
spot_shadow_map_precision: ShadowMapPrecision::Full,
fxaa: true,
hdr_settings: Default::default(),
use_parallax_mapping: true,
csm_settings: CsmSettings {
enabled: true,
size: 2048,
precision: ShadowMapPrecision::Full,
pcf: true,
},
use_occlusion_culling: false,
use_light_occlusion_culling: false,
}
}
pub fn medium() -> Self {
Self {
point_shadow_map_size: 512,
point_shadows_distance: 5.0,
point_shadows_enabled: true,
point_soft_shadows: false,
point_shadows_fade_out_range: 1.0,
spot_shadow_map_size: 512,
spot_shadows_distance: 5.0,
spot_shadows_enabled: true,
spot_soft_shadows: false,
spot_shadows_fade_out_range: 1.0,
use_ssao: true,
ssao_radius: 0.5,
light_scatter_enabled: false,
point_shadow_map_precision: ShadowMapPrecision::Half,
spot_shadow_map_precision: ShadowMapPrecision::Half,
fxaa: true,
hdr_settings: Default::default(),
use_parallax_mapping: false,
csm_settings: CsmSettings {
enabled: true,
size: 512,
precision: ShadowMapPrecision::Full,
pcf: false,
},
use_occlusion_culling: false,
use_light_occlusion_culling: false,
}
}
pub fn low() -> Self {
Self {
point_shadow_map_size: 1, point_shadows_distance: 0.0,
point_shadows_enabled: false,
point_soft_shadows: false,
point_shadows_fade_out_range: 1.0,
spot_shadow_map_size: 1,
spot_shadows_distance: 0.0,
spot_shadows_enabled: false,
spot_soft_shadows: false,
spot_shadows_fade_out_range: 1.0,
use_ssao: false,
ssao_radius: 0.5,
light_scatter_enabled: false,
point_shadow_map_precision: ShadowMapPrecision::Half,
spot_shadow_map_precision: ShadowMapPrecision::Half,
fxaa: false,
hdr_settings: HdrSettings {
bloom_settings: BloomSettings {
use_bloom: false,
..Default::default()
},
..Default::default()
},
use_parallax_mapping: false,
csm_settings: CsmSettings {
enabled: true,
size: 512,
precision: ShadowMapPrecision::Half,
pcf: false,
},
use_occlusion_culling: false,
use_light_occlusion_culling: false,
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, Reflect, Eq)]
pub struct CsmSettings {
pub enabled: bool,
pub size: usize,
pub precision: ShadowMapPrecision,
pub pcf: bool,
}
impl Default for CsmSettings {
fn default() -> Self {
Self {
enabled: true,
size: 2048,
precision: ShadowMapPrecision::Full,
pcf: true,
}
}
}
#[derive(
Copy,
Clone,
Hash,
PartialOrd,
PartialEq,
Eq,
Ord,
Debug,
Serialize,
Deserialize,
Reflect,
AsRefStr,
EnumString,
VariantNames,
TypeUuidProvider,
)]
#[type_uuid(id = "f9b2755b-248e-46ba-bcab-473eac1acdb8")]
pub enum ShadowMapPrecision {
Half,
Full,
}