From a23433b402ea71e5cd9b709b681a32cd6b21f9a1 Mon Sep 17 00:00:00 2001 From: Monty Marz Date: Wed, 8 Sep 2021 09:50:37 +0000 Subject: [PATCH] Bloom settings --- CHANGELOG.md | 1 + assets/voxygen/i18n/en/hud/settings.ron | 1 + voxygen/src/hud/settings_window/video.rs | 67 ++++++++++++++++++++++-- voxygen/src/render/mod.rs | 19 ++++--- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df2a2b272..0fc6c46810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Sprite pickup animations - Add VELOREN_ASSETS_OVERRIDE variable for specifying folder to partially override assets. - Cultist raiders +- Bloom Slider ### Changed diff --git a/assets/voxygen/i18n/en/hud/settings.ron b/assets/voxygen/i18n/en/hud/settings.ron index f16d039e63..fe1a6f241d 100644 --- a/assets/voxygen/i18n/en/hud/settings.ron +++ b/assets/voxygen/i18n/en/hud/settings.ron @@ -100,6 +100,7 @@ "hud.settings.lod_detail": "LoD Detail", "hud.settings.save_window_size": "Save window size", "hud.settings.reset_graphics": "Reset to Defaults", + "hud.settings.bloom": "Bloom", "hud.settings.master_volume": "Master Volume", "hud.settings.inactive_master_volume_perc": "Inactive Window Volume", diff --git a/voxygen/src/hud/settings_window/video.rs b/voxygen/src/hud/settings_window/video.rs index e577ecb6d6..3f720e327b 100644 --- a/voxygen/src/hud/settings_window/video.rs +++ b/voxygen/src/hud/settings_window/video.rs @@ -6,8 +6,8 @@ use crate::{ TEXT_COLOR, }, render::{ - AaMode, CloudMode, FluidMode, LightingMode, PresentMode, RenderMode, ShadowMapMode, - ShadowMode, UpscaleMode, + AaMode, BloomConfig, BloomFactor, BloomMode, CloudMode, FluidMode, LightingMode, + PresentMode, RenderMode, ShadowMapMode, ShadowMode, UpscaleMode, }, session::settings_change::Graphics as GraphicsChange, settings::Fps, @@ -67,6 +67,11 @@ widget_ids! { ambiance_value, aa_mode_text, aa_mode_list, + // + bloom_intensity_text, + bloom_intensity_slider, + bloom_intensity_value, + // upscale_factor_text, upscale_factor_list, cloud_mode_text, @@ -101,6 +106,7 @@ widget_ids! { shadow_mode_map_resolution_slider, shadow_mode_map_resolution_value, save_window_size_button, + } } @@ -646,9 +652,64 @@ impl<'a> Widget for Video<'a> { }))); } + // Bloom + let bloom_intensity = match render_mode.bloom { + BloomMode::Off => 0.0, + BloomMode::On(bloom) => bloom.factor.fraction(), + }; + let max_bloom = 0.3; + let bloom_value = ((bloom_intensity * 100.0 / max_bloom) as i32).to_string(); + + Text::new(self.localized_strings.get("hud.settings.bloom")) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .down_from(state.ids.aa_mode_list, 10.0) + .color(TEXT_COLOR) + .set(state.ids.bloom_intensity_text, ui); + if let Some(new_val) = ImageSlider::continuous( + bloom_intensity, + 0.0, + max_bloom, + self.imgs.slider_indicator, + self.imgs.slider, + ) + .w_h(104.0, 22.0) + .down_from(state.ids.bloom_intensity_text, 8.0) + .track_breadth(12.0) + .slider_length(10.0) + .pad_track((5.0, 5.0)) + .set(state.ids.bloom_intensity_slider, ui) + { + if new_val > f32::EPSILON { + // Toggle Bloom On and set Custom value to new_val + events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode { + bloom: { + BloomMode::On(BloomConfig { + factor: BloomFactor::Custom(new_val), + // TODO: Decide if this should be a separate setting + uniform_blur: false, + }) + }, + ..render_mode.clone() + }))) + } else { + // Toggle Bloom Off if the value is near 0 + events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode { + bloom: { BloomMode::Off }, + ..render_mode.clone() + }))) + } + } + Text::new(&format!("{}%", &bloom_value)) + .right_from(state.ids.bloom_intensity_slider, 8.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .color(TEXT_COLOR) + .set(state.ids.bloom_intensity_value, ui); + // Upscaling factor Text::new(self.localized_strings.get("hud.settings.upscale_factor")) - .down_from(state.ids.aa_mode_list, 8.0) + .down_from(state.ids.bloom_intensity_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/render/mod.rs b/voxygen/src/render/mod.rs index 26006ad843..594a114384 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -275,11 +275,11 @@ pub enum BloomFactor { Custom(f32), // other variant has to be placed last #[serde(other)] - Standard, + Medium, } impl Default for BloomFactor { - fn default() -> Self { Self::Standard } + fn default() -> Self { Self::Low } } impl BloomFactor { @@ -287,7 +287,7 @@ impl BloomFactor { pub fn fraction(self) -> f32 { match self { Self::Low => 0.05, - Self::Standard => 0.10, + Self::Medium => 0.10, Self::High => 0.25, Self::Custom(val) => val.max(0.0).min(1.0), } @@ -299,14 +299,14 @@ impl BloomFactor { pub struct BloomConfig { /// Controls fraction of output image luminosity that is blurred bloom /// - /// Defaults to `Standard` - factor: BloomFactor, + /// Defaults to `Low` + pub factor: BloomFactor, /// Turning this on make the bloom blur less sharply concentrated around the /// high intensity phenomena (removes adding in less blurred layers to the /// final blur) /// /// Defaults to `false` - uniform_blur: bool, + pub uniform_blur: bool, // TODO: allow configuring the blur radius and/or the number of passes } @@ -318,7 +318,12 @@ pub enum BloomMode { } impl Default for BloomMode { - fn default() -> Self { Self::Off } + fn default() -> Self { + Self::On(BloomConfig { + factor: BloomFactor::default(), + uniform_blur: false, + }) + } } impl BloomMode {