euv_core/game/engine3d/quality/
impl.rs1use super::*;
2
3impl Default for RenderQualityConfig {
5 fn default() -> Self {
11 Self::from_preset(QualityPreset::High)
12 }
13}
14
15impl ResolutionPreset {
17 #[must_use]
27 pub const fn dimensions(&self) -> (u32, u32) {
28 match self {
29 Self::Hd720 => (1280, 720),
30 Self::Fhd1080 => (1920, 1080),
31 Self::Qhd1440 => (2560, 1440),
32 Self::Uhd4k => (3840, 2160),
33 }
34 }
35}
36
37impl RenderQualityConfig {
39 #[must_use]
49 pub fn from_preset(preset: QualityPreset) -> Self {
50 match preset {
51 QualityPreset::Low => Self {
52 preset,
53 resolution_preset: ResolutionPreset::Hd720,
54 resolution_scale: 0.55,
55 dynamic_resolution: true,
56 target_fps: 120.0,
57 ray_tracing: RayTracingMode::Off,
58 reflection_bounces: 0,
59 upscaler: UpscalerMode::SpatialFsr,
60 anti_aliasing: AntiAliasingMode::Off,
61 draw_distance: 140.0,
62 lod_bias: 1.5,
63 frustum_culling: true,
64 chunk_streaming: true,
65 volumetric_fog: false,
66 gpu_instancing: true,
67 },
68 QualityPreset::Medium => Self {
69 preset,
70 resolution_preset: ResolutionPreset::Fhd1080,
71 resolution_scale: 0.72,
72 dynamic_resolution: true,
73 target_fps: 60.0,
74 ray_tracing: RayTracingMode::ShadowsOnly,
75 reflection_bounces: 0,
76 upscaler: UpscalerMode::SpatialFsr,
77 anti_aliasing: AntiAliasingMode::Fxaa,
78 draw_distance: 220.0,
79 lod_bias: 1.15,
80 frustum_culling: true,
81 chunk_streaming: true,
82 volumetric_fog: true,
83 gpu_instancing: true,
84 },
85 QualityPreset::High => Self {
86 preset,
87 resolution_preset: ResolutionPreset::Fhd1080,
88 resolution_scale: 0.95,
89 dynamic_resolution: true,
90 target_fps: 60.0,
91 ray_tracing: RayTracingMode::ShadowsAndReflections,
92 reflection_bounces: 1,
93 upscaler: UpscalerMode::SpatialFsr,
94 anti_aliasing: AntiAliasingMode::Fxaa,
95 draw_distance: 320.0,
96 lod_bias: 1.0,
97 frustum_culling: true,
98 chunk_streaming: true,
99 volumetric_fog: true,
100 gpu_instancing: true,
101 },
102 QualityPreset::Ultra => Self {
103 preset,
104 resolution_preset: ResolutionPreset::Qhd1440,
105 resolution_scale: 1.0,
106 dynamic_resolution: false,
107 target_fps: 60.0,
108 ray_tracing: RayTracingMode::ShadowsAndReflections,
109 reflection_bounces: 2,
110 upscaler: UpscalerMode::TemporalTaa,
111 anti_aliasing: AntiAliasingMode::Taa,
112 draw_distance: 420.0,
113 lod_bias: 0.8,
114 frustum_culling: true,
115 chunk_streaming: true,
116 volumetric_fog: true,
117 gpu_instancing: true,
118 },
119 QualityPreset::Cinematic => Self {
120 preset,
121 resolution_preset: ResolutionPreset::Uhd4k,
122 resolution_scale: 1.0,
123 dynamic_resolution: false,
124 target_fps: 60.0,
125 ray_tracing: RayTracingMode::FullPathTracedGi,
126 reflection_bounces: 2,
127 upscaler: UpscalerMode::Native,
128 anti_aliasing: AntiAliasingMode::Taa,
129 draw_distance: 520.0,
130 lod_bias: 0.6,
131 frustum_culling: true,
132 chunk_streaming: true,
133 volumetric_fog: true,
134 gpu_instancing: true,
135 },
136 }
137 }
138
139 pub fn adjust_dynamic_resolution(&mut self, frame_ms: f32) {
146 if !self.get_dynamic_resolution() {
147 return;
148 }
149 let budget_ms: f32 = 1000.0 / self.get_target_fps().max(30.0);
150 let cur: f32 = self.get_resolution_scale();
151 if frame_ms > budget_ms * 1.12 {
152 self.set_resolution_scale((cur - 0.04).clamp(0.40, 1.25));
153 } else if frame_ms < budget_ms * 0.72 {
154 self.set_resolution_scale((cur + 0.02).clamp(0.40, 1.25));
155 }
156 }
157}