diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index 76efb3a75e..fb46c2d209 100644 --- a/assets/voxygen/shaders/sprite-frag.glsl +++ b/assets/voxygen/shaders/sprite-frag.glsl @@ -28,9 +28,9 @@ layout(location = 4) in vec2 f_inst_light; // in float f_light; // in vec4 light_pos[2]; -layout(set = 2, binding = 1) +layout(set = 3, binding = 0) uniform texture2D t_col_light; -layout(set = 2, binding = 2) +layout(set = 3, binding = 1) uniform sampler s_col_light; //struct ShadowLocals { diff --git a/voxygen/src/render/pipelines/sprite.rs b/voxygen/src/render/pipelines/sprite.rs index 2688c092d2..0e516e873c 100644 --- a/voxygen/src/render/pipelines/sprite.rs +++ b/voxygen/src/render/pipelines/sprite.rs @@ -1,4 +1,4 @@ -use super::super::{AaMode, GlobalsLayouts, TerrainLayout}; +use super::super::{AaMode, Bound, Consts, GlobalsLayouts, TerrainLayout}; use bytemuck::{Pod, Zeroable}; use core::fmt; use vek::*; @@ -135,6 +135,8 @@ pub struct Locals { offs: [f32; 4], } +pub type BoundLocals = Bound>; + impl Default for Locals { fn default() -> Self { Self::new(Mat4::identity(), Vec3::one(), Vec3::zero(), 0.0) } } @@ -170,30 +172,26 @@ impl SpriteLayout { }, count: None, }, - // col lights - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Texture { - sample_type: wgpu::TextureSampleType::Float { filterable: true }, - view_dimension: wgpu::TextureViewDimension::D2, - multisampled: false, - }, - count: None, - }, - wgpu::BindGroupLayoutEntry { - binding: 2, - visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler { - filtering: true, - comparison: false, - }, - count: None, - }, ], }), } } + + pub fn bind_locals(&self, device: &wgpu::Device, locals: Consts) -> BoundLocals { + let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + label: None, + layout: &self.locals, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: locals.buf().as_entire_binding(), + }], + }); + + BoundLocals { + bind_group, + with: locals, + } + } } pub struct SpritePipeline { @@ -220,6 +218,7 @@ impl SpritePipeline { &global_layout.globals, &terrain_layout.locals, &layout.locals, + &global_layout.col_light, ], }); diff --git a/voxygen/src/render/renderer/binding.rs b/voxygen/src/render/renderer/binding.rs index 0f1c70a426..aea000fa07 100644 --- a/voxygen/src/render/renderer/binding.rs +++ b/voxygen/src/render/renderer/binding.rs @@ -2,7 +2,8 @@ use super::{ super::{ consts::Consts, pipelines::{ - figure, fluid, lod_terrain, terrain, ui, ColLights, GlobalModel, GlobalsBindGroup, + figure, fluid, lod_terrain, sprite, terrain, ui, ColLights, GlobalModel, + GlobalsBindGroup, }, texture::Texture, }, @@ -59,6 +60,11 @@ impl Renderer { self.layouts.terrain.bind_locals(&self.device, locals) } + pub fn create_sprite_bound_locals(&mut self, locals: &[sprite::Locals]) -> sprite::BoundLocals { + let locals = self.create_consts(locals); + self.layouts.sprite.bind_locals(&self.device, locals) + } + pub fn figure_bind_col_light(&self, col_light: Texture) -> ColLights { self.layouts.global.bind_col_light(&self.device, col_light) } @@ -67,6 +73,10 @@ impl Renderer { self.layouts.global.bind_col_light(&self.device, col_light) } + pub fn sprite_bind_col_light(&self, col_light: Texture) -> ColLights { + self.layouts.global.bind_col_light(&self.device, col_light) + } + pub fn fluid_bind_waves(&self, texture: Texture) -> fluid::BindGroup { self.layouts.fluid.bind(&self.device, texture) } diff --git a/voxygen/src/render/renderer/drawer.rs b/voxygen/src/render/renderer/drawer.rs index ca7a09888b..ab758410de 100644 --- a/voxygen/src/render/renderer/drawer.rs +++ b/voxygen/src/render/renderer/drawer.rs @@ -190,24 +190,27 @@ impl<'a> FirstPassDrawer<'a> { } } - /*pub fn draw_sprite<'b: 'a>( + pub fn draw_sprite<'b: 'a>( &mut self, - model: &'b Model, - instances: &'a Instances, - globals: &'b Consts, - lights: &'b Consts, - shadows: &'b Consts, - verts: Range, + model: &'b Model, + instances: &'b Instances, + terrain_locals: &'b terrain::BoundLocals, + locals: &'b sprite::BoundLocals, + col_lights: &'b ColLights, ) { self.render_pass .set_pipeline(&self.renderer.sprite_pipeline.pipeline); - self.render_pass.set_bind_group(0, &globals.bind_group, &[]); - self.render_pass.set_bind_group(1, &lights.bind_group, &[]); - self.render_pass.set_bind_group(2, &shadows.bind_group, &[]); - 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); - }*/ + self.render_pass + .set_bind_group(1, &terrain_locals.bind_group, &[]); + self.render_pass.set_bind_group(2, &locals.bind_group, &[]); + self.render_pass + .set_bind_group(3, &col_lights.bind_group, &[]); + self.render_pass.set_vertex_buffer(0, model.buf().slice(..)); + self.render_pass + .set_vertex_buffer(1, instances.buf().slice(..)); + self.render_pass + .draw(0..model.len() as u32, 0..instances.count() as u32); + } pub fn draw_fluid<'b: 'a>(&mut self, waves: &'b fluid::BindGroup) -> FluidDrawer<'_, 'a> { self.render_pass diff --git a/voxygen/src/scene/terrain.rs b/voxygen/src/scene/terrain.rs index 6d19c5ce08..07e8fb4b7a 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -272,7 +272,7 @@ fn mesh_worker + RectRasterableVol + ReadVol + Debug + ' struct SpriteData { /* mat: Mat4, */ - locals: Consts, + locals: pipelines::sprite::BoundLocals, model: Model, /* scale: Vec3, */ offset: Vec3, @@ -326,7 +326,7 @@ pub struct Terrain { // GPU data sprite_data: Arc>>, - sprite_col_lights: Texture, /* */ + sprite_col_lights: ColLights, /// As stated previously, this is always the very latest texture into which /// we allocate. Code cannot assume that this is the assigned texture /// for any particular chunk; look at the `texture` field in @@ -518,7 +518,7 @@ impl SpriteRenderContext { offset, }| { SpriteData { - locals: renderer.create_consts(&locals_buffer), + locals: renderer.create_sprite_bound_locals(&locals_buffer), model: renderer.create_model(&model).expect( "Failed to upload sprite model data to the GPU!", ), @@ -563,7 +563,8 @@ impl Terrain { mesh_todos_active: Arc::new(AtomicU64::new(0)), mesh_recv_overflow: 0.0, sprite_data: sprite_render_context.sprite_data, - sprite_col_lights: sprite_render_context.sprite_col_lights, + sprite_col_lights: renderer + .sprite_bind_col_light(sprite_render_context.sprite_col_lights), waves: { let waves_tex = renderer .create_texture( @@ -1546,15 +1547,14 @@ impl Terrain { } else { &self.sprite_data[&kind][4] }; - /*renderer.render_sprites( + + drawer.draw_sprite( model, - &self.sprite_col_lights, - global, + instances, &chunk.locals, locals, - &instances, - lod, - );*/ + &self.sprite_col_lights, + ); } } }