triangles upper and lower layer, low vertex reuse

This commit is contained in:
zomseffen 2024-05-22 19:47:49 +02:00
parent 32577d548b
commit a3e0b9a0c5
4 changed files with 64 additions and 33 deletions

View file

@ -21,39 +21,70 @@ pub struct Scene {
impl Scene {
pub unsafe fn prepare_data(&mut self, instance: &vulkanalia::Instance, device: &vulkanalia::Device, data: &AppData) -> Result<()> {
self.vertices.push(
vertex::Vertex::new(vec3(8.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), vec2(0.0, 0.0))
);
self.indices.push(0);
self.vertices.push(
vertex::Vertex::new(vec3(-8.0, 0.0, 0.0), vec3(0.0, 0.0, 1.0), vec2(0.0, 0.0))
);
self.indices.push(1);
self.vertices.push(
vertex::Vertex::new(vec3(0.0, 8.0, 0.0), vec3(1.0, 1.0, 0.0), vec2(0.0, 0.0))
);
self.indices.push(2);
self.vertices.push(
vertex::Vertex::new(vec3(0.0, -8.0, 0.0), vec3(0.0, 1.0, 1.0), vec2(0.0, 0.0))
);
self.indices.push(3);
let grid_size = 1;
let grid_size = 1000;
for x_index in -grid_size..grid_size {
for y_index in -grid_size..grid_size {
if !(((x_index as i32).abs() == 8 && y_index == 0) || (x_index == 0 && (y_index as i32).abs() == 8)){
let index = self.indices.len();
let vert = vertex::Vertex::new(
vec3(x_index as f32, y_index as f32, 0.0),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
);
self.vertices.push(vert);
self.indices.push(index as u32);
}
let index = self.vertices.len();
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, 0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.indices.push(index as u32);
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, 0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.indices.push(index as u32 + 1);
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 + 0.5, y_index as f32 + 0.5, 0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.indices.push(index as u32 + 2);
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 + 0.5, y_index as f32 - 0.5, 0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.indices.push(index as u32 + 2);
self.indices.push(index as u32 + 1);
self.indices.push(index as u32 + 3);
}
}
for x_index in -grid_size..grid_size {
for y_index in -grid_size..grid_size {
let index = self.vertices.len();
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, -0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, -0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 + 0.5, y_index as f32 + 0.5, -0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.vertices.push(vertex::Vertex::new(
vec3(x_index as f32 + 0.5, y_index as f32 - 0.5, -0.5),
vec3(0.0, 1.0, 0.0),
vec2(0.0, 0.0)
));
self.indices.push(index as u32 + 2);
self.indices.push(index as u32 + 1);
self.indices.push(index as u32);
self.indices.push(index as u32 + 3);
self.indices.push(index as u32 + 1);
self.indices.push(index as u32 + 2);
}
}