@thi.ng/shader-ast-stdlib 0.13.14 → 0.13.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +1 -1
  3. package/color/aces-film.js +2 -1
  4. package/color/levels.js +5 -4
  5. package/color/porter-duff.js +2 -1
  6. package/color/rgbe.js +3 -2
  7. package/fog/exp.js +4 -1
  8. package/fog/exp2.js +2 -1
  9. package/fog/linear.js +4 -1
  10. package/light/trilight.js +2 -1
  11. package/math/additive.js +2 -1
  12. package/math/cartesian.js +2 -1
  13. package/math/clamp.js +4 -3
  14. package/math/cross2.js +2 -1
  15. package/math/fit.js +4 -1
  16. package/math/magsq.js +2 -1
  17. package/math/mix-cubic.js +6 -5
  18. package/math/mix-quadratic.js +6 -5
  19. package/math/orthogonal.js +2 -1
  20. package/math/polar.js +3 -2
  21. package/matrix/convert.js +4 -3
  22. package/matrix/lookat.js +2 -1
  23. package/matrix/rotation.js +10 -9
  24. package/noise/curl3.js +2 -1
  25. package/noise/hash.js +16 -15
  26. package/noise/permute.js +6 -5
  27. package/noise/simplex2.js +3 -2
  28. package/noise/simplex3.d.ts +1 -0
  29. package/noise/simplex3.js +9 -3
  30. package/noise/voronoi2.js +3 -2
  31. package/noise/worley2.js +6 -3
  32. package/package.json +8 -8
  33. package/raymarch/ao.js +2 -1
  34. package/raymarch/direction.js +2 -1
  35. package/raymarch/normal.js +2 -1
  36. package/raymarch/scene.js +3 -2
  37. package/screen/uv.js +5 -4
  38. package/sdf/arc.js +2 -1
  39. package/sdf/bezier.js +3 -2
  40. package/sdf/box-rounded.js +2 -1
  41. package/sdf/box.js +3 -2
  42. package/sdf/cross.js +4 -3
  43. package/sdf/cylinder.js +3 -2
  44. package/sdf/hex.js +2 -1
  45. package/sdf/line.js +4 -3
  46. package/sdf/mirror.js +2 -1
  47. package/sdf/plane.js +7 -2
  48. package/sdf/polygon.js +2 -1
  49. package/sdf/polyhedra.js +3 -2
  50. package/sdf/repeat-polar.js +2 -1
  51. package/sdf/repeat.js +3 -2
  52. package/sdf/smooth-isec.js +2 -1
  53. package/sdf/smooth-sub.js +2 -1
  54. package/sdf/smooth-union.js +2 -1
  55. package/sdf/sphere.js +7 -2
  56. package/sdf/torus.js +2 -1
  57. package/sdf/tri.js +2 -1
  58. package/sdf/union.js +2 -1
  59. package/tex/blur.js +4 -3
  60. package/tex/index-uv.js +3 -2
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-05-05T21:29:28Z
3
+ - **Last updated**: 2023-05-24T14:26:03Z
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,12 @@ 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.13.15](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.13.15) (2023-05-11)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - re-use interned type constants ([f6fcbc5](https://github.com/thi-ng/umbrella/commit/f6fcbc5))
17
+
12
18
  ### [0.13.14](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.13.14) (2023-05-05)
13
19
 
14
20
  #### 🩹 Bug fixes
package/README.md CHANGED
@@ -101,7 +101,7 @@ For Node.js REPL:
101
101
  const shaderAstStdlib = await import("@thi.ng/shader-ast-stdlib");
102
102
  ```
103
103
 
104
- Package sizes (brotli'd, pre-treeshake): ESM: 10.96 KB
104
+ Package sizes (brotli'd, pre-treeshake): ESM: 11.64 KB
105
105
 
106
106
  ## Dependencies
107
107
 
@@ -1,3 +1,4 @@
1
+ import { V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { add, div, mul } from "@thi.ng/shader-ast/ast/ops";
3
4
  import { clamp01 } from "../math/clamp.js";
@@ -9,6 +10,6 @@ import { clamp01 } from "../math/clamp.js";
9
10
  *
10
11
  * @param col -
11
12
  */
12
- export const ACESFilm = defn("vec3", "ACESFilm", ["vec3"], (col) => [
13
+ export const ACESFilm = defn(V3, "ACESFilm", [V3], (col) => [
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)))),
14
15
  ]);
package/color/levels.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { F, M3, V2, V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
2
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
4
  import { indexMat } from "@thi.ng/shader-ast/ast/indexed";
4
- import { float, FLOAT0, FLOAT05, FLOAT1, vec3, VEC3_0, VEC3_1, } from "@thi.ng/shader-ast/ast/lit";
5
+ import { FLOAT0, FLOAT05, FLOAT1, VEC3_0, VEC3_1, float, vec3, } from "@thi.ng/shader-ast/ast/lit";
5
6
  import { lt, madd, mul, reciprocal, sub } from "@thi.ng/shader-ast/ast/ops";
6
7
  import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
7
8
  import { max, min, pow } from "@thi.ng/shader-ast/builtin/math";
@@ -13,7 +14,7 @@ import { fit01, fitClamped } from "../math/fit.js";
13
14
  * @remarks
14
15
  * Reference: https://stackoverflow.com/a/48859502/294515
15
16
  */
16
- export const midLevelGamma = defn("float", "midLevelGamma", ["float"], (mid) => [
17
+ export const midLevelGamma = defn(F, "midLevelGamma", [F], (mid) => [
17
18
  ret(reciprocal(ternary(lt(mid, FLOAT05), min(float(9.99), madd(float(9), sub(1, mul(mid, 2)), 1)), max(float(0.01), sub(1, sub(mul(mid, 2), 1)))))),
18
19
  ]);
19
20
  /**
@@ -29,7 +30,7 @@ export const midLevelGammaRGB = (mid) => vec3(midLevelGamma($x(mid)), midLevelGa
29
30
  * `vec2(min,max)`) with `gamma` correction. Results will be clamped to [0..1]
30
31
  * range.
31
32
  */
32
- export const levelAdjustGamma = defn("float", "levelAdjustGamma", ["float", "float", "vec2", "vec2"], (x, gamma, input, output) => [
33
+ export const levelAdjustGamma = defn(F, "levelAdjustGamma", [F, F, V2, V2], (x, gamma, input, output) => [
33
34
  ret(fit01(pow(fitClamped(x, $x(input), $y(input), FLOAT0, FLOAT1), gamma), $x(output), $y(output))),
34
35
  ]);
35
36
  /**
@@ -43,7 +44,7 @@ export const levelAdjustGamma = defn("float", "levelAdjustGamma", ["float", "flo
43
44
  * - 1st column = RGB min values
44
45
  * - 2nd column = RGB max values
45
46
  */
46
- export const levelAdjustGammaRGB = defn("vec3", "levelAdjustGammaRGB", ["vec3", "vec3", "mat3", "mat3"], (x, gamma, input, output) => [
47
+ export const levelAdjustGammaRGB = defn(V3, "levelAdjustGammaRGB", [V3, V3, M3, M3], (x, gamma, input, output) => [
47
48
  ret(fit01(pow(fitClamped(x, indexMat(input, 0), indexMat(input, 1), VEC3_0, VEC3_1), gamma), indexMat(output, 0), indexMat(output, 1))),
48
49
  ]);
49
50
  /**
@@ -1,3 +1,4 @@
1
+ import { V4 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { FLOAT0, FLOAT1, vec4 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
@@ -27,7 +28,7 @@ const __coeff = (col, f) => f === FLOAT0 ? vec4() : f === FLOAT1 ? col : mul(col
27
28
  * @param fa - src coeff fn
28
29
  * @param fb - dest coeff fn
29
30
  */
30
- export const porterDuff = (name, fa, fb) => defn("vec4", name, ["vec4", "vec4"], (a, b) => {
31
+ export const porterDuff = (name, fa, fb) => defn(V4, name, [V4, V4], (a, b) => {
31
32
  const sa = fa($w(a), $w(b));
32
33
  const sb = fb($w(a), $w(b));
33
34
  const src = __coeff(a, sa);
package/color/rgbe.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
2
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
- import { float, INT0, vec3, VEC3_0 } from "@thi.ng/shader-ast/ast/lit";
4
+ import { INT0, VEC3_0, float, vec3 } from "@thi.ng/shader-ast/ast/lit";
4
5
  import { gt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
5
6
  import { $w, $xyz } from "@thi.ng/shader-ast/ast/swizzle";
6
7
  import { exp2 } from "@thi.ng/shader-ast/builtin/math";
@@ -15,7 +16,7 @@ import { exp2 } from "@thi.ng/shader-ast/builtin/math";
15
16
  * https://github.com/box/hdrCompressor/blob/master/src/rgbe/rgbe.c
16
17
  *
17
18
  */
18
- export const decodeRGBE = defn("vec3", "decodeRGBE", ["ivec4"], (col) => {
19
+ export const decodeRGBE = defn(V3, "decodeRGBE", ["ivec4"], (col) => {
19
20
  return [
20
21
  ret(ternary(gt($w(col), INT0), mul(vec3($xyz(col)), exp2(float(sub($w(col), 136)))), VEC3_0)),
21
22
  ];
package/fog/exp.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
@@ -10,4 +11,6 @@ import { clamp01 } from "../math/clamp.js";
10
11
  * @param dist - float
11
12
  * @param density - float
12
13
  */
13
- export const fogExp = defn("float", "fogExp", ["float", "float"], (dist, density) => [ret(sub(FLOAT1, clamp01(exp(mul(neg(density), dist)))))]);
14
+ export const fogExp = defn(F, "fogExp", [F, F], (dist, density) => [
15
+ ret(sub(FLOAT1, clamp01(exp(mul(neg(density), dist))))),
16
+ ]);
package/fog/exp2.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
1
2
  import { assign } from "@thi.ng/shader-ast/ast/assign";
2
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
4
  import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
@@ -13,7 +14,7 @@ import { clamp01 } from "../math/clamp.js";
13
14
  * @param dist - float
14
15
  * @param density - float
15
16
  */
16
- export const fogExp2 = defn("float", "fogExp2", ["float", "float"], (dist, density) => [
17
+ export const fogExp2 = defn(F, "fogExp2", [F, F], (dist, density) => [
17
18
  assign(density, mul(density, dist)),
18
19
  ret(sub(FLOAT1, clamp01(exp2(mul(mul(density, density), -Math.LOG2E))))),
19
20
  ]);
package/fog/linear.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { clamp01 } from "../math/clamp.js";
3
4
  import { fitNorm1 } from "../math/fit.js";
@@ -10,4 +11,6 @@ import { fitNorm1 } from "../math/fit.js";
10
11
  * @param end - float
11
12
  *
12
13
  */
13
- export const fogLinear = defn("float", "fogLinear", ["float", "float", "float"], (dist, start, end) => [ret(clamp01(fitNorm1(dist, start, end)))]);
14
+ export const fogLinear = defn(F, "fogLinear", [F, F, F], (dist, start, end) => [
15
+ ret(clamp01(fitNorm1(dist, start, end))),
16
+ ]);
package/light/trilight.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { FLOAT0, FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { add, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
@@ -14,7 +15,7 @@ import { abs, dot, max } from "@thi.ng/shader-ast/builtin/math";
14
15
  * @param col2 - vec3
15
16
  * @param col3 - vec3
16
17
  */
17
- export const trilight = defn("vec3", "trilight", ["vec3", "vec3", "vec3", "vec3", "vec3"], (n, l, c1, c2, c3) => {
18
+ export const trilight = defn(V3, "trilight", [V3, V3, V3, V3, V3], (n, l, c1, c2, c3) => {
18
19
  let d;
19
20
  return [
20
21
  (d = sym(dot(n, l))),
package/math/additive.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
1
2
  import { assign } from "@thi.ng/shader-ast/ast/assign";
2
3
  import { forLoop } from "@thi.ng/shader-ast/ast/controlflow";
3
4
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
@@ -24,7 +25,7 @@ import { sym } from "@thi.ng/shader-ast/ast/sym";
24
25
  * @param oct -
25
26
  * @param name -
26
27
  */
27
- export const additive = (type, fn, oct = 4, name = gensym("additive_")) => defn("float", name, [[type], [type], "float"], (pos, shift, decay) => {
28
+ export const additive = (type, fn, oct = 4, name = gensym("additive_")) => defn(F, name, [[type], [type], F], (pos, shift, decay) => {
28
29
  let n;
29
30
  let amp;
30
31
  return [
package/math/cartesian.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { vec3 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { mul } from "@thi.ng/shader-ast/ast/ops";
@@ -18,7 +19,7 @@ export const cartesian2 = (v) => mul(cossin($y(v)), $x(v));
18
19
  *
19
20
  * @param v -
20
21
  */
21
- export const cartesian3 = defn("vec3", "cartesian3", ["vec3"], (v) => {
22
+ export const cartesian3 = defn(V3, "cartesian3", [V3], (v) => {
22
23
  let r;
23
24
  let t;
24
25
  let p;
package/math/clamp.js CHANGED
@@ -1,10 +1,11 @@
1
+ import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
2
3
  import { clamp } from "@thi.ng/shader-ast/builtin/math";
3
- const __clamp = (min, max) => (x) => x.type === "float"
4
+ const __clamp = (min, max) => (x) => x.type === F
4
5
  ? clamp(x, float(min), float(max))
5
- : x.type === "vec2"
6
+ : x.type === V2
6
7
  ? clamp(x, vec2(min), vec2(max))
7
- : x.type === "vec3"
8
+ : x.type === V3
8
9
  ? clamp(x, vec3(min), vec3(max))
9
10
  : clamp(x, vec4(min), vec4(max));
10
11
  /**
package/math/cross2.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F, V2 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
3
4
  import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
@@ -8,7 +9,7 @@ import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
8
9
  * @param a -
9
10
  * @param b -
10
11
  */
11
- export const cross2 = defn("float", "cross2", ["vec2", "vec2"], (a, b) => [
12
+ export const cross2 = defn(F, "cross2", [V2, V2], (a, b) => [
12
13
  ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b)))),
13
14
  ]);
14
15
  /**
package/math/fit.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
1
2
  import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
2
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
4
  import { FLOAT0, FLOAT05, FLOAT1, FLOAT2 } from "@thi.ng/shader-ast/ast/lit";
@@ -12,7 +13,9 @@ import { clamp01 } from "./clamp.js";
12
13
  * @param a -
13
14
  * @param b -
14
15
  */
15
- export const fitNorm1 = defn("float", "fitNorm1", ["float", "float", "float"], (x, a, b) => [ret(ternary(neq(a, b), div(sub(x, a), sub(b, a)), FLOAT0))]);
16
+ export const fitNorm1 = defn(F, "fitNorm1", [F, F, F], (x, a, b) => [
17
+ ret(ternary(neq(a, b), div(sub(x, a), sub(b, a)), FLOAT0)),
18
+ ]);
16
19
  /**
17
20
  * Fits value `x` from closed interval [a,b] to closed interval [c,d]. No
18
21
  * clamping performed.
package/math/magsq.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { dot } from "@thi.ng/shader-ast/builtin/math";
3
- const $ = (n) => defn("float", `magSq${n}`, [`vec${n}`], (v) => [ret(dot(v, v))]);
4
+ const $ = (n) => defn(F, `magSq${n}`, [`vec${n}`], (v) => [ret(dot(v, v))]);
4
5
  export const magSq2 = $(2);
5
6
  export const magSq3 = $(3);
6
7
  export const magSq4 = $(4);
package/math/mix-cubic.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { add, mul, sub } from "@thi.ng/shader-ast/ast/ops";
3
4
  import { sym } from "@thi.ng/shader-ast/ast/sym";
4
- const $ = (n, type) => defn(type, `mixCubic${n > 1 ? n : ""}`, [type, type, type, type, "float"], (a, b, c, d, t) => {
5
+ const $ = (n, type) => defn(type, `mixCubic${n > 1 ? n : ""}`, [type, type, type, type, F], (a, b, c, d, t) => {
5
6
  let s;
6
7
  let s2;
7
8
  let t2;
@@ -12,7 +13,7 @@ const $ = (n, type) => defn(type, `mixCubic${n > 1 ? n : ""}`, [type, type, type
12
13
  ret(add(add(add(mul(a, mul(s, s2)), mul(b, mul(3, mul(s2, t)))), mul(c, mul(3, mul(t2, s)))), mul(d, mul(t, t2)))),
13
14
  ];
14
15
  });
15
- export const mixCubic = $(1, "float");
16
- export const mixCubic2 = $(2, "vec2");
17
- export const mixCubic3 = $(3, "vec3");
18
- export const mixCubic4 = $(4, "vec4");
16
+ export const mixCubic = $(1, F);
17
+ export const mixCubic2 = $(2, V2);
18
+ export const mixCubic3 = $(3, V3);
19
+ export const mixCubic4 = $(4, V4);
@@ -1,14 +1,15 @@
1
+ import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { add, mul, sub } from "@thi.ng/shader-ast/ast/ops";
3
4
  import { sym } from "@thi.ng/shader-ast/ast/sym";
4
- const $ = (n, type) => defn(type, `mixQuadratic${n > 1 ? n : ""}`, [type, type, type, "float"], (a, b, c, t) => {
5
+ const $ = (n, type) => defn(type, `mixQuadratic${n > 1 ? n : ""}`, [type, type, type, F], (a, b, c, t) => {
5
6
  let s;
6
7
  return [
7
8
  (s = sym(sub(1, t))),
8
9
  ret(add(add(mul(a, mul(s, s)), mul(b, mul(2, mul(s, t)))), mul(c, mul(t, t)))),
9
10
  ];
10
11
  });
11
- export const mixQuadratic = $(1, "float");
12
- export const mixQuadratic2 = $(2, "vec2");
13
- export const mixQuadratic3 = $(3, "vec3");
14
- export const mixQuadratic4 = $(4, "vec4");
12
+ export const mixQuadratic = $(1, F);
13
+ export const mixQuadratic2 = $(2, V2);
14
+ export const mixQuadratic3 = $(3, V3);
15
+ export const mixQuadratic4 = $(4, V4);
@@ -1,3 +1,4 @@
1
+ import { V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
2
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
4
  import { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit";
@@ -23,6 +24,6 @@ export const perpendicularCW = (v) => vec2($y(v), neg($x(v)));
23
24
  *
24
25
  * http://lolengine.net/blog/2013/09/21/picking-orthogonal-vector-combing-coconuts
25
26
  */
26
- export const orthogonal3 = defn("vec3", "orthogonal3", ["vec3"], (v) => [
27
+ export const orthogonal3 = defn(V3, "orthogonal3", [V3], (v) => [
27
28
  ret(ternary(gt(abs($x(v)), abs($z(v))), vec3(neg($y(v)), $x(v), 0), vec3(0, neg($z(v)), $y(v)))),
28
29
  ]);
package/math/polar.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { V2, V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { div } from "@thi.ng/shader-ast/ast/ops";
@@ -10,7 +11,7 @@ import { asin, atan, length } from "@thi.ng/shader-ast/builtin/math";
10
11
  *
11
12
  * @param v -
12
13
  */
13
- export const polar2 = defn("vec2", "polar2", ["vec2"], (v) => [
14
+ export const polar2 = defn(V2, "polar2", [V2], (v) => [
14
15
  ret(vec2(length(v), atan(div($y(v), $x(v))))),
15
16
  ]);
16
17
  /**
@@ -20,7 +21,7 @@ export const polar2 = defn("vec2", "polar2", ["vec2"], (v) => [
20
21
  *
21
22
  * @param v -
22
23
  */
23
- export const polar3 = defn("vec3", "polar3", ["vec3"], (v) => {
24
+ export const polar3 = defn(V3, "polar3", [V3], (v) => {
24
25
  let r;
25
26
  return [
26
27
  (r = sym(length(v))),
package/matrix/convert.js CHANGED
@@ -1,12 +1,13 @@
1
+ import { M2, M3, M4 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { indexMat } from "@thi.ng/shader-ast/ast/indexed";
3
- import { mat3, mat4, vec3, VEC3_0, vec4 } from "@thi.ng/shader-ast/ast/lit";
4
- export const m22ToM33 = defn("mat3", "m22ToM33", ["mat2"], (m) => {
4
+ import { VEC3_0, mat3, mat4, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
5
+ export const m22ToM33 = defn(M3, "m22ToM33", [M2], (m) => {
5
6
  return [
6
7
  ret(mat3(vec3(indexMat(m, 0), 0), vec3(indexMat(m, 1), 0), VEC3_0)),
7
8
  ];
8
9
  });
9
- export const m33ToM44 = defn("mat4", "m33ToM44", ["mat3"], (m) => {
10
+ export const m33ToM44 = defn(M4, "m33ToM44", [M3], (m) => {
10
11
  return [
11
12
  ret(mat4(vec4(indexMat(m, 0), 0), vec4(indexMat(m, 1), 0), vec4(indexMat(m, 2), 0), vec4())),
12
13
  ];
package/matrix/lookat.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { M4, V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { mat4, vec4 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { neg, sub } from "@thi.ng/shader-ast/ast/ops";
@@ -11,7 +12,7 @@ import { cross, dot, normalize } from "@thi.ng/shader-ast/builtin/math";
11
12
  * @param target - vec3
12
13
  * @param up - vec3
13
14
  */
14
- export const lookat = defn("mat4", "lookat", ["vec3", "vec3", "vec3"], (eye, target, up) => {
15
+ export const lookat = defn(M4, "lookat", [V3, V3, V3], (eye, target, up) => {
15
16
  let x;
16
17
  let y;
17
18
  let z;
@@ -1,3 +1,4 @@
1
+ import { F, M2, M3, M4, V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { mat2, mat3, mat4, vec3 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { add, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
@@ -7,53 +8,53 @@ import { cos, sin } from "@thi.ng/shader-ast/builtin/math";
7
8
  import { perpendicularCCW } from "../math/orthogonal.js";
8
9
  import { cossin } from "../math/sincos.js";
9
10
  import { m33ToM44 } from "./convert.js";
10
- export const rotation2 = defn("mat2", "rotation2", ["float"], (theta) => {
11
+ export const rotation2 = defn(M2, "rotation2", [F], (theta) => {
11
12
  let cs;
12
13
  return [(cs = sym(cossin(theta))), ret(mat2(cs, perpendicularCCW(cs)))];
13
14
  });
14
- export const rotationX3 = defn("mat3", "rotationX3", ["float"], (theta) => {
15
+ export const rotationX3 = defn(M3, "rotationX3", [F], (theta) => {
15
16
  let cs;
16
17
  return [
17
18
  (cs = sym(cossin(theta))),
18
19
  ret(mat3(1, 0, 0, 0, $x(cs), $y(cs), 0, neg($y(cs)), $x(cs))),
19
20
  ];
20
21
  });
21
- export const rotationY3 = defn("mat3", "rotationY3", ["float"], (theta) => {
22
+ export const rotationY3 = defn(M3, "rotationY3", [F], (theta) => {
22
23
  let cs;
23
24
  return [
24
25
  (cs = sym(cossin(theta))),
25
26
  ret(mat3($x(cs), 0, neg($y(cs)), 0, 1, 0, $y(cs), 0, $x(cs))),
26
27
  ];
27
28
  });
28
- export const rotationZ3 = defn("mat3", "rotationZ3", ["float"], (theta) => {
29
+ export const rotationZ3 = defn(M3, "rotationZ3", [F], (theta) => {
29
30
  let cs;
30
31
  return [
31
32
  (cs = sym(cossin(theta))),
32
33
  ret(mat3($x(cs), $y(cs), 0, neg($y(cs)), $x(cs), 0, 0, 0, 1)),
33
34
  ];
34
35
  });
35
- export const rotationX4 = defn("mat4", "rotationX4", ["float"], (theta) => {
36
+ export const rotationX4 = defn(M4, "rotationX4", [F], (theta) => {
36
37
  let cs;
37
38
  return [
38
39
  (cs = sym(cossin(theta))),
39
40
  ret(mat4(1, 0, 0, 0, 0, $x(cs), $y(cs), 0, 0, neg($y(cs)), $x(cs), 0, 0, 0, 0, 1)),
40
41
  ];
41
42
  });
42
- export const rotationY4 = defn("mat4", "rotationY4", ["float"], (theta) => {
43
+ export const rotationY4 = defn(M4, "rotationY4", [F], (theta) => {
43
44
  let cs;
44
45
  return [
45
46
  (cs = sym(cossin(theta))),
46
47
  ret(mat4($x(cs), 0, neg($y(cs)), 0, 0, 1, 0, 0, $y(cs), 0, $x(cs), 0, 0, 0, 0, 1)),
47
48
  ];
48
49
  });
49
- export const rotationZ4 = defn("mat4", "rotationZ4", ["float"], (theta) => {
50
+ export const rotationZ4 = defn(M4, "rotationZ4", [F], (theta) => {
50
51
  let cs;
51
52
  return [
52
53
  (cs = sym(cossin(theta))),
53
54
  ret(mat4($x(cs), $y(cs), 0, 0, neg($y(cs)), $x(cs), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)),
54
55
  ];
55
56
  });
56
- export const rotationAroundAxis3 = defn("mat3", "rotationAroundAxis3", ["vec3", "float"], (axis, theta) => {
57
+ export const rotationAroundAxis3 = defn(M3, "rotationAroundAxis3", [V3, F], (axis, theta) => {
57
58
  let s;
58
59
  let c;
59
60
  let t;
@@ -65,4 +66,4 @@ export const rotationAroundAxis3 = defn("mat3", "rotationAroundAxis3", ["vec3",
65
66
  ret(mat3($$($x(axis), 1, $z(axis), neg($y(axis)), c, s, s), $$($y(axis), neg($z(axis)), 1, $x(axis), s, c, s), $$($z(axis), $y(axis), neg($x(axis)), 1, s, s, c))),
66
67
  ];
67
68
  });
68
- export const rotationAroundAxis4 = defn("mat4", "rotationAroundAxis4", ["vec3", "float"], (axis, theta) => [ret(m33ToM44(rotationAroundAxis3(axis, theta)))]);
69
+ export const rotationAroundAxis4 = defn(M4, "rotationAroundAxis4", [V3, F], (axis, theta) => [ret(m33ToM44(rotationAroundAxis3(axis, theta)))]);
package/noise/curl3.js CHANGED
@@ -1,10 +1,11 @@
1
+ import { F, V3 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
3
  import { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
4
5
  import { $, $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
5
6
  import { sym } from "@thi.ng/shader-ast/ast/sym";
6
7
  import { snoiseVec3 } from "./simplex3.js";
7
- export const curlNoise3 = defn("vec3", "curlNoise3", ["vec3", "float"], (p, e) => {
8
+ export const curlNoise3 = defn(V3, "curlNoise3", [V3, F], (p, e) => {
8
9
  let D;
9
10
  let px0;
10
11
  let px1;
package/noise/hash.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
1
2
  import { assign } from "@thi.ng/shader-ast/ast/assign";
2
3
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
3
4
  import { mat2, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
@@ -10,7 +11,7 @@ import { dot, fract, sin } from "@thi.ng/shader-ast/builtin/math";
10
11
  *
11
12
  * @param p -
12
13
  */
13
- export const hash2 = defn("vec2", "hash2", ["vec2"], (p) => [
14
+ export const hash2 = defn(V2, "hash2", [V2], (p) => [
14
15
  ret(fract(mul(sin(mul(p, mat2(127.1, 311.7, 269.5, 183.3))), 43758.5453))),
15
16
  ]);
16
17
  /**
@@ -18,7 +19,7 @@ export const hash2 = defn("vec2", "hash2", ["vec2"], (p) => [
18
19
  *
19
20
  * @param p -
20
21
  */
21
- export const hash3 = defn("vec3", "hash3", ["vec2"], (p) => [
22
+ export const hash3 = defn(V3, "hash3", [V2], (p) => [
22
23
  ret(fract(mul(sin(vec3(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)), dot(p, vec2(419.2, 371.9)))), 43758.5453))),
23
24
  ]);
24
25
  const H = vec3(0.1031, 0.103, 0.0973);
@@ -30,7 +31,7 @@ const H4 = vec4(0.1031, 0.103, 0.0973, 0.1099);
30
31
  *
31
32
  * @param p -
32
33
  */
33
- export const hash11 = defn("float", "hash11", ["float"], (p) => {
34
+ export const hash11 = defn(F, "hash11", [F], (p) => {
34
35
  let x;
35
36
  return [
36
37
  (x = sym(fract(mul(p, 0.1031)))),
@@ -46,7 +47,7 @@ export const hash11 = defn("float", "hash11", ["float"], (p) => {
46
47
  *
47
48
  * @param p -
48
49
  */
49
- export const hash12 = defn("float", "hash12", ["vec2"], (p) => {
50
+ export const hash12 = defn(F, "hash12", [V2], (p) => {
50
51
  let x;
51
52
  return [
52
53
  (x = sym(fract(mul($(p, "xyx"), 0.1031)))),
@@ -61,7 +62,7 @@ export const hash12 = defn("float", "hash12", ["vec2"], (p) => {
61
62
  *
62
63
  * @param p -
63
64
  */
64
- export const hash13 = defn("float", "hash13", ["vec3"], (p) => {
65
+ export const hash13 = defn(F, "hash13", [V3], (p) => {
65
66
  let x;
66
67
  return [
67
68
  (x = sym(fract(mul($(p, "xyx"), 0.1031)))),
@@ -76,7 +77,7 @@ export const hash13 = defn("float", "hash13", ["vec3"], (p) => {
76
77
  *
77
78
  * @param p -
78
79
  */
79
- export const hash21 = defn("vec2", "hash21", ["float"], (p) => {
80
+ export const hash21 = defn(V2, "hash21", [F], (p) => {
80
81
  let x;
81
82
  return [
82
83
  (x = sym(fract(mul(vec3(p), H)))),
@@ -91,7 +92,7 @@ export const hash21 = defn("vec2", "hash21", ["float"], (p) => {
91
92
  *
92
93
  * @param p -
93
94
  */
94
- export const hash22 = defn("vec2", "hash22", ["vec2"], (p) => {
95
+ export const hash22 = defn(V2, "hash22", [V2], (p) => {
95
96
  let x;
96
97
  return [
97
98
  (x = sym(fract(mul($(p, "xyx"), H)))),
@@ -106,7 +107,7 @@ export const hash22 = defn("vec2", "hash22", ["vec2"], (p) => {
106
107
  *
107
108
  * @param p -
108
109
  */
109
- export const hash23 = defn("vec2", "hash23", ["vec3"], (p) => {
110
+ export const hash23 = defn(V2, "hash23", [V3], (p) => {
110
111
  let x;
111
112
  return [
112
113
  (x = sym(fract(mul(p, H)))),
@@ -121,7 +122,7 @@ export const hash23 = defn("vec2", "hash23", ["vec3"], (p) => {
121
122
  *
122
123
  * @param p -
123
124
  */
124
- export const hash31 = defn("vec3", "hash31", ["float"], (p) => {
125
+ export const hash31 = defn(V3, "hash31", [F], (p) => {
125
126
  let x;
126
127
  return [
127
128
  (x = sym(fract(mul(p, H)))),
@@ -136,7 +137,7 @@ export const hash31 = defn("vec3", "hash31", ["float"], (p) => {
136
137
  *
137
138
  * @param p -
138
139
  */
139
- export const hash32 = defn("vec3", "hash32", ["vec2"], (p) => {
140
+ export const hash32 = defn(V3, "hash32", [V2], (p) => {
140
141
  let x;
141
142
  return [
142
143
  (x = sym(fract(mul($(p, "xyx"), H)))),
@@ -151,7 +152,7 @@ export const hash32 = defn("vec3", "hash32", ["vec2"], (p) => {
151
152
  *
152
153
  * @param p -
153
154
  */
154
- export const hash33 = defn("vec3", "hash33", ["vec3"], (p) => {
155
+ export const hash33 = defn(V3, "hash33", [V3], (p) => {
155
156
  let x;
156
157
  return [
157
158
  (x = sym(fract(mul(p, H)))),
@@ -166,7 +167,7 @@ export const hash33 = defn("vec3", "hash33", ["vec3"], (p) => {
166
167
  *
167
168
  * @param p -
168
169
  */
169
- export const hash41 = defn("vec4", "hash41", ["float"], (p) => {
170
+ export const hash41 = defn(V4, "hash41", [F], (p) => {
170
171
  let x;
171
172
  return [
172
173
  (x = sym(fract(mul(p, H4)))),
@@ -181,7 +182,7 @@ export const hash41 = defn("vec4", "hash41", ["float"], (p) => {
181
182
  *
182
183
  * @param p -
183
184
  */
184
- export const hash42 = defn("vec4", "hash42", ["vec2"], (p) => {
185
+ export const hash42 = defn(V4, "hash42", [V2], (p) => {
185
186
  let x;
186
187
  return [
187
188
  (x = sym(fract(mul($(p, "xyxy"), H4)))),
@@ -196,7 +197,7 @@ export const hash42 = defn("vec4", "hash42", ["vec2"], (p) => {
196
197
  *
197
198
  * @param p -
198
199
  */
199
- export const hash43 = defn("vec4", "hash43", ["vec3"], (p) => {
200
+ export const hash43 = defn(V4, "hash43", [V3], (p) => {
200
201
  let x;
201
202
  return [
202
203
  (x = sym(fract(mul($(p, "xyzx"), H4)))),
@@ -211,7 +212,7 @@ export const hash43 = defn("vec4", "hash43", ["vec3"], (p) => {
211
212
  *
212
213
  * @param p -
213
214
  */
214
- export const hash44 = defn("vec4", "hash44", ["vec4"], (p) => {
215
+ export const hash44 = defn(V4, "hash44", [V4], (p) => {
215
216
  let x;
216
217
  return [
217
218
  (x = sym(fract(mul(p, H4)))),
package/noise/permute.js CHANGED
@@ -1,11 +1,12 @@
1
+ import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
1
2
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
2
- import { float, FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
3
+ import { FLOAT1, float } from "@thi.ng/shader-ast/ast/lit";
3
4
  import { add, mul } from "@thi.ng/shader-ast/ast/ops";
4
5
  import { mod } from "@thi.ng/shader-ast/builtin/math";
5
6
  const __permute = (type, suffix = "") => defn(type, `permute${suffix}`, [type], (v) => [
6
7
  ret(mod(mul(v, add(mul(v, float(34)), FLOAT1)), float(289))),
7
8
  ]);
8
- export const permute = __permute("float");
9
- export const permute2 = __permute("vec2", "2");
10
- export const permute3 = __permute("vec3", "3");
11
- export const permute4 = __permute("vec4", "4");
9
+ export const permute = __permute(F);
10
+ export const permute2 = __permute(V2, "2");
11
+ export const permute3 = __permute(V3, "3");
12
+ export const permute4 = __permute(V4, "4");
package/noise/simplex2.js CHANGED
@@ -1,7 +1,8 @@
1
+ import { F, V2 } from "@thi.ng/shader-ast/api/types";
1
2
  import { assign } from "@thi.ng/shader-ast/ast/assign";
2
3
  import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
3
4
  import { defn, ret } from "@thi.ng/shader-ast/ast/function";
4
- import { float, FLOAT05, FLOAT1, vec2, vec3, VEC3_0, vec4, } from "@thi.ng/shader-ast/ast/lit";
5
+ import { FLOAT05, FLOAT1, VEC3_0, float, vec2, vec3, vec4, } from "@thi.ng/shader-ast/ast/lit";
5
6
  import { add, gt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
6
7
  import { $, $x, $xy, $y } from "@thi.ng/shader-ast/ast/swizzle";
7
8
  import { sym } from "@thi.ng/shader-ast/ast/sym";
@@ -14,7 +15,7 @@ import { permute3 } from "./permute.js";
14
15
  *
15
16
  * https://github.com/ashima/webgl-noise
16
17
  */
17
- export const snoise2 = defn("float", "snoise2", ["vec2"], (v) => {
18
+ export const snoise2 = defn(F, "snoise2", [V2], (v) => {
18
19
  let C;
19
20
  let i;
20
21
  let i1;