11//! a set of common SPIR-V Matrices, used for intrinsics
22
3+ use core:: fmt:: { Debug , Display , Formatter } ;
34use glam:: { Affine3A , Mat3 , Mat3A , Mat4 , Vec3 , Vec3A } ;
45
56/// A Matrix with 4 columns of [`Vec3`], very similar to glam's [`Affine3A`].
67///
78/// Primarily used in ray tracing extensions to represent object rotation, scale and translation.
9+ ///
10+ /// # Limitations
11+ /// These Limitations apply to all structs marked with `#[spirv(matrix)]`, which `Matrix4x3` is the only one in
12+ /// `spirv-std`. Most of these could be resolved, but since the use-cases for this type are so limited, there hasn't
13+ /// been much effort directed at rectifying them. If they are annoying you, and you have a good use-case, feel free to
14+ /// open an issue and ask for us to fix them.
15+ /// * Cannot be used within buffers, push constants or anything that requires an "explicit layout". Use [`Affine3A`],
16+ /// [`Mat4`] or the combination of [`Mat3`] with [`Vec3`] instead and convert them to `Matrix4x3` in the shader.
17+ /// * There may be other situations where this type may surprisingly fail!
818#[ derive( Clone , Copy , Default , PartialEq ) ]
919#[ repr( C ) ]
1020#[ spirv( matrix) ]
1121#[ allow( missing_docs) ]
1222pub struct Matrix4x3 {
13- pub x : Vec3A ,
14- pub y : Vec3A ,
15- pub z : Vec3A ,
16- pub w : Vec3A ,
23+ pub x_axis : Vec3A ,
24+ pub y_axis : Vec3A ,
25+ pub z_axis : Vec3A ,
26+ pub w_axis : Vec3A ,
1727}
1828
1929/// The `from_*` fn signatures should match [`Affine3A`], to make it easier to switch to [`Affine3A`] later.
20- /// The `to_*` fn signatures are custom
30+ /// The `to_*` fn signatures are custom.
2131impl Matrix4x3 {
2232 /// Convert from glam's [`Affine3A`]
2333 pub fn from_affine3a ( affine : Affine3A ) -> Self {
2434 Self {
25- x : affine. x_axis ,
26- y : affine. y_axis ,
27- z : affine. z_axis ,
28- w : affine. w_axis ,
35+ x_axis : affine. x_axis ,
36+ y_axis : affine. y_axis ,
37+ z_axis : affine. z_axis ,
38+ w_axis : affine. w_axis ,
2939 }
3040 }
3141
@@ -53,11 +63,11 @@ impl Matrix4x3 {
5363 pub fn to_affine3a ( self ) -> Affine3A {
5464 Affine3A {
5565 matrix3 : Mat3A {
56- x_axis : self . x ,
57- y_axis : self . y ,
58- z_axis : self . z ,
66+ x_axis : self . x_axis ,
67+ y_axis : self . y_axis ,
68+ z_axis : self . z_axis ,
5969 } ,
60- translation : self . w ,
70+ translation : self . w_axis ,
6171 }
6272 }
6373
@@ -76,3 +86,15 @@ impl Matrix4x3 {
7686 Mat4 :: from ( self . to_affine3a ( ) )
7787 }
7888}
89+
90+ impl Debug for Matrix4x3 {
91+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> core:: fmt:: Result {
92+ Debug :: fmt ( & self . to_mat4 ( ) , f)
93+ }
94+ }
95+
96+ impl Display for Matrix4x3 {
97+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> core:: fmt:: Result {
98+ Display :: fmt ( & self . to_mat4 ( ) , f)
99+ }
100+ }
0 commit comments