@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/fit.js
CHANGED
|
@@ -5,69 +5,21 @@ import { FLOAT0, FLOAT05, FLOAT1, FLOAT2 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
5
5
|
import { add, div, mul, neq, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
6
|
import { mix } from "@thi.ng/shader-ast/builtin/math";
|
|
7
7
|
import { clamp01 } from "./clamp.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* `a` equals `b`.
|
|
11
|
-
*
|
|
12
|
-
* @param x -
|
|
13
|
-
* @param a -
|
|
14
|
-
* @param b -
|
|
15
|
-
*/
|
|
16
|
-
export const fitNorm1 = defn(F, "fitNorm1", [F, F, F], (x, a, b) => [
|
|
17
|
-
ret(ternary(neq(a, b), div(sub(x, a), sub(b, a)), FLOAT0)),
|
|
8
|
+
const fitNorm1 = defn(F, "fitNorm1", [F, F, F], (x, a, b) => [
|
|
9
|
+
ret(ternary(neq(a, b), div(sub(x, a), sub(b, a)), FLOAT0))
|
|
18
10
|
]);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* @param x -
|
|
35
|
-
* @param a -
|
|
36
|
-
* @param b -
|
|
37
|
-
* @param c -
|
|
38
|
-
* @param d -
|
|
39
|
-
*/
|
|
40
|
-
export const fit = (x, a, b, c, d) => mix(c, d, fitNorm(x, a, b));
|
|
41
|
-
/**
|
|
42
|
-
* Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
|
|
43
|
-
*
|
|
44
|
-
* @param x -
|
|
45
|
-
* @param a -
|
|
46
|
-
* @param b -
|
|
47
|
-
* @param c -
|
|
48
|
-
* @param d -
|
|
49
|
-
*/
|
|
50
|
-
export const fitClamped = (x, a, b, c, d) => mix(c, d, clamp01(div(sub(x, a), sub(b, a))));
|
|
51
|
-
/**
|
|
52
|
-
* Inline function. Fits value `a` in [0..1] interval to new interval
|
|
53
|
-
* [b..c]. No clamping performed. Same as `mix(b, c, a)`
|
|
54
|
-
*
|
|
55
|
-
* @param a -
|
|
56
|
-
* @param b -
|
|
57
|
-
* @param c -
|
|
58
|
-
*/
|
|
59
|
-
export const fit01 = (a, b, c) => mix(b, c, a);
|
|
60
|
-
/**
|
|
61
|
-
* Inline function. Fits value `x` in [-1..+1] interval to [0..1]
|
|
62
|
-
* interval. No clamping performed.
|
|
63
|
-
*
|
|
64
|
-
* @param x -
|
|
65
|
-
*/
|
|
66
|
-
export const fit1101 = (x) => add(mul(x, FLOAT05), FLOAT05);
|
|
67
|
-
/**
|
|
68
|
-
* Inline function. Fits value `x` in [0..1] interval to [-1..+1]
|
|
69
|
-
* interval. No clamping performed.
|
|
70
|
-
*
|
|
71
|
-
* @param x -
|
|
72
|
-
*/
|
|
73
|
-
export const fit0111 = (x) => sub(mul(x, FLOAT2), FLOAT1);
|
|
11
|
+
const fitNorm = (x, a, b) => div(sub(x, a), sub(b, a));
|
|
12
|
+
const fit = (x, a, b, c, d) => mix(c, d, fitNorm(x, a, b));
|
|
13
|
+
const fitClamped = (x, a, b, c, d) => mix(c, d, clamp01(div(sub(x, a), sub(b, a))));
|
|
14
|
+
const fit01 = (a, b, c) => mix(b, c, a);
|
|
15
|
+
const fit1101 = (x) => add(mul(x, FLOAT05), FLOAT05);
|
|
16
|
+
const fit0111 = (x) => sub(mul(x, FLOAT2), FLOAT1);
|
|
17
|
+
export {
|
|
18
|
+
fit,
|
|
19
|
+
fit01,
|
|
20
|
+
fit0111,
|
|
21
|
+
fit1101,
|
|
22
|
+
fitClamped,
|
|
23
|
+
fitNorm,
|
|
24
|
+
fitNorm1
|
|
25
|
+
};
|
package/math/interval.js
CHANGED
|
@@ -4,30 +4,29 @@ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
|
4
4
|
import { FLOAT0, FLOAT1, FLOAT2 } from "@thi.ng/shader-ast/ast/lit";
|
|
5
5
|
import { div, lt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
6
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import {
|
|
8
|
+
abs,
|
|
9
|
+
ceil,
|
|
10
|
+
floor,
|
|
11
|
+
mix,
|
|
12
|
+
mod,
|
|
13
|
+
step
|
|
14
|
+
} from "@thi.ng/shader-ast/builtin/math";
|
|
15
|
+
const trunc = defn(F, null, [F], (x) => [
|
|
16
|
+
ret(ternary(lt(x, FLOAT0), ceil(x), floor(x)))
|
|
13
17
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Result will always have the sign of `x`.
|
|
17
|
-
*/
|
|
18
|
-
export const modulo = defn(F, null, [F, F], (x, y) => [
|
|
19
|
-
ret(sub(x, mul(y, trunc(div(x, y))))),
|
|
18
|
+
const modulo = defn(F, null, [F, F], (x, y) => [
|
|
19
|
+
ret(sub(x, mul(y, trunc(div(x, y)))))
|
|
20
20
|
]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export const foldback01 = defn(F, null, [F], (x) => {
|
|
28
|
-
let y;
|
|
29
|
-
return [
|
|
30
|
-
(y = sym(mod(abs(x), FLOAT2))),
|
|
31
|
-
ret(mix(y, sub(FLOAT2, y), step(FLOAT1, y))),
|
|
32
|
-
];
|
|
21
|
+
const foldback01 = defn(F, null, [F], (x) => {
|
|
22
|
+
let y;
|
|
23
|
+
return [
|
|
24
|
+
y = sym(mod(abs(x), FLOAT2)),
|
|
25
|
+
ret(mix(y, sub(FLOAT2, y), step(FLOAT1, y)))
|
|
26
|
+
];
|
|
33
27
|
});
|
|
28
|
+
export {
|
|
29
|
+
foldback01,
|
|
30
|
+
modulo,
|
|
31
|
+
trunc
|
|
32
|
+
};
|
package/math/magsq.js
CHANGED
|
@@ -2,6 +2,11 @@ import { F } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { dot } from "@thi.ng/shader-ast/builtin/math";
|
|
4
4
|
const $ = (n) => defn(F, `magSq${n}`, [`vec${n}`], (v) => [ret(dot(v, v))]);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const magSq2 = $(2);
|
|
6
|
+
const magSq3 = $(3);
|
|
7
|
+
const magSq4 = $(4);
|
|
8
|
+
export {
|
|
9
|
+
magSq2,
|
|
10
|
+
magSq3,
|
|
11
|
+
magSq4
|
|
12
|
+
};
|
package/math/maxcomp.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { $w, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
2
2
|
import { max } from "@thi.ng/shader-ast/builtin/math";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @param v -
|
|
13
|
-
*/
|
|
14
|
-
export const maxComp3 = (v) => max(maxComp2(v), $z(v));
|
|
15
|
-
/**
|
|
16
|
-
* Inline function. Returns max(v.x, v.y, v.z, v.w)
|
|
17
|
-
*
|
|
18
|
-
* @param v -
|
|
19
|
-
*/
|
|
20
|
-
export const maxComp4 = (v) => max(maxComp3(v), $w(v));
|
|
3
|
+
const maxComp2 = (v) => max($x(v), $y(v));
|
|
4
|
+
const maxComp3 = (v) => max(maxComp2(v), $z(v));
|
|
5
|
+
const maxComp4 = (v) => max(maxComp3(v), $w(v));
|
|
6
|
+
export {
|
|
7
|
+
maxComp2,
|
|
8
|
+
maxComp3,
|
|
9
|
+
maxComp4
|
|
10
|
+
};
|
package/math/mincomp.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import { $w, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
2
2
|
import { min } from "@thi.ng/shader-ast/builtin/math";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @param v -
|
|
13
|
-
*/
|
|
14
|
-
export const minComp3 = (v) => min(minComp2(v), $z(v));
|
|
15
|
-
/**
|
|
16
|
-
* Inline function. Returns min(v.x, v.y, v.z, v.w)
|
|
17
|
-
*
|
|
18
|
-
* @param v -
|
|
19
|
-
*/
|
|
20
|
-
export const minComp4 = (v) => min(minComp3(v), $w(v));
|
|
3
|
+
const minComp2 = (v) => min($x(v), $y(v));
|
|
4
|
+
const minComp3 = (v) => min(minComp2(v), $z(v));
|
|
5
|
+
const minComp4 = (v) => min(minComp3(v), $w(v));
|
|
6
|
+
export {
|
|
7
|
+
minComp2,
|
|
8
|
+
minComp3,
|
|
9
|
+
minComp4
|
|
10
|
+
};
|
package/math/mix-cubic.js
CHANGED
|
@@ -2,18 +2,40 @@ import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { add, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
4
4
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
5
|
-
const $ = (n, type) => defn(
|
|
5
|
+
const $ = (n, type) => defn(
|
|
6
|
+
type,
|
|
7
|
+
`mixCubic${n > 1 ? n : ""}`,
|
|
8
|
+
[type, type, type, type, F],
|
|
9
|
+
(a, b, c, d, t) => {
|
|
6
10
|
let s;
|
|
7
11
|
let s2;
|
|
8
12
|
let t2;
|
|
9
13
|
return [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
t2 = sym(mul(t, t)),
|
|
15
|
+
s = sym(sub(1, t)),
|
|
16
|
+
s2 = sym(mul(s, s)),
|
|
17
|
+
ret(
|
|
18
|
+
add(
|
|
19
|
+
add(
|
|
20
|
+
add(
|
|
21
|
+
mul(a, mul(s, s2)),
|
|
22
|
+
mul(b, mul(3, mul(s2, t)))
|
|
23
|
+
),
|
|
24
|
+
mul(c, mul(3, mul(t2, s)))
|
|
25
|
+
),
|
|
26
|
+
mul(d, mul(t, t2))
|
|
27
|
+
)
|
|
28
|
+
)
|
|
14
29
|
];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const mixCubic = $(1, F);
|
|
33
|
+
const mixCubic2 = $(2, V2);
|
|
34
|
+
const mixCubic3 = $(3, V3);
|
|
35
|
+
const mixCubic4 = $(4, V4);
|
|
36
|
+
export {
|
|
37
|
+
mixCubic,
|
|
38
|
+
mixCubic2,
|
|
39
|
+
mixCubic3,
|
|
40
|
+
mixCubic4
|
|
41
|
+
};
|
package/math/mix-quadratic.js
CHANGED
|
@@ -2,14 +2,33 @@ import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { add, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
4
4
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
5
|
-
const $ = (n, type) => defn(
|
|
5
|
+
const $ = (n, type) => defn(
|
|
6
|
+
type,
|
|
7
|
+
`mixQuadratic${n > 1 ? n : ""}`,
|
|
8
|
+
[type, type, type, F],
|
|
9
|
+
(a, b, c, t) => {
|
|
6
10
|
let s;
|
|
7
11
|
return [
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
s = sym(sub(1, t)),
|
|
13
|
+
ret(
|
|
14
|
+
add(
|
|
15
|
+
add(
|
|
16
|
+
mul(a, mul(s, s)),
|
|
17
|
+
mul(b, mul(2, mul(s, t)))
|
|
18
|
+
),
|
|
19
|
+
mul(c, mul(t, t))
|
|
20
|
+
)
|
|
21
|
+
)
|
|
10
22
|
];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
const mixQuadratic = $(1, F);
|
|
26
|
+
const mixQuadratic2 = $(2, V2);
|
|
27
|
+
const mixQuadratic3 = $(3, V3);
|
|
28
|
+
const mixQuadratic4 = $(4, V4);
|
|
29
|
+
export {
|
|
30
|
+
mixQuadratic,
|
|
31
|
+
mixQuadratic2,
|
|
32
|
+
mixQuadratic3,
|
|
33
|
+
mixQuadratic4
|
|
34
|
+
};
|
package/math/orthogonal.js
CHANGED
|
@@ -5,25 +5,19 @@ import { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
5
5
|
import { gt, neg } from "@thi.ng/shader-ast/ast/ops";
|
|
6
6
|
import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
7
|
import { abs } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
* @param v -
|
|
20
|
-
*/
|
|
21
|
-
export const perpendicularCW = (v) => vec2($y(v), neg($x(v)));
|
|
22
|
-
/**
|
|
23
|
-
* Returns an orthogonal vector to `v`.
|
|
24
|
-
*
|
|
25
|
-
* http://lolengine.net/blog/2013/09/21/picking-orthogonal-vector-combing-coconuts
|
|
26
|
-
*/
|
|
27
|
-
export const orthogonal3 = defn(V3, "orthogonal3", [V3], (v) => [
|
|
28
|
-
ret(ternary(gt(abs($x(v)), abs($z(v))), vec3(neg($y(v)), $x(v), 0), vec3(0, neg($z(v)), $y(v)))),
|
|
8
|
+
const perpendicularCCW = (v) => vec2(neg($y(v)), $x(v));
|
|
9
|
+
const perpendicularCW = (v) => vec2($y(v), neg($x(v)));
|
|
10
|
+
const orthogonal3 = defn(V3, "orthogonal3", [V3], (v) => [
|
|
11
|
+
ret(
|
|
12
|
+
ternary(
|
|
13
|
+
gt(abs($x(v)), abs($z(v))),
|
|
14
|
+
vec3(neg($y(v)), $x(v), 0),
|
|
15
|
+
vec3(0, neg($z(v)), $y(v))
|
|
16
|
+
)
|
|
17
|
+
)
|
|
29
18
|
]);
|
|
19
|
+
export {
|
|
20
|
+
orthogonal3,
|
|
21
|
+
perpendicularCCW,
|
|
22
|
+
perpendicularCW
|
|
23
|
+
};
|
package/math/osc.js
CHANGED
|
@@ -1,42 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
float,
|
|
3
|
+
FLOAT0,
|
|
4
|
+
FLOAT05,
|
|
5
|
+
FLOAT1,
|
|
6
|
+
FLOAT2,
|
|
7
|
+
TAU
|
|
8
|
+
} from "@thi.ng/shader-ast/ast/lit";
|
|
2
9
|
import { madd, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
3
10
|
import { abs, fract, sin, step } from "@thi.ng/shader-ast/builtin/math";
|
|
4
11
|
const defOsc = (fn) => (phase, freq, amp = FLOAT1, dc = FLOAT0) => madd(fn(mul(float(phase), float(freq))), amp, dc);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
26
|
-
* @param phase - normalized phase
|
|
27
|
-
* @param freq -
|
|
28
|
-
* @param amp -
|
|
29
|
-
* @param dc -
|
|
30
|
-
*/
|
|
31
|
-
export const triOsc = defOsc((phase) => sub(abs(madd(fract(phase), 4, float(-2))), FLOAT1));
|
|
32
|
-
/**
|
|
33
|
-
* Rect oscillator w/ customizable duty cycle (default: 0.5) (ported from
|
|
34
|
-
* thi.ng/dsp)
|
|
35
|
-
*
|
|
36
|
-
* @param phase - normalized phase
|
|
37
|
-
* @param freq -
|
|
38
|
-
* @param amp -
|
|
39
|
-
* @param dc -
|
|
40
|
-
* @param duty -
|
|
41
|
-
*/
|
|
42
|
-
export const rectOsc = (phase, freq, amp = FLOAT1, dc = FLOAT0, duty = FLOAT05) => madd(madd(step(float(duty), fract(mul(float(phase), float(freq)))), FLOAT2, float(-1)), amp, dc);
|
|
12
|
+
const sinOsc = defOsc((phase) => sin(mul(phase, TAU)));
|
|
13
|
+
const sawOsc = defOsc((phase) => sub(FLOAT1, mul(fract(phase), FLOAT2)));
|
|
14
|
+
const triOsc = defOsc(
|
|
15
|
+
(phase) => sub(abs(madd(fract(phase), 4, float(-2))), FLOAT1)
|
|
16
|
+
);
|
|
17
|
+
const rectOsc = (phase, freq, amp = FLOAT1, dc = FLOAT0, duty = FLOAT05) => madd(
|
|
18
|
+
madd(
|
|
19
|
+
step(float(duty), fract(mul(float(phase), float(freq)))),
|
|
20
|
+
FLOAT2,
|
|
21
|
+
float(-1)
|
|
22
|
+
),
|
|
23
|
+
amp,
|
|
24
|
+
dc
|
|
25
|
+
);
|
|
26
|
+
export {
|
|
27
|
+
rectOsc,
|
|
28
|
+
sawOsc,
|
|
29
|
+
sinOsc,
|
|
30
|
+
triOsc
|
|
31
|
+
};
|
package/math/polar.js
CHANGED
|
@@ -5,26 +5,17 @@ import { div } 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 { asin, atan, length } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* (angle in radians). See {@link cartesian2} for reverse operation.
|
|
11
|
-
*
|
|
12
|
-
* @param v -
|
|
13
|
-
*/
|
|
14
|
-
export const polar2 = defn(V2, "polar2", [V2], (v) => [
|
|
15
|
-
ret(vec2(length(v), atan(div($y(v), $x(v))))),
|
|
8
|
+
const polar2 = defn(V2, "polar2", [V2], (v) => [
|
|
9
|
+
ret(vec2(length(v), atan(div($y(v), $x(v)))))
|
|
16
10
|
]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*/
|
|
24
|
-
export const polar3 = defn(V3, "polar3", [V3], (v) => {
|
|
25
|
-
let r;
|
|
26
|
-
return [
|
|
27
|
-
(r = sym(length(v))),
|
|
28
|
-
ret(vec3(r, asin(div($z(v), r)), atan(div($y(v), $x(v))))),
|
|
29
|
-
];
|
|
11
|
+
const polar3 = defn(V3, "polar3", [V3], (v) => {
|
|
12
|
+
let r;
|
|
13
|
+
return [
|
|
14
|
+
r = sym(length(v)),
|
|
15
|
+
ret(vec3(r, asin(div($z(v), r)), atan(div($y(v), $x(v)))))
|
|
16
|
+
];
|
|
30
17
|
});
|
|
18
|
+
export {
|
|
19
|
+
polar2,
|
|
20
|
+
polar3
|
|
21
|
+
};
|
package/math/sincos.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
2
2
|
import { cos, sin } from "@thi.ng/shader-ast/builtin/math";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Inline function. Returns vec2(cos(x), sin(x)).
|
|
11
|
-
*
|
|
12
|
-
* @param x -
|
|
13
|
-
*/
|
|
14
|
-
export const cossin = (x) => vec2(cos(x), sin(x));
|
|
3
|
+
const sincos = (x) => vec2(sin(x), cos(x));
|
|
4
|
+
const cossin = (x) => vec2(cos(x), sin(x));
|
|
5
|
+
export {
|
|
6
|
+
cossin,
|
|
7
|
+
sincos
|
|
8
|
+
};
|
package/math/smoother-step.js
CHANGED
|
@@ -3,28 +3,30 @@ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
|
3
3
|
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
4
4
|
import { clamp01 } from "./clamp.js";
|
|
5
5
|
const $ = (n, type) => defn(type, `smootherStep01${n > 1 ? "_" + n : ""}`, [type], (x) => [
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
ret(mul(x, mul(x, mul(x, add(mul(x, sub(mul(x, 6), 15)), 10)))))
|
|
8
8
|
]);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
const smootherStep01 = $(1, F);
|
|
10
|
+
const smootherStep01_2 = $(2, V2);
|
|
11
|
+
const smootherStep01_3 = $(3, V3);
|
|
12
|
+
const smootherStep01_4 = $(4, V4);
|
|
13
|
+
const $$ = (n, type, fn) => defn(
|
|
14
|
+
type,
|
|
15
|
+
`smootherStep${n > 1 ? n : ""}`,
|
|
16
|
+
[type, type, type],
|
|
17
|
+
(e0, e1, x) => [ret(fn(clamp01(div(sub(x, e0), sub(e1, e0)))))]
|
|
18
|
+
);
|
|
19
|
+
const smootherStep = $$(1, F, smootherStep01);
|
|
20
|
+
const smootherStep2 = $$(2, V2, smootherStep01_2);
|
|
21
|
+
const smootherStep3 = $$(3, V3, smootherStep01_3);
|
|
22
|
+
const smootherStep4 = $$(4, V4, smootherStep01_4);
|
|
23
|
+
export {
|
|
24
|
+
smootherStep,
|
|
25
|
+
smootherStep01,
|
|
26
|
+
smootherStep01_2,
|
|
27
|
+
smootherStep01_3,
|
|
28
|
+
smootherStep01_4,
|
|
29
|
+
smootherStep2,
|
|
30
|
+
smootherStep3,
|
|
31
|
+
smootherStep4
|
|
32
|
+
};
|
package/matrix/convert.js
CHANGED
|
@@ -2,13 +2,24 @@ import { M2, M3, M4 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { indexMat } from "@thi.ng/shader-ast/ast/indexed";
|
|
4
4
|
import { VEC3_0, mat3, mat4, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const m22ToM33 = defn(M3, "m22ToM33", [M2], (m) => {
|
|
6
|
+
return [
|
|
7
|
+
ret(mat3(vec3(indexMat(m, 0), 0), vec3(indexMat(m, 1), 0), VEC3_0))
|
|
8
|
+
];
|
|
9
9
|
});
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const m33ToM44 = defn(M4, "m33ToM44", [M3], (m) => {
|
|
11
|
+
return [
|
|
12
|
+
ret(
|
|
13
|
+
mat4(
|
|
14
|
+
vec4(indexMat(m, 0), 0),
|
|
15
|
+
vec4(indexMat(m, 1), 0),
|
|
16
|
+
vec4(indexMat(m, 2), 0),
|
|
17
|
+
vec4()
|
|
18
|
+
)
|
|
19
|
+
)
|
|
20
|
+
];
|
|
14
21
|
});
|
|
22
|
+
export {
|
|
23
|
+
m22ToM33,
|
|
24
|
+
m33ToM44
|
|
25
|
+
};
|
package/matrix/lookat.js
CHANGED
|
@@ -4,22 +4,24 @@ import { mat4, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
6
6
|
import { cross, dot, normalize } from "@thi.ng/shader-ast/builtin/math";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
];
|
|
7
|
+
const lookat = defn(M4, "lookat", [V3, V3, V3], (eye, target, up) => {
|
|
8
|
+
let x;
|
|
9
|
+
let y;
|
|
10
|
+
let z;
|
|
11
|
+
return [
|
|
12
|
+
z = sym(normalize(sub(eye, target))),
|
|
13
|
+
x = sym(normalize(cross(up, z))),
|
|
14
|
+
y = sym(normalize(cross(z, x))),
|
|
15
|
+
ret(
|
|
16
|
+
mat4(
|
|
17
|
+
vec4(x, neg(dot(eye, x))),
|
|
18
|
+
vec4(up, neg(dot(eye, y))),
|
|
19
|
+
vec4(z, neg(dot(eye, z))),
|
|
20
|
+
vec4(0, 0, 0, 1)
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
];
|
|
25
24
|
});
|
|
25
|
+
export {
|
|
26
|
+
lookat
|
|
27
|
+
};
|
package/matrix/mvp.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { FLOAT1, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
2
2
|
import { mul } from "@thi.ng/shader-ast/ast/ops";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @param p -
|
|
8
|
-
* @param model -
|
|
9
|
-
* @param view -
|
|
10
|
-
* @param proj -
|
|
11
|
-
*/
|
|
12
|
-
export const transformMVP = (p, model, view, proj) => mul(mul(proj, mul(view, model)), vec4(p, FLOAT1));
|
|
3
|
+
const transformMVP = (p, model, view, proj) => mul(mul(proj, mul(view, model)), vec4(p, FLOAT1));
|
|
4
|
+
export {
|
|
5
|
+
transformMVP
|
|
6
|
+
};
|
package/matrix/normal.js
CHANGED
|
@@ -2,11 +2,7 @@ import { vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
2
2
|
import { mul } from "@thi.ng/shader-ast/ast/ops";
|
|
3
3
|
import { $xyz } from "@thi.ng/shader-ast/ast/swizzle";
|
|
4
4
|
import { normalize } from "@thi.ng/shader-ast/builtin/math";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* @param n -
|
|
10
|
-
* @param normalMat -
|
|
11
|
-
*/
|
|
12
|
-
export const surfaceNormal = (n, normalMat) => normalize($xyz(mul(normalMat, vec4(n, 0))));
|
|
5
|
+
const surfaceNormal = (n, normalMat) => normalize($xyz(mul(normalMat, vec4(n, 0))));
|
|
6
|
+
export {
|
|
7
|
+
surfaceNormal
|
|
8
|
+
};
|