From cbfe9b855c11b1ef603b7212c244e089b4461753 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 18 Jul 2026 04:10:00 -0700 Subject: draw a second square in order to test the depth buffer, which does not yet exist Force-Push: yes Change-Id: Ibb4c279ff8b83ad9c0c37897f623631c4e342fb0 --- shaders/shader.vert | 4 ++-- src/main.rs | 2 +- src/shader_data.rs | 39 +++++++++++++++++++++++++++------------ 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/shaders/shader.vert b/shaders/shader.vert index b14c94b..c07575a 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -12,7 +12,7 @@ layout(binding = 0) uniform UniformBlock { mat4 projection; } uniform_block; -layout(location = 0) in vec2 inPosition; +layout(location = 0) in vec3 inPosition; layout(location = 1) in vec3 inColor; layout(location = 2) in vec2 inTextureCoordinate; @@ -85,7 +85,7 @@ vec4 apply_all_transforms(vec3 position) { void main() { - gl_Position = apply_all_transforms(vec3(inPosition, 0.0)); + gl_Position = apply_all_transforms(inPosition); fragmentColor = inColor; fragmentTextureCoordinate = inTextureCoordinate; } diff --git a/src/main.rs b/src/main.rs index 2433a40..478a179 100644 --- a/src/main.rs +++ b/src/main.rs @@ -292,7 +292,7 @@ fn render_uniforms(device: &Device, device_memory: &vk::DeviceMemory, .rotate(&Vec3::new(0.0, 1.0, 0.0), time % TAU), translation: Vec3::new(0.0, 0.0, 0.0), }; - let view = Transformation::look_at(&Vec3::new(0.0, -1.0, -2.0), + let view = Transformation::look_at(&Vec3::new(0.0, -2.0, -2.0), &Vec3::new(0.0, 0.0, 0.0), &Vec3::new(0.0, -1.0, 0.0)); let aspect_ratio = extent.width as f32 / extent.height as f32; diff --git a/src/shader_data.rs b/src/shader_data.rs index 404d5fb..bd7ff82 100644 --- a/src/shader_data.rs +++ b/src/shader_data.rs @@ -5,24 +5,35 @@ use std::mem::size_of; use vulkanalia::vk::{ self, HasBuilder }; -pub static VERTICES: [Vertex; 4] = [ - Vertex::new(Vec2::new(-0.5, -0.5), Vec3::new(1.0, 0.0, 0.0), +pub static VERTICES: [Vertex; 8] = [ + Vertex::new(Vec3::new(-0.5, -0.5, 0.0), Vec3::new(1.0, 0.0, 0.0), Vec2::new(1.0, 0.0)), - Vertex::new(Vec2::new( 0.5, -0.5), Vec3::new(0.0, 1.0, 0.0), + Vertex::new(Vec3::new( 0.5, -0.5, 0.0), Vec3::new(0.0, 1.0, 0.0), Vec2::new(0.0, 0.0)), - Vertex::new(Vec2::new( 0.5, 0.5), Vec3::new(0.0, 0.0, 1.0), + Vertex::new(Vec3::new( 0.5, 0.5, 0.0), Vec3::new(0.0, 0.0, 1.0), Vec2::new(0.0, 1.0)), - Vertex::new(Vec2::new(-0.5, 0.5), Vec3::new(1.0, 1.0, 1.0), + Vertex::new(Vec3::new(-0.5, 0.5, 0.0), Vec3::new(1.0, 1.0, 1.0), + Vec2::new(1.0, 1.0)), + Vertex::new(Vec3::new(-0.5, -0.5, 0.5), Vec3::new(1.0, 0.0, 0.0), + Vec2::new(1.0, 0.0)), + Vertex::new(Vec3::new( 0.5, -0.5, 0.5), Vec3::new(0.0, 1.0, 0.0), + Vec2::new(0.0, 0.0)), + Vertex::new(Vec3::new( 0.5, 0.5, 0.5), Vec3::new(0.0, 0.0, 1.0), + Vec2::new(0.0, 1.0)), + Vertex::new(Vec3::new(-0.5, 0.5, 0.5), Vec3::new(1.0, 1.0, 1.0), Vec2::new(1.0, 1.0)), ]; -pub const INDICES: &[u16] = &[0, 1, 2, 2, 3, 0]; +pub const INDICES: &[u16] = &[ + 0, 1, 2, 2, 3, 0, + 4, 5, 6, 6, 7, 4, +]; #[repr(C)] #[derive(Clone, Debug)] pub struct Vertex { - pub position: Vec2, + pub position: Vec3, pub color: Vec3, pub texture_coordinates: Vec2, } @@ -37,7 +48,7 @@ pub struct UniformBlock { } impl Vertex { - const fn new(position: Vec2, color: Vec3, + const fn new(position: Vec3, color: Vec3, texture_coordinates: Vec2) -> Self { @@ -55,25 +66,29 @@ impl Vertex { pub fn attribute_descriptions() -> [vk::VertexInputAttributeDescription; 3] { + let mut offset: usize = 0; + let position = vk::VertexInputAttributeDescription::builder() .binding(0) .location(0) - .format(vk::Format::R32G32_SFLOAT) - .offset(0) + .format(vk::Format::R32G32B32_SFLOAT) + .offset(offset as u32) .build(); + offset += size_of::>(); let color = vk::VertexInputAttributeDescription::builder() .binding(0) .location(1) .format(vk::Format::R32G32B32_SFLOAT) - .offset(size_of::>() as u32) + .offset(offset as u32) .build(); + offset += size_of::>(); let texture_coordinates = vk::VertexInputAttributeDescription::builder() .binding(0) .location(2) .format(vk::Format::R32G32_SFLOAT) - .offset((size_of::>() + size_of::>()) as u32) + .offset(offset as u32) .build(); [position, color, texture_coordinates] -- cgit 1.4.1