@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/sdf/smooth-isec.js
CHANGED
|
@@ -6,23 +6,20 @@ import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
|
6
6
|
import { mix } from "@thi.ng/shader-ast/builtin/math";
|
|
7
7
|
import { clamp01 } from "../math/clamp.js";
|
|
8
8
|
import { fit1101 } from "../math/fit.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const sdfSmoothIntersect = defn(F, "sdOpSmoothIntersect", [F, F, F], (a, b, k) => {
|
|
9
|
+
const sdfSmoothIntersect = defn(
|
|
10
|
+
F,
|
|
11
|
+
"sdOpSmoothIntersect",
|
|
12
|
+
[F, F, F],
|
|
13
|
+
(a, b, k) => {
|
|
15
14
|
let h;
|
|
16
15
|
return [
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
h = sym(clamp01(fit1101(div(sub(b, a), k)))),
|
|
17
|
+
ret(add(mix(b, a, h), mul(mul(k, h), sub(FLOAT1, h))))
|
|
19
18
|
];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
export const sdfSmoothIntersectAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothIntersect(acc, x, k));
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const sdfSmoothIntersectAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothIntersect(acc, x, k));
|
|
22
|
+
export {
|
|
23
|
+
sdfSmoothIntersect,
|
|
24
|
+
sdfSmoothIntersectAll
|
|
25
|
+
};
|
package/sdf/smooth-sub.js
CHANGED
|
@@ -6,23 +6,20 @@ import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
|
6
6
|
import { mix } from "@thi.ng/shader-ast/builtin/math";
|
|
7
7
|
import { clamp01 } from "../math/clamp.js";
|
|
8
8
|
import { fit1101 } from "../math/fit.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const sdfSmoothSubtract = defn(F, "sdOpSmoothSubtract", [F, F, F], (a, b, k) => {
|
|
9
|
+
const sdfSmoothSubtract = defn(
|
|
10
|
+
F,
|
|
11
|
+
"sdOpSmoothSubtract",
|
|
12
|
+
[F, F, F],
|
|
13
|
+
(a, b, k) => {
|
|
15
14
|
let h;
|
|
16
15
|
return [
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
h = sym(clamp01(fit1101(div(add(b, a), k)))),
|
|
17
|
+
ret(add(mix(b, neg(a), h), mul(mul(k, h), sub(FLOAT1, h))))
|
|
19
18
|
];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
export const sdfSmoothSubtractAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothSubtract(acc, x, k));
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const sdfSmoothSubtractAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothSubtract(acc, x, k));
|
|
22
|
+
export {
|
|
23
|
+
sdfSmoothSubtract,
|
|
24
|
+
sdfSmoothSubtractAll
|
|
25
|
+
};
|
package/sdf/smooth-union.js
CHANGED
|
@@ -6,23 +6,20 @@ import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
|
6
6
|
import { mix } from "@thi.ng/shader-ast/builtin/math";
|
|
7
7
|
import { clamp01 } from "../math/clamp.js";
|
|
8
8
|
import { fit1101 } from "../math/fit.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const sdfSmoothUnion = defn(F, "sdOpSmoothUnion", [F, F, F], (a, b, k) => {
|
|
9
|
+
const sdfSmoothUnion = defn(
|
|
10
|
+
F,
|
|
11
|
+
"sdOpSmoothUnion",
|
|
12
|
+
[F, F, F],
|
|
13
|
+
(a, b, k) => {
|
|
15
14
|
let h;
|
|
16
15
|
return [
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
h = sym(clamp01(fit1101(div(sub(b, a), k)))),
|
|
17
|
+
ret(sub(mix(b, a, h), mul(mul(k, h), sub(FLOAT1, h))))
|
|
19
18
|
];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
export const sdfSmoothUnionAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothUnion(acc, x, k));
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
const sdfSmoothUnionAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothUnion(acc, x, k));
|
|
22
|
+
export {
|
|
23
|
+
sdfSmoothUnion,
|
|
24
|
+
sdfSmoothUnionAll
|
|
25
|
+
};
|
package/sdf/sphere.js
CHANGED
|
@@ -2,21 +2,13 @@ import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
4
4
|
import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
* @param p - vec2
|
|
9
|
-
* @param r - float
|
|
10
|
-
*/
|
|
11
|
-
export const sdfCircle = defn(F, "sdCircle", [V2, F], (p, r) => [
|
|
12
|
-
ret(sub(length(p), r)),
|
|
5
|
+
const sdfCircle = defn(F, "sdCircle", [V2, F], (p, r) => [
|
|
6
|
+
ret(sub(length(p), r))
|
|
13
7
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* @param p - vec3
|
|
18
|
-
* @param r - float
|
|
19
|
-
*/
|
|
20
|
-
export const sdfSphere = defn(F, "sdSphere", [V3, F], (p, r) => [
|
|
21
|
-
ret(sub(length(p), r)),
|
|
8
|
+
const sdfSphere = defn(F, "sdSphere", [V3, F], (p, r) => [
|
|
9
|
+
ret(sub(length(p), r))
|
|
22
10
|
]);
|
|
11
|
+
export {
|
|
12
|
+
sdfCircle,
|
|
13
|
+
sdfSphere
|
|
14
|
+
};
|
package/sdf/sub.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { neg } from "@thi.ng/shader-ast/ast/ops";
|
|
2
2
|
import { max } from "@thi.ng/shader-ast/builtin/math";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @param a -
|
|
8
|
-
* @param terms -
|
|
9
|
-
*/
|
|
10
|
-
export const sdfSubtract = (a, ...terms) => terms.reduce((a, b) => max(a, neg(b)), a);
|
|
3
|
+
const sdfSubtract = (a, ...terms) => terms.reduce((a2, b) => max(a2, neg(b)), a);
|
|
4
|
+
export {
|
|
5
|
+
sdfSubtract
|
|
6
|
+
};
|
package/sdf/torus.js
CHANGED
|
@@ -4,14 +4,9 @@ import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { $, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
6
|
import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* radii `r1`, `r2`.
|
|
10
|
-
*
|
|
11
|
-
* @param p - vec3
|
|
12
|
-
* @param r1 - float
|
|
13
|
-
* @param r2 - float
|
|
14
|
-
*/
|
|
15
|
-
export const sdfTorus = defn(F, "sdTorus", [V3, F, F], (p, r1, r2) => [
|
|
16
|
-
ret(sub(length(vec2(sub(length($(p, "xz")), r2), $y(p))), r1)),
|
|
7
|
+
const sdfTorus = defn(F, "sdTorus", [V3, F, F], (p, r1, r2) => [
|
|
8
|
+
ret(sub(length(vec2(sub(length($(p, "xz")), r2), $y(p))), r1))
|
|
17
9
|
]);
|
|
10
|
+
export {
|
|
11
|
+
sdfTorus
|
|
12
|
+
};
|
package/sdf/tri.js
CHANGED
|
@@ -7,13 +7,11 @@ import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
|
7
7
|
import { dot, min, sign, sqrt } from "@thi.ng/shader-ast/builtin/math";
|
|
8
8
|
import { clamp01 } from "../math/clamp.js";
|
|
9
9
|
import { cross2 } from "../math/cross2.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
export const sdfTriangle2 = defn(F, "sdTriangle", [V2, V2, V2, V2], (p, a, b, c) => {
|
|
10
|
+
const sdfTriangle2 = defn(
|
|
11
|
+
F,
|
|
12
|
+
"sdTriangle",
|
|
13
|
+
[V2, V2, V2, V2],
|
|
14
|
+
(p, a, b, c) => {
|
|
17
15
|
let e0, e1, e2;
|
|
18
16
|
let v0, v1, v2;
|
|
19
17
|
let pq0, pq1, pq2;
|
|
@@ -21,17 +19,29 @@ export const sdfTriangle2 = defn(F, "sdTriangle", [V2, V2, V2, V2], (p, a, b, c)
|
|
|
21
19
|
let d;
|
|
22
20
|
const $pq = (v, e) => sub(v, mul(e, clamp01(div(dot(v, e), dot(e, e)))));
|
|
23
21
|
return [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
e0 = sym(sub(b, a)),
|
|
23
|
+
e1 = sym(sub(c, b)),
|
|
24
|
+
e2 = sym(sub(a, c)),
|
|
25
|
+
v0 = sym(sub(p, a)),
|
|
26
|
+
v1 = sym(sub(p, b)),
|
|
27
|
+
v2 = sym(sub(p, c)),
|
|
28
|
+
pq0 = sym($pq(v0, e0)),
|
|
29
|
+
pq1 = sym($pq(v1, e1)),
|
|
30
|
+
pq2 = sym($pq(v2, e2)),
|
|
31
|
+
s = sym(sign(cross2(e0, e2))),
|
|
32
|
+
d = sym(
|
|
33
|
+
min(
|
|
34
|
+
min(
|
|
35
|
+
vec2(dot(pq0, pq0), mul(s, cross2(v0, e0))),
|
|
36
|
+
vec2(dot(pq1, pq1), mul(s, cross2(v1, e1)))
|
|
37
|
+
),
|
|
38
|
+
vec2(dot(pq2, pq2), mul(s, cross2(v2, e2)))
|
|
39
|
+
)
|
|
40
|
+
),
|
|
41
|
+
ret(mul(neg(sqrt($x(d))), sign($y(d))))
|
|
36
42
|
];
|
|
37
|
-
}
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
export {
|
|
46
|
+
sdfTriangle2
|
|
47
|
+
};
|
package/sdf/union.js
CHANGED
|
@@ -4,22 +4,11 @@ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
|
4
4
|
import { lt } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { $x } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
6
|
import { min } from "@thi.ng/shader-ast/builtin/math";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param a -
|
|
12
|
-
* @param terms -
|
|
13
|
-
*/
|
|
14
|
-
export const sdfUnion = (a, ...terms) => terms.reduce((a, b) => min(a, b), a);
|
|
15
|
-
/**
|
|
16
|
-
* SDF shape union for vec2 terms, i.e. the common form where the X coord
|
|
17
|
-
* defines distance and Y an object or material ID. Returns `a` or `b`,
|
|
18
|
-
* depending whose x-coord (dist) is smaller.
|
|
19
|
-
*
|
|
20
|
-
* @param a -
|
|
21
|
-
* @param b -
|
|
22
|
-
*/
|
|
23
|
-
export const sdfUnion2 = defn(V2, "sdfUnion2", [V2, V2], (a, b) => [
|
|
24
|
-
ret(ternary(lt($x(a), $x(b)), a, b)),
|
|
7
|
+
const sdfUnion = (a, ...terms) => terms.reduce((a2, b) => min(a2, b), a);
|
|
8
|
+
const sdfUnion2 = defn(V2, "sdfUnion2", [V2, V2], (a, b) => [
|
|
9
|
+
ret(ternary(lt($x(a), $x(b)), a, b))
|
|
25
10
|
]);
|
|
11
|
+
export {
|
|
12
|
+
sdfUnion,
|
|
13
|
+
sdfUnion2
|
|
14
|
+
};
|
package/tex/blur.js
CHANGED
|
@@ -5,52 +5,35 @@ import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
5
5
|
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
6
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
7
|
import { texture } from "@thi.ng/shader-ast/builtin/texture";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* 5x5 gaussian blur texture lookup, optimized, but based on:
|
|
21
|
-
*
|
|
22
|
-
* - http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
|
|
23
|
-
* - https://github.com/Jam3/glsl-fast-gaussian-blur
|
|
24
|
-
*
|
|
25
|
-
* @param tex - sampler2D
|
|
26
|
-
* @param res - resolution
|
|
27
|
-
* @param uv -
|
|
28
|
-
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
29
|
-
*/
|
|
30
|
-
export const blur5 = defn(V4, "blur5", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
8
|
+
const singlePass = (col, tex, uv, off, k) => assign(
|
|
9
|
+
col,
|
|
10
|
+
add(
|
|
11
|
+
col,
|
|
12
|
+
mul(add(texture(tex, add(uv, off)), texture(tex, sub(uv, off))), k)
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
const blur5 = defn(
|
|
16
|
+
V4,
|
|
17
|
+
"blur5",
|
|
18
|
+
["sampler2D", V2, V2, V2],
|
|
19
|
+
(tex, res, uv, dir) => {
|
|
31
20
|
let col;
|
|
32
21
|
let off;
|
|
33
22
|
const k1 = 0.29411764705882354;
|
|
34
23
|
const k2 = 0.35294117647058826;
|
|
35
24
|
return [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
off = sym(div(mul(vec2(1 + 1 / 3), dir), res)),
|
|
26
|
+
col = sym(mul(texture(tex, uv), k1)),
|
|
27
|
+
singlePass(col, tex, uv, off, k2),
|
|
28
|
+
ret(col)
|
|
40
29
|
];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* @param tex - sampler2D
|
|
49
|
-
* @param res - resolution
|
|
50
|
-
* @param uv -
|
|
51
|
-
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
52
|
-
*/
|
|
53
|
-
export const blur9 = defn(V4, "blur9", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
const blur9 = defn(
|
|
33
|
+
V4,
|
|
34
|
+
"blur9",
|
|
35
|
+
["sampler2D", V2, V2, V2],
|
|
36
|
+
(tex, res, uv, dir) => {
|
|
54
37
|
let col;
|
|
55
38
|
let off;
|
|
56
39
|
let off2;
|
|
@@ -58,27 +41,21 @@ export const blur9 = defn(V4, "blur9", ["sampler2D", V2, V2, V2], (tex, res, uv,
|
|
|
58
41
|
const k1 = 0.3162162162;
|
|
59
42
|
const k2 = 0.0702702703;
|
|
60
43
|
return [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
44
|
+
delta = sym(div(dir, res)),
|
|
45
|
+
off = sym(mul(delta, 1.3846153846)),
|
|
46
|
+
off2 = sym(mul(delta, 3.2307692308)),
|
|
47
|
+
col = sym(mul(texture(tex, uv), 0.227027027)),
|
|
48
|
+
singlePass(col, tex, uv, off, k1),
|
|
49
|
+
singlePass(col, tex, uv, off2, k2),
|
|
50
|
+
ret(col)
|
|
68
51
|
];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
* @param tex - sampler2D
|
|
77
|
-
* @param res - resolution
|
|
78
|
-
* @param uv -
|
|
79
|
-
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
80
|
-
*/
|
|
81
|
-
export const blur13 = defn(V4, "blur13", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
const blur13 = defn(
|
|
55
|
+
V4,
|
|
56
|
+
"blur13",
|
|
57
|
+
["sampler2D", V2, V2, V2],
|
|
58
|
+
(tex, res, uv, dir) => {
|
|
82
59
|
let col;
|
|
83
60
|
let off;
|
|
84
61
|
let off2;
|
|
@@ -88,14 +65,20 @@ export const blur13 = defn(V4, "blur13", ["sampler2D", V2, V2, V2], (tex, res, u
|
|
|
88
65
|
const k2 = 0.09447039785044732;
|
|
89
66
|
const k3 = 0.010381362401148057;
|
|
90
67
|
return [
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
68
|
+
delta = sym(div(dir, res)),
|
|
69
|
+
off = sym(mul(delta, 1.411764705882353)),
|
|
70
|
+
off2 = sym(mul(delta, 3.2941176470588234)),
|
|
71
|
+
off3 = sym(mul(delta, 5.176470588235294)),
|
|
72
|
+
col = sym(mul(texture(tex, uv), 0.1964825501511404)),
|
|
73
|
+
singlePass(col, tex, uv, off, k1),
|
|
74
|
+
singlePass(col, tex, uv, off2, k2),
|
|
75
|
+
singlePass(col, tex, uv, off3, k3),
|
|
76
|
+
ret(col)
|
|
100
77
|
];
|
|
101
|
-
}
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
export {
|
|
81
|
+
blur13,
|
|
82
|
+
blur5,
|
|
83
|
+
blur9
|
|
84
|
+
};
|
package/tex/index-coord.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import { uvec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
2
2
|
import { div, madd, modi } from "@thi.ng/shader-ast/ast/ops";
|
|
3
3
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
export const indexToCoord = (i, width) => uvec2(modi(i, width), div(i, width));
|
|
12
|
-
/**
|
|
13
|
-
* Inline function. Reverse op to {@link indexToCoord}. Not compatible with
|
|
14
|
-
* WebGL1.
|
|
15
|
-
*
|
|
16
|
-
* @param coord -
|
|
17
|
-
* @param width -
|
|
18
|
-
*/
|
|
19
|
-
export const coordToIndex = (coord, width) => madd($y(coord), width, $x(coord));
|
|
4
|
+
const indexToCoord = (i, width) => uvec2(modi(i, width), div(i, width));
|
|
5
|
+
const coordToIndex = (coord, width) => madd($y(coord), width, $x(coord));
|
|
6
|
+
export {
|
|
7
|
+
coordToIndex,
|
|
8
|
+
indexToCoord
|
|
9
|
+
};
|
package/tex/index-uv.js
CHANGED
|
@@ -3,23 +3,33 @@ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
|
3
3
|
import { float, int, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
4
|
import { add, div, modi, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
ret(
|
|
25
|
-
|
|
6
|
+
const indexToUV = defn(
|
|
7
|
+
V2,
|
|
8
|
+
"indexToUV",
|
|
9
|
+
[[I, "i", { prec: "highp" }], ["ivec2"]],
|
|
10
|
+
(i, size) => [
|
|
11
|
+
ret(
|
|
12
|
+
vec2(
|
|
13
|
+
div(float(modi(i, $x(size))), float($x(size))),
|
|
14
|
+
div(float(div(i, $x(size))), float($y(size)))
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
]
|
|
18
|
+
);
|
|
19
|
+
const uvToIndex = defn(
|
|
20
|
+
I,
|
|
21
|
+
"uvToIndex",
|
|
22
|
+
[V2, [I, "width", { prec: "highp" }]],
|
|
23
|
+
(uv, width) => [
|
|
24
|
+
ret(
|
|
25
|
+
add(
|
|
26
|
+
int(mul($x(uv), float(width))),
|
|
27
|
+
int(mul($y(uv), float(mul(width, width))))
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
]
|
|
31
|
+
);
|
|
32
|
+
export {
|
|
33
|
+
indexToUV,
|
|
34
|
+
uvToIndex
|
|
35
|
+
};
|
package/tex/read-index.js
CHANGED
|
@@ -1,35 +1,13 @@
|
|
|
1
1
|
import { $x, $xy, $xyz } from "@thi.ng/shader-ast/ast/swizzle";
|
|
2
2
|
import { texture } from "@thi.ng/shader-ast/builtin/texture";
|
|
3
3
|
import { indexToUV } from "./index-uv.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
* @param tex -
|
|
16
|
-
* @param i -
|
|
17
|
-
* @param size -
|
|
18
|
-
*/
|
|
19
|
-
export const readIndex2 = (tex, i, size) => $xy(readIndex4(tex, i, size));
|
|
20
|
-
/**
|
|
21
|
-
* Inline function. Returns vec3 (x,y,z components) at index `i` in `tex`.
|
|
22
|
-
*
|
|
23
|
-
* @param tex -
|
|
24
|
-
* @param i -
|
|
25
|
-
* @param size -
|
|
26
|
-
*/
|
|
27
|
-
export const readIndex3 = (tex, i, size) => $xyz(readIndex4(tex, i, size));
|
|
28
|
-
/**
|
|
29
|
-
* Inline function. Returns vec4 at index `i` in `tex`.
|
|
30
|
-
*
|
|
31
|
-
* @param tex -
|
|
32
|
-
* @param i -
|
|
33
|
-
* @param size -
|
|
34
|
-
*/
|
|
35
|
-
export const readIndex4 = (tex, i, size) => texture(tex, indexToUV(i, size));
|
|
4
|
+
const readIndex1 = (tex, i, size) => $x(readIndex4(tex, i, size));
|
|
5
|
+
const readIndex2 = (tex, i, size) => $xy(readIndex4(tex, i, size));
|
|
6
|
+
const readIndex3 = (tex, i, size) => $xyz(readIndex4(tex, i, size));
|
|
7
|
+
const readIndex4 = (tex, i, size) => texture(tex, indexToUV(i, size));
|
|
8
|
+
export {
|
|
9
|
+
readIndex1,
|
|
10
|
+
readIndex2,
|
|
11
|
+
readIndex3,
|
|
12
|
+
readIndex4
|
|
13
|
+
};
|