diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 1ff9b384df..08a5677db0 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -55,7 +55,7 @@ use crate::{ ecs::{comp as vcomp, comp::HpFloaterList}, hud::{img_ids::ImgsRot, prompt_dialog::DialogOutcomeEvent}, i18n::Localization, - render::{Consts, Globals, Renderer}, + render::{Consts, Globals, UiDrawer}, scene::camera::{self, Camera}, session::{ settings_change::{Chat as ChatChange, Interface as InterfaceChange, SettingsChange}, @@ -3608,11 +3608,11 @@ impl Hud { events } - pub fn render(&self, renderer: &mut Renderer, globals: &Consts) { + pub fn render<'a>(&'a self, drawer: &mut UiDrawer<'_, 'a>) { span!(_guard, "render", "Hud::render"); // Don't show anything if the UI is toggled off. if self.show.ui { - //self.ui.render(renderer, Some(globals)); + self.ui.render(drawer); } } diff --git a/voxygen/src/menu/main/mod.rs b/voxygen/src/menu/main/mod.rs index dcacf7cd2b..b6e5c2c6d2 100644 --- a/voxygen/src/menu/main/mod.rs +++ b/voxygen/src/menu/main/mod.rs @@ -351,7 +351,7 @@ impl PlayState for MainMenuState { .unwrap() { Some(d) => d, - // Couldn't get swap chain texture this fime + // Couldn't get swap chain texture this frame None => return, }; diff --git a/voxygen/src/render/renderer/binding.rs b/voxygen/src/render/renderer/binding.rs index 5ecfda32cf..691d9660a7 100644 --- a/voxygen/src/render/renderer/binding.rs +++ b/voxygen/src/render/renderer/binding.rs @@ -8,7 +8,6 @@ use super::{ }; impl Renderer { - // TODO: rework this to use the Bound type? pub fn bind_globals( &self, global_model: &GlobalModel, diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index c8f2b0e35f..6c31bd39bf 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -17,8 +17,8 @@ use crate::{ audio::{ambient::AmbientMgr, music::MusicMgr, sfx::SfxMgr, AudioFrontend}, render::{ create_clouds_mesh, create_pp_mesh, create_skybox_mesh, CloudsLocals, CloudsVertex, Consts, - GlobalModel, Globals, Light, Model, PostProcessLocals, PostProcessVertex, Renderer, Shadow, - ShadowLocals, SkyboxVertex, + GlobalModel, Globals, GlobalsBindGroup, Light, Model, PostProcessLocals, PostProcessVertex, + Renderer, Shadow, ShadowLocals, SkyboxVertex, }, settings::Settings, window::{AnalogGameInput, Event}, @@ -41,7 +41,7 @@ use vek::*; // TODO: Don't hard-code this. const CURSOR_PAN_SCALE: f32 = 0.005; -const MAX_LIGHT_COUNT: usize = 31; +const MAX_LIGHT_COUNT: usize = 20; // 31 (total shadow_mats is limited to 128 with default max_uniform_buffer_binding_size) const MAX_SHADOW_COUNT: usize = 24; const NUM_DIRECTED_LIGHTS: usize = 1; const LIGHT_DIST_RADIUS: f32 = 64.0; // The distance beyond which lights may not emit light from their origin @@ -82,6 +82,7 @@ struct PostProcess { pub struct Scene { data: GlobalModel, + globals_bind_group: GlobalsBindGroup, camera: Camera, camera_input_state: Vec2, event_lights: Vec, @@ -275,14 +276,21 @@ impl Scene { let resolution = renderer.resolution().map(|e| e as f32); let sprite_render_context = lazy_init(renderer); + let data = GlobalModel { + globals: renderer.create_consts(&[Globals::default()]), + lights: renderer.create_consts(&[Light::default(); MAX_LIGHT_COUNT]), + shadows: renderer.create_consts(&[Shadow::default(); MAX_SHADOW_COUNT]), + shadow_mats: renderer + .create_consts(&[ShadowLocals::default(); MAX_LIGHT_COUNT * 6 + 6]), + }; + + let lod = Lod::new(renderer, client, settings); + + let globals_bind_group = renderer.bind_globals(&data, lod.get_data()); + Self { - data: GlobalModel { - globals: renderer.create_consts(&[Globals::default()]), - lights: renderer.create_consts(&[Light::default(); MAX_LIGHT_COUNT]), - shadows: renderer.create_consts(&[Shadow::default(); MAX_SHADOW_COUNT]), - shadow_mats: renderer - .create_consts(&[ShadowLocals::default(); MAX_LIGHT_COUNT * 6 + 6]), - }, + data, + globals_bind_group, camera: Camera::new(resolution.x / resolution.y, CameraMode::ThirdPerson), camera_input_state: Vec2::zero(), event_lights: Vec::new(), @@ -299,7 +307,7 @@ impl Scene { locals: renderer.create_consts(&[PostProcessLocals::default()]), }, terrain: Terrain::new(renderer, sprite_render_context), - lod: Lod::new(renderer, client, settings), + lod, loaded_distance: 0.0, map_bounds: Vec2::new( client.world_data().min_chunk_alt(), @@ -992,6 +1000,8 @@ impl Scene { .maintain(audio, scene_data.state, client, &self.camera); } + pub fn global_bind_group(&self) -> &GlobalsBindGroup { &self.globals_bind_group } + /// Render the scene using the provided `Renderer`. pub fn render( &mut self, diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 075ff21c12..c3d2136df3 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -597,14 +597,14 @@ impl Terrain { }, mip_level_count: 1, sample_count: 1, - dimension: wgpu::TextureDimension::D1, + dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, usage: wgpu::TextureUsage::COPY_DST | wgpu::TextureUsage::SAMPLED, }, &wgpu::TextureViewDescriptor { label: Some("Atlas texture view"), format: Some(wgpu::TextureFormat::Rgba8UnormSrgb), - dimension: Some(wgpu::TextureViewDimension::D1), + dimension: Some(wgpu::TextureViewDimension::D2), aspect: wgpu::TextureAspect::All, base_mip_level: 0, level_count: None, diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index 969e70287b..1baf0a8611 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1417,8 +1417,18 @@ impl PlayState for SessionState { &scene_data, ); } + + let mut drawer = match renderer + .start_recording_frame(self.scene.global_bind_group()) + .unwrap() + { + Some(d) => d, + // Couldn't get swap chain texture this frame + None => return, + }; + // Draw the UI to the screen - self.hud.render(renderer, self.scene.globals()); + self.hud.render(&mut drawer.third_pass().draw_ui()); } }