mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Remove commented out sprite code, including the code for getting verts for sprites with a texture rather than a storage buffer
This commit is contained in:
parent
81939b4e4e
commit
9ec4fd5b4b
@ -30,8 +30,6 @@ layout(location = 7) in float inst_glow;
|
||||
layout(location = 8) in float model_wind_sway; // NOTE: this only varies per model
|
||||
layout(location = 9) in float model_z_scale; // NOTE: this only varies per model
|
||||
|
||||
//layout(set = 0, binding = 12) uniform utexture2D t_sprite_verts;
|
||||
//layout(set = 0, binding = 13) uniform sampler s_sprite_verts;
|
||||
layout(set = 0, binding = 12) restrict readonly buffer sprite_verts {
|
||||
uvec2 verts[];
|
||||
};
|
||||
@ -71,11 +69,7 @@ void main() {
|
||||
f_inst_light = vec2(inst_light, inst_glow);
|
||||
|
||||
// Index of the vertex data in the 1D vertex texture
|
||||
// TODO: dx12 warning to switch to uint for modulus here (test if it got speedup?)
|
||||
int vertex_index = int(uint(gl_VertexIndex) % VERT_PAGE_SIZE + inst_vert_page * VERT_PAGE_SIZE);
|
||||
//const int WIDTH = 8192; // TODO: temp
|
||||
//ivec2 tex_coords = ivec2(vertex_index % WIDTH, vertex_index / WIDTH);
|
||||
//uvec2 pos_atlas_pos_norm_ao = texelFetch(usampler2D(t_sprite_verts, s_sprite_verts), tex_coords, 0).xy;
|
||||
uvec2 pos_atlas_pos_norm_ao = verts[vertex_index];
|
||||
uint v_pos_norm = pos_atlas_pos_norm_ao.x;
|
||||
uint v_atlas_pos = pos_atlas_pos_norm_ao.y;
|
||||
|
@ -66,16 +66,6 @@ impl Vertex {
|
||||
atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) | ((atlas_pos.y as u32) & 0xFFFF) << 16,
|
||||
}
|
||||
}
|
||||
|
||||
/*fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
|
||||
const ATTRIBUTES: [wgpu::VertexAttribute; 3] =
|
||||
wgpu::vertex_attr_array![0 => Float32x3, 1 => Uint32, 2 => Uint32];
|
||||
wgpu::VertexBufferLayout {
|
||||
array_stride: Self::STRIDE,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: &ATTRIBUTES,
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
impl Default for Vertex {
|
||||
@ -95,57 +85,6 @@ pub fn create_verts_buffer(renderer: &mut Renderer, mesh: Mesh<Vertex>) -> Buffe
|
||||
wgpu::BufferUsage::STORAGE,
|
||||
mesh.vertices(),
|
||||
)
|
||||
//let mut verts = mesh.vertices_mut_vec();
|
||||
//let format = wgpu::TextureFormat::Rg32Uint;
|
||||
|
||||
// TODO: temp
|
||||
//const WIDTH: u32 = 8192;
|
||||
//let height = verts.len() as u32 / WIDTH;
|
||||
// Fill in verts to full texture size
|
||||
//verts.resize_with(height as usize * WIDTH as usize, Vertex::default);
|
||||
|
||||
/*let texture_info = wgpu::TextureDescriptor {
|
||||
label: Some("Sprite verts"),
|
||||
size: wgpu::Extent3d {
|
||||
width: WIDTH,
|
||||
height,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format,
|
||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST,
|
||||
};
|
||||
|
||||
let sampler_info = wgpu::SamplerDescriptor {
|
||||
label: None,
|
||||
address_mode_u: wgpu::AddressMode::Repeat,
|
||||
address_mode_v: wgpu::AddressMode::Repeat,
|
||||
address_mode_w: wgpu::AddressMode::Repeat,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let view_info = wgpu::TextureViewDescriptor {
|
||||
label: None,
|
||||
format: Some(format),
|
||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
base_mip_level: 0,
|
||||
mip_level_count: None,
|
||||
base_array_layer: 0,
|
||||
array_layer_count: None,
|
||||
};
|
||||
|
||||
renderer.create_texture_with_data_raw::<8>(
|
||||
&texture_info,
|
||||
&view_info,
|
||||
&sampler_info,
|
||||
bytemuck::cast_slice(verts),
|
||||
)*/
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -221,40 +160,13 @@ impl Default for Instance {
|
||||
|
||||
// TODO: ColLightsWrapper instead?
|
||||
pub struct Locals;
|
||||
/*#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Zeroable, Pod)]
|
||||
pub struct Locals {
|
||||
// Each matrix performs rotatation, translation, and scaling, relative to the sprite
|
||||
// origin, for all sprite instances. The matrix will be in an array indexed by the
|
||||
// sprite instance's orientation (0 through 7).
|
||||
mat: [[f32; 4]; 4],
|
||||
wind_sway: [f32; 4],
|
||||
offs: [f32; 4],
|
||||
}
|
||||
|
||||
impl Default for Locals {
|
||||
fn default() -> Self { Self::new(Mat4::identity(), Vec3::one(), Vec3::zero(), 0.0) }
|
||||
}
|
||||
|
||||
impl Locals {
|
||||
pub fn new(mat: Mat4<f32>, scale: Vec3<f32>, offs: Vec3<f32>, wind_sway: f32) -> Self {
|
||||
Self {
|
||||
mat: mat.into_col_arrays(),
|
||||
wind_sway: [scale.x, scale.y, scale.z, wind_sway],
|
||||
offs: [offs.x, offs.y, offs.z, 0.0],
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
pub struct SpriteGlobalsBindGroup {
|
||||
pub(in super::super) bind_group: wgpu::BindGroup,
|
||||
}
|
||||
|
||||
//pub type BoundLocals = Bound<Consts<Locals>>;
|
||||
|
||||
pub struct SpriteLayout {
|
||||
pub globals: wgpu::BindGroupLayout,
|
||||
//pub locals: wgpu::BindGroupLayout,
|
||||
}
|
||||
|
||||
impl SpriteLayout {
|
||||
@ -275,26 +187,6 @@ impl SpriteLayout {
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
/* sprite verts (t_sprite_verts) */
|
||||
/*wgpu::BindGroupLayoutEntry {
|
||||
binding: 12,
|
||||
visibility: wgpu::ShaderStage::VERTEX,
|
||||
ty: wgpu::BindingType::Texture {
|
||||
sample_type: wgpu::TextureSampleType::Uint,
|
||||
view_dimension: wgpu::TextureViewDimension::D2,
|
||||
multisampled: false,
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 13,
|
||||
visibility: wgpu::ShaderStage::VERTEX,
|
||||
ty: wgpu::BindingType::Sampler {
|
||||
filtering: false,
|
||||
comparison: false,
|
||||
},
|
||||
count: None,
|
||||
},*/
|
||||
]);
|
||||
|
||||
Self {
|
||||
@ -302,30 +194,6 @@ impl SpriteLayout {
|
||||
label: None,
|
||||
entries: &entries,
|
||||
}),
|
||||
/*locals: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: &[
|
||||
// locals
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
// instance buffer
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStage::Vertex,
|
||||
ty: wgpu::BufferBindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::
|
||||
}
|
||||
},
|
||||
],
|
||||
}),*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,15 +214,6 @@ impl SpriteLayout {
|
||||
binding: 12,
|
||||
resource: sprite_verts.buf.as_entire_binding(),
|
||||
},
|
||||
/* sprite verts (t_sprite_verts) */
|
||||
/*wgpu::BindGroupEntry {
|
||||
binding: 12,
|
||||
resource: wgpu::BindingResource::TextureView(&sprite_verts.view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 13,
|
||||
resource: wgpu::BindingResource::Sampler(&sprite_verts.sampler),
|
||||
},*/
|
||||
]);
|
||||
|
||||
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
@ -370,7 +229,6 @@ impl SpriteLayout {
|
||||
global_model: &GlobalModel,
|
||||
lod_data: &lod_terrain::LodData,
|
||||
noise: &Texture,
|
||||
//sprite_verts: &Texture,
|
||||
sprite_verts: &Buffer<Vertex>,
|
||||
) -> SpriteGlobalsBindGroup {
|
||||
let bind_group =
|
||||
@ -378,22 +236,6 @@ impl SpriteLayout {
|
||||
|
||||
SpriteGlobalsBindGroup { bind_group }
|
||||
}
|
||||
|
||||
/*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 {
|
||||
@ -419,7 +261,6 @@ impl SpritePipeline {
|
||||
&layout.globals,
|
||||
&global_layout.shadow_textures,
|
||||
&terrain_layout.locals,
|
||||
//&layout.locals,
|
||||
// Note: mergable with globals
|
||||
&global_layout.col_light,
|
||||
],
|
||||
|
@ -25,7 +25,6 @@ impl Renderer {
|
||||
&self,
|
||||
global_model: &GlobalModel,
|
||||
lod_data: &lod_terrain::LodData,
|
||||
//sprite_verts: &Texture,
|
||||
sprite_verts: &Buffer<sprite::Vertex>,
|
||||
) -> sprite::SpriteGlobalsBindGroup {
|
||||
self.layouts.sprite.bind_globals(
|
||||
@ -71,11 +70,6 @@ impl Renderer {
|
||||
self.layouts.shadow.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)
|
||||
}
|
||||
|
@ -673,15 +673,11 @@ impl<'pass_ref, 'pass: 'pass_ref> SpriteDrawer<'pass_ref, 'pass> {
|
||||
pub fn draw<'data: 'pass>(
|
||||
&mut self,
|
||||
terrain_locals: &'data terrain::BoundLocals,
|
||||
//model: &'data Model<sprite::Vertex>,
|
||||
//locals: &'data sprite::BoundLocals,
|
||||
instances: &'data Instances<sprite::Instance>,
|
||||
) {
|
||||
self.render_pass
|
||||
.set_bind_group(2, &terrain_locals.bind_group, &[]);
|
||||
//self.render_pass.set_bind_group(3, &locals.bind_group, &[]);
|
||||
|
||||
//self.render_pass.set_vertex_buffer(0, model.buf().slice(..));
|
||||
self.render_pass
|
||||
.set_vertex_buffer(0, instances.buf().slice(..));
|
||||
self.render_pass.draw_indexed(
|
||||
|
@ -280,9 +280,6 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug + '
|
||||
lod_level.push(instance);
|
||||
}
|
||||
}
|
||||
|
||||
//instances.entry(key).or_insert(Vec::new()).
|
||||
// push(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -399,14 +396,12 @@ impl SpriteRenderContext {
|
||||
|
||||
let max_size = guillotiere::Size::new(max_texture_size as i32, max_texture_size as i32);
|
||||
let mut greedy = GreedyMesh::new(max_size);
|
||||
// let mut locals_buffer = [SpriteLocals::default(); 8];
|
||||
let mut sprite_mesh = Mesh::new();
|
||||
let sprite_config_ = &sprite_config;
|
||||
// NOTE: Tracks the start vertex of the next model to be meshed.
|
||||
let sprite_data: HashMap<(SpriteKind, usize), _> = SpriteKind::into_enum_iter()
|
||||
.filter_map(|kind| Some((kind, kind.elim_case_pure(&sprite_config_.0).as_ref()?)))
|
||||
.flat_map(|(kind, sprite_config)| {
|
||||
// let wind_sway = sprite_config.wind_sway;
|
||||
sprite_config.variations.iter().enumerate().map(
|
||||
move |(
|
||||
variation,
|
||||
@ -443,8 +438,6 @@ impl SpriteRenderContext {
|
||||
scale
|
||||
}
|
||||
});
|
||||
//let sprite_mat: Mat4<f32> =
|
||||
// Mat4::translation_3d(offset).scaled_3d(SPRITE_SCALE);
|
||||
move |greedy: &mut GreedyMesh, sprite_mesh: &mut Mesh<SpriteVertex>| {
|
||||
let lod_sprite_data = scaled.map(|lod_scale_orig| {
|
||||
let lod_scale = model_scale
|
||||
@ -476,27 +469,11 @@ impl SpriteRenderContext {
|
||||
);
|
||||
|
||||
let sprite_scale = Vec3::one() / lod_scale;
|
||||
//let sprite_mat: Mat4<f32> =
|
||||
// sprite_mat * Mat4::scaling_3d(sprite_scale);
|
||||
/*locals_buffer.iter_mut().enumerate().for_each(
|
||||
|(ori, locals)| {
|
||||
let sprite_mat = sprite_mat.rotated_z(
|
||||
f32::consts::PI * 0.25 * ori as f32,
|
||||
);
|
||||
*locals = SpriteLocals::new(
|
||||
sprite_mat,
|
||||
sprite_scale,
|
||||
offset,
|
||||
wind_sway,
|
||||
);
|
||||
},
|
||||
);*/
|
||||
|
||||
SpriteData {
|
||||
vert_pages: start_page_num as u32..end_page_num as u32,
|
||||
scale: sprite_scale,
|
||||
offset,
|
||||
//locals: locals_buffer,
|
||||
}
|
||||
});
|
||||
|
||||
@ -547,7 +524,7 @@ impl SpriteRenderContext {
|
||||
let sprite_verts_buffer = create_sprite_verts_buffer(renderer, sprite_mesh);
|
||||
|
||||
Self {
|
||||
// TODO: this are all Arcs, would it makes sense to factor out the Arc?
|
||||
// TODO: these are all Arcs, would it makes sense to factor out the Arc?
|
||||
sprite_config: Arc::clone(&sprite_config),
|
||||
sprite_data: Arc::new(sprite_data),
|
||||
sprite_col_lights: Arc::new(sprite_col_lights),
|
||||
@ -1553,6 +1530,8 @@ impl<V: RectRasterableVol> Terrain<V> {
|
||||
chunk_center + chunk_size.x * 0.5 - chunk_size.y * 0.5,
|
||||
));
|
||||
if focus_dist_sqrd < sprite_render_distance.powi(2) {
|
||||
// TODO: do we really need this configurement by wind-sway, if not remove
|
||||
// commented code, if so store the max wind sway of sprites in each chunk
|
||||
let lod_level = /*let SpriteData { model, locals, .. } = if kind
|
||||
.0
|
||||
.elim_case_pure(&self.sprite_config.0)
|
||||
|
Loading…
Reference in New Issue
Block a user