@thi.ng/shader-ast-stdlib 0.18.15 → 0.18.16
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 +9 -1
- package/README.md +2 -2
- package/math/easing.js +18 -53
- package/math/osc.js +6 -4
- package/noise/hash.js +12 -36
- package/package.json +8 -8
- package/sdf/polyhedra.js +8 -11
- package/tex/blur.js +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-
|
|
3
|
+
- **Last updated**: 2024-06-21T19:34:38Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
### [0.18.16](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.18.16) (2024-06-21)
|
|
13
|
+
|
|
14
|
+
#### ♻️ Refactoring
|
|
15
|
+
|
|
16
|
+
- dedupe polynomial easing fns ([1c0b095](https://github.com/thi-ng/umbrella/commit/1c0b095))
|
|
17
|
+
- redefine hash fns via HOF templates ([d143855](https://github.com/thi-ng/umbrella/commit/d143855))
|
|
18
|
+
- enforce uniform naming convention of internal functions ([56992b2](https://github.com/thi-ng/umbrella/commit/56992b2))
|
|
19
|
+
|
|
12
20
|
## [0.18.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.18.0) (2024-03-07)
|
|
13
21
|
|
|
14
22
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://mastodon.thi.ng/@toxi)
|
|
8
8
|
|
|
9
9
|
> [!NOTE]
|
|
10
|
-
> This is one of
|
|
10
|
+
> This is one of 193 standalone projects, maintained as part
|
|
11
11
|
> of the [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo
|
|
12
12
|
> and anti-framework.
|
|
13
13
|
>
|
|
@@ -115,7 +115,7 @@ For Node.js REPL:
|
|
|
115
115
|
const std = await import("@thi.ng/shader-ast-stdlib");
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
118
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 14.03 KB
|
|
119
119
|
|
|
120
120
|
## Dependencies
|
|
121
121
|
|
package/math/easing.js
CHANGED
|
@@ -33,67 +33,32 @@ const easeOutSine = defEasing((x) => [ret(sin(mul(x, HALF_PI)))]);
|
|
|
33
33
|
const easeInOutSine = defEasing((x) => [
|
|
34
34
|
ret(div(neg(sub(cos(mul(PI, x)), FLOAT1)), FLOAT2))
|
|
35
35
|
]);
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
]);
|
|
40
|
-
const easeInOutQuad = defEasing((x) => [
|
|
41
|
-
ret(
|
|
42
|
-
ternary(
|
|
43
|
-
lt(x, FLOAT05),
|
|
44
|
-
mul(FLOAT2, pow(x, FLOAT2)),
|
|
45
|
-
sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2), FLOAT2))
|
|
46
|
-
)
|
|
47
|
-
)
|
|
48
|
-
]);
|
|
49
|
-
const easeInCubic = defEasing((x) => [ret(pow(x, float(3)))]);
|
|
50
|
-
const easeOutCubic = defEasing((x) => [
|
|
51
|
-
ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(3))))
|
|
52
|
-
]);
|
|
53
|
-
const easeInOutCubic = defEasing((x) => [
|
|
36
|
+
const __easeIn = (k) => (x) => [ret(pow(x, k))];
|
|
37
|
+
const __easeOut = (k) => (x) => [ret(sub(FLOAT1, pow(sub(FLOAT1, x), k)))];
|
|
38
|
+
const __easeInOut = (a, b) => (x) => [
|
|
54
39
|
ret(
|
|
55
40
|
ternary(
|
|
56
41
|
lt(x, FLOAT05),
|
|
57
|
-
mul(
|
|
42
|
+
mul(a, pow(x, b)),
|
|
58
43
|
sub(
|
|
59
44
|
FLOAT1,
|
|
60
|
-
div(pow(madd(neg(FLOAT2), x, FLOAT2),
|
|
45
|
+
div(pow(madd(neg(FLOAT2), x, FLOAT2), b), FLOAT2)
|
|
61
46
|
)
|
|
62
47
|
)
|
|
63
48
|
)
|
|
64
|
-
]
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
]);
|
|
81
|
-
const easeInQuint = defEasing((x) => [ret(pow(x, float(5)))]);
|
|
82
|
-
const easeOutQuint = defEasing((x) => [
|
|
83
|
-
ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(5))))
|
|
84
|
-
]);
|
|
85
|
-
const easeInOutQuint = defEasing((x) => [
|
|
86
|
-
ret(
|
|
87
|
-
ternary(
|
|
88
|
-
lt(x, FLOAT05),
|
|
89
|
-
mul(float(16), pow(x, float(5))),
|
|
90
|
-
sub(
|
|
91
|
-
FLOAT1,
|
|
92
|
-
div(pow(madd(neg(FLOAT2), x, FLOAT2), float(5)), FLOAT2)
|
|
93
|
-
)
|
|
94
|
-
)
|
|
95
|
-
)
|
|
96
|
-
]);
|
|
49
|
+
];
|
|
50
|
+
const easeInQuad = defEasing(__easeIn(FLOAT2));
|
|
51
|
+
const easeOutQuad = defEasing(__easeOut(FLOAT2));
|
|
52
|
+
const easeInOutQuad = defEasing(__easeInOut(FLOAT2, FLOAT2));
|
|
53
|
+
const easeInCubic = defEasing(__easeIn(float(3)));
|
|
54
|
+
const easeOutCubic = defEasing(__easeOut(float(3)));
|
|
55
|
+
const easeInOutCubic = defEasing(__easeInOut(float(4), float(3)));
|
|
56
|
+
const easeInQuart = defEasing(__easeIn(float(4)));
|
|
57
|
+
const easeOutQuart = defEasing(__easeOut(float(4)));
|
|
58
|
+
const easeInOutQuart = defEasing(__easeInOut(float(8), float(4)));
|
|
59
|
+
const easeInQuint = defEasing(__easeIn(float(5)));
|
|
60
|
+
const easeOutQuint = defEasing(__easeOut(float(5)));
|
|
61
|
+
const easeInOutQuint = defEasing(__easeInOut(float(16), float(5)));
|
|
97
62
|
const easeInExpo = defEasing((x) => [
|
|
98
63
|
ret(
|
|
99
64
|
ternary(eq(x, FLOAT0), FLOAT0, exp2(sub(mul(float(10), x), float(10))))
|
package/math/osc.js
CHANGED
|
@@ -8,10 +8,12 @@ import {
|
|
|
8
8
|
} from "@thi.ng/shader-ast/ast/lit";
|
|
9
9
|
import { madd, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
10
10
|
import { abs, fract, sin, step } from "@thi.ng/shader-ast/builtin/math";
|
|
11
|
-
const
|
|
12
|
-
const sinOsc =
|
|
13
|
-
const sawOsc =
|
|
14
|
-
|
|
11
|
+
const __defOsc = (fn) => (phase, freq, amp = FLOAT1, dc = FLOAT0) => madd(fn(mul(float(phase), float(freq))), amp, dc);
|
|
12
|
+
const sinOsc = __defOsc((phase) => sin(mul(phase, TAU)));
|
|
13
|
+
const sawOsc = __defOsc(
|
|
14
|
+
(phase) => sub(FLOAT1, mul(fract(phase), FLOAT2))
|
|
15
|
+
);
|
|
16
|
+
const triOsc = __defOsc(
|
|
15
17
|
(phase) => sub(abs(madd(fract(phase), 4, float(-2))), FLOAT1)
|
|
16
18
|
);
|
|
17
19
|
const rectOsc = (phase, freq, amp = FLOAT1, dc = FLOAT0, duty = FLOAT05) => madd(
|
package/noise/hash.js
CHANGED
|
@@ -35,15 +35,7 @@ const hash11 = defn(F, "hash11", [F], (p) => {
|
|
|
35
35
|
ret(fract(x))
|
|
36
36
|
];
|
|
37
37
|
});
|
|
38
|
-
const
|
|
39
|
-
let x;
|
|
40
|
-
return [
|
|
41
|
-
x = sym(fract(mul($(p, "xyx"), 0.1031))),
|
|
42
|
-
addSelf(x, dot(x, add($(x, "yzx"), 19.19))),
|
|
43
|
-
ret(fract(mul(add($x(x), $y(x)), $z(x))))
|
|
44
|
-
];
|
|
45
|
-
});
|
|
46
|
-
const hash13 = defn(F, "hash13", [V3], (p) => {
|
|
38
|
+
const __hash1 = (V) => defn(F, null, [V], (p) => {
|
|
47
39
|
let x;
|
|
48
40
|
return [
|
|
49
41
|
x = sym(fract(mul($(p, "xyx"), 0.1031))),
|
|
@@ -51,6 +43,8 @@ const hash13 = defn(F, "hash13", [V3], (p) => {
|
|
|
51
43
|
ret(fract(mul(add($x(x), $y(x)), $z(x))))
|
|
52
44
|
];
|
|
53
45
|
});
|
|
46
|
+
const hash12 = __hash1(V2);
|
|
47
|
+
const hash13 = __hash1(V3);
|
|
54
48
|
const hash21 = defn(V2, "hash21", [F], (p) => {
|
|
55
49
|
let x;
|
|
56
50
|
return [
|
|
@@ -75,7 +69,7 @@ const hash23 = defn(V2, "hash23", [V3], (p) => {
|
|
|
75
69
|
ret(fract(mul(add($(x, "xx"), $(x, "yz")), $(x, "zy"))))
|
|
76
70
|
];
|
|
77
71
|
});
|
|
78
|
-
const
|
|
72
|
+
const __hash3 = (I) => defn(V3, null, [I], (p) => {
|
|
79
73
|
let x;
|
|
80
74
|
return [
|
|
81
75
|
x = sym(fract(mul(p, H))),
|
|
@@ -83,6 +77,7 @@ const hash31 = defn(V3, "hash31", [F], (p) => {
|
|
|
83
77
|
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx"))))
|
|
84
78
|
];
|
|
85
79
|
});
|
|
80
|
+
const hash31 = __hash3(F);
|
|
86
81
|
const hash32 = defn(V3, "hash32", [V2], (p) => {
|
|
87
82
|
let x;
|
|
88
83
|
return [
|
|
@@ -91,15 +86,8 @@ const hash32 = defn(V3, "hash32", [V2], (p) => {
|
|
|
91
86
|
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx"))))
|
|
92
87
|
];
|
|
93
88
|
});
|
|
94
|
-
const hash33 =
|
|
95
|
-
|
|
96
|
-
return [
|
|
97
|
-
x = sym(fract(mul(p, H))),
|
|
98
|
-
addSelf(x, dot(x, add($(x, "yzx"), 19.19))),
|
|
99
|
-
ret(fract(mul(add($(x, "xxy"), $(x, "yzz")), $(x, "zyx"))))
|
|
100
|
-
];
|
|
101
|
-
});
|
|
102
|
-
const hash41 = defn(V4, "hash41", [F], (p) => {
|
|
89
|
+
const hash33 = __hash3(V3);
|
|
90
|
+
const __hash4 = (I) => defn(V4, null, [I], (p) => {
|
|
103
91
|
let x;
|
|
104
92
|
return [
|
|
105
93
|
x = sym(fract(mul(p, H4))),
|
|
@@ -107,7 +95,7 @@ const hash41 = defn(V4, "hash41", [F], (p) => {
|
|
|
107
95
|
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
108
96
|
];
|
|
109
97
|
});
|
|
110
|
-
const
|
|
98
|
+
const __hash4a = (I) => defn(V4, null, [I], (p) => {
|
|
111
99
|
let x;
|
|
112
100
|
return [
|
|
113
101
|
x = sym(fract(mul($(p, "xyxy"), H4))),
|
|
@@ -115,22 +103,10 @@ const hash42 = defn(V4, "hash42", [V2], (p) => {
|
|
|
115
103
|
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
116
104
|
];
|
|
117
105
|
});
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
addSelf(x, dot(x, add($(x, "wzxy"), 19.19))),
|
|
123
|
-
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
124
|
-
];
|
|
125
|
-
});
|
|
126
|
-
const hash44 = defn(V4, "hash44", [V4], (p) => {
|
|
127
|
-
let x;
|
|
128
|
-
return [
|
|
129
|
-
x = sym(fract(mul(p, H4))),
|
|
130
|
-
addSelf(x, dot(x, add($(x, "wzxy"), 19.19))),
|
|
131
|
-
ret(fract(mul(add($(x, "xxyz"), $(x, "yzzw")), $(x, "zywx"))))
|
|
132
|
-
];
|
|
133
|
-
});
|
|
106
|
+
const hash41 = __hash4(F);
|
|
107
|
+
const hash42 = __hash4a(V2);
|
|
108
|
+
const hash43 = __hash4a(V3);
|
|
109
|
+
const hash44 = __hash4(V4);
|
|
134
110
|
export {
|
|
135
111
|
hash11,
|
|
136
112
|
hash12,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-stdlib",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.16",
|
|
4
4
|
"description": "Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/thi-ng/umbrella.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://
|
|
13
|
+
"homepage": "https://thi.ng/shader-ast-stdlib",
|
|
14
14
|
"funding": [
|
|
15
15
|
{
|
|
16
16
|
"type": "github",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@thi.ng/api": "^8.11.
|
|
43
|
-
"@thi.ng/shader-ast": "^0.15.
|
|
42
|
+
"@thi.ng/api": "^8.11.3",
|
|
43
|
+
"@thi.ng/shader-ast": "^0.15.16"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@microsoft/api-extractor": "^7.
|
|
47
|
-
"esbuild": "^0.21.
|
|
46
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
47
|
+
"esbuild": "^0.21.5",
|
|
48
48
|
"typedoc": "^0.25.13",
|
|
49
|
-
"typescript": "^5.
|
|
49
|
+
"typescript": "^5.5.2"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|
|
52
52
|
"ast",
|
|
@@ -371,5 +371,5 @@
|
|
|
371
371
|
],
|
|
372
372
|
"year": 2019
|
|
373
373
|
},
|
|
374
|
-
"gitHead": "
|
|
374
|
+
"gitHead": "154c95cf9d6bab32174498ec3b5b5d87e42be7f9\n"
|
|
375
375
|
}
|
package/sdf/polyhedra.js
CHANGED
|
@@ -3,7 +3,7 @@ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
|
3
3
|
import { FLOAT0, PHI, vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
4
|
import { add, reciprocal, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { abs, dot, max, pow } from "@thi.ng/shader-ast/builtin/math";
|
|
6
|
-
const
|
|
6
|
+
const __normalize = ([x, y, z]) => {
|
|
7
7
|
const m = 1 / Math.hypot(x, y, z);
|
|
8
8
|
return [x * m, y * m, z * m];
|
|
9
9
|
};
|
|
@@ -28,8 +28,8 @@ const GDF = [
|
|
|
28
28
|
[-1, 0, phi],
|
|
29
29
|
[phi, 1, 0],
|
|
30
30
|
[-phi, 1, 0]
|
|
31
|
-
].map((v) => vec3(...
|
|
32
|
-
const
|
|
31
|
+
].map((v) => vec3(...__normalize(v)));
|
|
32
|
+
const __defGDF = (id, vecs) => [
|
|
33
33
|
defn(F, id, [V3, F], (p, r) => [
|
|
34
34
|
ret(
|
|
35
35
|
sub(
|
|
@@ -56,26 +56,23 @@ const defGDF = (id, vecs) => [
|
|
|
56
56
|
)
|
|
57
57
|
])
|
|
58
58
|
];
|
|
59
|
-
const [sdfOctahedron, sdfOctahedronSmooth] =
|
|
59
|
+
const [sdfOctahedron, sdfOctahedronSmooth] = __defGDF(
|
|
60
60
|
"sdfOctahedron",
|
|
61
61
|
GDF.slice(3, 7)
|
|
62
62
|
);
|
|
63
|
-
const [sdfDodecahedron, sdfDodecahedronSmooth] =
|
|
63
|
+
const [sdfDodecahedron, sdfDodecahedronSmooth] = __defGDF(
|
|
64
64
|
"sdfDodecahedron",
|
|
65
65
|
GDF.slice(13)
|
|
66
66
|
);
|
|
67
|
-
const [sdfIcosahedron, sdfIcosahedronSmooth] =
|
|
67
|
+
const [sdfIcosahedron, sdfIcosahedronSmooth] = __defGDF(
|
|
68
68
|
"sdfIcosahedron",
|
|
69
69
|
GDF.slice(3, 13)
|
|
70
70
|
);
|
|
71
|
-
const [sdfTruncatedOctahedron, sdfTruncatedOctahedronSmooth] =
|
|
71
|
+
const [sdfTruncatedOctahedron, sdfTruncatedOctahedronSmooth] = __defGDF(
|
|
72
72
|
"sdfTruncatedOctahedron",
|
|
73
73
|
GDF.slice(0, 7)
|
|
74
74
|
);
|
|
75
|
-
const [sdfTruncatedIcosahedron, sdfTruncatedIcosahedronSmooth] =
|
|
76
|
-
"sdfTruncatedIcosahedron",
|
|
77
|
-
GDF.slice(3)
|
|
78
|
-
);
|
|
75
|
+
const [sdfTruncatedIcosahedron, sdfTruncatedIcosahedronSmooth] = __defGDF("sdfTruncatedIcosahedron", GDF.slice(3));
|
|
79
76
|
export {
|
|
80
77
|
sdfDodecahedron,
|
|
81
78
|
sdfDodecahedronSmooth,
|
package/tex/blur.js
CHANGED
|
@@ -4,7 +4,7 @@ import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
|
4
4
|
import { add, addSelf, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
5
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
6
6
|
import { texture } from "@thi.ng/shader-ast/builtin/texture";
|
|
7
|
-
const
|
|
7
|
+
const __singlePass = (col, tex, uv, off, k) => addSelf(
|
|
8
8
|
col,
|
|
9
9
|
mul(add(texture(tex, add(uv, off)), texture(tex, sub(uv, off))), k)
|
|
10
10
|
);
|
|
@@ -20,7 +20,7 @@ const blur5 = defn(
|
|
|
20
20
|
return [
|
|
21
21
|
off = sym(div(mul(vec2(1 + 1 / 3), dir), res)),
|
|
22
22
|
col = sym(mul(texture(tex, uv), k1)),
|
|
23
|
-
|
|
23
|
+
__singlePass(col, tex, uv, off, k2),
|
|
24
24
|
ret(col)
|
|
25
25
|
];
|
|
26
26
|
}
|
|
@@ -41,8 +41,8 @@ const blur9 = defn(
|
|
|
41
41
|
off = sym(mul(delta, 1.3846153846)),
|
|
42
42
|
off2 = sym(mul(delta, 3.2307692308)),
|
|
43
43
|
col = sym(mul(texture(tex, uv), 0.227027027)),
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
__singlePass(col, tex, uv, off, k1),
|
|
45
|
+
__singlePass(col, tex, uv, off2, k2),
|
|
46
46
|
ret(col)
|
|
47
47
|
];
|
|
48
48
|
}
|
|
@@ -66,9 +66,9 @@ const blur13 = defn(
|
|
|
66
66
|
off2 = sym(mul(delta, 3.2941176470588234)),
|
|
67
67
|
off3 = sym(mul(delta, 5.176470588235294)),
|
|
68
68
|
col = sym(mul(texture(tex, uv), 0.1964825501511404)),
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
__singlePass(col, tex, uv, off, k1),
|
|
70
|
+
__singlePass(col, tex, uv, off2, k2),
|
|
71
|
+
__singlePass(col, tex, uv, off3, k3),
|
|
72
72
|
ret(col)
|
|
73
73
|
];
|
|
74
74
|
}
|