triangles upper and lower layer, low vertex reuse
This commit is contained in:
parent
32577d548b
commit
a3e0b9a0c5
4 changed files with 64 additions and 33 deletions
|
@ -16,7 +16,7 @@ layout(location = 0) out vec3 geoColor;
|
||||||
layout(location = 1) out vec2 geoTexCoord;
|
layout(location = 1) out vec2 geoTexCoord;
|
||||||
|
|
||||||
void main() {
|
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;
|
geoColor = inColor;
|
||||||
geoTexCoord = inTexCoord;
|
geoTexCoord = inTexCoord;
|
||||||
}
|
}
|
BIN
shaders/vert.spv
BIN
shaders/vert.spv
Binary file not shown.
|
@ -669,7 +669,7 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
|
||||||
.vertex_attribute_descriptions(&attribute_descriptions);
|
.vertex_attribute_descriptions(&attribute_descriptions);
|
||||||
|
|
||||||
let input_assembly_state = vk::PipelineInputAssemblyStateCreateInfo::builder()
|
let input_assembly_state = vk::PipelineInputAssemblyStateCreateInfo::builder()
|
||||||
.topology(vk::PrimitiveTopology::POINT_LIST)
|
.topology(vk::PrimitiveTopology::TRIANGLE_LIST)
|
||||||
.primitive_restart_enable(false);
|
.primitive_restart_enable(false);
|
||||||
|
|
||||||
let viewport = vk::Viewport::builder()
|
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)?;
|
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()
|
let info = vk::GraphicsPipelineCreateInfo::builder()
|
||||||
.stages(stages)
|
.stages(stages)
|
||||||
.vertex_input_state(&vertex_input_state)
|
.vertex_input_state(&vertex_input_state)
|
||||||
|
|
83
src/scene.rs
83
src/scene.rs
|
@ -21,40 +21,71 @@ pub struct Scene {
|
||||||
|
|
||||||
impl Scene {
|
impl Scene {
|
||||||
pub unsafe fn prepare_data(&mut self, instance: &vulkanalia::Instance, device: &vulkanalia::Device, data: &AppData) -> Result<()> {
|
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(
|
let grid_size = 1000;
|
||||||
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;
|
|
||||||
for x_index in -grid_size..grid_size {
|
for x_index in -grid_size..grid_size {
|
||||||
for y_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.vertices.len();
|
||||||
let index = self.indices.len();
|
self.vertices.push(vertex::Vertex::new(
|
||||||
let vert = vertex::Vertex::new(
|
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, 0.5),
|
||||||
vec3(x_index as f32, y_index as f32, 0.0),
|
|
||||||
vec3(0.0, 1.0, 0.0),
|
vec3(0.0, 1.0, 0.0),
|
||||||
vec2(0.0, 0.0)
|
vec2(0.0, 0.0)
|
||||||
);
|
));
|
||||||
self.vertices.push(vert);
|
|
||||||
self.indices.push(index as u32);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(self.vertex_buffer, self.vertex_buffer_memory) = buffer::create_vertex_buffer(instance, device, &data, &self.vertices)?;
|
(self.vertex_buffer, self.vertex_buffer_memory) = buffer::create_vertex_buffer(instance, device, &data, &self.vertices)?;
|
||||||
|
|
Loading…
Reference in a new issue