Fix mesh byte generation

This commit is contained in:
Carter Anderson 2020-04-19 15:39:24 -07:00
parent d8b183de02
commit 86d0ae6470
4 changed files with 17 additions and 13 deletions

View file

@ -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<dyn Schedulable> {
})
}
#[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");
}
}

View file

@ -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);
}

View file

@ -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);

View file

@ -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;
}