From a3e0b9a0c51288ef41dd7f3f24688e72e3742904 Mon Sep 17 00:00:00 2001 From: zomseffen Date: Wed, 22 May 2024 19:47:49 +0200 Subject: [PATCH] triangles upper and lower layer, low vertex reuse --- shaders/shader.vert | 2 +- shaders/vert.spv | Bin 1848 -> 1992 bytes src/main.rs | 4 +- src/scene.rs | 91 +++++++++++++++++++++++++++++--------------- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/shaders/shader.vert b/shaders/shader.vert index 76bf4e0..1ffef71 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -16,7 +16,7 @@ layout(location = 0) out vec3 geoColor; layout(location = 1) out vec2 geoTexCoord; void main() { - gl_Position = ubo.geom_rot * ubo.model * vec4(inPosition, 1.0); + gl_Position = ubo.proj * ubo.view * ubo.geom_rot * ubo.model * vec4(inPosition, 1.0); geoColor = inColor; geoTexCoord = inTexCoord; } \ No newline at end of file diff --git a/shaders/vert.spv b/shaders/vert.spv index 308206e3c29da1ea60f40e998fa5b866d70b7187..d3b1d595054fb92959371395decfceffbde62135 100644 GIT binary patch delta 811 zcmYk3OG*P#5Jl@Hwhp8dB}n`mjlUTGzg9#gWZ=Mo3NAqrMQq4KK`?G1W+jq|OK=ko z9J&a>d)j_t!=Q`rf&j_NOcC z!e3p+_4qb!$hE+_lDg}=Un&rTMm6V`5A`^1T!;xQ>MUg*U5(b`==2>)O1u9tza(~P zo>u?ksPmOAI+ty`pwO(UK~4pOLPqfMsC*g}l`qS73t6G0cv_Ym{9YO}6dZbL=LECo zL+Y30q1A;F{Yn~3f0HzTU<-!Rc1__7**(kV(SBN=@WaAOM zhD#3-u)fSZ$UyPB>Q(pjtDoX`A<6}{yqU8(i|lw1-7HkhY**M5nnL{5eRZxf{B@;M z^rueJPM(vVN(*gf;_JSoQYeKUc^*1%?Ih_vN(n6U5d(9v%EMED2)KrV0q diff --git a/src/main.rs b/src/main.rs index 4fdb3a8..0fb944e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -669,7 +669,7 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu .vertex_attribute_descriptions(&attribute_descriptions); let input_assembly_state = vk::PipelineInputAssemblyStateCreateInfo::builder() - .topology(vk::PrimitiveTopology::POINT_LIST) + .topology(vk::PrimitiveTopology::TRIANGLE_LIST) .primitive_restart_enable(false); let viewport = vk::Viewport::builder() @@ -735,7 +735,7 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu data.pipeline_layout = device.create_pipeline_layout(&layout_info, None)?; - let stages = &[vert_stage, geo_stage, frag_stage]; + let stages = &[vert_stage, frag_stage]; let info = vk::GraphicsPipelineCreateInfo::builder() .stages(stages) .vertex_input_state(&vertex_input_state) diff --git a/src/scene.rs b/src/scene.rs index ed131a2..f1d91d8 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -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); } }