@thi.ng/shader-ast-stdlib 0.18.15 → 0.18.17

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-05-08T18:24:32Z
3
+ - **Last updated**: 2024-06-29T09:28:36Z
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
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
8
8
 
9
9
  > [!NOTE]
10
- > This is one of 192 standalone projects, maintained as part
10
+ > This is one of 189 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: 13.93 KB
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 easeInQuad = defEasing((x) => [ret(pow(x, FLOAT2))]);
37
- const easeOutQuad = defEasing((x) => [
38
- ret(sub(FLOAT1, pow(sub(FLOAT1, x), FLOAT2)))
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(float(4), pow(x, float(3))),
42
+ mul(a, pow(x, b)),
58
43
  sub(
59
44
  FLOAT1,
60
- div(pow(madd(neg(FLOAT2), x, FLOAT2), float(3)), FLOAT2)
45
+ div(pow(madd(neg(FLOAT2), x, FLOAT2), b), FLOAT2)
61
46
  )
62
47
  )
63
48
  )
64
- ]);
65
- const easeInQuart = defEasing((x) => [ret(pow(x, float(4)))]);
66
- const easeOutQuart = defEasing((x) => [
67
- ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(4))))
68
- ]);
69
- const easeInOutQuart = defEasing((x) => [
70
- ret(
71
- ternary(
72
- lt(x, FLOAT05),
73
- mul(float(8), pow(x, float(4))),
74
- sub(
75
- FLOAT1,
76
- div(pow(madd(neg(FLOAT2), x, FLOAT2), float(4)), FLOAT2)
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 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((phase) => sub(FLOAT1, mul(fract(phase), FLOAT2)));
14
- const triOsc = defOsc(
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 hash12 = defn(F, "hash12", [V2], (p) => {
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 hash31 = defn(V3, "hash31", [F], (p) => {
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 = defn(V3, "hash33", [V3], (p) => {
95
- let x;
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 hash42 = defn(V4, "hash42", [V2], (p) => {
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 hash43 = defn(V4, "hash43", [V3], (p) => {
119
- let x;
120
- return [
121
- x = sym(fract(mul($(p, "xyzx"), H4))),
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.15",
3
+ "version": "0.18.17",
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://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib#readme",
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.2",
43
- "@thi.ng/shader-ast": "^0.15.15"
42
+ "@thi.ng/api": "^8.11.4",
43
+ "@thi.ng/shader-ast": "^0.15.17"
44
44
  },
45
45
  "devDependencies": {
46
- "@microsoft/api-extractor": "^7.43.2",
47
- "esbuild": "^0.21.1",
46
+ "@microsoft/api-extractor": "^7.47.0",
47
+ "esbuild": "^0.21.5",
48
48
  "typedoc": "^0.25.13",
49
- "typescript": "^5.4.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": "df34b4a9e650cc7323575356de207d78933bdcf3\n"
374
+ "gitHead": "7b950c112fba0b2e7c450765b15624c3382f1354\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 normalize = ([x, y, z]) => {
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(...normalize(v)));
32
- const defGDF = (id, vecs) => [
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] = defGDF(
59
+ const [sdfOctahedron, sdfOctahedronSmooth] = __defGDF(
60
60
  "sdfOctahedron",
61
61
  GDF.slice(3, 7)
62
62
  );
63
- const [sdfDodecahedron, sdfDodecahedronSmooth] = defGDF(
63
+ const [sdfDodecahedron, sdfDodecahedronSmooth] = __defGDF(
64
64
  "sdfDodecahedron",
65
65
  GDF.slice(13)
66
66
  );
67
- const [sdfIcosahedron, sdfIcosahedronSmooth] = defGDF(
67
+ const [sdfIcosahedron, sdfIcosahedronSmooth] = __defGDF(
68
68
  "sdfIcosahedron",
69
69
  GDF.slice(3, 13)
70
70
  );
71
- const [sdfTruncatedOctahedron, sdfTruncatedOctahedronSmooth] = defGDF(
71
+ const [sdfTruncatedOctahedron, sdfTruncatedOctahedronSmooth] = __defGDF(
72
72
  "sdfTruncatedOctahedron",
73
73
  GDF.slice(0, 7)
74
74
  );
75
- const [sdfTruncatedIcosahedron, sdfTruncatedIcosahedronSmooth] = defGDF(
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 singlePass = (col, tex, uv, off, k) => addSelf(
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
- singlePass(col, tex, uv, off, k2),
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
- singlePass(col, tex, uv, off, k1),
45
- singlePass(col, tex, uv, off2, k2),
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
- singlePass(col, tex, uv, off, k1),
70
- singlePass(col, tex, uv, off2, k2),
71
- singlePass(col, tex, uv, off3, k3),
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
  }