mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Re enable sprite rendering
This commit is contained in:
parent
0394a9afce
commit
b3985422b1
@ -28,9 +28,9 @@ layout(location = 4) in vec2 f_inst_light;
|
|||||||
// in float f_light;
|
// in float f_light;
|
||||||
// in vec4 light_pos[2];
|
// in vec4 light_pos[2];
|
||||||
|
|
||||||
layout(set = 2, binding = 1)
|
layout(set = 3, binding = 0)
|
||||||
uniform texture2D t_col_light;
|
uniform texture2D t_col_light;
|
||||||
layout(set = 2, binding = 2)
|
layout(set = 3, binding = 1)
|
||||||
uniform sampler s_col_light;
|
uniform sampler s_col_light;
|
||||||
|
|
||||||
//struct ShadowLocals {
|
//struct ShadowLocals {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use super::super::{AaMode, GlobalsLayouts, TerrainLayout};
|
use super::super::{AaMode, Bound, Consts, GlobalsLayouts, TerrainLayout};
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
@ -135,6 +135,8 @@ pub struct Locals {
|
|||||||
offs: [f32; 4],
|
offs: [f32; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type BoundLocals = Bound<Consts<Locals>>;
|
||||||
|
|
||||||
impl Default for Locals {
|
impl Default for Locals {
|
||||||
fn default() -> Self { Self::new(Mat4::identity(), Vec3::one(), Vec3::zero(), 0.0) }
|
fn default() -> Self { Self::new(Mat4::identity(), Vec3::one(), Vec3::zero(), 0.0) }
|
||||||
}
|
}
|
||||||
@ -170,30 +172,26 @@ impl SpriteLayout {
|
|||||||
},
|
},
|
||||||
count: None,
|
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 {
|
pub struct SpritePipeline {
|
||||||
@ -220,6 +218,7 @@ impl SpritePipeline {
|
|||||||
&global_layout.globals,
|
&global_layout.globals,
|
||||||
&terrain_layout.locals,
|
&terrain_layout.locals,
|
||||||
&layout.locals,
|
&layout.locals,
|
||||||
|
&global_layout.col_light,
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@ use super::{
|
|||||||
super::{
|
super::{
|
||||||
consts::Consts,
|
consts::Consts,
|
||||||
pipelines::{
|
pipelines::{
|
||||||
figure, fluid, lod_terrain, terrain, ui, ColLights, GlobalModel, GlobalsBindGroup,
|
figure, fluid, lod_terrain, sprite, terrain, ui, ColLights, GlobalModel,
|
||||||
|
GlobalsBindGroup,
|
||||||
},
|
},
|
||||||
texture::Texture,
|
texture::Texture,
|
||||||
},
|
},
|
||||||
@ -59,6 +60,11 @@ impl Renderer {
|
|||||||
self.layouts.terrain.bind_locals(&self.device, locals)
|
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> {
|
pub fn figure_bind_col_light(&self, col_light: Texture) -> ColLights<figure::Locals> {
|
||||||
self.layouts.global.bind_col_light(&self.device, col_light)
|
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)
|
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 {
|
pub fn fluid_bind_waves(&self, texture: Texture) -> fluid::BindGroup {
|
||||||
self.layouts.fluid.bind(&self.device, texture)
|
self.layouts.fluid.bind(&self.device, texture)
|
||||||
}
|
}
|
||||||
|
@ -190,24 +190,27 @@ impl<'a> FirstPassDrawer<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn draw_sprite<'b: 'a>(
|
pub fn draw_sprite<'b: 'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
model: &'b Model,
|
model: &'b Model<sprite::Vertex>,
|
||||||
instances: &'a Instances<sprite::Instance>,
|
instances: &'b Instances<sprite::Instance>,
|
||||||
globals: &'b Consts<Globals>,
|
terrain_locals: &'b terrain::BoundLocals,
|
||||||
lights: &'b Consts<Light>,
|
locals: &'b sprite::BoundLocals,
|
||||||
shadows: &'b Consts<Shadow>,
|
col_lights: &'b ColLights<sprite::Locals>,
|
||||||
verts: Range<u32>,
|
|
||||||
) {
|
) {
|
||||||
self.render_pass
|
self.render_pass
|
||||||
.set_pipeline(&self.renderer.sprite_pipeline.pipeline);
|
.set_pipeline(&self.renderer.sprite_pipeline.pipeline);
|
||||||
self.render_pass.set_bind_group(0, &globals.bind_group, &[]);
|
self.render_pass
|
||||||
self.render_pass.set_bind_group(1, &lights.bind_group, &[]);
|
.set_bind_group(1, &terrain_locals.bind_group, &[]);
|
||||||
self.render_pass.set_bind_group(2, &shadows.bind_group, &[]);
|
self.render_pass.set_bind_group(2, &locals.bind_group, &[]);
|
||||||
self.render_pass.set_vertex_buffer(0, &model.vbuf, 0, 0);
|
self.render_pass
|
||||||
self.render_pass.set_vertex_buffer(1, &instances.ibuf, 0, 0);
|
.set_bind_group(3, &col_lights.bind_group, &[]);
|
||||||
self.render_pass.draw(verts, 0..instances.count() as u32);
|
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> {
|
pub fn draw_fluid<'b: 'a>(&mut self, waves: &'b fluid::BindGroup) -> FluidDrawer<'_, 'a> {
|
||||||
self.render_pass
|
self.render_pass
|
||||||
|
@ -272,7 +272,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
|
|||||||
|
|
||||||
struct SpriteData {
|
struct SpriteData {
|
||||||
/* mat: Mat4<f32>, */
|
/* mat: Mat4<f32>, */
|
||||||
locals: Consts<SpriteLocals>,
|
locals: pipelines::sprite::BoundLocals,
|
||||||
model: Model<SpriteVertex>,
|
model: Model<SpriteVertex>,
|
||||||
/* scale: Vec3<f32>, */
|
/* scale: Vec3<f32>, */
|
||||||
offset: Vec3<f32>,
|
offset: Vec3<f32>,
|
||||||
@ -326,7 +326,7 @@ pub struct Terrain<V: RectRasterableVol = TerrainChunk> {
|
|||||||
|
|
||||||
// GPU data
|
// GPU data
|
||||||
sprite_data: Arc<HashMap<(SpriteKind, usize), Vec<SpriteData>>>,
|
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
|
/// As stated previously, this is always the very latest texture into which
|
||||||
/// we allocate. Code cannot assume that this is the assigned texture
|
/// we allocate. Code cannot assume that this is the assigned texture
|
||||||
/// for any particular chunk; look at the `texture` field in
|
/// for any particular chunk; look at the `texture` field in
|
||||||
@ -518,7 +518,7 @@ impl SpriteRenderContext {
|
|||||||
offset,
|
offset,
|
||||||
}| {
|
}| {
|
||||||
SpriteData {
|
SpriteData {
|
||||||
locals: renderer.create_consts(&locals_buffer),
|
locals: renderer.create_sprite_bound_locals(&locals_buffer),
|
||||||
model: renderer.create_model(&model).expect(
|
model: renderer.create_model(&model).expect(
|
||||||
"Failed to upload sprite model data to the GPU!",
|
"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_todos_active: Arc::new(AtomicU64::new(0)),
|
||||||
mesh_recv_overflow: 0.0,
|
mesh_recv_overflow: 0.0,
|
||||||
sprite_data: sprite_render_context.sprite_data,
|
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: {
|
waves: {
|
||||||
let waves_tex = renderer
|
let waves_tex = renderer
|
||||||
.create_texture(
|
.create_texture(
|
||||||
@ -1546,15 +1547,14 @@ impl<V: RectRasterableVol> Terrain<V> {
|
|||||||
} else {
|
} else {
|
||||||
&self.sprite_data[&kind][4]
|
&self.sprite_data[&kind][4]
|
||||||
};
|
};
|
||||||
/*renderer.render_sprites(
|
|
||||||
|
drawer.draw_sprite(
|
||||||
model,
|
model,
|
||||||
&self.sprite_col_lights,
|
instances,
|
||||||
global,
|
|
||||||
&chunk.locals,
|
&chunk.locals,
|
||||||
locals,
|
locals,
|
||||||
&instances,
|
&self.sprite_col_lights,
|
||||||
lod,
|
);
|
||||||
);*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user