add slider for rain map resolution

This commit is contained in:
IsseW 2022-04-06 14:00:06 +02:00
parent 6d40caed23
commit 08b0989789
9 changed files with 101 additions and 35 deletions

View File

@ -106,6 +106,7 @@
"hud.settings.shadow_rendering_mode.cheap": "Cheap",
"hud.settings.shadow_rendering_mode.map": "Map",
"hud.settings.shadow_rendering_mode.map.resolution": "Resolution",
"hud.settings.rain_occlusion.resolution": "Rain Occlusion Resolution",
"hud.settings.lod_detail": "LoD Detail",
"hud.settings.save_window_size": "Save window size",
"hud.settings.reset_graphics": "Reset to Defaults",

View File

@ -48,7 +48,7 @@ use common::{
trade::{PendingTrade, SitePrices, TradeAction, TradeId, TradeResult},
uid::{Uid, UidAllocator},
vol::RectVolSize,
weather::{self, Weather, WeatherGrid},
weather::{Weather, WeatherGrid},
};
#[cfg(feature = "tracy")] use common_base::plot;
use common_base::{prof_span, span};

View File

@ -15,7 +15,7 @@ use common::{
trade::{PendingTrade, SitePrices, TradeId, TradeResult},
uid::Uid,
uuid::Uuid,
weather::{Weather, WeatherGrid},
weather::WeatherGrid,
};
use hashbrown::HashMap;
use serde::{Deserialize, Serialize};

View File

@ -101,7 +101,6 @@ use common::{
uid::Uid,
util::{srgba_to_linear, Dir},
vol::RectRasterableVol,
weather::Weather,
};
use common_base::{prof_span, span};
use common_net::{

View File

@ -116,6 +116,9 @@ widget_ids! {
shadow_mode_map_resolution_text,
shadow_mode_map_resolution_slider,
shadow_mode_map_resolution_value,
rain_map_resolution_text,
rain_map_resolution_slider,
rain_map_resolution_value,
save_window_size_button,
}
@ -1116,11 +1119,51 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.shadow_mode_map_resolution_value, ui);
}
// Rain occlusion texture size
// Display the shadow map mode if selected.
Text::new(
self.localized_strings
.get("hud.settings.rain_occlusion.resolution"),
)
.down_from(state.ids.shadow_mode_list, 10.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.rain_map_resolution_text, ui);
if let Some(new_val) = ImageSlider::discrete(
(render_mode.rain_occlusion.resolution.log2() * 4.0).round() as i8,
-8,
8,
self.imgs.slider_indicator,
self.imgs.slider,
)
.w_h(104.0, 22.0)
.right_from(state.ids.rain_map_resolution_text, 8.0)
.track_breadth(12.0)
.slider_length(10.0)
.pad_track((5.0, 5.0))
.set(state.ids.rain_map_resolution_slider, ui)
{
events.push(GraphicsChange::ChangeRenderMode(Box::new(RenderMode {
rain_occlusion: ShadowMapMode {
resolution: 2.0f32.powf(f32::from(new_val) / 4.0),
},
..render_mode.clone()
})));
}
Text::new(&format!("{}", render_mode.rain_occlusion.resolution))
.right_from(state.ids.rain_map_resolution_slider, 8.0)
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.color(TEXT_COLOR)
.set(state.ids.rain_map_resolution_value, ui);
// GPU Profiler
Text::new(self.localized_strings.get("hud.settings.gpu_profiler"))
.font_size(self.fonts.cyri.scale(14))
.font_id(self.fonts.cyri.conrod_id)
.down_from(state.ids.shadow_mode_list, 8.0)
.down_from(state.ids.rain_map_resolution_text, 8.0)
.color(TEXT_COLOR)
.set(state.ids.gpu_profiler_label, ui);

View File

@ -11,7 +11,8 @@
trait_alias,
option_get_or_insert_default,
map_try_insert,
slice_as_chunks
slice_as_chunks,
unzip_option
)]
#![recursion_limit = "2048"]

View File

@ -347,6 +347,7 @@ pub struct RenderMode {
pub fluid: FluidMode,
pub lighting: LightingMode,
pub shadow: ShadowMode,
pub rain_occlusion: ShadowMapMode,
pub bloom: BloomMode,
/// 0.0..1.0
pub point_glow: f32,
@ -366,6 +367,8 @@ impl Default for RenderMode {
fluid: FluidMode::default(),
lighting: LightingMode::default(),
shadow: ShadowMode::default(),
// TODO: should 0.5 be default for rain_occlusion?
rain_occlusion: ShadowMapMode { resolution: 0.5 },
bloom: BloomMode::default(),
point_glow: 0.35,
experimental_shaders: HashSet::default(),
@ -385,6 +388,7 @@ impl RenderMode {
fluid: self.fluid,
lighting: self.lighting,
shadow: self.shadow,
rain_occlusion: self.rain_occlusion,
bloom: self.bloom,
point_glow: self.point_glow,
experimental_shaders: self.experimental_shaders,
@ -407,6 +411,7 @@ pub struct PipelineModes {
fluid: FluidMode,
lighting: LightingMode,
pub shadow: ShadowMode,
pub rain_occlusion: ShadowMapMode,
bloom: BloomMode,
point_glow: f32,
experimental_shaders: HashSet<ExperimentalShader>,

View File

@ -369,7 +369,7 @@ impl Renderer {
let rain_occlusion_view = RainOcclusionMap::create_view(
&device,
(dims.width, dims.height),
&ShadowMapMode::try_from(pipeline_modes.shadow).unwrap_or_default(),
&pipeline_modes.rain_occlusion,
)
.map_err(|err| {
warn!("Could not create rain occlusion map views: {:?}", err);
@ -724,48 +724,65 @@ impl Renderer {
State::Nothing => None, // Should never hit this
};
if let (Some(((point_depth, directed_depth), rain_depth)), ShadowMode::Map(mode)) =
let mut update_shadow_bind = false;
let (shadow_views, rain_views) = shadow_views.unzip();
if let (Some((point_depth, directed_depth)), ShadowMode::Map(mode)) =
(shadow_views, self.pipeline_modes.shadow)
{
match (
ShadowMap::create_shadow_views(&self.device, (dims.x, dims.y), &mode),
RainOcclusionMap::create_view(&self.device, (dims.x, dims.y), &mode),
) {
(Ok((new_point_depth, new_directed_depth)), Ok(new_rain_depth)) => {
match ShadowMap::create_shadow_views(&self.device, (dims.x, dims.y), &mode) {
Ok((new_point_depth, new_directed_depth)) => {
*point_depth = new_point_depth;
*directed_depth = new_directed_depth;
*rain_depth = new_rain_depth;
// Recreate the shadow bind group if needed
if let State::Complete {
shadow:
Shadow {
bind,
map: ShadowMap::Enabled(shadow_map),
rain_map: RainOcclusionMap::Enabled(rain_occlusion_map),
..
},
..
} = &mut self.state
{
*bind = self.layouts.global.bind_shadow_textures(
&self.device,
&shadow_map.point_depth,
&shadow_map.directed_depth,
&rain_occlusion_map.depth,
);
}
update_shadow_bind = true;
},
(shadow, rain) => {
shadow => {
if let Err(err) = shadow {
warn!("Could not create shadow map views: {:?}", err);
}
},
}
}
if let Some(rain_depth) = rain_views {
match RainOcclusionMap::create_view(
&self.device,
(dims.x, dims.y),
&self.pipeline_modes.rain_occlusion,
) {
Ok(new_rain_depth) => {
*rain_depth = new_rain_depth;
update_shadow_bind = true;
},
rain => {
if let Err(err) = rain {
warn!("Could not create rain occlusion map view: {:?}", err);
}
},
}
}
if update_shadow_bind {
// Recreate the shadow bind group if needed
if let State::Complete {
shadow:
Shadow {
bind,
map: ShadowMap::Enabled(shadow_map),
rain_map: RainOcclusionMap::Enabled(rain_occlusion_map),
..
},
..
} = &mut self.state
{
*bind = self.layouts.global.bind_shadow_textures(
&self.device,
&shadow_map.point_depth,
&shadow_map.directed_depth,
&rain_occlusion_map.depth,
);
}
}
} else {
self.is_minimized = true;
}

View File

@ -266,8 +266,8 @@ impl SessionState {
| InventoryUpdateEvent::Swapped
| InventoryUpdateEvent::Given
| InventoryUpdateEvent::Collected(_)
| InventoryUpdateEvent::EntityCollectFailed(_)
| InventoryUpdateEvent::BlockCollectFailed(_)
| InventoryUpdateEvent::EntityCollectFailed { .. }
| InventoryUpdateEvent::BlockCollectFailed { .. }
| InventoryUpdateEvent::Craft => {
global_state
.audio