File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ pub mod natural_log;
23
23
pub mod mix;
24
24
pub mod pow;
25
25
pub mod exp2;
26
+ pub mod log2;
26
27
27
28
pub mod prelude;
28
29
Original file line number Diff line number Diff line change
1
+ //! WGSL `smoothstep()`
2
+
3
+ use crate :: glam:: { Vec2 , Vec3 , Vec4 } ;
4
+
5
+ #[ cfg( feature = "spirv-std" ) ]
6
+ #[ allow( unused_imports) ]
7
+ use spirv_std:: num_traits:: Float ;
8
+
9
+ /// Equivalent of the WGSL `log2()` function.
10
+ ///
11
+ /// Returns 2 raised to the power of x.
12
+ pub trait Log2 {
13
+ fn log2 ( self ) -> Self ;
14
+ }
15
+
16
+ impl Log2 for f32 {
17
+ fn log2 ( self ) -> Self {
18
+ #[ cfg( feature = "spirv-std" ) ]
19
+ {
20
+ spirv_std:: num_traits:: Float :: log2 ( self )
21
+ }
22
+
23
+ #[ cfg( feature = "glam" ) ]
24
+ {
25
+ self . log2 ( )
26
+ }
27
+ }
28
+ }
29
+
30
+ impl Log2 for Vec2 {
31
+ fn log2 ( self ) -> Self {
32
+ Vec2 :: new ( Log2 :: log2 ( self . x ) , Log2 :: log2 ( self . y ) )
33
+ }
34
+ }
35
+
36
+ impl Log2 for Vec3 {
37
+ fn log2 ( self ) -> Self {
38
+ Vec3 :: new ( Log2 :: log2 ( self . x ) , Log2 :: log2 ( self . y ) , Log2 :: log2 ( self . z ) )
39
+ }
40
+ }
41
+
42
+ impl Log2 for Vec4 {
43
+ fn log2 ( self ) -> Self {
44
+ Vec4 :: new (
45
+ Log2 :: log2 ( self . x ) ,
46
+ Log2 :: log2 ( self . y ) ,
47
+ Log2 :: log2 ( self . z ) ,
48
+ Log2 :: log2 ( self . w ) ,
49
+ )
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments