-
Couldn't load subscription status.
- Fork 78
Matrix4x3 v2 #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Matrix4x3 v2 #433
Changes from all commits
169005c
680317c
6b699a5
951a990
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,31 +1,39 @@ | ||||||||||||||||||||||
| //! a set of common SPIR-V Matrices, used for intrinsics | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| use core::fmt::{Debug, Display, Formatter}; | ||||||||||||||||||||||
| use glam::{Affine3A, Mat3, Mat3A, Mat4, Vec3, Vec3A}; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// A Matrix with 4 columns of [`Vec3`], very similar to glam's [`Affine3A`]. | ||||||||||||||||||||||
| /// | ||||||||||||||||||||||
| /// Primarily used in ray tracing extensions to represent object rotation, scale and translation. | ||||||||||||||||||||||
| /// | ||||||||||||||||||||||
| /// # Limitations | ||||||||||||||||||||||
| /// These Limitations apply to all structs marked with `#[spirv(matrix)]`, which `Matrix4x3` is the only one in | ||||||||||||||||||||||
| /// `spirv-std`: | ||||||||||||||||||||||
| /// * Cannot be used within buffers, push constants or anything that requires an "explicit layout". Use [`Affine3A`], | ||||||||||||||||||||||
| /// [`Mat4`] or the combination of [`Mat3`] with [`Vec3`] instead and convert them to `Matrix4x3` in the shader. | ||||||||||||||||||||||
| /// * There may be other situations where this type may surprisingly fail! | ||||||||||||||||||||||
| #[derive(Clone, Copy, Default, PartialEq)] | ||||||||||||||||||||||
| #[repr(C)] | ||||||||||||||||||||||
| #[spirv(matrix)] | ||||||||||||||||||||||
| #[allow(missing_docs)] | ||||||||||||||||||||||
| pub struct Matrix4x3 { | ||||||||||||||||||||||
| pub x: Vec3A, | ||||||||||||||||||||||
| pub y: Vec3A, | ||||||||||||||||||||||
| pub z: Vec3A, | ||||||||||||||||||||||
| pub w: Vec3A, | ||||||||||||||||||||||
| pub x_axis: Vec3A, | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this change? Is it more or less consistent with other APIs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More consistent, now the member names are the same of glam's matrices. Split it out into a separate commit to make it easier to reason about rust-gpu/crates/spirv-std/src/matrix.rs Lines 29 to 38 in 951a990
|
||||||||||||||||||||||
| pub y_axis: Vec3A, | ||||||||||||||||||||||
| pub z_axis: Vec3A, | ||||||||||||||||||||||
| pub w_axis: Vec3A, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// The `from_*` fn signatures should match [`Affine3A`], to make it easier to switch to [`Affine3A`] later. | ||||||||||||||||||||||
| /// The `to_*` fn signatures are custom | ||||||||||||||||||||||
| /// The `to_*` fn signatures are custom. | ||||||||||||||||||||||
| impl Matrix4x3 { | ||||||||||||||||||||||
| /// Convert from glam's [`Affine3A`] | ||||||||||||||||||||||
| pub fn from_affine3a(affine: Affine3A) -> Self { | ||||||||||||||||||||||
| Self { | ||||||||||||||||||||||
| x: affine.x_axis, | ||||||||||||||||||||||
| y: affine.y_axis, | ||||||||||||||||||||||
| z: affine.z_axis, | ||||||||||||||||||||||
| w: affine.w_axis, | ||||||||||||||||||||||
| x_axis: affine.x_axis, | ||||||||||||||||||||||
| y_axis: affine.y_axis, | ||||||||||||||||||||||
| z_axis: affine.z_axis, | ||||||||||||||||||||||
| w_axis: affine.w_axis, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -53,11 +61,11 @@ impl Matrix4x3 { | |||||||||||||||||||||
| pub fn to_affine3a(self) -> Affine3A { | ||||||||||||||||||||||
| Affine3A { | ||||||||||||||||||||||
| matrix3: Mat3A { | ||||||||||||||||||||||
| x_axis: self.x, | ||||||||||||||||||||||
| y_axis: self.y, | ||||||||||||||||||||||
| z_axis: self.z, | ||||||||||||||||||||||
| x_axis: self.x_axis, | ||||||||||||||||||||||
| y_axis: self.y_axis, | ||||||||||||||||||||||
| z_axis: self.z_axis, | ||||||||||||||||||||||
| }, | ||||||||||||||||||||||
| translation: self.w, | ||||||||||||||||||||||
| translation: self.w_axis, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -76,3 +84,15 @@ impl Matrix4x3 { | |||||||||||||||||||||
| Mat4::from(self.to_affine3a()) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl Debug for Matrix4x3 { | ||||||||||||||||||||||
| fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||||||||||||||||||||||
| Debug::fmt(&self.to_mat4(), f) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl Display for Matrix4x3 { | ||||||||||||||||||||||
| fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||||||||||||||||||||||
| Display::fmt(&self.to_mat4(), f) | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit too inward facing. Just state the limitations. I guess you can optionally ask for a task.