diff --git a/assets/voxygen/shaders/sprite-frag.glsl b/assets/voxygen/shaders/sprite-frag.glsl index f6fc47f3ff..ccf4970da7 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 1ebb89461a..6d16f74e3b 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 c6f950a2b9..2f1e2a3089 100644 --- a/voxygen/src/scene/terrain.rs +++ b/voxygen/src/scene/terrain.rs @@ -231,7 +231,7 @@ fn mesh_worker + RectRasterableVol + ReadVol + Debug + ' struct SpriteData { /* mat: Mat4, */ - locals: Consts, + locals: pipelines::sprite::BoundLocals, model: Model, /* scale: Vec3, */ offset: Vec3, @@ -270,7 +270,7 @@ pub struct Terrain { // GPU data sprite_data: Arc>>, col_lights: ColLights, - sprite_col_lights: Texture, /* */ + sprite_col_lights: ColLights, waves: FluidWaves, phantom: PhantomData, @@ -386,7 +386,8 @@ impl Terrain { SpriteData { /* vertex_range */ model, offset, - locals: renderer.create_consts(&locals_buffer), + locals: renderer + .create_sprite_bound_locals(&locals_buffer), } }) .collect::>(), @@ -410,7 +411,7 @@ impl Terrain { mesh_todo: HashMap::default(), mesh_todos_active: Arc::new(AtomicU64::new(0)), sprite_data: Arc::new(sprite_data), - sprite_col_lights, + sprite_col_lights: renderer.sprite_bind_col_light(sprite_col_lights), waves: { let waves_tex = renderer .create_texture( @@ -1184,15 +1185,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, + ); } } }