1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// shader math glue layer

pub trait ShaderMath{
    fn abs(self)->Self;
    
    fn sin(self)->Self;
    fn cos(self)->Self;
    fn tan(self)->Self;
    fn asin(self)->Self;
    fn acos(self)->Self;
    fn atan(self)->Self;
    
    fn sinh(self)->Self;
    fn cosh(self)->Self;
    fn tanh(self)->Self;
    fn asinh(self)->Self;
    fn acosh(self)->Self;
    fn atanh(self)->Self;

    fn fract(self)->Self;
    fn ceil(self)->Self;
    fn floor(self)->Self;
    fn min(self, v:Self)->Self;
    fn max(self, v:Self)->Self;
    fn clamp(self, low:Self, high:Self)->Self;
    fn exp(self)->Self;
    fn exp2(self)->Self;
    fn ln(self)->Self;
    fn log2(self)->Self;
    fn log10(self)->Self;
    fn powf(self, v:Self)->Self;
    fn powi(self, p:i32)->Self;
}

impl ShaderMath for f32{
    fn abs(self)->Self{self.abs()}
    fn sin(self)->Self{self.sin()}
    fn cos(self)->Self{self.cos()}
    fn tan(self)->Self{self.tan()}
    fn asin(self)->Self{self.asin()}
    fn acos(self)->Self{self.acos()}
    fn atan(self)->Self{self.atan()}

    fn sinh(self)->Self{self.sinh()}
    fn cosh(self)->Self{self.cosh()}
    fn tanh(self)->Self{self.tanh()}
    fn asinh(self)->Self{self.asinh()}
    fn acosh(self)->Self{self.acosh()}
    fn atanh(self)->Self{self.atanh()}

    fn fract(self)->Self{self.fract()}
    fn ceil(self)->Self{self.ceil()}
    fn floor(self)->Self{self.floor()}
    fn min(self, v:Self)->Self{self.min(v)}
    fn max(self, v:Self)->Self{self.max(v)}
    fn clamp(self, low:Self, high:Self)->Self{self.max(low).min(high)}
    fn exp(self)->Self{self.exp()}
    fn exp2(self)->Self{self.exp2()}
    fn ln(self)->Self{self.ln()}
    fn log2(self)->Self{self.log2()}
    fn log10(self)->Self{self.log10()}
    fn powf(self, v:Self)->Self{self.powf(v)}
    fn powi(self, v:i32)->Self{self.powi(v)}
}

impl ShaderMath for f64{
    fn abs(self)->Self{self.abs()}

    fn sin(self)->Self{self.sin()}
    fn cos(self)->Self{self.cos()}
    fn tan(self)->Self{self.tan()}
    fn asin(self)->Self{self.asin()}
    fn acos(self)->Self{self.acos()}
    fn atan(self)->Self{self.atan()}

    fn sinh(self)->Self{self.sinh()}
    fn cosh(self)->Self{self.cosh()}
    fn tanh(self)->Self{self.tanh()}
    fn asinh(self)->Self{self.asinh()}
    fn acosh(self)->Self{self.acosh()}
    fn atanh(self)->Self{self.atanh()}


    fn fract(self)->Self{self.fract()}
    fn ceil(self)->Self{self.ceil()}
    fn floor(self)->Self{self.floor()}
    fn min(self, v:Self)->Self{self.min(v)}
    fn max(self, v:Self)->Self{self.max(v)}
    fn clamp(self, low:Self, high:Self)->Self{self.max(low).min(high)}
    fn exp(self)->Self{self.exp()}
    fn exp2(self)->Self{self.exp2()}
    fn ln(self)->Self{self.ln()}
    fn log2(self)->Self{self.log2()}
    fn log10(self)->Self{self.log10()}
    fn powf(self, v:Self)->Self{self.powf(v)}
    fn powi(self, v:i32)->Self{self.powi(v)}
}

pub fn abs<T:ShaderMath>(v:T)->T{v.abs()}

pub fn sin<T:ShaderMath>(v:T)->T{v.sin()}
pub fn cos<T:ShaderMath>(v:T)->T{v.cos()}
pub fn tan<T:ShaderMath>(v:T)->T{v.tan()}
pub fn asin<T:ShaderMath>(v:T)->T{v.asin()}
pub fn acos<T:ShaderMath>(v:T)->T{v.acos()}
pub fn atan<T:ShaderMath>(v:T)->T{v.atan()}

pub fn sinh<T:ShaderMath>(v:T)->T{v.sinh()}
pub fn cosh<T:ShaderMath>(v:T)->T{v.cosh()}
pub fn tanh<T:ShaderMath>(v:T)->T{v.tanh()}
pub fn asinh<T:ShaderMath>(v:T)->T{v.asinh()}
pub fn acosh<T:ShaderMath>(v:T)->T{v.acosh()}
pub fn atanh<T:ShaderMath>(v:T)->T{v.atanh()}

pub fn fract<T:ShaderMath>(v:T)->T{v.fract()}
pub fn ceil<T:ShaderMath>(v:T)->T{v.ceil()}
pub fn floor<T:ShaderMath>(v:T)->T{v.floor()}
pub fn min<T:ShaderMath>(v:T,l:T)->T{v.min(l)}
pub fn max<T:ShaderMath>(v:T,l:T)->T{v.max(l)}
pub fn clamp<T:ShaderMath>(v:T,l:T,h:T)->T{v.clamp(l,h)}
pub fn exp<T:ShaderMath>(v:T)->T{v.exp()}
pub fn exp2<T:ShaderMath>(v:T)->T{v.exp2()}
pub fn ln<T:ShaderMath>(v:T)->T{v.ln()}
pub fn log2<T:ShaderMath>(v:T)->T{v.log2()}
pub fn log10<T:ShaderMath>(v:T)->T{v.log10()}
pub fn pow<T:ShaderMath>(v:T,l:T)->T{v.powf(l)}
pub fn powf<T:ShaderMath>(v:T,l:T)->T{v.powf(l)}
pub fn powi<T:ShaderMath>(v:T,l:i32)->T{v.powi(l)}

/*
abs
asin
acos
atan
sin
cos
tan
ceil
floor
min
max
clamp

exp
exp2
log
log2
ln
pow
tanh
fract

cross
distance
dot
inverse
length
normalize
*/