diff --git a/assets/voxygen/shaders/clouds-frag.glsl b/assets/voxygen/shaders/clouds-frag.glsl index a8470c82d8..fd9a402b76 100644 --- a/assets/voxygen/shaders/clouds-frag.glsl +++ b/assets/voxygen/shaders/clouds-frag.glsl @@ -65,6 +65,7 @@ vec3 wpos_at(vec2 uv) { } void main() { + // TODO: precompute in the vertex shader? vec2 uv = (f_pos + 1.0) * 0.5; vec4 color = texture(sampler2D(t_src_color, s_src_color), uv); diff --git a/assets/voxygen/shaders/clouds-vert.glsl b/assets/voxygen/shaders/clouds-vert.glsl index da3c4b312d..6a4b469af1 100644 --- a/assets/voxygen/shaders/clouds-vert.glsl +++ b/assets/voxygen/shaders/clouds-vert.glsl @@ -18,12 +18,16 @@ #include -layout(location = 0) in vec2 v_pos; - layout(location = 0) out vec2 f_pos; void main() { + // Generate fullscreen triangle + vec2 v_pos = vec2( + float(gl_VertexIndex / 2) * 4.0 - 1.0, + float(gl_VertexIndex % 2) * 4.0 - 1.0 + ); + f_pos = v_pos; - gl_Position = vec4(v_pos, -1.0, 1.0); + gl_Position = vec4(v_pos, 0.0, 1.0); } diff --git a/assets/voxygen/shaders/postprocess-frag.glsl b/assets/voxygen/shaders/postprocess-frag.glsl index 31cbcf2a7e..23f45fb4f2 100644 --- a/assets/voxygen/shaders/postprocess-frag.glsl +++ b/assets/voxygen/shaders/postprocess-frag.glsl @@ -180,6 +180,7 @@ vec3 wpos_at(vec2 uv) { */ void main() { + // TODO: precompute in the vertex shader? vec2 uv = (f_pos + 1.0) * 0.5; /* if (medium.x == 1u) { diff --git a/assets/voxygen/shaders/postprocess-vert.glsl b/assets/voxygen/shaders/postprocess-vert.glsl index da3c4b312d..5afae03464 100644 --- a/assets/voxygen/shaders/postprocess-vert.glsl +++ b/assets/voxygen/shaders/postprocess-vert.glsl @@ -23,7 +23,13 @@ layout(location = 0) in vec2 v_pos; layout(location = 0) out vec2 f_pos; void main() { + // Generate fullscreen triangle + vec2 v_pos = vec2( + float(gl_VertexIndex / 2) * 4.0 - 1.0, + float(gl_VertexIndex % 2) * 4.0 - 1.0 + ); + f_pos = v_pos; - gl_Position = vec4(v_pos, -1.0, 1.0); + gl_Position = vec4(v_pos, 0.0, 1.0); } diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 7751c6dba9..6e04d71862 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -240,8 +240,15 @@ impl PlayState for CharSelectionState { //self.scene // .render(renderer, client.get_tick(), humanoid_body, loadout); + // Render world + /* let mut first_pass = */ + drawer.first_pass(); + // Clouds + drawer.second_pass().draw_clouds(); + // PostProcess and UI + let mut third_pass = drawer.third_pass(); + third_pass.draw_post_process(); // Draw the UI to the screen. - self.char_selection_ui - .render(&mut drawer.third_pass().draw_ui()); + self.char_selection_ui.render(&mut third_pass.draw_ui()); } } diff --git a/voxygen/src/render/mod.rs b/voxygen/src/render/mod.rs index 9a4230f514..32b42581eb 100644 --- a/voxygen/src/render/mod.rs +++ b/voxygen/src/render/mod.rs @@ -19,9 +19,7 @@ pub use self::{ mesh::{Mesh, Quad, Tri}, model::{DynamicModel, Model, SubModel}, pipelines::{ - clouds::{ - create_mesh as create_clouds_mesh, Locals as CloudsLocals, Vertex as CloudsVertex, - }, + clouds::Locals as CloudsLocals, figure::{ BoneData as FigureBoneData, BoneMeshes, FigureLayout, FigureModel, Locals as FigureLocals, @@ -29,9 +27,7 @@ pub use self::{ fluid::Vertex as FluidVertex, lod_terrain::{LodData, Vertex as LodTerrainVertex}, particle::{Instance as ParticleInstance, Vertex as ParticleVertex}, - postprocess::{ - create_mesh as create_pp_mesh, Locals as PostProcessLocals, Vertex as PostProcessVertex, - }, + postprocess::Locals as PostProcessLocals, shadow::Locals as ShadowLocals, skybox::{create_mesh as create_skybox_mesh, Vertex as SkyboxVertex}, sprite::{Instance as SpriteInstance, Locals as SpriteLocals, Vertex as SpriteVertex}, diff --git a/voxygen/src/render/pipelines/clouds.rs b/voxygen/src/render/pipelines/clouds.rs index ec65f6eb5b..62e82f9023 100644 --- a/voxygen/src/render/pipelines/clouds.rs +++ b/voxygen/src/render/pipelines/clouds.rs @@ -1,5 +1,5 @@ use super::{ - super::{AaMode, Mesh, Tri}, + super::{AaMode, Bound, Consts, Mesh, Tri}, GlobalsLayouts, }; use bytemuck::{Pod, Zeroable}; @@ -25,7 +25,7 @@ impl Locals { } } -#[repr(C)] +/*#[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] pub struct Vertex { pos: [f32; 2], @@ -62,6 +62,10 @@ pub fn create_mesh() -> Mesh { )); mesh +}*/ + +pub struct BindGroup { + pub(in super::super) bind_group: wgpu::BindGroup, } pub struct CloudsLayout { @@ -123,6 +127,44 @@ impl CloudsLayout { }), } } + + pub fn bind( + &self, + device: &wgpu::Device, + src_color: &wgpu::TextureView, + src_depth: &wgpu::TextureView, + sampler: &wgpu::Sampler, + locals: &Consts, + ) -> BindGroup { + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: None, + layout: &self.layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(src_color), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(sampler), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView(src_depth), + }, + wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Sampler(sampler), + }, + wgpu::BindGroupEntry { + binding: 4, + resource: locals.buf().as_entire_binding(), + }, + ], + }); + + BindGroup { bind_group } + } } pub struct CloudsPipeline { @@ -134,7 +176,6 @@ impl CloudsPipeline { device: &wgpu::Device, vs_module: &wgpu::ShaderModule, fs_module: &wgpu::ShaderModule, - sc_desc: &wgpu::SwapChainDescriptor, global_layout: &GlobalsLayouts, layout: &CloudsLayout, aa_mode: AaMode, @@ -166,6 +207,7 @@ impl CloudsPipeline { module: fs_module, entry_point: "main", }), + // TODO: this could be None? rasterization_state: Some(wgpu::RasterizationStateDescriptor { front_face: wgpu::FrontFace::Ccw, cull_mode: wgpu::CullMode::Back, @@ -177,25 +219,15 @@ impl CloudsPipeline { }), primitive_topology: wgpu::PrimitiveTopology::TriangleList, color_states: &[wgpu::ColorStateDescriptor { - format: sc_desc.format, + format: wgpu::TextureFormat::Rgba8UnormSrgb, color_blend: wgpu::BlendDescriptor::REPLACE, alpha_blend: wgpu::BlendDescriptor::REPLACE, write_mask: wgpu::ColorWrite::ALL, }], - depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor { - format: wgpu::TextureFormat::Depth24Plus, - depth_write_enabled: false, - depth_compare: wgpu::CompareFunction::Always, - stencil: wgpu::StencilStateDescriptor { - front: wgpu::StencilStateFaceDescriptor::IGNORE, - back: wgpu::StencilStateFaceDescriptor::IGNORE, - read_mask: !0, - write_mask: !0, - }, - }), + depth_stencil_state: None, vertex_state: wgpu::VertexStateDescriptor { index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[Vertex::desc()], + vertex_buffers: &[/*Vertex::desc()*/], }, sample_count: samples, sample_mask: !0, diff --git a/voxygen/src/render/pipelines/mod.rs b/voxygen/src/render/pipelines/mod.rs index 3e6c065ee0..ffa08b4eb1 100644 --- a/voxygen/src/render/pipelines/mod.rs +++ b/voxygen/src/render/pipelines/mod.rs @@ -290,7 +290,7 @@ impl GlobalsLayouts { binding: 5, visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::SampledTexture { - component_type: wgpu::TextureComponentType::Float, + component_type: wgpu::TextureComponentType::Uint, dimension: wgpu::TextureViewDimension::D2, multisampled: false, }, diff --git a/voxygen/src/render/pipelines/postprocess.rs b/voxygen/src/render/pipelines/postprocess.rs index 0ef5a02072..f8a9f0dc19 100644 --- a/voxygen/src/render/pipelines/postprocess.rs +++ b/voxygen/src/render/pipelines/postprocess.rs @@ -1,4 +1,4 @@ -use super::super::{AaMode, GlobalsLayouts, Mesh, Tri}; +use super::super::{AaMode, Bound, Consts, GlobalsLayouts, Mesh, Tri}; use bytemuck::{Pod, Zeroable}; use vek::*; @@ -22,7 +22,7 @@ impl Locals { } } -#[repr(C)] +/*#[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod)] pub struct Vertex { pub pos: [f32; 2], @@ -59,16 +59,20 @@ pub fn create_mesh() -> Mesh { )); mesh +}*/ + +pub struct BindGroup { + pub(in super::super) bind_group: wgpu::BindGroup, } pub struct PostProcessLayout { - pub src_color: wgpu::BindGroupLayout, + pub layout: wgpu::BindGroupLayout, } impl PostProcessLayout { pub fn new(device: &wgpu::Device) -> Self { Self { - src_color: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + layout: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: None, entries: &[ // src color @@ -119,6 +123,44 @@ impl PostProcessLayout { }), } } + + pub fn bind( + &self, + device: &wgpu::Device, + src_color: &wgpu::TextureView, + src_depth: &wgpu::TextureView, + sampler: &wgpu::Sampler, + locals: &Consts, + ) -> BindGroup { + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: None, + layout: &self.layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(src_color), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(sampler), + }, + wgpu::BindGroupEntry { + binding: 2, + resource: wgpu::BindingResource::TextureView(src_depth), + }, + wgpu::BindGroupEntry { + binding: 3, + resource: wgpu::BindingResource::Sampler(sampler), + }, + wgpu::BindGroupEntry { + binding: 4, + resource: locals.buf().as_entire_binding(), + }, + ], + }); + + BindGroup { bind_group } + } } pub struct PostProcessPipeline { @@ -140,7 +182,7 @@ impl PostProcessPipeline { device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("Post process pipeline layout"), push_constant_ranges: &[], - bind_group_layouts: &[&global_layout.globals, &layout.src_color], + bind_group_layouts: &[&global_layout.globals, &layout.layout], }); let samples = match aa_mode { @@ -191,7 +233,7 @@ impl PostProcessPipeline { }), vertex_state: wgpu::VertexStateDescriptor { index_format: wgpu::IndexFormat::Uint16, - vertex_buffers: &[Vertex::desc()], + vertex_buffers: &[/*Vertex::desc()*/], }, sample_count: samples, sample_mask: !0, diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index 3f1c7efa1c..4ac30ba263 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -134,18 +134,85 @@ pub struct ShadowMapRenderer { } /// A type that stores all the layouts associated with this renderer. -pub struct Layouts { - // TODO: pub(self)?? - pub(self) global: GlobalsLayouts, +struct Layouts { + global: GlobalsLayouts, - pub(self) clouds: clouds::CloudsLayout, - pub(self) figure: figure::FigureLayout, - pub(self) fluid: fluid::FluidLayout, - pub(self) postprocess: postprocess::PostProcessLayout, - pub(self) shadow: shadow::ShadowLayout, - pub(self) sprite: sprite::SpriteLayout, - pub(self) terrain: terrain::TerrainLayout, - pub(self) ui: ui::UiLayout, + clouds: clouds::CloudsLayout, + figure: figure::FigureLayout, + fluid: fluid::FluidLayout, + postprocess: postprocess::PostProcessLayout, + shadow: shadow::ShadowLayout, + sprite: sprite::SpriteLayout, + terrain: terrain::TerrainLayout, + ui: ui::UiLayout, +} + +struct Locals { + clouds: Consts, + clouds_bind: clouds::BindGroup, + + postprocess: Consts, + postprocess_bind: postprocess::BindGroup, +} + +impl Locals { + fn new( + device: &wgpu::Device, + layouts: &Layouts, + clouds_locals: Consts, + postprocess_locals: Consts, + tgt_color_view: &wgpu::TextureView, + tgt_depth_view: &wgpu::TextureView, + tgt_color_pp_view: &wgpu::TextureView, + sampler: &wgpu::Sampler, + ) -> Self { + let clouds_bind = layouts.clouds.bind( + device, + tgt_color_view, + tgt_depth_view, + sampler, + &clouds_locals, + ); + let postprocess_bind = layouts.postprocess.bind( + device, + tgt_color_pp_view, + tgt_depth_view, + sampler, + &postprocess_locals, + ); + + Self { + clouds: clouds_locals, + clouds_bind, + postprocess: postprocess_locals, + postprocess_bind, + } + } + + fn rebind( + &mut self, + device: &wgpu::Device, + layouts: &Layouts, + tgt_color_view: &wgpu::TextureView, + tgt_depth_view: &wgpu::TextureView, + tgt_color_pp_view: &wgpu::TextureView, + sampler: &wgpu::Sampler, + ) { + self.clouds_bind = layouts.clouds.bind( + device, + tgt_color_view, + tgt_depth_view, + sampler, + &self.clouds, + ); + self.postprocess_bind = layouts.postprocess.bind( + device, + tgt_color_pp_view, + tgt_depth_view, + sampler, + &self.postprocess, + ); + } } /// A type that encapsulates rendering state. `Renderer` is central to Voxygen's @@ -189,6 +256,12 @@ pub struct Renderer { shaders: AssetHandle, + // Note: we keep these here since their bind groups need to be updated if we resize the + // color/depth textures + locals: Locals, + + shader_reload_indicator: ReloadIndicator, + noise_tex: Texture, mode: RenderMode, @@ -376,6 +449,28 @@ impl Renderer { Some(wgpu::AddressMode::Repeat), )?; + let clouds_locals = { + let mut consts = Consts::new(&device, 1); + consts.update(&device, &queue, &[clouds::Locals::default()], 0); + consts + }; + let postprocess_locals = { + let mut consts = Consts::new(&device, 1); + consts.update(&device, &queue, &[postprocess::Locals::default()], 0); + consts + }; + + let locals = Locals::new( + &device, + &layouts, + clouds_locals, + postprocess_locals, + &tgt_color_view, + &tgt_depth_view, + &tgt_color_pp_view, + &sampler, + ); + Ok(Self { device, queue, @@ -407,6 +502,8 @@ impl Renderer { postprocess_pipeline, shaders, //player_shadow_pipeline, + locals, + noise_tex, mode, @@ -460,6 +557,17 @@ impl Renderer { self.tgt_color_view = tgt_color_view; self.tgt_depth_view = tgt_depth_view; self.tgt_color_pp_view = tgt_color_pp_view; + // Rebind views to clouds/postprocess bind groups + self.locals.rebind( + &self.device, + &self.layouts, + &self.tgt_color_view, + &self.tgt_depth_view, + &self.tgt_color_pp_view, + &self.sampler, + ); + + // TODO: rebind globals if let (Some(shadow_map), ShadowMode::Map(mode)) = (self.shadow_map.as_mut(), self.mode.shadow) { @@ -824,6 +932,7 @@ impl Renderer { "Renderer::start_recording_frame" ); + // TODO: does this make sense here? self.device.poll(wgpu::Maintain::Poll); // If the shaders files were changed attempt to recreate the shaders @@ -922,10 +1031,22 @@ impl Renderer { } /// Update a set of constants with the provided values. - pub fn update_consts(&mut self, consts: &mut Consts, vals: &[T]) { + pub fn update_consts(&self, consts: &mut Consts, vals: &[T]) { consts.update(&self.device, &self.queue, vals, 0) } + pub fn update_clouds_locals(&mut self, new_val: clouds::Locals) { + self.locals + .clouds + .update(&self.device, &self.queue, &[new_val], 0) + } + + pub fn update_postprocess_locals(&mut self, new_val: postprocess::Locals) { + self.locals + .postprocess + .update(&self.device, &self.queue, &[new_val], 0) + } + /// Create a new set of instances with the provided values. pub fn create_instances( &mut self, @@ -2049,7 +2170,7 @@ fn create_pipelines( device, &create_shader("clouds-vert", ShaderKind::Vertex)?, &create_shader("clouds-frag", ShaderKind::Fragment)?, - sc_desc, + // TODO: pass in format of intermediate color buffer &layouts.global, &layouts.clouds, mode.aa, diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index 036283d673..3eaf9bce59 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -5,7 +5,8 @@ use super::{ instances::Instances, model::{DynamicModel, Model}, pipelines::{ - figure, fluid, postprocess, sprite, terrain, ui, GlobalsBindGroup, Light, Shadow, + clouds, figure, fluid, postprocess, sprite, terrain, ui, GlobalsBindGroup, Light, + Shadow, }, }, Renderer, @@ -36,8 +37,8 @@ impl<'a> Drawer<'a> { } } - /*pub fn first_pass(&mut self) -> FirstPassDrawer { - let render_pass = + pub fn first_pass(&mut self) -> FirstPassDrawer { + let mut render_pass = self.encoder .as_mut() .unwrap() @@ -45,19 +46,19 @@ impl<'a> Drawer<'a> { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &self.renderer.tgt_color_view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::TRANSPARENT, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), + store: true, + }, }], depth_stencil_attachment: Some( wgpu::RenderPassDepthStencilAttachmentDescriptor { - attachment: &self.renderer.depth_stencil_texture.view, - depth_load_op: wgpu::LoadOp::Clear, - depth_store_op: wgpu::StoreOp::Store, - clear_depth: 1.0, - stencil_load_op: wgpu::LoadOp::Clear, - stencil_store_op: wgpu::StoreOp::Store, - clear_stencil: 0, + attachment: &self.renderer.tgt_depth_view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::Clear(1.0), + store: true, + }), + stencil_ops: None, }, ), }); @@ -71,7 +72,7 @@ impl<'a> Drawer<'a> { } pub fn second_pass(&mut self) -> SecondPassDrawer { - let render_pass = + let mut render_pass = self.encoder .as_mut() .unwrap() @@ -79,9 +80,10 @@ impl<'a> Drawer<'a> { color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor { attachment: &self.renderer.tgt_color_pp_view, resolve_target: None, - load_op: wgpu::LoadOp::Clear, - store_op: wgpu::StoreOp::Store, - clear_color: wgpu::Color::TRANSPARENT, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT), + store: true, + }, }], depth_stencil_attachment: None, }); @@ -92,7 +94,7 @@ impl<'a> Drawer<'a> { render_pass, renderer: &self.renderer, } - }*/ + } pub fn third_pass(&mut self) -> ThirdPassDrawer { let mut render_pass = @@ -126,26 +128,27 @@ impl<'a> Drawer<'a> { ThirdPassDrawer { render_pass, renderer: &self.renderer, - //postprocess_locals: &self.postprocess_locals, } } } impl<'a> Drop for Drawer<'a> { fn drop(&mut self) { + // TODO: submitting things to the queue can let the gpu start on them sooner + // maybe we should submit each render pass to the queue as they are produced? self.renderer .queue .submit(std::iter::once(self.encoder.take().unwrap().finish())); } } -/*pub struct FirstPassDrawer<'a> { +pub struct FirstPassDrawer<'a> { pub(super) render_pass: wgpu::RenderPass<'a>, pub renderer: &'a Renderer, } impl<'a> FirstPassDrawer<'a> { - pub fn draw_skybox<'b: 'a>( + /*pub fn draw_skybox<'b: 'a>( &mut self, model: &'b Model, globals: &'b Consts, @@ -236,7 +239,7 @@ impl<'a> FirstPassDrawer<'a> { self.render_pass.set_vertex_buffer(0, &model.vbuf, 0, 0); self.render_pass.set_vertex_buffer(1, &instances.ibuf, 0, 0); self.render_pass.draw(verts, 0..instances.count() as u32); - } + }*/ } pub struct SecondPassDrawer<'a> { @@ -245,40 +248,27 @@ pub struct SecondPassDrawer<'a> { } impl<'a> SecondPassDrawer<'a> { - pub fn draw_post_process<'b: 'a>( - &mut self, - model: &'b Model, - globals: &'b Consts, - verts: Range, - ) { + pub fn draw_clouds<'b: 'a>(&mut self) { self.render_pass - .set_pipeline(&self.renderer.postprocess_pipeline.pipeline); - self.render_pass.set_bind_group(0, &globals.bind_group, &[]); + .set_pipeline(&self.renderer.clouds_pipeline.pipeline); self.render_pass - .set_bind_group(1, self.postprocess_locals, &[]); - self.render_pass.set_vertex_buffer(0, &model.vbuf, 0, 0); - self.render_pass.draw(verts, 0..1); + .set_bind_group(1, &self.renderer.locals.clouds_bind.bind_group, &[]); + self.render_pass.draw(0..3, 0..1); } -}*/ +} pub struct ThirdPassDrawer<'a> { render_pass: wgpu::RenderPass<'a>, renderer: &'a Renderer, - //postprocess_locals: &'a wgpu::BindGroup, } impl<'a> ThirdPassDrawer<'a> { - pub fn draw_post_process<'b: 'a>( - &mut self, - model: &'b Model, - verts: Range, - ) { + pub fn draw_post_process<'b: 'a>(&mut self) { self.render_pass .set_pipeline(&self.renderer.postprocess_pipeline.pipeline); - //self.render_pass - // .set_bind_group(1, self.postprocess_locals, &[]); - self.render_pass.set_vertex_buffer(0, model.buf().slice(..)); - self.render_pass.draw(verts, 0..1); + self.render_pass + .set_bind_group(1, &self.renderer.locals.postprocess_bind.bind_group, &[]); + self.render_pass.draw(0..3, 0..1); } pub fn draw_ui<'c>(&'c mut self) -> UiDrawer<'c, 'a> { diff --git a/voxygen/src/scene/mod.rs b/voxygen/src/scene/mod.rs index a2a64d1d80..8062c6cf91 100644 --- a/voxygen/src/scene/mod.rs +++ b/voxygen/src/scene/mod.rs @@ -16,9 +16,8 @@ pub use self::{ 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, GlobalsBindGroup, Light, Model, PostProcessLocals, PostProcessVertex, - Renderer, Shadow, ShadowLocals, SkyboxVertex, + create_skybox_mesh, CloudsLocals, Consts, GlobalModel, Globals, GlobalsBindGroup, Light, + Model, PostProcessLocals, Renderer, Shadow, ShadowLocals, SkyboxVertex, }, settings::Settings, window::{AnalogGameInput, Event}, @@ -71,16 +70,6 @@ struct Skybox { model: Model, } -struct Clouds { - model: Model, - locals: Consts, -} - -struct PostProcess { - model: Model, - locals: Consts, -} - pub struct Scene { data: GlobalModel, globals_bind_group: GlobalsBindGroup, @@ -89,8 +78,6 @@ pub struct Scene { event_lights: Vec, skybox: Skybox, - clouds: Clouds, - postprocess: PostProcess, terrain: Terrain, pub lod: Lod, loaded_distance: f32, @@ -293,14 +280,6 @@ impl Scene { skybox: Skybox { model: renderer.create_model(&create_skybox_mesh()).unwrap(), }, - clouds: Clouds { - model: renderer.create_model(&create_clouds_mesh()).unwrap(), - locals: renderer.create_consts(&[CloudsLocals::default()]), - }, - postprocess: PostProcess { - model: renderer.create_model(&create_pp_mesh()).unwrap(), - locals: renderer.create_consts(&[PostProcessLocals::default()]), - }, terrain: Terrain::new(renderer), lod, loaded_distance: 0.0, @@ -665,14 +644,8 @@ impl Scene { self.camera.get_mode(), scene_data.sprite_render_distance as f32 - 20.0, )]); - renderer.update_consts(&mut self.clouds.locals, &[CloudsLocals::new( - proj_mat_inv, - view_mat_inv, - )]); - renderer.update_consts(&mut self.postprocess.locals, &[PostProcessLocals::new( - proj_mat_inv, - view_mat_inv, - )]); + renderer.update_clouds_locals(CloudsLocals::new(proj_mat_inv, view_mat_inv)); + renderer.update_postprocess_locals(PostProcessLocals::new(proj_mat_inv, view_mat_inv)); // Maintain LoD. self.lod.maintain(renderer); @@ -1081,21 +1054,5 @@ impl Scene { // Render particle effects. self.particle_mgr.render(renderer, scene_data, global, lod); - - // TODO: - // // Render clouds (a post-processing effect) - // renderer.render_clouds( - // &self.clouds.model, - // &global.globals, - // &self.clouds.locals, - // self.lod.get_data(), - // ); - - // renderer.render_post_process( - // &self.postprocess.model, - // &global.globals, - // &self.postprocess.locals, - // self.lod.get_data(), - // ); } } diff --git a/voxygen/src/scene/simple.rs b/voxygen/src/scene/simple.rs index c1b8ad7c24..86b0224b86 100644 --- a/voxygen/src/scene/simple.rs +++ b/voxygen/src/scene/simple.rs @@ -1,9 +1,8 @@ use crate::{ mesh::{greedy::GreedyMesh, segment::generate_mesh_base_vol_terrain}, render::{ - create_clouds_mesh, create_pp_mesh, create_skybox_mesh, BoneMeshes, CloudsLocals, - CloudsVertex, Consts, FigureModel, GlobalModel, Globals, GlobalsBindGroup, Light, LodData, - Mesh, Model, PostProcessLocals, PostProcessVertex, Renderer, Shadow, ShadowLocals, + create_skybox_mesh, BoneMeshes, Consts, FigureModel, GlobalModel, Globals, + GlobalsBindGroup, Light, LodData, Mesh, Model, Renderer, Shadow, ShadowLocals, SkyboxVertex, TerrainVertex, }, scene::{ @@ -57,24 +56,12 @@ struct Skybox { model: Model, } -struct PostProcess { - model: Model, - locals: Consts, -} - -struct Clouds { - model: Model, - locals: Consts, -} - pub struct Scene { data: GlobalModel, globals_bind_group: GlobalsBindGroup, camera: Camera, skybox: Skybox, - clouds: Clouds, - postprocess: PostProcess, lod: LodData, map_bounds: Vec2, @@ -134,14 +121,6 @@ impl Scene { skybox: Skybox { model: renderer.create_model(&create_skybox_mesh()).unwrap(), }, - clouds: Clouds { - model: renderer.create_model(&create_clouds_mesh()).unwrap(), - locals: renderer.create_consts(&[CloudsLocals::default()]), - }, - postprocess: PostProcess { - model: renderer.create_model(&create_pp_mesh()).unwrap(), - locals: renderer.create_consts(&[PostProcessLocals::default()]), - }, lod, map_bounds, diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8687832502..bd28529b81 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -1403,8 +1403,16 @@ impl PlayState for SessionState { None => return, }; + // Render world + /* let mut first_pass = */ + drawer.first_pass(); + // Clouds + drawer.second_pass().draw_clouds(); + // PostProcess and UI + let mut third_pass = drawer.third_pass(); + third_pass.draw_post_process(); // Draw the UI to the screen - self.hud.render(&mut drawer.third_pass().draw_ui()); + self.hud.render(&mut third_pass.draw_ui()); } } diff --git a/voxygen/src/ui/ice/renderer/mod.rs b/voxygen/src/ui/ice/renderer/mod.rs index a169374122..d75239e84d 100644 --- a/voxygen/src/ui/ice/renderer/mod.rs +++ b/voxygen/src/ui/ice/renderer/mod.rs @@ -763,7 +763,7 @@ impl IcedRenderer { } } - pub fn render<'pass, 'data: 'pass>(&'data self, drawer: &mut UiDrawer<'_, 'pass>) { + pub fn render<'a>(&'a self, drawer: &mut UiDrawer<'_, 'a>) { span!(_guard, "render", "IcedRenderer::render"); let mut drawer = drawer.prepare(&self.interface_locals, &self.model, self.window_scissor); for draw_command in self.draw_commands.iter() {