@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/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/color/aces-film.js
CHANGED
|
@@ -2,14 +2,16 @@ import { V3 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { add, div, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
4
4
|
import { clamp01 } from "../math/clamp.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ret(clamp01(div(mul(col, add(mul(col, 2.51), 0.03)), add(mul(col, add(mul(col, 2.43), 0.59)), 0.14)))),
|
|
5
|
+
const ACESFilm = defn(V3, "ACESFilm", [V3], (col) => [
|
|
6
|
+
ret(
|
|
7
|
+
clamp01(
|
|
8
|
+
div(
|
|
9
|
+
mul(col, add(mul(col, 2.51), 0.03)),
|
|
10
|
+
add(mul(col, add(mul(col, 2.43), 0.59)), 0.14)
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
)
|
|
15
14
|
]);
|
|
15
|
+
export {
|
|
16
|
+
ACESFilm
|
|
17
|
+
};
|
package/color/levels.js
CHANGED
|
@@ -2,74 +2,88 @@ import { F, M3, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
3
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
4
|
import { indexMat } from "@thi.ng/shader-ast/ast/indexed";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
FLOAT0,
|
|
7
|
+
FLOAT05,
|
|
8
|
+
FLOAT1,
|
|
9
|
+
VEC3_0,
|
|
10
|
+
VEC3_1,
|
|
11
|
+
float,
|
|
12
|
+
vec3
|
|
13
|
+
} from "@thi.ng/shader-ast/ast/lit";
|
|
6
14
|
import { lt, madd, mul, reciprocal, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
7
15
|
import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
8
16
|
import { max, min, pow } from "@thi.ng/shader-ast/builtin/math";
|
|
9
17
|
import { fit01, fitClamped } from "../math/fit.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const midLevelGamma = defn(F, "midLevelGamma", [F], (mid) => [
|
|
19
|
+
ret(
|
|
20
|
+
reciprocal(
|
|
21
|
+
ternary(
|
|
22
|
+
lt(mid, FLOAT05),
|
|
23
|
+
min(float(9.99), madd(float(9), sub(1, mul(mid, 2)), 1)),
|
|
24
|
+
max(float(0.01), sub(1, sub(mul(mid, 2), 1)))
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
)
|
|
19
28
|
]);
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
const midLevelGammaRGB = (mid) => vec3(
|
|
30
|
+
midLevelGamma($x(mid)),
|
|
31
|
+
midLevelGamma($y(mid)),
|
|
32
|
+
midLevelGamma($z(mid))
|
|
33
|
+
);
|
|
34
|
+
const levelAdjustGamma = defn(
|
|
35
|
+
F,
|
|
36
|
+
"levelAdjustGamma",
|
|
37
|
+
[F, F, V2, V2],
|
|
38
|
+
(x, gamma, input, output) => [
|
|
39
|
+
ret(
|
|
40
|
+
fit01(
|
|
41
|
+
pow(
|
|
42
|
+
fitClamped(
|
|
43
|
+
x,
|
|
44
|
+
$x(input),
|
|
45
|
+
$y(input),
|
|
46
|
+
FLOAT0,
|
|
47
|
+
FLOAT1
|
|
48
|
+
),
|
|
49
|
+
gamma
|
|
50
|
+
),
|
|
51
|
+
$x(output),
|
|
52
|
+
$y(output)
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
]
|
|
56
|
+
);
|
|
57
|
+
const levelAdjustGammaRGB = defn(
|
|
58
|
+
V3,
|
|
59
|
+
"levelAdjustGammaRGB",
|
|
60
|
+
[V3, V3, M3, M3],
|
|
61
|
+
(x, gamma, input, output) => [
|
|
62
|
+
ret(
|
|
63
|
+
fit01(
|
|
64
|
+
pow(
|
|
65
|
+
fitClamped(
|
|
66
|
+
x,
|
|
67
|
+
indexMat(input, 0),
|
|
68
|
+
indexMat(input, 1),
|
|
69
|
+
VEC3_0,
|
|
70
|
+
VEC3_1
|
|
71
|
+
),
|
|
72
|
+
gamma
|
|
73
|
+
),
|
|
74
|
+
indexMat(output, 0),
|
|
75
|
+
indexMat(output, 1)
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
]
|
|
79
|
+
);
|
|
80
|
+
const levelAdjustMid = (x, mid, input, output) => levelAdjustGamma(x, midLevelGamma(mid), input, output);
|
|
81
|
+
const levelAdjustMidRGB = (x, mid, input, output) => levelAdjustGammaRGB(x, midLevelGammaRGB(mid), input, output);
|
|
82
|
+
export {
|
|
83
|
+
levelAdjustGamma,
|
|
84
|
+
levelAdjustGammaRGB,
|
|
85
|
+
levelAdjustMid,
|
|
86
|
+
levelAdjustMidRGB,
|
|
87
|
+
midLevelGamma,
|
|
88
|
+
midLevelGammaRGB
|
|
89
|
+
};
|
package/color/linear-srgb.js
CHANGED
|
@@ -3,24 +3,14 @@ import { pow } from "@thi.ng/shader-ast/builtin/math";
|
|
|
3
3
|
const GAMMA = float(2.2);
|
|
4
4
|
const INV_GAMMA = float(1 / 2.2);
|
|
5
5
|
const $ = (t, x) => ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}[t.type]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
export const toLinear = (x) => pow(x, $(x, GAMMA));
|
|
19
|
-
/**
|
|
20
|
-
* Inline function. Converts linear color term (1D-4D) to sRGB via
|
|
21
|
-
* `pow(rgb, 1.0 / GAMMA)`, where gamma is hardcoded to 2.2. For vec4
|
|
22
|
-
* args, the `w` component (alpha) remains unchanged.
|
|
23
|
-
*
|
|
24
|
-
* @param x -
|
|
25
|
-
*/
|
|
26
|
-
export const toSRGB = (x) => pow(x, $(x, INV_GAMMA));
|
|
6
|
+
float: x,
|
|
7
|
+
vec2: vec2(x),
|
|
8
|
+
vec3: vec3(x),
|
|
9
|
+
vec4: vec4(x, x, x, 1)
|
|
10
|
+
})[t.type];
|
|
11
|
+
const toLinear = (x) => pow(x, $(x, GAMMA));
|
|
12
|
+
const toSRGB = (x) => pow(x, $(x, INV_GAMMA));
|
|
13
|
+
export {
|
|
14
|
+
toLinear,
|
|
15
|
+
toSRGB
|
|
16
|
+
};
|
package/color/luminance.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
2
2
|
import { dot } from "@thi.ng/shader-ast/builtin/math";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export const luminanceRGB = (rgb) => dot(rgb, vec3(0.299, 0.587, 0.114));
|
|
3
|
+
const luminanceRGB = (rgb) => dot(rgb, vec3(0.299, 0.587, 0.114));
|
|
4
|
+
export {
|
|
5
|
+
luminanceRGB
|
|
6
|
+
};
|
package/color/porter-duff.js
CHANGED
|
@@ -4,60 +4,56 @@ import { FLOAT0, FLOAT1, vec4 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { $w, $xyz } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
6
|
import { clamp01 } from "../math/clamp.js";
|
|
7
|
-
/** @internal */
|
|
8
7
|
const __coeff = (col, f) => f === FLOAT0 ? vec4() : f === FLOAT1 ? col : mul(col, f);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* {@link ZERO} or {@link ONE}.
|
|
22
|
-
*
|
|
23
|
-
* *IMPORTANT*: Both colors MUST be use pre-multiplied alpha for correct
|
|
24
|
-
* results. If needed, use {@link premultiplyAlpha} and
|
|
25
|
-
* {@link postmultiplyAlpha}.
|
|
26
|
-
*
|
|
27
|
-
* @param name - function name
|
|
28
|
-
* @param fa - src coeff fn
|
|
29
|
-
* @param fb - dest coeff fn
|
|
30
|
-
*/
|
|
31
|
-
export const porterDuff = (name, fa, fb) => defn(V4, name, [V4, V4], (a, b) => {
|
|
32
|
-
const sa = fa($w(a), $w(b));
|
|
33
|
-
const sb = fb($w(a), $w(b));
|
|
34
|
-
const src = __coeff(a, sa);
|
|
35
|
-
const dest = __coeff(b, sb);
|
|
36
|
-
const srcZero = sa === FLOAT0;
|
|
37
|
-
const destZero = sb === FLOAT0;
|
|
38
|
-
return [
|
|
39
|
-
ret(srcZero && destZero
|
|
40
|
-
? vec4()
|
|
41
|
-
: clamp01(srcZero ? dest : destZero ? src : add(src, dest))),
|
|
42
|
-
];
|
|
8
|
+
const porterDuff = (name, fa, fb) => defn(V4, name, [V4, V4], (a, b) => {
|
|
9
|
+
const sa = fa($w(a), $w(b));
|
|
10
|
+
const sb = fb($w(a), $w(b));
|
|
11
|
+
const src = __coeff(a, sa);
|
|
12
|
+
const dest = __coeff(b, sb);
|
|
13
|
+
const srcZero = sa === FLOAT0;
|
|
14
|
+
const destZero = sb === FLOAT0;
|
|
15
|
+
return [
|
|
16
|
+
ret(
|
|
17
|
+
srcZero && destZero ? vec4() : clamp01(srcZero ? dest : destZero ? src : add(src, dest))
|
|
18
|
+
)
|
|
19
|
+
];
|
|
43
20
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export
|
|
63
|
-
|
|
21
|
+
const premultiplyAlpha = (col) => vec4(mul($xyz(col), $w(col)), $w(col));
|
|
22
|
+
const postmultiplyAlpha = (col) => vec4(div($xyz(col), $w(col)), $w(col));
|
|
23
|
+
const ZERO = () => FLOAT0;
|
|
24
|
+
const ONE = () => FLOAT1;
|
|
25
|
+
const A = (a) => a;
|
|
26
|
+
const B = (_, b) => b;
|
|
27
|
+
const ONE_MINUS_A = (a) => sub(FLOAT1, a);
|
|
28
|
+
const ONE_MINUS_B = (_, b) => sub(FLOAT1, b);
|
|
29
|
+
const blendSrcOver = porterDuff("blendSrcOver", ONE, ONE_MINUS_A);
|
|
30
|
+
const blendDestOver = porterDuff("blendDestOver", ONE_MINUS_B, ONE);
|
|
31
|
+
const blendSrcIn = porterDuff("blendSrcIn", B, ZERO);
|
|
32
|
+
const blendDestIn = porterDuff("blendDestIn", ZERO, A);
|
|
33
|
+
const blendSrcOut = porterDuff("blendSrcOut", ONE_MINUS_B, ZERO);
|
|
34
|
+
const blendDestOut = porterDuff("blendDestOut", ZERO, ONE_MINUS_A);
|
|
35
|
+
const blendSrcAtop = porterDuff("blendSrcAtop", B, ONE_MINUS_A);
|
|
36
|
+
const blendDestAtop = porterDuff("blendDestAtop", ONE_MINUS_B, A);
|
|
37
|
+
const blendXor = porterDuff("blendXor", ONE_MINUS_B, ONE_MINUS_A);
|
|
38
|
+
const blendPlus = porterDuff("blendPlus", ONE, ONE);
|
|
39
|
+
export {
|
|
40
|
+
A,
|
|
41
|
+
B,
|
|
42
|
+
ONE,
|
|
43
|
+
ONE_MINUS_A,
|
|
44
|
+
ONE_MINUS_B,
|
|
45
|
+
ZERO,
|
|
46
|
+
blendDestAtop,
|
|
47
|
+
blendDestIn,
|
|
48
|
+
blendDestOut,
|
|
49
|
+
blendDestOver,
|
|
50
|
+
blendPlus,
|
|
51
|
+
blendSrcAtop,
|
|
52
|
+
blendSrcIn,
|
|
53
|
+
blendSrcOut,
|
|
54
|
+
blendSrcOver,
|
|
55
|
+
blendXor,
|
|
56
|
+
porterDuff,
|
|
57
|
+
postmultiplyAlpha,
|
|
58
|
+
premultiplyAlpha
|
|
59
|
+
};
|
package/color/rgbe.js
CHANGED
|
@@ -5,19 +5,17 @@ import { INT0, VEC3_0, float, vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
5
5
|
import { gt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
6
|
import { $w, $xyz } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
7
|
import { exp2 } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
export const decodeRGBE = defn(V3, "decodeRGBE", ["ivec4"], (col) => {
|
|
20
|
-
return [
|
|
21
|
-
ret(ternary(gt($w(col), INT0), mul(vec3($xyz(col)), exp2(float(sub($w(col), 136)))), VEC3_0)),
|
|
22
|
-
];
|
|
8
|
+
const decodeRGBE = defn(V3, "decodeRGBE", ["ivec4"], (col) => {
|
|
9
|
+
return [
|
|
10
|
+
ret(
|
|
11
|
+
ternary(
|
|
12
|
+
gt($w(col), INT0),
|
|
13
|
+
mul(vec3($xyz(col)), exp2(float(sub($w(col), 136)))),
|
|
14
|
+
VEC3_0
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
];
|
|
23
18
|
});
|
|
19
|
+
export {
|
|
20
|
+
decodeRGBE
|
|
21
|
+
};
|
package/fog/exp.js
CHANGED
|
@@ -4,13 +4,9 @@ import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { exp } from "@thi.ng/shader-ast/builtin/math";
|
|
6
6
|
import { clamp01 } from "../math/clamp.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* saturated fog distance and density.
|
|
10
|
-
*
|
|
11
|
-
* @param dist - float
|
|
12
|
-
* @param density - float
|
|
13
|
-
*/
|
|
14
|
-
export const fogExp = defn(F, "fogExp", [F, F], (dist, density) => [
|
|
15
|
-
ret(sub(FLOAT1, clamp01(exp(mul(neg(density), dist))))),
|
|
7
|
+
const fogExp = defn(F, "fogExp", [F, F], (dist, density) => [
|
|
8
|
+
ret(sub(FLOAT1, clamp01(exp(mul(neg(density), dist)))))
|
|
16
9
|
]);
|
|
10
|
+
export {
|
|
11
|
+
fogExp
|
|
12
|
+
};
|
package/fog/exp2.js
CHANGED
|
@@ -5,16 +5,10 @@ import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
5
5
|
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
6
|
import { exp2 } from "@thi.ng/shader-ast/builtin/math";
|
|
7
7
|
import { clamp01 } from "../math/clamp.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* [`exp2()`](https://docs.thi.ng/umbrella/shader-ast/functions/exp2.html)
|
|
12
|
-
* internally.
|
|
13
|
-
*
|
|
14
|
-
* @param dist - float
|
|
15
|
-
* @param density - float
|
|
16
|
-
*/
|
|
17
|
-
export const fogExp2 = defn(F, "fogExp2", [F, F], (dist, density) => [
|
|
18
|
-
assign(density, mul(density, dist)),
|
|
19
|
-
ret(sub(FLOAT1, clamp01(exp2(mul(mul(density, density), -Math.LOG2E))))),
|
|
8
|
+
const fogExp2 = defn(F, "fogExp2", [F, F], (dist, density) => [
|
|
9
|
+
assign(density, mul(density, dist)),
|
|
10
|
+
ret(sub(FLOAT1, clamp01(exp2(mul(mul(density, density), -Math.LOG2E)))))
|
|
20
11
|
]);
|
|
12
|
+
export {
|
|
13
|
+
fogExp2
|
|
14
|
+
};
|
package/fog/linear.js
CHANGED
|
@@ -2,15 +2,9 @@ import { F } from "@thi.ng/shader-ast/api/types";
|
|
|
2
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
3
|
import { clamp01 } from "../math/clamp.js";
|
|
4
4
|
import { fitNorm1 } from "../math/fit.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* distances.
|
|
8
|
-
*
|
|
9
|
-
* @param dist - float
|
|
10
|
-
* @param start - float
|
|
11
|
-
* @param end - float
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
export const fogLinear = defn(F, "fogLinear", [F, F, F], (dist, start, end) => [
|
|
15
|
-
ret(clamp01(fitNorm1(dist, start, end))),
|
|
5
|
+
const fogLinear = defn(F, "fogLinear", [F, F, F], (dist, start, end) => [
|
|
6
|
+
ret(clamp01(fitNorm1(dist, start, end)))
|
|
16
7
|
]);
|
|
8
|
+
export {
|
|
9
|
+
fogLinear
|
|
10
|
+
};
|
package/isec/point.js
CHANGED
|
@@ -5,19 +5,25 @@ import { add } from "@thi.ng/shader-ast/ast/ops";
|
|
|
5
5
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
6
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
7
|
import { distance, min, step } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
const isPointInCircle = defn(
|
|
9
|
+
"bool",
|
|
10
|
+
null,
|
|
11
|
+
[V2, V2, F],
|
|
12
|
+
(p, pos, radius) => [ret(bool(step(distance(p, pos), radius)))]
|
|
13
|
+
);
|
|
14
|
+
const isPointInRect = defn(
|
|
15
|
+
"bool",
|
|
16
|
+
null,
|
|
17
|
+
[V2, V2, V2],
|
|
18
|
+
(p, pos, size) => {
|
|
18
19
|
let q;
|
|
19
20
|
return [
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
q = sym(min(step(pos, p), step(p, add(pos, size)))),
|
|
22
|
+
ret(bool(min($x(q), $y(q))))
|
|
22
23
|
];
|
|
23
|
-
}
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
export {
|
|
27
|
+
isPointInCircle,
|
|
28
|
+
isPointInRect
|
|
29
|
+
};
|
package/light/lambert.js
CHANGED
|
@@ -2,32 +2,11 @@ import { FLOAT0 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
2
2
|
import { madd, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
3
3
|
import { dot, max } from "@thi.ng/shader-ast/builtin/math";
|
|
4
4
|
import { fit1101 } from "../math/fit.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Inline function. Computes Half-Lambertian term. Both vectors must be
|
|
15
|
-
* pre-normalized.
|
|
16
|
-
*
|
|
17
|
-
* https://developer.valvesoftware.com/wiki/Half_Lambert
|
|
18
|
-
*
|
|
19
|
-
* @param n -
|
|
20
|
-
* @param ldir -
|
|
21
|
-
*/
|
|
22
|
-
export const halfLambert = (n, ldir) => fit1101(dot(n, ldir));
|
|
23
|
-
/**
|
|
24
|
-
* Inline function. Computes:
|
|
25
|
-
*
|
|
26
|
-
* col = lambert * lightCol * diffuseCol + ambientCol
|
|
27
|
-
*
|
|
28
|
-
* @param lambertian - float
|
|
29
|
-
* @param diffuseCol - vec3
|
|
30
|
-
* @param lightCol - vec3
|
|
31
|
-
* @param ambientCol - vec3
|
|
32
|
-
*/
|
|
33
|
-
export const diffuseLighting = (lambertian, diffuse, light, ambient) => madd(mul(light, lambertian), diffuse, ambient);
|
|
5
|
+
const lambert = (n, ldir) => max(dot(n, ldir), FLOAT0);
|
|
6
|
+
const halfLambert = (n, ldir) => fit1101(dot(n, ldir));
|
|
7
|
+
const diffuseLighting = (lambertian, diffuse, light, ambient) => madd(mul(light, lambertian), diffuse, ambient);
|
|
8
|
+
export {
|
|
9
|
+
diffuseLighting,
|
|
10
|
+
halfLambert,
|
|
11
|
+
lambert
|
|
12
|
+
};
|
package/light/trilight.js
CHANGED
|
@@ -4,21 +4,23 @@ import { FLOAT0, FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { add, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
6
6
|
import { abs, dot, max } from "@thi.ng/shader-ast/builtin/math";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* @param surfNormal - vec3
|
|
13
|
-
* @param lightDir - vec3
|
|
14
|
-
* @param col1 - vec3
|
|
15
|
-
* @param col2 - vec3
|
|
16
|
-
* @param col3 - vec3
|
|
17
|
-
*/
|
|
18
|
-
export const trilight = defn(V3, "trilight", [V3, V3, V3, V3, V3], (n, l, c1, c2, c3) => {
|
|
7
|
+
const trilight = defn(
|
|
8
|
+
V3,
|
|
9
|
+
"trilight",
|
|
10
|
+
[V3, V3, V3, V3, V3],
|
|
11
|
+
(n, l, c1, c2, c3) => {
|
|
19
12
|
let d;
|
|
20
13
|
return [
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
d = sym(dot(n, l)),
|
|
15
|
+
ret(
|
|
16
|
+
add(
|
|
17
|
+
add(mul(c1, max(d, FLOAT0)), mul(c2, sub(FLOAT1, abs(d)))),
|
|
18
|
+
mul(c3, max(dot(neg(n), l), FLOAT0))
|
|
19
|
+
)
|
|
20
|
+
)
|
|
23
21
|
];
|
|
24
|
-
}
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
export {
|
|
25
|
+
trilight
|
|
26
|
+
};
|