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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
void math_add(float a, float b, float c, out float result)
{
result = a + b;
}
void math_subtract(float a, float b, float c, out float result)
{
result = a - b;
}
void math_multiply(float a, float b, float c, out float result)
{
result = a * b;
}
void math_divide(float a, float b, float c, out float result)
{
result = safe_divide(a, b);
}
void math_power(float a, float b, float c, out float result)
{
if (a >= 0.0) {
result = compatible_pow(a, b);
}
else {
float fraction = mod(abs(b), 1.0);
if (fraction > 0.999 || fraction < 0.001) {
result = compatible_pow(a, floor(b + 0.5));
}
else {
result = 0.0;
}
}
}
void math_logarithm(float a, float b, float c, out float result)
{
result = (a > 0.0 && b > 0.0) ? log2(a) / log2(b) : 0.0;
}
void math_sqrt(float a, float b, float c, out float result)
{
result = (a > 0.0) ? sqrt(a) : 0.0;
}
void math_inversesqrt(float a, float b, float c, out float result)
{
result = inversesqrt(a);
}
void math_absolute(float a, float b, float c, out float result)
{
result = abs(a);
}
void math_radians(float a, float b, float c, out float result)
{
result = radians(a);
}
void math_degrees(float a, float b, float c, out float result)
{
result = degrees(a);
}
void math_minimum(float a, float b, float c, out float result)
{
result = min(a, b);
}
void math_maximum(float a, float b, float c, out float result)
{
result = max(a, b);
}
void math_less_than(float a, float b, float c, out float result)
{
result = (a < b) ? 1.0 : 0.0;
}
void math_greater_than(float a, float b, float c, out float result)
{
result = (a > b) ? 1.0 : 0.0;
}
void math_round(float a, float b, float c, out float result)
{
result = floor(a + 0.5);
}
void math_floor(float a, float b, float c, out float result)
{
result = floor(a);
}
void math_ceil(float a, float b, float c, out float result)
{
result = ceil(a);
}
void math_fraction(float a, float b, float c, out float result)
{
result = a - floor(a);
}
void math_modulo(float a, float b, float c, out float result)
{
result = compatible_fmod(a, b);
}
void math_trunc(float a, float b, float c, out float result)
{
result = trunc(a);
}
void math_snap(float a, float b, float c, out float result)
{
result = floor(safe_divide(a, b)) * b;
}
void math_pingpong(float a, float b, float c, out float result)
{
result = (b != 0.0) ? abs(fract((a - b) / (b * 2.0)) * b * 2.0 - b) : 0.0;
}
/* Adapted from godotengine math_funcs.h. */
void math_wrap(float a, float b, float c, out float result)
{
float range = b - c;
result = (range != 0.0) ? a - (range * floor((a - c) / range)) : c;
}
void math_sine(float a, float b, float c, out float result)
{
result = sin(a);
}
void math_cosine(float a, float b, float c, out float result)
{
result = cos(a);
}
void math_tangent(float a, float b, float c, out float result)
{
result = tan(a);
}
void math_sinh(float a, float b, float c, out float result)
{
result = sinh(a);
}
void math_cosh(float a, float b, float c, out float result)
{
result = cosh(a);
}
void math_tanh(float a, float b, float c, out float result)
{
result = tanh(a);
}
void math_arcsine(float a, float b, float c, out float result)
{
result = (a <= 1.0 && a >= -1.0) ? asin(a) : 0.0;
}
void math_arccosine(float a, float b, float c, out float result)
{
result = (a <= 1.0 && a >= -1.0) ? acos(a) : 0.0;
}
void math_arctangent(float a, float b, float c, out float result)
{
result = atan(a);
}
void math_arctan2(float a, float b, float c, out float result)
{
result = atan(a, b);
}
void math_sign(float a, float b, float c, out float result)
{
result = sign(a);
}
void math_exponent(float a, float b, float c, out float result)
{
result = exp(a);
}
void math_compare(float a, float b, float c, out float result)
{
result = (abs(a - b) <= max(c, 1e-5)) ? 1.0 : 0.0;
}
void math_multiply_add(float a, float b, float c, out float result)
{
result = a * b + c;
}
/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */
void math_smoothmin(float a, float b, float c, out float result)
{
if (c != 0.0) {
float h = max(c - abs(a - b), 0.0) / c;
result = min(a, b) - h * h * h * c * (1.0 / 6.0);
}
else {
result = min(a, b);
}
}
void math_smoothmax(float a, float b, float c, out float result)
{
math_smoothmin(-a, -b, c, result);
result = -result;
}
|