@thi.ng/shader-ast-stdlib 0.16.9 → 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 -5
- 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/matrix/rotation.js
CHANGED
|
@@ -8,62 +8,146 @@ import { cos, sin } from "@thi.ng/shader-ast/builtin/math";
|
|
|
8
8
|
import { perpendicularCCW } from "../math/orthogonal.js";
|
|
9
9
|
import { cossin } from "../math/sincos.js";
|
|
10
10
|
import { m33ToM44 } from "./convert.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const rotation2 = defn(M2, "rotation2", [F], (theta) => {
|
|
12
|
+
let cs;
|
|
13
|
+
return [cs = sym(cossin(theta)), ret(mat2(cs, perpendicularCCW(cs)))];
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const rotationX3 = defn(M3, "rotationX3", [F], (theta) => {
|
|
16
|
+
let cs;
|
|
17
|
+
return [
|
|
18
|
+
cs = sym(cossin(theta)),
|
|
19
|
+
ret(mat3(1, 0, 0, 0, $x(cs), $y(cs), 0, neg($y(cs)), $x(cs)))
|
|
20
|
+
];
|
|
21
21
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const rotationY3 = defn(M3, "rotationY3", [F], (theta) => {
|
|
23
|
+
let cs;
|
|
24
|
+
return [
|
|
25
|
+
cs = sym(cossin(theta)),
|
|
26
|
+
ret(mat3($x(cs), 0, neg($y(cs)), 0, 1, 0, $y(cs), 0, $x(cs)))
|
|
27
|
+
];
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const rotationZ3 = defn(M3, "rotationZ3", [F], (theta) => {
|
|
30
|
+
let cs;
|
|
31
|
+
return [
|
|
32
|
+
cs = sym(cossin(theta)),
|
|
33
|
+
ret(mat3($x(cs), $y(cs), 0, neg($y(cs)), $x(cs), 0, 0, 0, 1))
|
|
34
|
+
];
|
|
35
35
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const rotationX4 = defn(M4, "rotationX4", [F], (theta) => {
|
|
37
|
+
let cs;
|
|
38
|
+
return [
|
|
39
|
+
cs = sym(cossin(theta)),
|
|
40
|
+
ret(
|
|
41
|
+
mat4(
|
|
42
|
+
1,
|
|
43
|
+
0,
|
|
44
|
+
0,
|
|
45
|
+
0,
|
|
46
|
+
0,
|
|
47
|
+
$x(cs),
|
|
48
|
+
$y(cs),
|
|
49
|
+
0,
|
|
50
|
+
0,
|
|
51
|
+
neg($y(cs)),
|
|
52
|
+
$x(cs),
|
|
53
|
+
0,
|
|
54
|
+
0,
|
|
55
|
+
0,
|
|
56
|
+
0,
|
|
57
|
+
1
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
];
|
|
42
61
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
const rotationY4 = defn(M4, "rotationY4", [F], (theta) => {
|
|
63
|
+
let cs;
|
|
64
|
+
return [
|
|
65
|
+
cs = sym(cossin(theta)),
|
|
66
|
+
ret(
|
|
67
|
+
mat4(
|
|
68
|
+
$x(cs),
|
|
69
|
+
0,
|
|
70
|
+
neg($y(cs)),
|
|
71
|
+
0,
|
|
72
|
+
0,
|
|
73
|
+
1,
|
|
74
|
+
0,
|
|
75
|
+
0,
|
|
76
|
+
$y(cs),
|
|
77
|
+
0,
|
|
78
|
+
$x(cs),
|
|
79
|
+
0,
|
|
80
|
+
0,
|
|
81
|
+
0,
|
|
82
|
+
0,
|
|
83
|
+
1
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
];
|
|
49
87
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
88
|
+
const rotationZ4 = defn(M4, "rotationZ4", [F], (theta) => {
|
|
89
|
+
let cs;
|
|
90
|
+
return [
|
|
91
|
+
cs = sym(cossin(theta)),
|
|
92
|
+
ret(
|
|
93
|
+
mat4(
|
|
94
|
+
$x(cs),
|
|
95
|
+
$y(cs),
|
|
96
|
+
0,
|
|
97
|
+
0,
|
|
98
|
+
neg($y(cs)),
|
|
99
|
+
$x(cs),
|
|
100
|
+
0,
|
|
101
|
+
0,
|
|
102
|
+
0,
|
|
103
|
+
0,
|
|
104
|
+
1,
|
|
105
|
+
0,
|
|
106
|
+
0,
|
|
107
|
+
0,
|
|
108
|
+
0,
|
|
109
|
+
1
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
];
|
|
56
113
|
});
|
|
57
|
-
|
|
114
|
+
const rotationAroundAxis3 = defn(
|
|
115
|
+
M3,
|
|
116
|
+
"rotationAroundAxis3",
|
|
117
|
+
[V3, F],
|
|
118
|
+
(axis, theta) => {
|
|
58
119
|
let s;
|
|
59
120
|
let c;
|
|
60
121
|
let t;
|
|
61
|
-
const $$ = (a, b,
|
|
122
|
+
const $$ = (a, b, c2, d, e, f, g) => add(mul(mul(axis, a), t), mul(vec3(b, c2, d), vec3(e, f, g)));
|
|
62
123
|
return [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
124
|
+
s = sym(sin(theta)),
|
|
125
|
+
c = sym(cos(theta)),
|
|
126
|
+
t = sym(sub(1, c)),
|
|
127
|
+
ret(
|
|
128
|
+
mat3(
|
|
129
|
+
$$($x(axis), 1, $z(axis), neg($y(axis)), c, s, s),
|
|
130
|
+
$$($y(axis), neg($z(axis)), 1, $x(axis), s, c, s),
|
|
131
|
+
$$($z(axis), $y(axis), neg($x(axis)), 1, s, s, c)
|
|
132
|
+
)
|
|
133
|
+
)
|
|
67
134
|
];
|
|
68
|
-
}
|
|
69
|
-
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
const rotationAroundAxis4 = defn(
|
|
138
|
+
M4,
|
|
139
|
+
"rotationAroundAxis4",
|
|
140
|
+
[V3, F],
|
|
141
|
+
(axis, theta) => [ret(m33ToM44(rotationAroundAxis3(axis, theta)))]
|
|
142
|
+
);
|
|
143
|
+
export {
|
|
144
|
+
rotation2,
|
|
145
|
+
rotationAroundAxis3,
|
|
146
|
+
rotationAroundAxis4,
|
|
147
|
+
rotationX3,
|
|
148
|
+
rotationX4,
|
|
149
|
+
rotationY3,
|
|
150
|
+
rotationY4,
|
|
151
|
+
rotationZ3,
|
|
152
|
+
rotationZ4
|
|
153
|
+
};
|
package/noise/curl3.js
CHANGED
|
@@ -5,22 +5,34 @@ import { add, div, mul, sub } 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 { snoiseVec3 } from "./simplex3.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
8
|
+
const curlNoise3 = defn(V3, "curlNoise3", [V3, F], (p, e) => {
|
|
9
|
+
let D;
|
|
10
|
+
let px0;
|
|
11
|
+
let px1;
|
|
12
|
+
let py0;
|
|
13
|
+
let py1;
|
|
14
|
+
let pz0;
|
|
15
|
+
let pz1;
|
|
16
|
+
return [
|
|
17
|
+
D = sym(vec2(e, 0)),
|
|
18
|
+
px0 = sym(snoiseVec3(sub(p, $(D, "xyy")))),
|
|
19
|
+
px1 = sym(snoiseVec3(add(p, $(D, "xyy")))),
|
|
20
|
+
py0 = sym(snoiseVec3(sub(p, $(D, "yxy")))),
|
|
21
|
+
py1 = sym(snoiseVec3(add(p, $(D, "yxy")))),
|
|
22
|
+
pz0 = sym(snoiseVec3(sub(p, $(D, "yyx")))),
|
|
23
|
+
pz1 = sym(snoiseVec3(add(p, $(D, "yyx")))),
|
|
24
|
+
ret(
|
|
25
|
+
div(
|
|
26
|
+
vec3(
|
|
27
|
+
add(sub(sub($z(py1), $z(py0)), $y(pz1)), $y(pz0)),
|
|
28
|
+
add(sub(sub($x(pz1), $x(pz0)), $z(px1)), $z(px0)),
|
|
29
|
+
add(sub(sub($y(px1), $y(px0)), $x(py1)), $x(py0))
|
|
30
|
+
),
|
|
31
|
+
mul(2, e)
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
];
|
|
26
35
|
});
|
|
36
|
+
export {
|
|
37
|
+
curlNoise3
|
|
38
|
+
};
|
package/noise/hash.js
CHANGED
|
@@ -6,217 +6,146 @@ import { add, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
|
6
6
|
import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
7
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
8
8
|
import { dot, fract, sin } from "@thi.ng/shader-ast/builtin/math";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @param p -
|
|
13
|
-
*/
|
|
14
|
-
export const hash2 = defn(V2, "hash2", [V2], (p) => [
|
|
15
|
-
ret(fract(mul(sin(mul(p, mat2(127.1, 311.7, 269.5, 183.3))), 43758.5453))),
|
|
9
|
+
const hash2 = defn(V2, "hash2", [V2], (p) => [
|
|
10
|
+
ret(fract(mul(sin(mul(p, mat2(127.1, 311.7, 269.5, 183.3))), 43758.5453)))
|
|
16
11
|
]);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
const hash3 = defn(V3, "hash3", [V2], (p) => [
|
|
13
|
+
ret(
|
|
14
|
+
fract(
|
|
15
|
+
mul(
|
|
16
|
+
sin(
|
|
17
|
+
vec3(
|
|
18
|
+
dot(p, vec2(127.1, 311.7)),
|
|
19
|
+
dot(p, vec2(269.5, 183.3)),
|
|
20
|
+
dot(p, vec2(419.2, 371.9))
|
|
21
|
+
)
|
|
22
|
+
),
|
|
23
|
+
43758.5453
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
)
|
|
24
27
|
]);
|
|
25
28
|
const H = vec3(0.1031, 0.103, 0.0973);
|
|
26
29
|
const H4 = vec4(0.1031, 0.103, 0.0973, 0.1099);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let x;
|
|
36
|
-
return [
|
|
37
|
-
(x = sym(fract(mul(p, 0.1031)))),
|
|
38
|
-
assign(x, mul(x, add(x, 19.19))),
|
|
39
|
-
assign(x, mul(x, add(x, x))),
|
|
40
|
-
ret(fract(x)),
|
|
41
|
-
];
|
|
30
|
+
const hash11 = defn(F, "hash11", [F], (p) => {
|
|
31
|
+
let x;
|
|
32
|
+
return [
|
|
33
|
+
x = sym(fract(mul(p, 0.1031))),
|
|
34
|
+
assign(x, mul(x, add(x, 19.19))),
|
|
35
|
+
assign(x, mul(x, add(x, x))),
|
|
36
|
+
ret(fract(x))
|
|
37
|
+
];
|
|
42
38
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export const hash12 = defn(F, "hash12", [V2], (p) => {
|
|
51
|
-
let x;
|
|
52
|
-
return [
|
|
53
|
-
(x = sym(fract(mul($(p, "xyx"), 0.1031)))),
|
|
54
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
55
|
-
ret(fract(mul(add($x(x), $y(x)), $z(x)))),
|
|
56
|
-
];
|
|
39
|
+
const hash12 = defn(F, "hash12", [V2], (p) => {
|
|
40
|
+
let x;
|
|
41
|
+
return [
|
|
42
|
+
x = sym(fract(mul($(p, "xyx"), 0.1031))),
|
|
43
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
44
|
+
ret(fract(mul(add($x(x), $y(x)), $z(x))))
|
|
45
|
+
];
|
|
57
46
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export const hash13 = defn(F, "hash13", [V3], (p) => {
|
|
66
|
-
let x;
|
|
67
|
-
return [
|
|
68
|
-
(x = sym(fract(mul($(p, "xyx"), 0.1031)))),
|
|
69
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
70
|
-
ret(fract(mul(add($x(x), $y(x)), $z(x)))),
|
|
71
|
-
];
|
|
47
|
+
const hash13 = defn(F, "hash13", [V3], (p) => {
|
|
48
|
+
let x;
|
|
49
|
+
return [
|
|
50
|
+
x = sym(fract(mul($(p, "xyx"), 0.1031))),
|
|
51
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
52
|
+
ret(fract(mul(add($x(x), $y(x)), $z(x))))
|
|
53
|
+
];
|
|
72
54
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
export const hash21 = defn(V2, "hash21", [F], (p) => {
|
|
81
|
-
let x;
|
|
82
|
-
return [
|
|
83
|
-
(x = sym(fract(mul(vec3(p), H)))),
|
|
84
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
85
|
-
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy")))),
|
|
86
|
-
];
|
|
55
|
+
const hash21 = defn(V2, "hash21", [F], (p) => {
|
|
56
|
+
let x;
|
|
57
|
+
return [
|
|
58
|
+
x = sym(fract(mul(vec3(p), H))),
|
|
59
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
60
|
+
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy"))))
|
|
61
|
+
];
|
|
87
62
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export const hash22 = defn(V2, "hash22", [V2], (p) => {
|
|
96
|
-
let x;
|
|
97
|
-
return [
|
|
98
|
-
(x = sym(fract(mul($(p, "xyx"), H)))),
|
|
99
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
100
|
-
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy")))),
|
|
101
|
-
];
|
|
63
|
+
const hash22 = defn(V2, "hash22", [V2], (p) => {
|
|
64
|
+
let x;
|
|
65
|
+
return [
|
|
66
|
+
x = sym(fract(mul($(p, "xyx"), H))),
|
|
67
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
68
|
+
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy"))))
|
|
69
|
+
];
|
|
102
70
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
export const hash23 = defn(V2, "hash23", [V3], (p) => {
|
|
111
|
-
let x;
|
|
112
|
-
return [
|
|
113
|
-
(x = sym(fract(mul(p, H)))),
|
|
114
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
115
|
-
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy")))),
|
|
116
|
-
];
|
|
71
|
+
const hash23 = defn(V2, "hash23", [V3], (p) => {
|
|
72
|
+
let x;
|
|
73
|
+
return [
|
|
74
|
+
x = sym(fract(mul(p, H))),
|
|
75
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
76
|
+
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy"))))
|
|
77
|
+
];
|
|
117
78
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export const hash31 = defn(V3, "hash31", [F], (p) => {
|
|
126
|
-
let x;
|
|
127
|
-
return [
|
|
128
|
-
(x = sym(fract(mul(p, H)))),
|
|
129
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
130
|
-
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx")))),
|
|
131
|
-
];
|
|
79
|
+
const hash31 = defn(V3, "hash31", [F], (p) => {
|
|
80
|
+
let x;
|
|
81
|
+
return [
|
|
82
|
+
x = sym(fract(mul(p, H))),
|
|
83
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
84
|
+
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx"))))
|
|
85
|
+
];
|
|
132
86
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
export const hash32 = defn(V3, "hash32", [V2], (p) => {
|
|
141
|
-
let x;
|
|
142
|
-
return [
|
|
143
|
-
(x = sym(fract(mul($(p, "xyx"), H)))),
|
|
144
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
145
|
-
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx")))),
|
|
146
|
-
];
|
|
87
|
+
const hash32 = defn(V3, "hash32", [V2], (p) => {
|
|
88
|
+
let x;
|
|
89
|
+
return [
|
|
90
|
+
x = sym(fract(mul($(p, "xyx"), H))),
|
|
91
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
92
|
+
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx"))))
|
|
93
|
+
];
|
|
147
94
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
export const hash33 = defn(V3, "hash33", [V3], (p) => {
|
|
156
|
-
let x;
|
|
157
|
-
return [
|
|
158
|
-
(x = sym(fract(mul(p, H)))),
|
|
159
|
-
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
160
|
-
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx")))),
|
|
161
|
-
];
|
|
95
|
+
const hash33 = defn(V3, "hash33", [V3], (p) => {
|
|
96
|
+
let x;
|
|
97
|
+
return [
|
|
98
|
+
x = sym(fract(mul(p, H))),
|
|
99
|
+
assign(x, add(x, dot(x, add($(x, "yzx"), 19.19)))),
|
|
100
|
+
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx"))))
|
|
101
|
+
];
|
|
162
102
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
export const hash41 = defn(V4, "hash41", [F], (p) => {
|
|
171
|
-
let x;
|
|
172
|
-
return [
|
|
173
|
-
(x = sym(fract(mul(p, H4)))),
|
|
174
|
-
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
175
|
-
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx")))),
|
|
176
|
-
];
|
|
103
|
+
const hash41 = defn(V4, "hash41", [F], (p) => {
|
|
104
|
+
let x;
|
|
105
|
+
return [
|
|
106
|
+
x = sym(fract(mul(p, H4))),
|
|
107
|
+
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
108
|
+
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
109
|
+
];
|
|
177
110
|
});
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
export const hash42 = defn(V4, "hash42", [V2], (p) => {
|
|
186
|
-
let x;
|
|
187
|
-
return [
|
|
188
|
-
(x = sym(fract(mul($(p, "xyxy"), H4)))),
|
|
189
|
-
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
190
|
-
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx")))),
|
|
191
|
-
];
|
|
111
|
+
const hash42 = defn(V4, "hash42", [V2], (p) => {
|
|
112
|
+
let x;
|
|
113
|
+
return [
|
|
114
|
+
x = sym(fract(mul($(p, "xyxy"), H4))),
|
|
115
|
+
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
116
|
+
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
117
|
+
];
|
|
192
118
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
export const hash43 = defn(V4, "hash43", [V3], (p) => {
|
|
201
|
-
let x;
|
|
202
|
-
return [
|
|
203
|
-
(x = sym(fract(mul($(p, "xyzx"), H4)))),
|
|
204
|
-
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
205
|
-
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx")))),
|
|
206
|
-
];
|
|
119
|
+
const hash43 = defn(V4, "hash43", [V3], (p) => {
|
|
120
|
+
let x;
|
|
121
|
+
return [
|
|
122
|
+
x = sym(fract(mul($(p, "xyzx"), H4))),
|
|
123
|
+
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
124
|
+
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
125
|
+
];
|
|
207
126
|
});
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
export const hash44 = defn(V4, "hash44", [V4], (p) => {
|
|
216
|
-
let x;
|
|
217
|
-
return [
|
|
218
|
-
(x = sym(fract(mul(p, H4)))),
|
|
219
|
-
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
220
|
-
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx")))),
|
|
221
|
-
];
|
|
127
|
+
const hash44 = defn(V4, "hash44", [V4], (p) => {
|
|
128
|
+
let x;
|
|
129
|
+
return [
|
|
130
|
+
x = sym(fract(mul(p, H4))),
|
|
131
|
+
assign(x, add(x, dot(x, add($(x, "wzxy"), 19.19)))),
|
|
132
|
+
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
133
|
+
];
|
|
222
134
|
});
|
|
135
|
+
export {
|
|
136
|
+
hash11,
|
|
137
|
+
hash12,
|
|
138
|
+
hash13,
|
|
139
|
+
hash2,
|
|
140
|
+
hash21,
|
|
141
|
+
hash22,
|
|
142
|
+
hash23,
|
|
143
|
+
hash3,
|
|
144
|
+
hash31,
|
|
145
|
+
hash32,
|
|
146
|
+
hash33,
|
|
147
|
+
hash41,
|
|
148
|
+
hash42,
|
|
149
|
+
hash43,
|
|
150
|
+
hash44
|
|
151
|
+
};
|
package/noise/permute.js
CHANGED
|
@@ -4,9 +4,15 @@ import { FLOAT1, float } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { add, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { mod } from "@thi.ng/shader-ast/builtin/math";
|
|
6
6
|
const __permute = (type, suffix = "") => defn(type, `permute${suffix}`, [type], (v) => [
|
|
7
|
-
|
|
7
|
+
ret(mod(mul(v, add(mul(v, float(34)), FLOAT1)), float(289)))
|
|
8
8
|
]);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const permute = __permute(F);
|
|
10
|
+
const permute2 = __permute(V2, "2");
|
|
11
|
+
const permute3 = __permute(V3, "3");
|
|
12
|
+
const permute4 = __permute(V4, "4");
|
|
13
|
+
export {
|
|
14
|
+
permute,
|
|
15
|
+
permute2,
|
|
16
|
+
permute3,
|
|
17
|
+
permute4
|
|
18
|
+
};
|