Skip to content

Commit

Permalink
switch to mat4 in ray-tracing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Vecvec committed Sep 24, 2024
1 parent a5dfc77 commit a8916b0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions examples/src/ray_cube_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
#[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]
Expand Down Expand Up @@ -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(),
}
};

Expand Down
10 changes: 5 additions & 5 deletions examples/src/ray_cube_fragment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
#[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.
Expand Down Expand Up @@ -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(),
}
};

Expand Down Expand Up @@ -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]));
}
Expand Down
10 changes: 5 additions & 5 deletions examples/src/ray_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
}
};

Expand Down Expand Up @@ -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]));
}
Expand Down
12 changes: 6 additions & 6 deletions examples/src/ray_shadows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ fn create_vertices() -> (Vec<Vertex>, Vec<u16>) {
#[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.
Expand Down Expand Up @@ -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),
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/src/ray_traced_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
}
};

Expand Down

0 comments on commit a8916b0

Please sign in to comment.