@thi.ng/shader-ast-stdlib 0.13.13 → 0.13.15
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 +14 -1
- package/README.md +1 -1
- package/color/aces-film.js +2 -1
- package/color/levels.js +5 -4
- package/color/porter-duff.js +2 -1
- package/color/rgbe.js +3 -2
- package/fog/exp.js +4 -1
- package/fog/exp2.js +2 -1
- package/fog/linear.js +4 -1
- package/light/trilight.js +2 -1
- package/math/additive.js +4 -2
- package/math/cartesian.js +2 -1
- package/math/clamp.js +4 -3
- package/math/cross2.js +2 -1
- package/math/fit.js +4 -1
- package/math/magsq.js +2 -1
- package/math/mix-cubic.js +6 -5
- package/math/mix-quadratic.js +6 -5
- package/math/orthogonal.js +2 -1
- package/math/polar.js +3 -2
- package/matrix/convert.js +4 -3
- package/matrix/lookat.js +2 -1
- package/matrix/rotation.js +10 -9
- package/noise/curl3.js +2 -1
- package/noise/hash.js +16 -15
- package/noise/permute.js +6 -5
- package/noise/simplex2.js +3 -2
- package/noise/simplex3.d.ts +1 -0
- package/noise/simplex3.js +9 -3
- package/noise/voronoi2.js +3 -2
- package/noise/worley2.d.ts +12 -7
- package/noise/worley2.js +18 -9
- package/package.json +8 -8
- package/raymarch/ao.d.ts +2 -1
- package/raymarch/ao.js +5 -2
- package/raymarch/direction.js +2 -1
- package/raymarch/normal.js +3 -1
- package/raymarch/scene.js +6 -4
- package/screen/uv.js +5 -4
- package/sdf/arc.js +2 -1
- package/sdf/bezier.js +3 -2
- package/sdf/box-rounded.js +2 -1
- package/sdf/box.js +3 -2
- package/sdf/cross.js +4 -3
- package/sdf/cylinder.js +3 -2
- package/sdf/hex.js +2 -1
- package/sdf/line.js +4 -3
- package/sdf/mirror.js +2 -1
- package/sdf/plane.js +7 -2
- package/sdf/polygon.js +4 -3
- package/sdf/polyhedra.js +3 -2
- package/sdf/repeat-polar.js +2 -1
- package/sdf/repeat.js +3 -2
- package/sdf/smooth-isec.js +2 -1
- package/sdf/smooth-sub.js +2 -1
- package/sdf/smooth-union.js +2 -1
- package/sdf/sphere.js +7 -2
- package/sdf/torus.js +2 -1
- package/sdf/tri.js +2 -1
- package/sdf/union.js +2 -1
- package/tex/blur.js +4 -3
- 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-
|
|
3
|
+
- **Last updated**: 2023-05-11T12:16:33Z
|
|
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,19 @@ 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
|
+
|
|
18
|
+
### [0.13.14](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.13.14) (2023-05-05)
|
|
19
|
+
|
|
20
|
+
#### 🩹 Bug fixes
|
|
21
|
+
|
|
22
|
+
- fix [#399](https://github.com/thi-ng/umbrella/issues/399) update HOF function naming ([f4b62d7](https://github.com/thi-ng/umbrella/commit/f4b62d7))
|
|
23
|
+
- ensure generated HOFs are using unique names to allow multiple instances
|
|
24
|
+
|
|
12
25
|
## [0.13.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.13.0) (2023-01-10)
|
|
13
26
|
|
|
14
27
|
#### 🚀 Features
|
package/README.md
CHANGED
package/color/aces-film.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 { 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(
|
|
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 {
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
/**
|
package/color/porter-duff.js
CHANGED
|
@@ -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(
|
|
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 {
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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,7 +1,9 @@
|
|
|
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";
|
|
4
|
-
import {
|
|
5
|
+
import { gensym } from "@thi.ng/shader-ast/ast/idgen";
|
|
6
|
+
import { FLOAT0, FLOAT05, float } from "@thi.ng/shader-ast/ast/lit";
|
|
5
7
|
import { add, inc, lt, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
6
8
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
9
|
/**
|
|
@@ -23,7 +25,7 @@ import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
|
23
25
|
* @param oct -
|
|
24
26
|
* @param name -
|
|
25
27
|
*/
|
|
26
|
-
export const additive = (type, fn, oct = 4, name = "
|
|
28
|
+
export const additive = (type, fn, oct = 4, name = gensym("additive_")) => defn(F, name, [[type], [type], F], (pos, shift, decay) => {
|
|
27
29
|
let n;
|
|
28
30
|
let amp;
|
|
29
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(
|
|
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 ===
|
|
4
|
+
const __clamp = (min, max) => (x) => x.type === F
|
|
4
5
|
? clamp(x, float(min), float(max))
|
|
5
|
-
: x.type ===
|
|
6
|
+
: x.type === V2
|
|
6
7
|
? clamp(x, vec2(min), vec2(max))
|
|
7
|
-
: x.type ===
|
|
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(
|
|
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(
|
|
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(
|
|
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,
|
|
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,
|
|
16
|
-
export const mixCubic2 = $(2,
|
|
17
|
-
export const mixCubic3 = $(3,
|
|
18
|
-
export const mixCubic4 = $(4,
|
|
16
|
+
export const mixCubic = $(1, F);
|
|
17
|
+
export const mixCubic2 = $(2, V2);
|
|
18
|
+
export const mixCubic3 = $(3, V3);
|
|
19
|
+
export const mixCubic4 = $(4, V4);
|
package/math/mix-quadratic.js
CHANGED
|
@@ -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,
|
|
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,
|
|
12
|
-
export const mixQuadratic2 = $(2,
|
|
13
|
-
export const mixQuadratic3 = $(3,
|
|
14
|
-
export const mixQuadratic4 = $(4,
|
|
12
|
+
export const mixQuadratic = $(1, F);
|
|
13
|
+
export const mixQuadratic2 = $(2, V2);
|
|
14
|
+
export const mixQuadratic3 = $(3, V3);
|
|
15
|
+
export const mixQuadratic4 = $(4, V4);
|
package/math/orthogonal.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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(
|
|
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,
|
|
4
|
-
export const m22ToM33 = defn(
|
|
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(
|
|
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(
|
|
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;
|
package/matrix/rotation.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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 {
|
|
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(
|
|
9
|
-
export const permute2 = __permute(
|
|
10
|
-
export const permute3 = __permute(
|
|
11
|
-
export const permute4 = __permute(
|
|
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");
|