From 86d0ae6470a25f3ce62d9f7e1d0bec4d69f9bafc Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Sun, 19 Apr 2020 15:39:24 -0700 Subject: [PATCH] Fix mesh byte generation --- bevy_render/src/mesh.rs | 25 +++++++++++-------- .../pipeline/pipelines/forward/forward.frag | 2 +- .../pipeline/pipelines/forward/forward.vert | 1 + .../pipelines/forward_flat/forward_flat.vert | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bevy_render/src/mesh.rs b/bevy_render/src/mesh.rs index 39a70a2b2f..806575490c 100644 --- a/bevy_render/src/mesh.rs +++ b/bevy_render/src/mesh.rs @@ -62,9 +62,9 @@ pub struct VertexAttribute { } impl VertexAttribute { - pub const POSITION: &'static str = "position"; - pub const NORMAL: &'static str = "normal"; - pub const UV: &'static str = "uv"; + pub const POSITION: &'static str = "Vertex_Position"; + pub const NORMAL: &'static str = "Vertex_Normal"; + pub const UV: &'static str = "Vertex_Uv"; pub fn position(positions: Vec<[f32; 3]>) -> Self { VertexAttribute { @@ -127,7 +127,7 @@ impl Mesh { match self .attributes .iter() - .find(|a| VertexFormat::from(&a.values) == vertex_attribute.format) + .find(|a| vertex_attribute.name == a.name) { Some(mesh_attribute) => { let attribute_bytes = mesh_attribute.values.get_bytes(); @@ -321,8 +321,12 @@ pub fn mesh_batcher_system() -> Box { }) } -#[cfg(tests)] +#[cfg(test)] mod tests { + use crate::{Vertex, pipeline::state_descriptors::PrimitiveTopology, shader::AsUniforms}; + use super::{Mesh, VertexAttribute}; + use zerocopy::AsBytes; + #[test] fn test_get_vertex_bytes() { let vertices = &[ @@ -335,9 +339,9 @@ mod tests { let mut normals = Vec::new(); let mut uvs = Vec::new(); for (position, normal, uv) in vertices.iter() { - positions.push(position.clone()); - normals.push(normal.clone()); - uvs.push(uv.clone()); + positions.push(*position); + normals.push(*normal); + uvs.push(*uv); } let mesh = Mesh { @@ -368,8 +372,7 @@ mod tests { }, ]; - let descriptor = Vertex::get_vertex_buffer_descriptor(); - - assert_eq!(mesh.get_vertex_buffer_bytes(descriptor), expected_vertices.as_bytes(), "buffer bytes are equal"); + let descriptor = Vertex::get_vertex_buffer_descriptor().unwrap(); + assert_eq!(mesh.get_vertex_buffer_bytes(descriptor).unwrap(), expected_vertices.as_bytes(), "buffer bytes are equal"); } } diff --git a/bevy_render/src/pipeline/pipelines/forward/forward.frag b/bevy_render/src/pipeline/pipelines/forward/forward.frag index a3b3d934fa..62463c76a1 100644 --- a/bevy_render/src/pipeline/pipelines/forward/forward.frag +++ b/bevy_render/src/pipeline/pipelines/forward/forward.frag @@ -53,5 +53,5 @@ void main() { } // multiply the light by material color o_Target = vec4(color, 1.0) * albedo; - o_Target = vec4(v_Normal, 1.0); + // o_Target = vec4(v_Normal, 1.0); } diff --git a/bevy_render/src/pipeline/pipelines/forward/forward.vert b/bevy_render/src/pipeline/pipelines/forward/forward.vert index 01f3a7eb25..d2b497912c 100644 --- a/bevy_render/src/pipeline/pipelines/forward/forward.vert +++ b/bevy_render/src/pipeline/pipelines/forward/forward.vert @@ -36,6 +36,7 @@ void main() { # endif v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz; + v_Normal = mat3(Model) * Vertex_Normal; v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz; v_Uv = Vertex_Uv; gl_Position = ViewProj * vec4(v_Position, 1.0); diff --git a/bevy_render/src/pipeline/pipelines/forward_flat/forward_flat.vert b/bevy_render/src/pipeline/pipelines/forward_flat/forward_flat.vert index fe2985c357..bd5018dc2c 100644 --- a/bevy_render/src/pipeline/pipelines/forward_flat/forward_flat.vert +++ b/bevy_render/src/pipeline/pipelines/forward_flat/forward_flat.vert @@ -21,7 +21,7 @@ layout(set = 1, binding = 1) uniform StandardMaterial_albedo { }; void main() { - v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz; + v_Normal = mat3(Model) * Vertex_Normal; v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz; gl_Position = ViewProj * v_Position; }