diff --git a/CHANGELOG.md b/CHANGELOG.md index 0559a4dd4d..7bcc7d88b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Allow spawning individual pet species, not just generic body kinds. - Configurable fonts - Tanslation status tracking +- Added gamma setting ### Changed diff --git a/assets/voxygen/i18n/en.ron b/assets/voxygen/i18n/en.ron index e09f419d0a..f13969a9b5 100644 --- a/assets/voxygen/i18n/en.ron +++ b/assets/voxygen/i18n/en.ron @@ -208,6 +208,7 @@ Enjoy your stay in the World of Veloren."#, "hud.settings.view_distance": "View Distance", "hud.settings.maximum_fps": "Maximum FPS", "hud.settings.fov": "Field of View (deg)", + "hud.settings.gamma": "Gamma", "hud.settings.antialiasing_mode": "AntiAliasing Mode", "hud.settings.cloud_rendering_mode": "Cloud Rendering Mode", "hud.settings.fluid_rendering_mode": "Fluid Rendering Mode", diff --git a/assets/voxygen/shaders/include/globals.glsl b/assets/voxygen/shaders/include/globals.glsl index 471320a7ef..e0e97949e2 100644 --- a/assets/voxygen/shaders/include/globals.glsl +++ b/assets/voxygen/shaders/include/globals.glsl @@ -12,4 +12,5 @@ uniform u_globals { uvec4 light_shadow_count; uvec4 medium; ivec4 select_pos; + vec4 gamma; }; diff --git a/assets/voxygen/shaders/postprocess-frag.glsl b/assets/voxygen/shaders/postprocess-frag.glsl index 4193bda525..cd0c87a772 100644 --- a/assets/voxygen/shaders/postprocess-frag.glsl +++ b/assets/voxygen/shaders/postprocess-frag.glsl @@ -45,7 +45,7 @@ void main() { //hsva_color.z = 1.0 - 1.0 / (1.0 * hsva_color.z + 1.0); //vec4 final_color = vec4(hsv2rgb(hsva_color.rgb), hsva_color.a); - vec4 final_color = aa_color; + vec4 final_color = pow(aa_color, gamma); if (medium.x == 1u) { final_color *= vec4(0.2, 0.2, 0.8, 1.0); diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index ae2bc278de..023a701d71 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -201,6 +201,7 @@ pub enum Event { ChangeAudioDevice(String), ChangeMaxFPS(u32), ChangeFOV(u16), + ChangeGamma(f32), AdjustWindowSize([u16; 2]), ToggleFullscreen, ChangeAaMode(AaMode), @@ -1762,6 +1763,9 @@ impl Hud { settings_window::Event::AdjustFOV(new_fov) => { events.push(Event::ChangeFOV(new_fov)); }, + settings_window::Event::AdjustGamma(new_gamma) => { + events.push(Event::ChangeGamma(new_gamma)); + }, settings_window::Event::ChangeAaMode(new_aa_mode) => { events.push(Event::ChangeAaMode(new_aa_mode)); }, diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index 58b71226de..1c63978804 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -89,6 +89,9 @@ widget_ids! { fov_slider, fov_text, fov_value, + gamma_slider, + gamma_text, + gamma_value, aa_mode_text, aa_mode_list, cloud_mode_text, @@ -199,6 +202,7 @@ pub enum Event { ToggleMouseYInvert(bool), AdjustViewDistance(u32), AdjustFOV(u16), + AdjustGamma(f32), AdjustWindowSize([u16; 2]), ToggleFullscreen, ChangeAaMode(AaMode), @@ -1554,9 +1558,41 @@ impl<'a> Widget for SettingsWindow<'a> { .color(TEXT_COLOR) .set(state.ids.fov_value, ui); + // Gamma + Text::new(&self.localized_strings.get("hud.settings.gamma")) + .down_from(state.ids.fov_slider, 10.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .color(TEXT_COLOR) + .set(state.ids.gamma_text, ui); + + if let Some(new_val) = ImageSlider::discrete( + (self.global_state.settings.graphics.gamma.log2() * 8.0).round() as i32, + 8, + -8, + self.imgs.slider_indicator, + self.imgs.slider, + ) + .w_h(104.0, 22.0) + .down_from(state.ids.gamma_text, 8.0) + .track_breadth(12.0) + .slider_length(10.0) + .pad_track((5.0, 5.0)) + .set(state.ids.gamma_slider, ui) + { + events.push(Event::AdjustGamma(2.0f32.powf(new_val as f32 / 8.0))); + } + + Text::new(&format!("{}", self.global_state.settings.graphics.gamma)) + .right_from(state.ids.gamma_slider, 8.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .color(TEXT_COLOR) + .set(state.ids.gamma_value, ui); + // AaMode Text::new(&self.localized_strings.get("hud.settings.antialiasing_mode")) - .down_from(state.ids.fov_slider, 8.0) + .down_from(state.ids.gamma_slider, 8.0) .font_size(self.fonts.cyri.scale(14)) .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index a3691c3bea..6dc28fb820 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -99,6 +99,7 @@ impl PlayState for CharSelectionState { global_state.window.renderer_mut(), &self.client.borrow(), humanoid_body.clone(), + global_state.settings.graphics.gamma, ); // Render the scene. diff --git a/voxygen/src/menu/char_selection/scene.rs b/voxygen/src/menu/char_selection/scene.rs index a28d502dfd..c09f794013 100644 --- a/voxygen/src/menu/char_selection/scene.rs +++ b/voxygen/src/menu/char_selection/scene.rs @@ -119,6 +119,7 @@ impl Scene { renderer: &mut Renderer, client: &Client, body: Option, + gamma: f32, ) { self.camera.set_focus_pos(Vec3::unit_z() * 1.5); self.camera.update(client.state().get_time()); @@ -142,6 +143,7 @@ impl Scene { 0, BlockKind::Air, None, + gamma, )]) { error!("Renderer failed to update: {:?}", err); } diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index c797fcd96e..4e6fd5b282 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -26,6 +26,7 @@ gfx_defines! { light_shadow_count: [u32; 4] = "light_shadow_count", medium: [u32; 4] = "medium", select_pos: [i32; 4] = "select_pos", + gamma: [f32; 4] = "gamma", } constant Light { @@ -53,6 +54,7 @@ impl Globals { shadow_count: usize, medium: BlockKind, select_pos: Option>, + gamma: f32, ) -> Self { Self { view_mat: arr_to_mat(view_mat.into_col_array()), @@ -70,6 +72,7 @@ impl Globals { .map(|sp| Vec4::from(sp) + Vec4::unit_w()) .unwrap_or(Vec4::zero()) .into_array(), + gamma: [gamma; 4], } } } @@ -89,6 +92,7 @@ impl Default for Globals { 0, BlockKind::Air, None, + 1.0, ) } } diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index fd54ae6b62..6653a75e8e 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -149,6 +149,7 @@ impl Scene { renderer: &mut Renderer, audio: &mut AudioFrontend, client: &Client, + gamma: f32, ) { // Get player position. let player_pos = client @@ -296,6 +297,7 @@ impl Scene { .map(|b| b.kind()) .unwrap_or(BlockKind::Air), self.select_pos, + gamma, )]) .expect("Failed to update global constants"); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8dfc6595c8..a45ab1ad0f 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -551,6 +551,10 @@ impl PlayState for SessionState { global_state.settings.save_to_file_warn(); self.scene.camera_mut().set_fov_deg(new_fov); }, + HudEvent::ChangeGamma(new_gamma) => { + global_state.settings.graphics.gamma = new_gamma; + global_state.settings.save_to_file_warn(); + }, HudEvent::ChangeAaMode(new_aa_mode) => { // Do this first so if it crashes the setting isn't saved :) global_state @@ -610,6 +614,7 @@ impl PlayState for SessionState { global_state.window.renderer_mut(), &mut global_state.audio, &self.client.borrow(), + global_state.settings.graphics.gamma, ); // Render the session. diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 9b4f5f6922..8d339f2837 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -191,6 +191,7 @@ pub struct GraphicsSettings { pub view_distance: u32, pub max_fps: u32, pub fov: u16, + pub gamma: f32, pub aa_mode: AaMode, pub cloud_mode: CloudMode, pub fluid_mode: FluidMode, @@ -204,6 +205,7 @@ impl Default for GraphicsSettings { view_distance: 10, max_fps: 60, fov: 50, + gamma: 1.0, aa_mode: AaMode::Fxaa, cloud_mode: CloudMode::Regular, fluid_mode: FluidMode::Shiny,