diff --git a/src/render_domain.rs b/src/render_domain.rs index 0d333f81..90395dfd 100644 --- a/src/render_domain.rs +++ b/src/render_domain.rs @@ -292,7 +292,7 @@ layout(set=0,binding=2,scalar) buffer readonly MeshVertexPositions {{ }}; layout(set=0,binding=4,scalar) buffer readonly MeshIndices {{ - uint16_t indices[]; + uint8_t indices[]; }}; layout(set=0,binding=6,scalar) buffer readonly MeshletsBuffer {{ @@ -1763,7 +1763,7 @@ impl orchestrator::EntitySubscriber for VisibilityWorldRenderDomain { let meshlet_index_stream = mesh.index_streams.iter().find(|is| is.stream_type == mesh_resource_handler::IndexStreamTypes::Meshlets).unwrap(); - assert_eq!(meshlet_index_stream.data_type, mesh_resource_handler::IntegralTypes::U16, "Meshlet index stream is not u16"); + assert_eq!(meshlet_index_stream.data_type, mesh_resource_handler::IntegralTypes::U8, "Meshlet index stream is not u8"); for _ in 0..meshlet_count { let meshlet_vertex_count = (mesh.vertex_count - mesh_vertex_count).min(63) as u8; diff --git a/src/rendering/visibility_shader_generator.rs b/src/rendering/visibility_shader_generator.rs index 7260b69b..86e75a02 100644 --- a/src/rendering/visibility_shader_generator.rs +++ b/src/rendering/visibility_shader_generator.rs @@ -196,7 +196,7 @@ layout(set=2, binding=3, scalar) buffer readonly Normals { }; layout(set=2, binding=4, scalar) buffer readonly Indeces { - uint16_t indeces[]; + uint8_t indeces[]; }; const float PI = 3.14159265359; diff --git a/src/resource_manager/mesh_resource_handler.rs b/src/resource_manager/mesh_resource_handler.rs index b2390368..02d900a0 100644 --- a/src/resource_manager/mesh_resource_handler.rs +++ b/src/resource_manager/mesh_resource_handler.rs @@ -116,14 +116,15 @@ impl ResourceHandler for MeshResourceHandler { index_count += meshlet.triangle_count as usize * 3; for i in 0..meshlet.triangle_count as usize { for x in meshlet.indices[i] { - (x as u16).to_le_bytes().iter().for_each(|byte| buffer.push(*byte)); + assert!(x <= 64, "Meshlet index out of bounds"); // Max vertices per meshlet + buffer.push(x as u8); } } } assert_eq!(index_count, optimized_indices.len()); - index_streams.push(IndexStream{ data_type: IntegralTypes::U16, stream_type: IndexStreamTypes::Meshlets, offset, count: optimized_indices.len() as u32 }); + index_streams.push(IndexStream{ data_type: IntegralTypes::U8, stream_type: IndexStreamTypes::Meshlets, offset, count: optimized_indices.len() as u32 }); } let mesh = Mesh { @@ -404,7 +405,7 @@ mod tests { assert_eq!(mesh.index_streams[1].stream_type, IndexStreamTypes::Meshlets); assert_eq!(mesh.index_streams[1].offset, offset); assert_eq!(mesh.index_streams[1].count, 36); - assert_eq!(mesh.index_streams[1].data_type, IntegralTypes::U16); + assert_eq!(mesh.index_streams[1].data_type, IntegralTypes::U8); let resource_request = resource_manager.request_resource("Box"); @@ -486,23 +487,23 @@ mod tests { assert_eq!(mesh.index_streams[1].stream_type, IndexStreamTypes::Meshlets); assert_eq!(mesh.index_streams[1].offset, offset); assert_eq!(mesh.index_streams[1].count, 3936 * 3); - assert_eq!(mesh.index_streams[1].data_type, IntegralTypes::U16); + assert_eq!(mesh.index_streams[1].data_type, IntegralTypes::U8); let vertex_positions = unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const Vector3, mesh.vertex_count as usize) }; assert_eq!(vertex_positions.len(), 11808); - assert_eq!(vertex_positions[0], Vector3::new(0.492188f32, 0.185547f32, 0.720703f32)); - assert_eq!(vertex_positions[1], Vector3::new(0.472656f32, 0.243042f32, 0.751221f32)); - assert_eq!(vertex_positions[2], Vector3::new(0.463867f32, 0.198242f32, 0.753418f32)); + assert_eq!(vertex_positions[0], Vector3::new(0.492188f32, 0.185547f32, -0.720703f32)); + assert_eq!(vertex_positions[1], Vector3::new(0.472656f32, 0.243042f32, -0.751221f32)); + assert_eq!(vertex_positions[2], Vector3::new(0.463867f32, 0.198242f32, -0.753418f32)); let vertex_normals = unsafe { std::slice::from_raw_parts((buffer.as_ptr() as *const Vector3).add(11808), mesh.vertex_count as usize) }; assert_eq!(vertex_normals.len(), 11808); - assert_eq!(vertex_normals[0], Vector3::new(0.703351f32, -0.228379f32, 0.673156f32)); - assert_eq!(vertex_normals[1], Vector3::new(0.818977f32, -0.001884f32, 0.573824f32)); - assert_eq!(vertex_normals[2], Vector3::new(0.776439f32, -0.262265f32, 0.573027f32)); + assert_eq!(vertex_normals[0], Vector3::new(0.703351f32, -0.228379f32, -0.673156f32)); + assert_eq!(vertex_normals[1], Vector3::new(0.818977f32, -0.001884f32, -0.573824f32)); + assert_eq!(vertex_normals[2], Vector3::new(0.776439f32, -0.262265f32, -0.573027f32)); } #[test] @@ -546,23 +547,23 @@ mod tests { assert_eq!(mesh.index_streams[1].stream_type, IndexStreamTypes::Meshlets); assert_eq!(mesh.index_streams[1].offset, offset); assert_eq!(mesh.index_streams[1].count, 36); - assert_eq!(mesh.index_streams[1].data_type, IntegralTypes::U16); + assert_eq!(mesh.index_streams[1].data_type, IntegralTypes::U8); // Cast buffer to Vector3 let vertex_positions = unsafe { std::slice::from_raw_parts(buffer.as_ptr() as *const Vector3, mesh.vertex_count as usize) }; assert_eq!(vertex_positions.len(), 24); - assert_eq!(vertex_positions[0], Vector3::new(-0.5f32, -0.5f32, 0.5f32)); - assert_eq!(vertex_positions[1], Vector3::new(0.5f32, -0.5f32, 0.5f32)); - assert_eq!(vertex_positions[2], Vector3::new(-0.5f32, 0.5f32, 0.5f32)); + assert_eq!(vertex_positions[0], Vector3::new(-0.5f32, -0.5f32, -0.5f32)); + assert_eq!(vertex_positions[1], Vector3::new(0.5f32, -0.5f32, -0.5f32)); + assert_eq!(vertex_positions[2], Vector3::new(-0.5f32, 0.5f32, -0.5f32)); // Cast buffer + 12 * 24 to Vector3 let vertex_normals = unsafe { std::slice::from_raw_parts((buffer.as_ptr() as *const Vector3).add(24), mesh.vertex_count as usize) }; assert_eq!(vertex_normals.len(), 24); - assert_eq!(vertex_normals[0], Vector3::new(0f32, 0f32, 1f32)); - assert_eq!(vertex_normals[1], Vector3::new(0f32, 0f32, 1f32)); - assert_eq!(vertex_normals[2], Vector3::new(0f32, 0f32, 1f32)); + assert_eq!(vertex_normals[0], Vector3::new(0f32, 0f32, -1f32)); + assert_eq!(vertex_normals[1], Vector3::new(0f32, 0f32, -1f32)); + assert_eq!(vertex_normals[2], Vector3::new(0f32, 0f32, -1f32)); // Cast buffer + 12 * 24 + 12 * 24 to u16 let indeces = unsafe { std::slice::from_raw_parts((buffer.as_ptr().add(12 * 24 + 12 * 24)) as *const u16, mesh.index_streams[0].count as usize) }; @@ -609,17 +610,17 @@ mod tests { let vertex_positions = unsafe { std::slice::from_raw_parts(vertex_buffer.as_ptr() as *const Vector3, mesh.vertex_count as usize) }; assert_eq!(vertex_positions.len(), 24); - assert_eq!(vertex_positions[0], Vector3::new(-0.5f32, -0.5f32, 0.5f32)); - assert_eq!(vertex_positions[1], Vector3::new(0.5f32, -0.5f32, 0.5f32)); - assert_eq!(vertex_positions[2], Vector3::new(-0.5f32, 0.5f32, 0.5f32)); + assert_eq!(vertex_positions[0], Vector3::new(-0.5f32, -0.5f32, -0.5f32)); + assert_eq!(vertex_positions[1], Vector3::new(0.5f32, -0.5f32, -0.5f32)); + assert_eq!(vertex_positions[2], Vector3::new(-0.5f32, 0.5f32, -0.5f32)); // Cast vertex_buffer + 12 * 24 to Vector3 let vertex_normals = unsafe { std::slice::from_raw_parts((vertex_buffer.as_ptr() as *const Vector3).add(24) as *const Vector3, mesh.vertex_count as usize) }; assert_eq!(vertex_normals.len(), 24); - assert_eq!(vertex_normals[0], Vector3::new(0f32, 0f32, 1f32)); - assert_eq!(vertex_normals[1], Vector3::new(0f32, 0f32, 1f32)); - assert_eq!(vertex_normals[2], Vector3::new(0f32, 0f32, 1f32)); + assert_eq!(vertex_normals[0], Vector3::new(0f32, 0f32, -1f32)); + assert_eq!(vertex_normals[1], Vector3::new(0f32, 0f32, -1f32)); + assert_eq!(vertex_normals[2], Vector3::new(0f32, 0f32, -1f32)); // Cast index_buffer to u16 @@ -676,17 +677,17 @@ mod tests { let vertex_positions_buffer = unsafe { std::slice::from_raw_parts(vertex_positions_buffer.as_ptr() as *const Vector3, mesh.vertex_count as usize) }; assert_eq!(vertex_positions_buffer.len(), 24); - assert_eq!(vertex_positions_buffer[0], Vector3::new(-0.5f32, -0.5f32, 0.5f32)); - assert_eq!(vertex_positions_buffer[1], Vector3::new(0.5f32, -0.5f32, 0.5f32)); - assert_eq!(vertex_positions_buffer[2], Vector3::new(-0.5f32, 0.5f32, 0.5f32)); + assert_eq!(vertex_positions_buffer[0], Vector3::new(-0.5f32, -0.5f32, -0.5f32)); + assert_eq!(vertex_positions_buffer[1], Vector3::new(0.5f32, -0.5f32, -0.5f32)); + assert_eq!(vertex_positions_buffer[2], Vector3::new(-0.5f32, 0.5f32, -0.5f32)); // Cast vertex_normals_buffer to Vector3 let vertex_normals_buffer = unsafe { std::slice::from_raw_parts(vertex_normals_buffer.as_ptr() as *const Vector3, mesh.vertex_count as usize) }; assert_eq!(vertex_normals_buffer.len(), 24); - assert_eq!(vertex_normals_buffer[0], Vector3::new(0f32, 0f32, 1f32)); - assert_eq!(vertex_normals_buffer[1], Vector3::new(0f32, 0f32, 1f32)); - assert_eq!(vertex_normals_buffer[2], Vector3::new(0f32, 0f32, 1f32)); + assert_eq!(vertex_normals_buffer[0], Vector3::new(0f32, 0f32, -1f32)); + assert_eq!(vertex_normals_buffer[1], Vector3::new(0f32, 0f32, -1f32)); + assert_eq!(vertex_normals_buffer[2], Vector3::new(0f32, 0f32, -1f32)); // Cast index_buffer to u16