From a8916b03ad4fe6ee0877ab1a3382d0b192586395 Mon Sep 17 00:00:00 2001 From: Vecvec Date: Wed, 25 Sep 2024 07:28:28 +1200 Subject: [PATCH] switch to mat4 in ray-tracing examples --- Cargo.lock | 3 +++ examples/Cargo.toml | 2 +- examples/src/ray_cube_compute/mod.rs | 8 ++++---- examples/src/ray_cube_fragment/mod.rs | 10 +++++----- examples/src/ray_scene/mod.rs | 10 +++++----- examples/src/ray_shadows/mod.rs | 12 ++++++------ examples/src/ray_traced_triangle/mod.rs | 8 ++++---- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53b56d84df..00f0b18b01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1305,6 +1305,9 @@ name = "glam" version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "779ae4bf7e8421cf91c0b3b64e7e8b40b862fba4d393f59150042de7c4965a94" +dependencies = [ + "bytemuck", +] [[package]] name = "glow" diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f5beed1d22..73a575dce5 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -34,7 +34,7 @@ cfg-if.workspace = true encase = { workspace = true, features = ["glam"] } flume.workspace = true getrandom.workspace = true -glam.workspace = true +glam = {workspace = true, features = ["bytemuck"] } ktx2.workspace = true log.workspace = true nanorand.workspace = true diff --git a/examples/src/ray_cube_compute/mod.rs b/examples/src/ray_cube_compute/mod.rs index 6d312f232b..4700c1463c 100644 --- a/examples/src/ray_cube_compute/mod.rs +++ b/examples/src/ray_cube_compute/mod.rs @@ -70,8 +70,8 @@ fn create_vertices() -> (Vec, Vec) { #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable)] struct Uniforms { - view_inverse: [[f32; 4]; 4], - proj_inverse: [[f32; 4]; 4], + view_inverse: Mat4, + proj_inverse: Mat4, } #[inline] @@ -205,8 +205,8 @@ impl crate::framework::Example for Example { ); Uniforms { - view_inverse: view.inverse().to_cols_array_2d(), - proj_inverse: proj.inverse().to_cols_array_2d(), + view_inverse: view.inverse(), + proj_inverse: proj.inverse(), } }; diff --git a/examples/src/ray_cube_fragment/mod.rs b/examples/src/ray_cube_fragment/mod.rs index 5b052c728d..6d42f6b470 100644 --- a/examples/src/ray_cube_fragment/mod.rs +++ b/examples/src/ray_cube_fragment/mod.rs @@ -68,8 +68,8 @@ fn create_vertices() -> (Vec, Vec) { #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable)] struct Uniforms { - view_inverse: [[f32; 4]; 4], - proj_inverse: [[f32; 4]; 4], + view_inverse: Mat4, + proj_inverse: Mat4, } /// A wrapper for `pop_error_scope` futures that panics if an error occurs. @@ -134,8 +134,8 @@ impl crate::framework::Example for Example { ); Uniforms { - view_inverse: view.inverse().to_cols_array_2d(), - proj_inverse: proj.inverse().to_cols_array_2d(), + view_inverse: view.inverse(), + proj_inverse: proj.inverse(), } }; @@ -287,7 +287,7 @@ impl crate::framework::Example for Example { 1000.0, ); - self.uniforms.proj_inverse = proj.inverse().to_cols_array_2d(); + self.uniforms.proj_inverse = proj.inverse(); queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[self.uniforms])); } diff --git a/examples/src/ray_scene/mod.rs b/examples/src/ray_scene/mod.rs index 601bc4b0f2..e9f4df55bb 100644 --- a/examples/src/ray_scene/mod.rs +++ b/examples/src/ray_scene/mod.rs @@ -20,8 +20,8 @@ struct Vertex { #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable)] struct Uniforms { - view_inverse: [[f32; 4]; 4], - proj_inverse: [[f32; 4]; 4], + view_inverse: Mat4, + proj_inverse: Mat4, } /// A wrapper for `pop_error_scope` futures that panics if an error occurs. @@ -344,8 +344,8 @@ impl crate::framework::Example for Example { ); Uniforms { - view_inverse: view.inverse().to_cols_array_2d(), - proj_inverse: proj.inverse().to_cols_array_2d(), + view_inverse: view.inverse(), + proj_inverse: proj.inverse(), } }; @@ -455,7 +455,7 @@ impl crate::framework::Example for Example { 1000.0, ); - self.uniforms.proj_inverse = proj.inverse().to_cols_array_2d(); + self.uniforms.proj_inverse = proj.inverse(); queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(&[self.uniforms])); } diff --git a/examples/src/ray_shadows/mod.rs b/examples/src/ray_shadows/mod.rs index e81d0eb3ac..99ba017b0a 100644 --- a/examples/src/ray_shadows/mod.rs +++ b/examples/src/ray_shadows/mod.rs @@ -45,9 +45,9 @@ fn create_vertices() -> (Vec, Vec) { #[repr(C)] #[derive(Clone, Copy, Pod, Zeroable)] struct Uniforms { - view_inverse: [[f32; 4]; 4], - proj_inverse: [[f32; 4]; 4], - vertex: [[f32; 4]; 4], + view_inverse: Mat4, + proj_inverse: Mat4, + vertex: Mat4, } /// A wrapper for `pop_error_scope` futures that panics if an error occurs. @@ -94,9 +94,9 @@ fn create_matrix(config: &wgpu::SurfaceConfiguration) -> Uniforms { ); Uniforms { - view_inverse: view.inverse().to_cols_array_2d(), - proj_inverse: proj.inverse().to_cols_array_2d(), - vertex: (proj * view).to_cols_array_2d(), + view_inverse: view.inverse(), + proj_inverse: proj.inverse(), + vertex: (proj * view), } } diff --git a/examples/src/ray_traced_triangle/mod.rs b/examples/src/ray_traced_triangle/mod.rs index 26d9094cbf..1b80738331 100644 --- a/examples/src/ray_traced_triangle/mod.rs +++ b/examples/src/ray_traced_triangle/mod.rs @@ -22,8 +22,8 @@ struct Example { #[repr(C)] #[derive(bytemuck::Pod, bytemuck::Zeroable, Clone, Copy, Debug)] struct Uniforms { - view_inverse: [[f32; 4]; 4], - proj_inverse: [[f32; 4]; 4], + view_inverse: Mat4, + proj_inverse: Mat4, } impl crate::framework::Example for Example { @@ -194,8 +194,8 @@ impl crate::framework::Example for Example { let proj = Mat4::perspective_rh(59.0_f32.to_radians(), 1.0, 0.001, 1000.0); Uniforms { - view_inverse: view.inverse().to_cols_array_2d(), - proj_inverse: proj.inverse().to_cols_array_2d(), + view_inverse: view.inverse(), + proj_inverse: proj.inverse(), } };