1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::data::Colors;
use egui::DragValue;
#[cfg(feature = "saves")]
use serde::{Deserialize, Serialize};
use std::num::NonZeroU8;
use wgpu::Color;
pub use wgpu::PowerPreference;
/// Global rendering settings
#[derive(Clone)]
#[cfg_attr(feature = "saves", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "saves", serde(default))]
pub struct Settings {
//vsync: bool,
//show_fps: bool,
/// Only redraw scene when window asks for it
pub lazy_draw: bool,
/// Disable storing last redraw in buffer
pub rerender: bool,
/// Number of frame used in temporal anti aliasing, `None` disables taa
///
/// TAA is only crudely applied for a number of fixed frames when the scene stops changing.
/// Defaults to 16 frames.
pub taa: Option<NonZeroU8>,
/// Ground shadow
pub shadow: bool,
/// Background color
pub background_color: Color,
pub mouse_sensitivity: f32,
pub zoom_sensitivity: f32,
pub default_color_map: Colors,
pub fit_camera_on_start: bool,
pub ssao_enabled: bool,
/// When rendering headless, or when the scene was just updated,
/// render n frames instead of only one to leverage temporal
/// accumulation for AA (roundabout way to supersample screenshots).
pub minimum_frame_per_screenshot: NonZeroU8,
/// Preference for which rendering device will be obtained. Defaults to None, taking the
/// first device presented.
///
/// Only read when `run` is called, changing the value has no effect after.
pub power_preference: PowerPreference,
}
impl Default for Settings {
fn default() -> Settings {
Settings {
lazy_draw: true,
rerender: false,
taa: NonZeroU8::new(16),
shadow: true,
background_color: Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
},
mouse_sensitivity: 0.1,
zoom_sensitivity: 0.1,
default_color_map: Colors::Viridis,
fit_camera_on_start: true,
ssao_enabled: true,
minimum_frame_per_screenshot: NonZeroU8::new(16).unwrap(),
power_preference: PowerPreference::None,
}
}
}
impl Settings {
pub fn draw_ui(&mut self, ui: &mut egui::Ui, refresh_screen: &mut bool) {
ui.collapsing("Settings", |ui| {
ui.horizontal(|ui| {
let mut value = self.taa.map(|v| v.get()).unwrap_or(0) as f32;
ui.add(
DragValue::new(&mut value)
.range(0..=64)
.prefix("TAA frames: "),
);
let value = NonZeroU8::new(value as u8);
if self.taa != value {
self.taa = value;
*refresh_screen = true;
}
});
*refresh_screen |= ui.checkbox(&mut self.shadow, "Ground shadow").clicked();
ui.horizontal(|ui| {
ui.add(
DragValue::new(&mut self.mouse_sensitivity)
.range(0. ..=100.)
.speed(0.01)
.prefix("Mouse sensitivity: "),
);
});
ui.horizontal(|ui| {
ui.add(
DragValue::new(&mut self.zoom_sensitivity)
.range(0. ..=100.)
.speed(0.01)
.prefix("Zoom sensitivity: "),
);
});
if ui.checkbox(&mut self.ssao_enabled, "SSAO").changed() {
*refresh_screen = true;
}
});
}
}