@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/viz/function.js
CHANGED
|
@@ -2,76 +2,78 @@ import { F, V2 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
3
3
|
import { forLoop, ifThen } from "@thi.ng/shader-ast/ast/controlflow";
|
|
4
4
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
FLOAT0,
|
|
7
|
+
FLOAT2,
|
|
8
|
+
VEC2_0,
|
|
9
|
+
VEC2_1,
|
|
10
|
+
float,
|
|
11
|
+
vec2
|
|
12
|
+
} from "@thi.ng/shader-ast/ast/lit";
|
|
13
|
+
import {
|
|
14
|
+
add,
|
|
15
|
+
div,
|
|
16
|
+
gt,
|
|
17
|
+
inc,
|
|
18
|
+
lt,
|
|
19
|
+
lte,
|
|
20
|
+
or,
|
|
21
|
+
sub
|
|
22
|
+
} from "@thi.ng/shader-ast/ast/ops";
|
|
7
23
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
8
24
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
9
25
|
import { fit } from "../math/fit.js";
|
|
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
|
-
ifThen(gt(count, div(total, FLOAT2)), [
|
|
57
|
-
assign(count, sub(total, count)),
|
|
58
|
-
]),
|
|
59
|
-
]
|
|
60
|
-
: []),
|
|
61
|
-
ret(div(count, total)),
|
|
62
|
-
];
|
|
63
|
-
});
|
|
26
|
+
const functionSampler = (fn, map, opts) => {
|
|
27
|
+
const { min, max, radius, step, area } = {
|
|
28
|
+
min: 0,
|
|
29
|
+
max: 1,
|
|
30
|
+
radius: 1,
|
|
31
|
+
step: 4,
|
|
32
|
+
area: false,
|
|
33
|
+
...opts
|
|
34
|
+
};
|
|
35
|
+
return defn(F, void 0, [V2, V2], (frag, res) => {
|
|
36
|
+
let count, total;
|
|
37
|
+
let q;
|
|
38
|
+
const invStep = float(2 * radius / step);
|
|
39
|
+
return [
|
|
40
|
+
q = sym(map(frag, res)),
|
|
41
|
+
// bail out early if outside [min..max] interval
|
|
42
|
+
ifThen(or(lt($x(q), float(min)), gt($x(q), float(max))), [
|
|
43
|
+
ret(FLOAT0)
|
|
44
|
+
]),
|
|
45
|
+
count = sym(FLOAT0),
|
|
46
|
+
total = sym(FLOAT0),
|
|
47
|
+
forLoop(
|
|
48
|
+
sym(float(-radius)),
|
|
49
|
+
(x) => lte(x, float(radius)),
|
|
50
|
+
(x) => assign(x, add(x, invStep)),
|
|
51
|
+
(x) => [
|
|
52
|
+
forLoop(
|
|
53
|
+
sym(float(-radius)),
|
|
54
|
+
(y) => lte(y, float(radius)),
|
|
55
|
+
(y) => assign(y, add(y, invStep)),
|
|
56
|
+
(y) => [
|
|
57
|
+
inc(total),
|
|
58
|
+
assign(q, map(add(frag, vec2(x, y)), res)),
|
|
59
|
+
ifThen(gt(fn($x(q)), $y(q)), [inc(count)])
|
|
60
|
+
]
|
|
61
|
+
)
|
|
62
|
+
]
|
|
63
|
+
),
|
|
64
|
+
...!area ? [
|
|
65
|
+
ifThen(gt(count, div(total, FLOAT2)), [
|
|
66
|
+
assign(count, sub(total, count))
|
|
67
|
+
])
|
|
68
|
+
] : [],
|
|
69
|
+
ret(div(count, total))
|
|
70
|
+
];
|
|
71
|
+
});
|
|
64
72
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* coordinates within a screen rect (defined by `pos` & `size` in UV space) into
|
|
68
|
-
* the domain of the sampled function interval.
|
|
69
|
-
*
|
|
70
|
-
* @param amin
|
|
71
|
-
* @param amax
|
|
72
|
-
* @param bmin
|
|
73
|
-
* @param bmax
|
|
74
|
-
*/
|
|
75
|
-
export const functionDomainMapper = (amin, amax, bmin = VEC2_0, bmax = VEC2_1) => defn(V2, undefined, [V2, V2], (p, res) => [
|
|
76
|
-
ret(fit(div(p, res), amin, amax, bmin, bmax)),
|
|
73
|
+
const functionDomainMapper = (amin, amax, bmin = VEC2_0, bmax = VEC2_1) => defn(V2, void 0, [V2, V2], (p, res) => [
|
|
74
|
+
ret(fit(div(p, res), amin, amax, bmin, bmax))
|
|
77
75
|
]);
|
|
76
|
+
export {
|
|
77
|
+
functionDomainMapper,
|
|
78
|
+
functionSampler
|
|
79
|
+
};
|