Re enable sprite rendering

This commit is contained in:
Capucho 2020-12-07 14:24:48 +00:00 committed by Avi Weinstock
parent 0394a9afce
commit b3985422b1
5 changed files with 60 additions and 48 deletions

View File

@ -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 {

View File

@ -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<Consts<Locals>>;
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<Locals>) -> 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,
],
});

View File

@ -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<figure::Locals> {
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<sprite::Locals> {
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)
}

View File

@ -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<sprite::Instance>,
globals: &'b Consts<Globals>,
lights: &'b Consts<Light>,
shadows: &'b Consts<Shadow>,
verts: Range<u32>,
model: &'b Model<sprite::Vertex>,
instances: &'b Instances<sprite::Instance>,
terrain_locals: &'b terrain::BoundLocals,
locals: &'b sprite::BoundLocals,
col_lights: &'b ColLights<sprite::Locals>,
) {
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

View File

@ -272,7 +272,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
struct SpriteData {
/* mat: Mat4<f32>, */
locals: Consts<SpriteLocals>,
locals: pipelines::sprite::BoundLocals,
model: Model<SpriteVertex>,
/* scale: Vec3<f32>, */
offset: Vec3<f32>,
@ -326,7 +326,7 @@ pub struct Terrain<V: RectRasterableVol = TerrainChunk> {
// GPU data
sprite_data: Arc<HashMap<(SpriteKind, usize), Vec<SpriteData>>>,
sprite_col_lights: Texture, /* <ColLightFmt> */
sprite_col_lights: ColLights<pipelines::sprite::Locals>,
/// 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<V: RectRasterableVol> Terrain<V> {
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<V: RectRasterableVol> Terrain<V> {
} 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,
);
}
}
}