Browse Source

add normals and alpha to vertex info

master
Alison Watson 6 months ago
parent
commit
163fae8e88
4 changed files with 35 additions and 19 deletions
  1. +3
    -3
      glsl/main.frag
  2. +6
    -5
      glsl/main.vert
  3. +10
    -3
      source/framework/data/vertex.rs
  4. +16
    -8
      source/main_test/entry.rs

+ 3
- 3
glsl/main.frag View File

@@ -1,5 +1,5 @@
layout(location = 0) in vec3 vertex_color;
layout(location = 1) in vec3 vertex_texcoord;
layout(location = 0) in vec3 vertex_texcoord;
layout(location = 1) in vec4 vertex_color;

layout(location = 0) out vec4 frag_color;

@@ -7,7 +7,7 @@ layout(binding = 1) uniform sampler2D u_sampler;

void main() {
frag_color = texture(u_sampler, vertex_texcoord.xy);
frag_color *= vec4(vertex_color, 1.0);
frag_color *= vertex_color;
}

// EOF

+ 6
- 5
glsl/main.vert View File

@@ -1,9 +1,10 @@
layout(location = 0) in vec3 in_position;
layout(location = 1) in vec3 in_color;
layout(location = 2) in vec3 in_texcoord;
layout(location = 1) in vec3 in_texcoord;
layout(location = 2) in vec3 in_normal;
layout(location = 3) in vec4 in_color;

layout(location = 0) out vec3 vertex_color;
layout(location = 1) out vec3 vertex_texcoord;
layout(location = 0) out vec3 vertex_texcoord;
layout(location = 1) out vec4 vertex_color;

layout(binding = 0) uniform Uniforms {
mat4 obj;
@@ -18,8 +19,8 @@ void main() {
uniforms.obj *
vec4(in_position, 1.0);

vertex_color = in_color;
vertex_texcoord = in_texcoord;
vertex_color = in_color;
}

// EOF

+ 10
- 3
source/framework/data/vertex.rs View File

@@ -4,8 +4,9 @@ use cgmath::{Vector3, Vector4};
#[repr(C, packed)]
pub struct Vertex {
pub pos: Vector3<f32>,
pub clr: Vector3<f32>,
pub tex: Vector3<f32>,
pub nrm: Vector3<f32>,
pub clr: Vector4<f32>,
}

impl Vertex {
@@ -16,7 +17,7 @@ impl Vertex {
input_rate: vk::VertexInputRate::VERTEX,
}];

pub const ATTR_DESC: [vk::VertexInputAttributeDescription; 3] = [
pub const ATTR_DESC: [vk::VertexInputAttributeDescription; 4] = [
vk::VertexInputAttributeDescription {
location: 0,
binding: 0,
@@ -33,7 +34,13 @@ impl Vertex {
location: 2,
binding: 0,
format: vk::Format::R32G32B32_SFLOAT,
offset: 4 * 3 + 4 * 3,
offset: 4 * 3 * 2,
},
vk::VertexInputAttributeDescription {
location: 3,
binding: 0,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: 4 * 3 * 3,
},
];
}


+ 16
- 8
source/main_test/entry.rs View File

@@ -483,43 +483,51 @@ pub fn run(
const VERTICES: &[Vertex] = &[
Vertex {
pos: Vector3::new(-0.5, -0.5, 0.0),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(0.0, 0.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(0.5, -0.5, 0.0),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(1.0, 0.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(0.5, 0.5, 0.0),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(1.0, 1.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(-0.5, 0.5, 0.0),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(0.0, 1.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(-0.5, -0.5, -0.5),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(0.0, 0.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(0.5, -0.5, -0.5),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(1.0, 0.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(0.5, 0.5, -0.5),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(1.0, 1.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
Vertex {
pos: Vector3::new(-0.5, 0.5, -0.5),
clr: Vector3::new(1.0, 1.0, 1.0),
tex: Vector3::new(0.0, 1.0, 0.0),
nrm: Vector3::new(0.0, 0.0, 1.0),
clr: Vector4::new(1.0, 1.0, 1.0, 1.0),
},
];



Loading…
Cancel
Save