@thi.ng/shader-ast-stdlib 0.16.8 → 0.16.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +0 -1
- package/color/aces-film.js +12 -10
- package/color/levels.js +80 -66
- package/color/linear-srgb.js +11 -21
- package/color/luminance.js +4 -6
- package/color/porter-duff.js +51 -55
- package/color/rgbe.js +13 -15
- package/fog/exp.js +5 -9
- package/fog/exp2.js +6 -12
- package/fog/linear.js +5 -11
- package/isec/point.js +19 -13
- package/light/lambert.js +8 -29
- package/light/trilight.js +17 -15
- package/math/additive.js +27 -32
- package/math/cartesian.js +21 -24
- package/math/clamp.js +7 -19
- package/math/cross2.js +7 -19
- package/math/dist-chebyshev.js +8 -3
- package/math/dist-manhattan.js +8 -3
- package/math/easing.js +325 -88
- package/math/fit.js +17 -65
- package/math/interval.js +23 -24
- package/math/magsq.js +8 -3
- package/math/maxcomp.js +8 -18
- package/math/mincomp.js +8 -18
- package/math/mix-cubic.js +32 -10
- package/math/mix-quadratic.js +27 -8
- package/math/orthogonal.js +15 -21
- package/math/osc.js +28 -39
- package/math/polar.js +12 -21
- package/math/sincos.js +6 -12
- package/math/smoother-step.js +26 -24
- package/matrix/convert.js +19 -8
- package/matrix/lookat.js +20 -18
- package/matrix/mvp.js +4 -10
- package/matrix/normal.js +4 -8
- package/matrix/rotation.js +131 -47
- package/noise/curl3.js +30 -18
- package/noise/hash.js +126 -197
- package/noise/permute.js +11 -5
- package/noise/simplex2.js +87 -41
- package/noise/simplex3.js +168 -75
- package/noise/voronoi2.js +67 -50
- package/noise/worley2.js +70 -58
- package/package.json +8 -6
- package/raymarch/ao.js +25 -24
- package/raymarch/direction.js +16 -9
- package/raymarch/normal.js +10 -16
- package/raymarch/point-at.js +4 -11
- package/raymarch/scene.js +35 -44
- package/screen/uv.js +23 -30
- package/sdf/annular.js +4 -7
- package/sdf/arc.js +20 -19
- package/sdf/bezier.js +93 -57
- package/sdf/box-rounded.js +14 -18
- package/sdf/box.js +16 -24
- package/sdf/cross.js +23 -44
- package/sdf/cylinder.js +9 -14
- package/sdf/hex.js +22 -19
- package/sdf/isec.js +4 -8
- package/sdf/line.js +14 -29
- package/sdf/mirror.js +17 -13
- package/sdf/plane.js +8 -18
- package/sdf/polygon.js +51 -29
- package/sdf/polyhedra.js +78 -43
- package/sdf/polyline.js +30 -7
- package/sdf/repeat-polar.js +13 -17
- package/sdf/repeat.js +7 -15
- package/sdf/round.js +4 -10
- package/sdf/smooth-isec.js +14 -17
- package/sdf/smooth-sub.js +14 -17
- package/sdf/smooth-union.js +14 -17
- package/sdf/sphere.js +8 -16
- package/sdf/sub.js +4 -8
- package/sdf/torus.js +5 -10
- package/sdf/tri.js +30 -20
- package/sdf/union.js +7 -18
- package/tex/blur.js +53 -70
- package/tex/index-coord.js +6 -16
- package/tex/index-uv.js +30 -20
- package/tex/read-index.js +10 -32
- package/viz/function.js +70 -68
package/math/additive.js
CHANGED
|
@@ -6,36 +6,31 @@ import { gensym } from "@thi.ng/shader-ast/ast/idgen";
|
|
|
6
6
|
import { FLOAT0, FLOAT05, float } from "@thi.ng/shader-ast/ast/lit";
|
|
7
7
|
import { add, inc, lt, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
8
8
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
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
|
-
(amp = sym(FLOAT05)),
|
|
34
|
-
forLoop(sym(FLOAT0), (i) => lt(i, float(oct)), inc, (i) => [
|
|
35
|
-
assign(n, add(n, mul(amp, fn(add(pos, mul(i, shift)))))),
|
|
36
|
-
assign(amp, mul(amp, decay)),
|
|
37
|
-
assign(pos, mul(pos, 2)),
|
|
38
|
-
]),
|
|
39
|
-
ret(n),
|
|
40
|
-
];
|
|
9
|
+
const additive = (type, fn, oct = 4, name = gensym("additive_")) => defn(F, name, [[type], [type], F], (pos, shift, decay) => {
|
|
10
|
+
let n;
|
|
11
|
+
let amp;
|
|
12
|
+
return [
|
|
13
|
+
n = sym(FLOAT0),
|
|
14
|
+
amp = sym(FLOAT05),
|
|
15
|
+
forLoop(
|
|
16
|
+
sym(FLOAT0),
|
|
17
|
+
(i) => lt(i, float(oct)),
|
|
18
|
+
inc,
|
|
19
|
+
(i) => [
|
|
20
|
+
assign(
|
|
21
|
+
n,
|
|
22
|
+
add(
|
|
23
|
+
n,
|
|
24
|
+
mul(amp, fn(add(pos, mul(i, shift))))
|
|
25
|
+
)
|
|
26
|
+
),
|
|
27
|
+
assign(amp, mul(amp, decay)),
|
|
28
|
+
assign(pos, mul(pos, 2))
|
|
29
|
+
]
|
|
30
|
+
),
|
|
31
|
+
ret(n)
|
|
32
|
+
];
|
|
41
33
|
});
|
|
34
|
+
export {
|
|
35
|
+
additive
|
|
36
|
+
};
|
package/math/cartesian.js
CHANGED
|
@@ -5,28 +5,25 @@ import { mul } from "@thi.ng/shader-ast/ast/ops";
|
|
|
5
5
|
import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
6
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
7
|
import { cossin } from "./sincos.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
let p;
|
|
26
|
-
return [
|
|
27
|
-
(r = sym($x(v))),
|
|
28
|
-
(t = sym(cossin($y(v)))),
|
|
29
|
-
(p = sym(cossin($z(v)))),
|
|
30
|
-
ret(vec3(mul(mul(r, $x(t)), $x(p)), mul(mul(r, $x(t)), $y(p)), mul(r, $y(t)))),
|
|
31
|
-
];
|
|
8
|
+
const cartesian2 = (v) => mul(cossin($y(v)), $x(v));
|
|
9
|
+
const cartesian3 = defn(V3, "cartesian3", [V3], (v) => {
|
|
10
|
+
let r;
|
|
11
|
+
let t;
|
|
12
|
+
let p;
|
|
13
|
+
return [
|
|
14
|
+
r = sym($x(v)),
|
|
15
|
+
t = sym(cossin($y(v))),
|
|
16
|
+
p = sym(cossin($z(v))),
|
|
17
|
+
ret(
|
|
18
|
+
vec3(
|
|
19
|
+
mul(mul(r, $x(t)), $x(p)),
|
|
20
|
+
mul(mul(r, $x(t)), $y(p)),
|
|
21
|
+
mul(r, $y(t))
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
];
|
|
32
25
|
});
|
|
26
|
+
export {
|
|
27
|
+
cartesian2,
|
|
28
|
+
cartesian3
|
|
29
|
+
};
|
package/math/clamp.js
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
2
2
|
import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
3
|
import { clamp } from "@thi.ng/shader-ast/builtin/math";
|
|
4
|
-
const __clamp = (min, max) => (x) => x.type === F
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Inline function, expands to equivalent of `clamp(x, 0, 1)`.
|
|
13
|
-
*
|
|
14
|
-
* @param x -
|
|
15
|
-
*/
|
|
16
|
-
export const clamp01 = __clamp(0, 1);
|
|
17
|
-
/**
|
|
18
|
-
* Inline function, expands to equivalent of `clamp(x, -1, 1)`.
|
|
19
|
-
*
|
|
20
|
-
* @param x -
|
|
21
|
-
*/
|
|
22
|
-
export const clamp11 = __clamp(-1, 1);
|
|
4
|
+
const __clamp = (min, max) => (x) => x.type === F ? clamp(x, float(min), float(max)) : x.type === V2 ? clamp(x, vec2(min), vec2(max)) : x.type === V3 ? clamp(x, vec3(min), vec3(max)) : clamp(x, vec4(min), vec4(max));
|
|
5
|
+
const clamp01 = __clamp(0, 1);
|
|
6
|
+
const clamp11 = __clamp(-1, 1);
|
|
7
|
+
export {
|
|
8
|
+
clamp01,
|
|
9
|
+
clamp11
|
|
10
|
+
};
|
package/math/cross2.js
CHANGED
|
@@ -2,23 +2,11 @@ import { F, V2 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
4
4
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* {@link crossC2}.
|
|
8
|
-
*
|
|
9
|
-
* @param a -
|
|
10
|
-
* @param b -
|
|
11
|
-
*/
|
|
12
|
-
export const cross2 = defn(F, "cross2", [V2, V2], (a, b) => [
|
|
13
|
-
ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b)))),
|
|
5
|
+
const cross2 = defn(F, "cross2", [V2, V2], (a, b) => [
|
|
6
|
+
ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b))))
|
|
14
7
|
]);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @param ay -
|
|
21
|
-
* @param bx -
|
|
22
|
-
* @param by -
|
|
23
|
-
*/
|
|
24
|
-
export const crossC2 = (ax, ay, bx, by) => sub(mul(ax, by), mul(ay, bx));
|
|
8
|
+
const crossC2 = (ax, ay, bx, by) => sub(mul(ax, by), mul(ay, bx));
|
|
9
|
+
export {
|
|
10
|
+
cross2,
|
|
11
|
+
crossC2
|
|
12
|
+
};
|
package/math/dist-chebyshev.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
2
2
|
import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
3
3
|
import { abs, max } from "@thi.ng/shader-ast/builtin/math";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const distChebyshev2 = (a, b) => max(abs(sub($x(a), $x(b))), abs(sub($y(a), $y(b))));
|
|
5
|
+
const distChebyshev3 = (a, b) => max(distChebyshev2(a, b), abs(sub($z(a), $z(b))));
|
|
6
|
+
const distChebyshev4 = (a, b) => max(distChebyshev2(a, b), distChebyshev2($(a, "zw"), $(b, "zw")));
|
|
7
|
+
export {
|
|
8
|
+
distChebyshev2,
|
|
9
|
+
distChebyshev3,
|
|
10
|
+
distChebyshev4
|
|
11
|
+
};
|
package/math/dist-manhattan.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { add, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
2
2
|
import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
3
3
|
import { abs } from "@thi.ng/shader-ast/builtin/math";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const distManhattan2 = (a, b) => add(abs(sub($x(a), $x(b))), abs(sub($y(a), $y(b))));
|
|
5
|
+
const distManhattan3 = (a, b) => add(distManhattan2(a, b), abs(sub($z(a), $z(b))));
|
|
6
|
+
const distManhattan4 = (a, b) => add(distManhattan2(a, b), distManhattan2($(a, "zw"), $(b, "zw")));
|
|
7
|
+
export {
|
|
8
|
+
distManhattan2,
|
|
9
|
+
distManhattan3,
|
|
10
|
+
distManhattan4
|
|
11
|
+
};
|
package/math/easing.js
CHANGED
|
@@ -1,117 +1,354 @@
|
|
|
1
1
|
import { F } from "@thi.ng/shader-ast/api/types";
|
|
2
2
|
import { ifThen, ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
3
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
FLOAT0,
|
|
6
|
+
FLOAT05,
|
|
7
|
+
FLOAT1,
|
|
8
|
+
FLOAT2,
|
|
9
|
+
HALF_PI,
|
|
10
|
+
PI,
|
|
11
|
+
TAU,
|
|
12
|
+
float
|
|
13
|
+
} from "@thi.ng/shader-ast/ast/lit";
|
|
14
|
+
import {
|
|
15
|
+
add,
|
|
16
|
+
div,
|
|
17
|
+
eq,
|
|
18
|
+
gte,
|
|
19
|
+
lt,
|
|
20
|
+
lte,
|
|
21
|
+
madd,
|
|
22
|
+
mul,
|
|
23
|
+
neg,
|
|
24
|
+
reciprocal,
|
|
25
|
+
sub
|
|
26
|
+
} from "@thi.ng/shader-ast/ast/ops";
|
|
6
27
|
import { cos, exp2, pow, sin, sqrt } from "@thi.ng/shader-ast/builtin/math";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param body
|
|
12
|
-
*/
|
|
13
|
-
export const defEasing = (body) => defn(F, null, [F], body);
|
|
14
|
-
export const easeInSine = defEasing((x) => [
|
|
15
|
-
ret(sub(FLOAT1, cos(mul(x, HALF_PI)))),
|
|
28
|
+
const defEasing = (body) => defn(F, null, [F], body);
|
|
29
|
+
const easeInSine = defEasing((x) => [
|
|
30
|
+
ret(sub(FLOAT1, cos(mul(x, HALF_PI))))
|
|
16
31
|
]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
32
|
+
const easeOutSine = defEasing((x) => [ret(sin(mul(x, HALF_PI)))]);
|
|
33
|
+
const easeInOutSine = defEasing((x) => [
|
|
34
|
+
ret(div(neg(sub(cos(mul(PI, x)), FLOAT1)), FLOAT2))
|
|
20
35
|
]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
const easeInQuad = defEasing((x) => [ret(pow(x, FLOAT2))]);
|
|
37
|
+
const easeOutQuad = defEasing((x) => [
|
|
38
|
+
ret(sub(FLOAT1, pow(sub(FLOAT1, x), FLOAT2)))
|
|
24
39
|
]);
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
const easeInOutQuad = defEasing((x) => [
|
|
41
|
+
ret(
|
|
42
|
+
ternary(
|
|
43
|
+
lt(x, FLOAT05),
|
|
44
|
+
mul(FLOAT2, pow(x, FLOAT2)),
|
|
45
|
+
sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2), FLOAT2))
|
|
46
|
+
)
|
|
47
|
+
)
|
|
27
48
|
]);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
const easeInCubic = defEasing((x) => [ret(pow(x, float(3)))]);
|
|
50
|
+
const easeOutCubic = defEasing((x) => [
|
|
51
|
+
ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(3))))
|
|
31
52
|
]);
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
const easeInOutCubic = defEasing((x) => [
|
|
54
|
+
ret(
|
|
55
|
+
ternary(
|
|
56
|
+
lt(x, FLOAT05),
|
|
57
|
+
mul(float(4), pow(x, float(3))),
|
|
58
|
+
sub(
|
|
59
|
+
FLOAT1,
|
|
60
|
+
div(pow(madd(neg(FLOAT2), x, FLOAT2), float(3)), FLOAT2)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
)
|
|
34
64
|
]);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
65
|
+
const easeInQuart = defEasing((x) => [ret(pow(x, float(4)))]);
|
|
66
|
+
const easeOutQuart = defEasing((x) => [
|
|
67
|
+
ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(4))))
|
|
38
68
|
]);
|
|
39
|
-
|
|
40
|
-
|
|
69
|
+
const easeInOutQuart = defEasing((x) => [
|
|
70
|
+
ret(
|
|
71
|
+
ternary(
|
|
72
|
+
lt(x, FLOAT05),
|
|
73
|
+
mul(float(8), pow(x, float(4))),
|
|
74
|
+
sub(
|
|
75
|
+
FLOAT1,
|
|
76
|
+
div(pow(madd(neg(FLOAT2), x, FLOAT2), float(4)), FLOAT2)
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
)
|
|
41
80
|
]);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
const easeInQuint = defEasing((x) => [ret(pow(x, float(5)))]);
|
|
82
|
+
const easeOutQuint = defEasing((x) => [
|
|
83
|
+
ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(5))))
|
|
45
84
|
]);
|
|
46
|
-
|
|
47
|
-
|
|
85
|
+
const easeInOutQuint = defEasing((x) => [
|
|
86
|
+
ret(
|
|
87
|
+
ternary(
|
|
88
|
+
lt(x, FLOAT05),
|
|
89
|
+
mul(float(16), pow(x, float(5))),
|
|
90
|
+
sub(
|
|
91
|
+
FLOAT1,
|
|
92
|
+
div(pow(madd(neg(FLOAT2), x, FLOAT2), float(5)), FLOAT2)
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
)
|
|
48
96
|
]);
|
|
49
|
-
|
|
50
|
-
|
|
97
|
+
const easeInExpo = defEasing((x) => [
|
|
98
|
+
ret(
|
|
99
|
+
ternary(eq(x, FLOAT0), FLOAT0, exp2(sub(mul(float(10), x), float(10))))
|
|
100
|
+
)
|
|
51
101
|
]);
|
|
52
|
-
|
|
53
|
-
|
|
102
|
+
const easeOutExpo = defEasing((x) => [
|
|
103
|
+
ret(
|
|
104
|
+
ternary(
|
|
105
|
+
eq(x, FLOAT1),
|
|
106
|
+
FLOAT1,
|
|
107
|
+
sub(FLOAT1, exp2(mul(neg(float(10)), x)))
|
|
108
|
+
)
|
|
109
|
+
)
|
|
54
110
|
]);
|
|
55
|
-
|
|
56
|
-
|
|
111
|
+
const easeInOutExpo = defEasing((x) => [
|
|
112
|
+
ret(
|
|
113
|
+
ternary(
|
|
114
|
+
eq(x, FLOAT0),
|
|
115
|
+
FLOAT0,
|
|
116
|
+
ternary(
|
|
117
|
+
eq(x, FLOAT1),
|
|
118
|
+
FLOAT1,
|
|
119
|
+
ternary(
|
|
120
|
+
lt(x, FLOAT05),
|
|
121
|
+
div(exp2(sub(mul(float(20), x), float(10))), FLOAT2),
|
|
122
|
+
div(
|
|
123
|
+
sub(FLOAT2, exp2(madd(neg(float(20)), x, float(10)))),
|
|
124
|
+
FLOAT2
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
)
|
|
57
130
|
]);
|
|
58
|
-
|
|
59
|
-
|
|
131
|
+
const easeInCirc = defEasing((x) => [
|
|
132
|
+
ret(sub(FLOAT1, sqrt(sub(FLOAT1, pow(x, FLOAT2)))))
|
|
60
133
|
]);
|
|
61
|
-
|
|
62
|
-
|
|
134
|
+
const easeOutCirc = defEasing((x) => [
|
|
135
|
+
ret(sqrt(sub(FLOAT1, pow(sub(x, FLOAT1), FLOAT2))))
|
|
63
136
|
]);
|
|
64
|
-
|
|
65
|
-
|
|
137
|
+
const easeInOutCirc = defEasing((x) => [
|
|
138
|
+
ret(
|
|
139
|
+
ternary(
|
|
140
|
+
lt(x, FLOAT05),
|
|
141
|
+
div(
|
|
142
|
+
sub(FLOAT1, sqrt(sub(FLOAT1, pow(mul(FLOAT2, x), FLOAT2)))),
|
|
143
|
+
FLOAT2
|
|
144
|
+
),
|
|
145
|
+
div(
|
|
146
|
+
add(
|
|
147
|
+
sqrt(
|
|
148
|
+
sub(FLOAT1, pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2))
|
|
149
|
+
),
|
|
150
|
+
FLOAT1
|
|
151
|
+
),
|
|
152
|
+
FLOAT2
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
)
|
|
66
156
|
]);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
157
|
+
const easeInBack = defEasing((x) => {
|
|
158
|
+
const c1 = 1.70158;
|
|
159
|
+
const c3 = c1 + 1;
|
|
160
|
+
return [ret(sub(mul(c3, pow(x, float(3))), mul(c1, pow(x, FLOAT2))))];
|
|
71
161
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
162
|
+
const easeOutBack = defEasing((x) => {
|
|
163
|
+
const c1 = 1.70158;
|
|
164
|
+
const c3 = c1 + 1;
|
|
165
|
+
return [
|
|
166
|
+
ret(
|
|
167
|
+
add(
|
|
168
|
+
madd(float(c3), pow(sub(x, FLOAT1), float(3)), FLOAT1),
|
|
169
|
+
mul(c1, pow(sub(x, FLOAT1), FLOAT2))
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
];
|
|
78
173
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
174
|
+
const easeInOutBack = defEasing((x) => {
|
|
175
|
+
const c1 = 1.70158;
|
|
176
|
+
const c2 = c1 * 1.525;
|
|
177
|
+
return [
|
|
178
|
+
ret(
|
|
179
|
+
ternary(
|
|
180
|
+
lt(x, FLOAT05),
|
|
181
|
+
div(
|
|
182
|
+
mul(
|
|
183
|
+
pow(mul(FLOAT2, x), FLOAT2),
|
|
184
|
+
sub(mul(mul(add(c2, FLOAT1), FLOAT2), x), c2)
|
|
185
|
+
),
|
|
186
|
+
FLOAT2
|
|
187
|
+
),
|
|
188
|
+
div(
|
|
189
|
+
add(
|
|
190
|
+
mul(
|
|
191
|
+
pow(sub(mul(FLOAT2, x), FLOAT2), FLOAT2),
|
|
192
|
+
add(
|
|
193
|
+
mul(
|
|
194
|
+
add(c2, FLOAT1),
|
|
195
|
+
sub(mul(x, FLOAT2), FLOAT2)
|
|
196
|
+
),
|
|
197
|
+
c2
|
|
198
|
+
)
|
|
199
|
+
),
|
|
200
|
+
FLOAT2
|
|
201
|
+
),
|
|
202
|
+
FLOAT2
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
];
|
|
85
207
|
});
|
|
86
|
-
|
|
87
|
-
|
|
208
|
+
const easeInElastic = defEasing((x) => [
|
|
209
|
+
ret(
|
|
210
|
+
ternary(
|
|
211
|
+
eq(x, FLOAT0),
|
|
212
|
+
FLOAT0,
|
|
213
|
+
ternary(
|
|
214
|
+
eq(x, FLOAT1),
|
|
215
|
+
FLOAT1,
|
|
216
|
+
mul(
|
|
217
|
+
neg(exp2(sub(mul(10, x), 10))),
|
|
218
|
+
sin(mul(sub(mul(x, 10), 10.75), div(TAU, 3)))
|
|
219
|
+
)
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
)
|
|
88
223
|
]);
|
|
89
|
-
|
|
90
|
-
|
|
224
|
+
const easeOutElastic = defEasing((x) => [
|
|
225
|
+
ret(
|
|
226
|
+
ternary(
|
|
227
|
+
lte(x, FLOAT0),
|
|
228
|
+
FLOAT0,
|
|
229
|
+
ternary(
|
|
230
|
+
gte(x, FLOAT1),
|
|
231
|
+
FLOAT1,
|
|
232
|
+
madd(
|
|
233
|
+
exp2(mul(-10, x)),
|
|
234
|
+
sin(mul(sub(mul(x, 10), 0.75), div(TAU, 3))),
|
|
235
|
+
FLOAT1
|
|
236
|
+
)
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
)
|
|
91
240
|
]);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
241
|
+
const easeInOutElastic = defEasing((x) => {
|
|
242
|
+
const c5 = div(TAU, 4.5);
|
|
243
|
+
return [
|
|
244
|
+
ret(
|
|
245
|
+
ternary(
|
|
246
|
+
eq(x, FLOAT0),
|
|
247
|
+
FLOAT0,
|
|
248
|
+
ternary(
|
|
249
|
+
eq(x, FLOAT1),
|
|
250
|
+
FLOAT1,
|
|
251
|
+
ternary(
|
|
252
|
+
lt(x, FLOAT05),
|
|
253
|
+
div(
|
|
254
|
+
neg(
|
|
255
|
+
mul(
|
|
256
|
+
exp2(sub(mul(20, x), 10)),
|
|
257
|
+
sin(mul(sub(mul(20, x), 11.125), c5))
|
|
258
|
+
)
|
|
259
|
+
),
|
|
260
|
+
FLOAT2
|
|
261
|
+
),
|
|
262
|
+
add(
|
|
263
|
+
div(
|
|
264
|
+
mul(
|
|
265
|
+
exp2(madd(neg(float(20)), x, float(10))),
|
|
266
|
+
sin(mul(sub(mul(20, x), 11.125), c5))
|
|
267
|
+
),
|
|
268
|
+
FLOAT2
|
|
269
|
+
),
|
|
270
|
+
FLOAT1
|
|
271
|
+
)
|
|
272
|
+
)
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
)
|
|
276
|
+
];
|
|
97
277
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
]
|
|
278
|
+
const easeOutBounce = defEasing((x) => {
|
|
279
|
+
const n1 = 7.5625;
|
|
280
|
+
const d1 = float(2.75);
|
|
281
|
+
return [
|
|
282
|
+
ifThen(lt(x, reciprocal(d1)), [ret(mul(n1, pow(x, FLOAT2)))]),
|
|
283
|
+
ifThen(lt(x, div(FLOAT2, d1)), [
|
|
284
|
+
ret(
|
|
285
|
+
add(
|
|
286
|
+
mul(mul(n1, sub(x, div(1.5, d1))), sub(x, div(1.5, d1))),
|
|
287
|
+
0.75
|
|
288
|
+
)
|
|
289
|
+
)
|
|
290
|
+
]),
|
|
291
|
+
ifThen(lt(x, div(2.5, d1)), [
|
|
292
|
+
ret(
|
|
293
|
+
add(
|
|
294
|
+
mul(mul(n1, sub(x, div(2.25, d1))), sub(x, div(2.25, d1))),
|
|
295
|
+
0.9375
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
]),
|
|
299
|
+
ret(
|
|
300
|
+
add(
|
|
301
|
+
mul(mul(n1, sub(x, div(2.625, d1))), sub(x, div(2.625, d1))),
|
|
302
|
+
0.984375
|
|
303
|
+
)
|
|
304
|
+
)
|
|
305
|
+
];
|
|
111
306
|
});
|
|
112
|
-
|
|
113
|
-
|
|
307
|
+
const easeInBounce = defEasing((x) => [
|
|
308
|
+
ret(sub(FLOAT1, easeOutBounce(sub(FLOAT1, x))))
|
|
114
309
|
]);
|
|
115
|
-
|
|
116
|
-
|
|
310
|
+
const easeInOutBounce = defEasing((x) => [
|
|
311
|
+
ret(
|
|
312
|
+
ternary(
|
|
313
|
+
lt(x, FLOAT05),
|
|
314
|
+
div(
|
|
315
|
+
sub(FLOAT1, easeOutBounce(sub(FLOAT1, mul(FLOAT2, x)))),
|
|
316
|
+
FLOAT2
|
|
317
|
+
),
|
|
318
|
+
div(add(FLOAT1, easeOutBounce(sub(mul(FLOAT2, x), FLOAT1))), FLOAT2)
|
|
319
|
+
)
|
|
320
|
+
)
|
|
117
321
|
]);
|
|
322
|
+
export {
|
|
323
|
+
defEasing,
|
|
324
|
+
easeInBack,
|
|
325
|
+
easeInBounce,
|
|
326
|
+
easeInCirc,
|
|
327
|
+
easeInCubic,
|
|
328
|
+
easeInElastic,
|
|
329
|
+
easeInExpo,
|
|
330
|
+
easeInOutBack,
|
|
331
|
+
easeInOutBounce,
|
|
332
|
+
easeInOutCirc,
|
|
333
|
+
easeInOutCubic,
|
|
334
|
+
easeInOutElastic,
|
|
335
|
+
easeInOutExpo,
|
|
336
|
+
easeInOutQuad,
|
|
337
|
+
easeInOutQuart,
|
|
338
|
+
easeInOutQuint,
|
|
339
|
+
easeInOutSine,
|
|
340
|
+
easeInQuad,
|
|
341
|
+
easeInQuart,
|
|
342
|
+
easeInQuint,
|
|
343
|
+
easeInSine,
|
|
344
|
+
easeOutBack,
|
|
345
|
+
easeOutBounce,
|
|
346
|
+
easeOutCirc,
|
|
347
|
+
easeOutCubic,
|
|
348
|
+
easeOutElastic,
|
|
349
|
+
easeOutExpo,
|
|
350
|
+
easeOutQuad,
|
|
351
|
+
easeOutQuart,
|
|
352
|
+
easeOutQuint,
|
|
353
|
+
easeOutSine
|
|
354
|
+
};
|