diff --git a/examples/simple.rs b/examples/simple.rs index 04c2ed5d70..90d8d6db90 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -167,7 +167,7 @@ fn main() { let mut scheduler = SystemScheduler::::new(); let cube = Mesh::load(MeshType::Cube); - let plane = Mesh::load(MeshType::Plane{ size: 25 }); + let plane = Mesh::load(MeshType::Plane{ size: 24.5 }); let mut mesh_storage = AssetStorage::::new(); let _cube_handle = mesh_storage.add(cube, "cube"); diff --git a/src/application.rs b/src/application.rs index 45c73e7c7d..990c5c7ce0 100644 --- a/src/application.rs +++ b/src/application.rs @@ -62,13 +62,13 @@ impl Application { step_mode: wgpu::InputStepMode::Vertex, attributes: &[ wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Char4, + format: wgpu::VertexFormat::Float4, offset: 0, shader_location: 0, }, wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Char4, - offset: 4 * 1, + format: wgpu::VertexFormat::Float4, + offset: 4 * 4, shader_location: 1, }, ], diff --git a/src/render/forward/forward.vert b/src/render/forward/forward.vert index 5e02939393..4cada407c1 100644 --- a/src/render/forward/forward.vert +++ b/src/render/forward/forward.vert @@ -1,7 +1,7 @@ #version 450 -layout(location = 0) in ivec4 a_Pos; -layout(location = 1) in ivec4 a_Normal; +layout(location = 0) in vec4 a_Pos; +layout(location = 1) in vec4 a_Normal; layout(location = 0) out vec3 v_Normal; layout(location = 1) out vec4 v_Position; diff --git a/src/render/mesh.rs b/src/render/mesh.rs index 02f2856ccb..be902a248a 100644 --- a/src/render/mesh.rs +++ b/src/render/mesh.rs @@ -5,7 +5,7 @@ use zerocopy::AsBytes; pub enum MeshType { Cube, Plane { - size: i8 + size: f32 } } @@ -44,45 +44,38 @@ impl Asset for Mesh { } } -pub fn vertex(pos: [i8; 3], nor: [i8; 3]) -> Vertex { - Vertex { - pos: [pos[0], pos[1], pos[2], 1], - normal: [nor[0], nor[1], nor[2], 0], - } -} - pub fn create_cube() -> (Vec, Vec) { let vertex_data = [ // top (0, 0, 1) - vertex([-1, -1, 1], [0, 0, 1]), - vertex([1, -1, 1], [0, 0, 1]), - vertex([1, 1, 1], [0, 0, 1]), - vertex([-1, 1, 1], [0, 0, 1]), + Vertex::from(([-1, -1, 1], [0, 0, 1])), + Vertex::from(([1, -1, 1], [0, 0, 1])), + Vertex::from(([1, 1, 1], [0, 0, 1])), + Vertex::from(([-1, 1, 1], [0, 0, 1])), // bottom (0, 0, -1) - vertex([-1, 1, -1], [0, 0, -1]), - vertex([1, 1, -1], [0, 0, -1]), - vertex([1, -1, -1], [0, 0, -1]), - vertex([-1, -1, -1], [0, 0, -1]), + Vertex::from(([-1, 1, -1], [0, 0, -1])), + Vertex::from(([1, 1, -1], [0, 0, -1])), + Vertex::from(([1, -1, -1], [0, 0, -1])), + Vertex::from(([-1, -1, -1], [0, 0, -1])), // right (1, 0, 0) - vertex([1, -1, -1], [1, 0, 0]), - vertex([1, 1, -1], [1, 0, 0]), - vertex([1, 1, 1], [1, 0, 0]), - vertex([1, -1, 1], [1, 0, 0]), + Vertex::from(([1, -1, -1], [1, 0, 0])), + Vertex::from(([1, 1, -1], [1, 0, 0])), + Vertex::from(([1, 1, 1], [1, 0, 0])), + Vertex::from(([1, -1, 1], [1, 0, 0])), // left (-1, 0, 0) - vertex([-1, -1, 1], [-1, 0, 0]), - vertex([-1, 1, 1], [-1, 0, 0]), - vertex([-1, 1, -1], [-1, 0, 0]), - vertex([-1, -1, -1], [-1, 0, 0]), + Vertex::from(([-1, -1, 1], [-1, 0, 0])), + Vertex::from(([-1, 1, 1], [-1, 0, 0])), + Vertex::from(([-1, 1, -1], [-1, 0, 0])), + Vertex::from(([-1, -1, -1], [-1, 0, 0])), // front (0, 1, 0) - vertex([1, 1, -1], [0, 1, 0]), - vertex([-1, 1, -1], [0, 1, 0]), - vertex([-1, 1, 1], [0, 1, 0]), - vertex([1, 1, 1], [0, 1, 0]), + Vertex::from(([1, 1, -1], [0, 1, 0])), + Vertex::from(([-1, 1, -1], [0, 1, 0])), + Vertex::from(([-1, 1, 1], [0, 1, 0])), + Vertex::from(([1, 1, 1], [0, 1, 0])), // back (0, -1, 0) - vertex([1, -1, 1], [0, -1, 0]), - vertex([-1, -1, 1], [0, -1, 0]), - vertex([-1, -1, -1], [0, -1, 0]), - vertex([1, -1, -1], [0, -1, 0]), + Vertex::from(([1, -1, 1], [0, -1, 0])), + Vertex::from(([-1, -1, 1], [0, -1, 0])), + Vertex::from(([-1, -1, -1], [0, -1, 0])), + Vertex::from(([1, -1, -1], [0, -1, 0])), ]; let index_data: &[u16] = &[ @@ -97,12 +90,12 @@ pub fn create_cube() -> (Vec, Vec) { (vertex_data.to_vec(), index_data.to_vec()) } -pub fn create_plane(size: i8) -> (Vec, Vec) { +pub fn create_plane(size: f32) -> (Vec, Vec) { let vertex_data = [ - vertex([size, -size, 0], [0, 0, 1]), - vertex([size, size, 0], [0, 0, 1]), - vertex([-size, -size, 0], [0, 0, 1]), - vertex([-size, size, 0], [0, 0, 1]), + Vertex::from(([size, -size, 0.0], [0.0, 0.0, 1.0])), + Vertex::from(([size, size, 0.0], [0.0, 0.0, 1.0])), + Vertex::from(([-size, -size, 0.0], [0.0, 0.0, 1.0])), + Vertex::from(([-size, size, 0.0], [0.0, 0.0, 1.0])), ]; let index_data: &[u16] = &[0, 1, 2, 2, 1, 3]; diff --git a/src/render/shadow/shadow.vert b/src/render/shadow/shadow.vert index e4426b7455..c4c41455c8 100644 --- a/src/render/shadow/shadow.vert +++ b/src/render/shadow/shadow.vert @@ -1,6 +1,6 @@ #version 450 -layout(location = 0) in ivec4 a_Pos; +layout(location = 0) in vec4 a_Pos; layout(set = 0, binding = 0) uniform Globals { mat4 u_ViewProj; diff --git a/src/vertex.rs b/src/vertex.rs index 963b7bb783..f5eda43b12 100644 --- a/src/vertex.rs +++ b/src/vertex.rs @@ -1,8 +1,45 @@ use zerocopy::{AsBytes, FromBytes}; +use std::convert::From; #[repr(C)] #[derive(Clone, Copy, AsBytes, FromBytes)] pub struct Vertex { - pub pos: [i8; 4], - pub normal: [i8; 4], + pub position: [f32; 4], + pub normal: [f32; 4], +} + +impl From<([f32; 4], [f32; 4])> for Vertex { + fn from((position, normal): ([f32; 4], [f32; 4])) -> Self { + Vertex { + position: position, + normal: normal, + } + } +} + +impl From<([f32; 3], [f32; 3])> for Vertex { + fn from((position, normal): ([f32; 3], [f32; 3])) -> Self { + Vertex { + position: [position[0] as f32, position[1] as f32, position[2] as f32, 1.0], + normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, 0.0], + } + } +} + +impl From<([i8; 4], [i8; 4])> for Vertex { + fn from((position, normal): ([i8; 4], [i8; 4])) -> Self { + Vertex { + position: [position[0] as f32, position[1] as f32, position[2] as f32, position[3] as f32], + normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, normal[3] as f32], + } + } +} + +impl From<([i8; 3], [i8; 3])> for Vertex { + fn from((position, normal): ([i8; 3], [i8; 3])) -> Self { + Vertex { + position: [position[0] as f32, position[1] as f32, position[2] as f32, 1.0], + normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, 0.0], + } + } } \ No newline at end of file