@thi.ng/shader-ast-stdlib 0.13.14 → 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 +7 -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 +2 -1
- 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.js +6 -3
- package/package.json +8 -8
- package/raymarch/ao.js +2 -1
- package/raymarch/direction.js +2 -1
- package/raymarch/normal.js +2 -1
- package/raymarch/scene.js +3 -2
- 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 +2 -1
- 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/noise/simplex3.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const snoise3: import("@thi.ng/shader-ast").TaggedFn1<"vec3", "float">;
|
|
2
|
+
export declare const snoiseVec32: import("@thi.ng/shader-ast").TaggedFn1<"vec3", "vec2">;
|
|
2
3
|
export declare const snoiseVec3: import("@thi.ng/shader-ast").TaggedFn1<"vec3", "vec3">;
|
|
3
4
|
//# sourceMappingURL=simplex3.d.ts.map
|
package/noise/simplex3.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { F, V2, V3 } 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
|
-
import {
|
|
4
|
+
import { FLOAT0, FLOAT05, FLOAT1, FLOAT2, float, vec2, vec3, vec4, } from "@thi.ng/shader-ast/ast/lit";
|
|
4
5
|
import { add, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
6
|
import { $, $w, $x, $xy, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
7
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
8
|
import { abs, dot, floor, max, min, mod, step, } from "@thi.ng/shader-ast/builtin/math";
|
|
8
9
|
import { permute4 } from "./permute.js";
|
|
9
|
-
export const snoise3 = defn(
|
|
10
|
+
export const snoise3 = defn(F, "snoise3", [V3], (v) => {
|
|
10
11
|
let g;
|
|
11
12
|
let j;
|
|
12
13
|
let l;
|
|
@@ -72,7 +73,12 @@ export const snoise3 = defn("float", "snoise3", ["vec3"], (v) => {
|
|
|
72
73
|
ret(mul(42, dot(mul(m, m), vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3))))),
|
|
73
74
|
];
|
|
74
75
|
});
|
|
75
|
-
export const
|
|
76
|
+
export const snoiseVec32 = defn(V2, "snoiseVec3", [V3], (p) => {
|
|
77
|
+
return [
|
|
78
|
+
ret(vec2(snoise3(p), snoise3(vec3(sub($y(p), 19.1), add($z(p), 33.4), add($x(p), 47.2))))),
|
|
79
|
+
];
|
|
80
|
+
});
|
|
81
|
+
export const snoiseVec3 = defn(V3, "snoiseVec3", [V3], (p) => {
|
|
76
82
|
return [
|
|
77
83
|
ret(vec3(snoise3(p), snoise3(vec3(sub($y(p), 19.1), add($z(p), 33.4), add($x(p), 47.2))), snoise3(vec3(add($z(p), 74.2), sub($x(p), 124.5), add($y(p), 99.4))))),
|
|
78
84
|
];
|
package/noise/voronoi2.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 { forLoop } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
4
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
-
import {
|
|
5
|
+
import { FLOAT0, SQRT2, float, int, vec2, vec3, } from "@thi.ng/shader-ast/ast/lit";
|
|
5
6
|
import { add, div, inc, lte, madd, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
7
|
import { $xy, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
8
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
@@ -25,7 +26,7 @@ import { hash32 } from "./hash.js";
|
|
|
25
26
|
* @param u -
|
|
26
27
|
* @param v -
|
|
27
28
|
*/
|
|
28
|
-
export const voronoise2 = defn(
|
|
29
|
+
export const voronoise2 = defn(F, "voronoise2", [V2, F, F], (x, u, v) => {
|
|
29
30
|
let p;
|
|
30
31
|
let f;
|
|
31
32
|
let coeff;
|
package/noise/worley2.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } 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";
|
|
@@ -8,8 +9,10 @@ import { $, $x, $xy, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
|
|
|
8
9
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
9
10
|
import { abs, floor, fract, max, min, mod, sqrt, } from "@thi.ng/shader-ast/builtin/math";
|
|
10
11
|
import { permute3 } from "./permute.js";
|
|
11
|
-
export const worleyDist = defn(
|
|
12
|
-
|
|
12
|
+
export const worleyDist = defn(V3, "worleyDist", [V3, V3], (a, b) => [
|
|
13
|
+
ret(add(mul(a, a), mul(b, b))),
|
|
14
|
+
]);
|
|
15
|
+
export const worleyDistManhattan = defn(V3, "worleyDistManhatten", [V3, V3], (a, b) => [ret(add(abs(a), abs(b)))]);
|
|
13
16
|
/**
|
|
14
17
|
* Higher order function. Computes 2D Worley noise using provided distance
|
|
15
18
|
* function. The returned function takes 2 args: position and jitter amount, the
|
|
@@ -28,7 +31,7 @@ export const worleyDistManhattan = defn("vec3", "worleyDistManhatten", ["vec3",
|
|
|
28
31
|
* @param distFn -
|
|
29
32
|
* @param name -
|
|
30
33
|
*/
|
|
31
|
-
export const worley2 = (distFn, name = gensym("worley2_")) => defn(
|
|
34
|
+
export const worley2 = (distFn, name = gensym("worley2_")) => defn(V2, name, [V2, F], (P, jitter) => {
|
|
32
35
|
const K = float(1 / 7);
|
|
33
36
|
const Ko = float(3 / 7);
|
|
34
37
|
const oI = sym(vec3(-1, 0, 1));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-stdlib",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.15",
|
|
4
4
|
"description": "Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.8.
|
|
38
|
-
"@thi.ng/shader-ast": "^0.12.
|
|
37
|
+
"@thi.ng/api": "^8.8.1",
|
|
38
|
+
"@thi.ng/shader-ast": "^0.12.52"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@microsoft/api-extractor": "^7.34.
|
|
42
|
-
"@thi.ng/testament": "^0.3.
|
|
43
|
-
"rimraf": "^
|
|
41
|
+
"@microsoft/api-extractor": "^7.34.8",
|
|
42
|
+
"@thi.ng/testament": "^0.3.16",
|
|
43
|
+
"rimraf": "^5.0.0",
|
|
44
44
|
"tools": "^0.0.1",
|
|
45
|
-
"typedoc": "^0.
|
|
45
|
+
"typedoc": "^0.24.6",
|
|
46
46
|
"typescript": "^5.0.4"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
|
@@ -330,5 +330,5 @@
|
|
|
330
330
|
],
|
|
331
331
|
"year": 2019
|
|
332
332
|
},
|
|
333
|
-
"gitHead": "
|
|
333
|
+
"gitHead": "20ab11b687a13228f6a8cecdc5f05ba9105122ea\n"
|
|
334
334
|
}
|
package/raymarch/ao.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V3 } 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";
|
|
@@ -17,7 +18,7 @@ import { clamp01 } from "../math/clamp.js";
|
|
|
17
18
|
* @param numSamples -
|
|
18
19
|
* @param name -
|
|
19
20
|
*/
|
|
20
|
-
export const raymarchAO = (scene, numSamples = 5, name = gensym("raymarchAO_")) => defn(
|
|
21
|
+
export const raymarchAO = (scene, numSamples = 5, name = gensym("raymarchAO_")) => defn(F, name, [V3, V3], (p, n) => {
|
|
21
22
|
let r;
|
|
22
23
|
let w;
|
|
23
24
|
let d0;
|
package/raymarch/direction.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { FLOAT2, vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { div, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -9,7 +10,7 @@ import { normalize, radians, tan } from "@thi.ng/shader-ast/builtin/math";
|
|
|
9
10
|
* @param res - vec2
|
|
10
11
|
* @param fov - float vertical FOV (in degrees)
|
|
11
12
|
*/
|
|
12
|
-
export const raymarchDir = defn(
|
|
13
|
+
export const raymarchDir = defn(V3, "raymarchDir", [V2, V2, F], (frag, res, fov) => {
|
|
13
14
|
let uv;
|
|
14
15
|
return [
|
|
15
16
|
(uv = sym(sub(frag, div(res, FLOAT2)))),
|
package/raymarch/normal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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 { gensym } from "@thi.ng/shader-ast/ast/idgen";
|
|
3
4
|
import { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
@@ -14,7 +15,7 @@ import { normalize } from "@thi.ng/shader-ast/builtin/math";
|
|
|
14
15
|
* @param scene -
|
|
15
16
|
* @param name -
|
|
16
17
|
*/
|
|
17
|
-
export const raymarchNormal = (scene, name = gensym("raymarchNormal_")) => defn(
|
|
18
|
+
export const raymarchNormal = (scene, name = gensym("raymarchNormal_")) => defn(V3, name, [V3, F], (p, smooth) => {
|
|
18
19
|
let dn;
|
|
19
20
|
const comp = (id) => sub($x(scene(add(p, $(dn, id)))), $x(scene(sub(p, $(dn, id)))));
|
|
20
21
|
return [
|
package/raymarch/scene.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
3
|
import { brk, forLoop, ifThen } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
4
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
@@ -34,12 +35,12 @@ export const raymarchScene = (scene, _opts) => {
|
|
|
34
35
|
bias: 0.7,
|
|
35
36
|
..._opts,
|
|
36
37
|
};
|
|
37
|
-
return defn(
|
|
38
|
+
return defn(V2, opts.name, [V3, V3], (pos, dir) => {
|
|
38
39
|
let total;
|
|
39
40
|
let res;
|
|
40
41
|
return [
|
|
41
42
|
(total = sym(float(opts.near))),
|
|
42
|
-
(res = sym(
|
|
43
|
+
(res = sym(V2)),
|
|
43
44
|
forLoop(sym(INT0), (i) => lt(i, int(opts.steps)), inc, () => [
|
|
44
45
|
assign(res, scene(rayPointAt(pos, dir, total))),
|
|
45
46
|
ifThen(lt($x(res), float(opts.eps)), [
|
package/screen/uv.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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 { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
|
-
import { bvec4, vec2
|
|
4
|
+
import { VEC2_1, bvec4, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
5
|
import { add, div, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
5
6
|
import { $x, $xy, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
7
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
|
-
import { greaterThan, lessThan
|
|
8
|
+
import { _any, greaterThan, lessThan } from "@thi.ng/shader-ast/builtin/bvec";
|
|
8
9
|
import { fit0111 } from "../math/fit.js";
|
|
9
10
|
/**
|
|
10
11
|
* Computes UV coord in [0..1] interval from given `fragCoord` and screen `res`.
|
|
@@ -21,7 +22,7 @@ export const fragUV = (fragCoord, res) => div($xy(fragCoord), res);
|
|
|
21
22
|
* @param fragCoord - vec2
|
|
22
23
|
* @param res - vec2
|
|
23
24
|
*/
|
|
24
|
-
export const aspectCorrectedUV = defn(
|
|
25
|
+
export const aspectCorrectedUV = defn(V2, "aspectCorrectedUV", [V2, V2], (pos, res) => {
|
|
25
26
|
let uv;
|
|
26
27
|
return [
|
|
27
28
|
(uv = sym(fit0111(div(pos, res)))),
|
|
@@ -39,6 +40,6 @@ export const aspectCorrectedUV = defn("vec2", "aspectCorrectedUV", ["vec2", "vec
|
|
|
39
40
|
* borderMask(vec2(0.2, 0.2), 0.1) // false
|
|
40
41
|
* ```
|
|
41
42
|
*/
|
|
42
|
-
export const borderMask = defn("bool", "borderMask", [
|
|
43
|
+
export const borderMask = defn("bool", "borderMask", [V2, F], (uv, width) => [
|
|
43
44
|
ret(_any(bvec4(lessThan(uv, vec2(width)), greaterThan(add(uv, width), VEC2_1)))),
|
|
44
45
|
]);
|
package/sdf/arc.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2 } 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 } from "@thi.ng/shader-ast/ast/lit";
|
|
@@ -16,7 +17,7 @@ import { abs, cos, length, sin } from "@thi.ng/shader-ast/builtin/math";
|
|
|
16
17
|
* - https://www.shadertoy.com/view/wl23RK
|
|
17
18
|
* - https://iquilezles.org/articles/distfunctions2d/
|
|
18
19
|
*/
|
|
19
|
-
export const sdfArc2 = defn(
|
|
20
|
+
export const sdfArc2 = defn(F, "sdfArc", [V2, F, F, F], (p, apert, ra, rb) => {
|
|
20
21
|
let q;
|
|
21
22
|
let sc;
|
|
22
23
|
return [
|
package/sdf/bezier.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 { ifThen } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
4
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
-
import {
|
|
5
|
+
import { FLOAT0, FLOAT1, FLOAT2, float, vec2, } from "@thi.ng/shader-ast/ast/lit";
|
|
5
6
|
import { add, div, gte, lt, madd, mul, neg, sub, } from "@thi.ng/shader-ast/ast/ops";
|
|
6
7
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
8
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
@@ -18,7 +19,7 @@ import { cross2 } from "../math/cross2.js";
|
|
|
18
19
|
* - https://www.shadertoy.com/view/MlKcDD
|
|
19
20
|
* - https://iquilezles.org/articles/distfunctions2d/
|
|
20
21
|
*/
|
|
21
|
-
export const sdfQuadratic2 = defn(
|
|
22
|
+
export const sdfQuadratic2 = defn(F, "sdfQuadratic2", [V2, V2, V2, V2], (pos, A, B, C) => {
|
|
22
23
|
let a, b, c, d;
|
|
23
24
|
let kk, kx, ky, kz;
|
|
24
25
|
let p, q, p3, q2, h;
|
package/sdf/box-rounded.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V4 } 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, VEC2_0 } from "@thi.ng/shader-ast/ast/lit";
|
|
@@ -18,7 +19,7 @@ import { maxComp2 } from "../math/maxcomp.js";
|
|
|
18
19
|
* @param size - vec2
|
|
19
20
|
* @param r - vec4
|
|
20
21
|
*/
|
|
21
|
-
export const sdfBoxRounded = defn(
|
|
22
|
+
export const sdfBoxRounded = defn(F, "sdfBoxRounded", [V2, V2, V4], (p, size, r) => {
|
|
22
23
|
let q, t, d;
|
|
23
24
|
return [
|
|
24
25
|
(t = sym(ternary(gt($x(p), FLOAT0), $xy(r), $(r, "zw")))),
|
package/sdf/box.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { FLOAT0, VEC2_0, VEC3_0 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { maxComp2, maxComp3 } from "../math/maxcomp.js";
|
|
|
10
11
|
* @param p - vec2
|
|
11
12
|
* @param size - vec2
|
|
12
13
|
*/
|
|
13
|
-
export const sdfBox2 = defn(
|
|
14
|
+
export const sdfBox2 = defn(F, "sdfBox2", [V2, V2], (p, size) => {
|
|
14
15
|
let d;
|
|
15
16
|
return [
|
|
16
17
|
(d = sym(sub(abs(p), size))),
|
|
@@ -23,7 +24,7 @@ export const sdfBox2 = defn("float", "sdfBox2", ["vec2", "vec2"], (p, size) => {
|
|
|
23
24
|
* @param p - vec3
|
|
24
25
|
* @param size - vec3
|
|
25
26
|
*/
|
|
26
|
-
export const sdfBox3 = defn(
|
|
27
|
+
export const sdfBox3 = defn(F, "sdfBox3", [V3, V3], (p, size) => {
|
|
27
28
|
let d;
|
|
28
29
|
return [
|
|
29
30
|
(d = sym(sub(abs(p), size))),
|
package/sdf/cross.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 { ifThen, ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
4
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
-
import { FLOAT0, FLOAT05,
|
|
5
|
+
import { FLOAT0, FLOAT05, VEC2_0, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
5
6
|
import { add, gt, madd, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
7
|
import { $, $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
8
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
@@ -22,7 +23,7 @@ import { maxComp2 } from "../math/maxcomp.js";
|
|
|
22
23
|
* @param size -
|
|
23
24
|
* @param r -
|
|
24
25
|
*/
|
|
25
|
-
export const sdfCross2 = defn(
|
|
26
|
+
export const sdfCross2 = defn(F, "sdfCross2", [V2, V2, F], (p, size, r) => {
|
|
26
27
|
let a, q, w;
|
|
27
28
|
let k;
|
|
28
29
|
return [
|
|
@@ -46,7 +47,7 @@ export const sdfCross2 = defn("float", "sdfCross2", ["vec2", "vec2", "float"], (
|
|
|
46
47
|
* @param size -
|
|
47
48
|
* @param r -
|
|
48
49
|
*/
|
|
49
|
-
export const sdfRoundedX2 = defn(
|
|
50
|
+
export const sdfRoundedX2 = defn(F, "sdfRoundedX", [V2, F, F], (p, size, r) => {
|
|
50
51
|
let q;
|
|
51
52
|
return [
|
|
52
53
|
(q = sym(abs(p))),
|
package/sdf/cylinder.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { F, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
|
-
import { FLOAT0,
|
|
3
|
+
import { FLOAT0, VEC2_0, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
4
5
|
import { $, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
5
6
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
@@ -13,7 +14,7 @@ import { maxComp2 } from "../math/maxcomp.js";
|
|
|
13
14
|
* @param h - float
|
|
14
15
|
* @param r - float
|
|
15
16
|
*/
|
|
16
|
-
export const sdfCylinder = defn(
|
|
17
|
+
export const sdfCylinder = defn(F, "sdCylinder", [V3, F, F], (p, h, r) => {
|
|
17
18
|
let d;
|
|
18
19
|
return [
|
|
19
20
|
(d = sym(sub(abs(vec2(length($(p, "xz")), $y(p))), vec2(h, r)))),
|
package/sdf/hex.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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 { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
4
|
import { FLOAT0, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
@@ -12,7 +13,7 @@ import { abs, clamp, dot, length, min, sign, } from "@thi.ng/shader-ast/builtin/
|
|
|
12
13
|
* Ported from original GLSL impl by Inigo Quilez:
|
|
13
14
|
* - https://iquilezles.org/articles/distfunctions2d/
|
|
14
15
|
*/
|
|
15
|
-
export const sdfHexagon2 = defn(
|
|
16
|
+
export const sdfHexagon2 = defn(F, "sdfHexagon2", [V2, F], (p, r) => {
|
|
16
17
|
const TAN30 = 0.5773502691896257;
|
|
17
18
|
let k, q;
|
|
18
19
|
return [
|
package/sdf/line.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
3
4
|
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
@@ -10,7 +11,7 @@ import { clamp01 } from "../math/clamp.js";
|
|
|
10
11
|
* @param a -
|
|
11
12
|
* @param b -
|
|
12
13
|
*/
|
|
13
|
-
const $ = (n, type) => defn(
|
|
14
|
+
const $ = (n, type) => defn(F, `sdLine${n}`, [type, type, type], (p, a, b) => {
|
|
14
15
|
let pa, ba;
|
|
15
16
|
return [
|
|
16
17
|
(pa = sym(sub(p, a))),
|
|
@@ -25,7 +26,7 @@ const $ = (n, type) => defn("float", `sdLine${n}`, [type, type, type], (p, a, b)
|
|
|
25
26
|
* @param a - vec2
|
|
26
27
|
* @param b - vec2
|
|
27
28
|
*/
|
|
28
|
-
export const sdfLine2 = $(2,
|
|
29
|
+
export const sdfLine2 = $(2, V2);
|
|
29
30
|
/**
|
|
30
31
|
* Returns signed distance from `p` to 3D line segment `a` -> `b`.
|
|
31
32
|
*
|
|
@@ -33,4 +34,4 @@ export const sdfLine2 = $(2, "vec2");
|
|
|
33
34
|
* @param a - vec3
|
|
34
35
|
* @param b - vec3
|
|
35
36
|
*/
|
|
36
|
-
export const sdfLine3 = $(3,
|
|
37
|
+
export const sdfLine3 = $(3, V3);
|
package/sdf/mirror.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { V2 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { FLOAT05, VEC2_1, VEC2_2 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { floor, mod } from "@thi.ng/shader-ast/builtin/math";
|
|
|
10
11
|
* @param p - point
|
|
11
12
|
* @param size - mirror box size
|
|
12
13
|
*/
|
|
13
|
-
export const sdfMirror2 = defn(
|
|
14
|
+
export const sdfMirror2 = defn(V2, "sdfMirror2", [V2, V2], (p, size) => {
|
|
14
15
|
let halfSize;
|
|
15
16
|
return [
|
|
16
17
|
(halfSize = sym(mul(size, FLOAT05))),
|
package/sdf/plane.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { add } from "@thi.ng/shader-ast/ast/ops";
|
|
3
4
|
import { dot } from "@thi.ng/shader-ast/builtin/math";
|
|
@@ -8,7 +9,9 @@ import { dot } from "@thi.ng/shader-ast/builtin/math";
|
|
|
8
9
|
* @param normal - vec2
|
|
9
10
|
* @param w - float
|
|
10
11
|
*/
|
|
11
|
-
export const sdfPlane2 = defn(
|
|
12
|
+
export const sdfPlane2 = defn(F, "sdPlane2", [V2, V2, F], (p, n, w) => [
|
|
13
|
+
ret(add(dot(p, n), w)),
|
|
14
|
+
]);
|
|
12
15
|
/**
|
|
13
16
|
* Returns signed distance from `p` to plane defined by `normal` and `w`.
|
|
14
17
|
*
|
|
@@ -16,4 +19,6 @@ export const sdfPlane2 = defn("float", "sdPlane2", ["vec2", "vec2", "float"], (p
|
|
|
16
19
|
* @param normal - vec3
|
|
17
20
|
* @param w - float
|
|
18
21
|
*/
|
|
19
|
-
export const sdfPlane3 = defn(
|
|
22
|
+
export const sdfPlane3 = defn(F, "sdPlane3", [V3, V3, F], (p, n, w) => [
|
|
23
|
+
ret(add(dot(p, n), w)),
|
|
24
|
+
]);
|
package/sdf/polygon.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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 { forLoop, ifThen } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
4
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
@@ -19,7 +20,7 @@ import { clamp01 } from "../math/clamp.js";
|
|
|
19
20
|
*
|
|
20
21
|
* @param N
|
|
21
22
|
*/
|
|
22
|
-
export const sdfPolygon2 = (N) => defn(
|
|
23
|
+
export const sdfPolygon2 = (N) => defn(F, `sdfPolygon2_${N}`, [V2, ["vec2[]", "pts", { num: N }]], (p, pts) => {
|
|
23
24
|
let d, s;
|
|
24
25
|
let b, e, w, t;
|
|
25
26
|
let pi, pj;
|
package/sdf/polyhedra.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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 { FLOAT0, PHI, vec3 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, reciprocal, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -40,10 +41,10 @@ const GDF = [
|
|
|
40
41
|
* @param vecs -
|
|
41
42
|
*/
|
|
42
43
|
const defGDF = (id, vecs) => [
|
|
43
|
-
defn(
|
|
44
|
+
defn(F, id, [V3, F], (p, r) => [
|
|
44
45
|
ret(sub(vecs.reduce((acc, v) => max(acc, abs(dot(p, v))), FLOAT0), r)),
|
|
45
46
|
]),
|
|
46
|
-
defn(
|
|
47
|
+
defn(F, id + "Smooth", [V3, F, F], (p, r, e) => [
|
|
47
48
|
ret(sub(pow(vecs.reduce((acc, v) => add(acc, pow(abs(dot(p, v)), e)), FLOAT0), reciprocal(e)), r)),
|
|
48
49
|
]),
|
|
49
50
|
];
|
package/sdf/repeat-polar.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 { FLOAT05, TAU } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -12,7 +13,7 @@ import { cossin } from "../math/sincos.js";
|
|
|
12
13
|
* @param p - point
|
|
13
14
|
* @param n - number of polar repetitions
|
|
14
15
|
*/
|
|
15
|
-
export const sdfRepeatPolar2 = defn(
|
|
16
|
+
export const sdfRepeatPolar2 = defn(V2, "sdfRepeatPolar2", [V2, F], (p, n) => {
|
|
16
17
|
let angle;
|
|
17
18
|
let angle2;
|
|
18
19
|
let a;
|
package/sdf/repeat.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 { FLOAT05 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -11,11 +12,11 @@ const $ = (n, type) => defn(type, `sdTxRepeat${n}`, [type, type], (p, c) => [
|
|
|
11
12
|
* @param p - vec2
|
|
12
13
|
* @param c - vec2
|
|
13
14
|
*/
|
|
14
|
-
export const sdfRepeat2 = $(2,
|
|
15
|
+
export const sdfRepeat2 = $(2, V2);
|
|
15
16
|
/**
|
|
16
17
|
* 3D domain repetition by wrapping position `p` into period `c`.
|
|
17
18
|
*
|
|
18
19
|
* @param p - vec3
|
|
19
20
|
* @param c - vec3
|
|
20
21
|
*/
|
|
21
|
-
export const sdfRepeat3 = $(3,
|
|
22
|
+
export const sdfRepeat3 = $(3, V3);
|
package/sdf/smooth-isec.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 { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { fit1101 } from "../math/fit.js";
|
|
|
10
11
|
* @param d2 - float
|
|
11
12
|
* @param k - float
|
|
12
13
|
*/
|
|
13
|
-
export const sdfSmoothIntersect = defn(
|
|
14
|
+
export const sdfSmoothIntersect = defn(F, "sdOpSmoothIntersect", [F, F, F], (a, b, k) => {
|
|
14
15
|
let h;
|
|
15
16
|
return [
|
|
16
17
|
(h = sym(clamp01(fit1101(div(sub(b, a), k))))),
|
package/sdf/smooth-sub.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 { add, div, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { fit1101 } from "../math/fit.js";
|
|
|
10
11
|
* @param d2 - float
|
|
11
12
|
* @param k - float
|
|
12
13
|
*/
|
|
13
|
-
export const sdfSmoothSubtract = defn(
|
|
14
|
+
export const sdfSmoothSubtract = defn(F, "sdOpSmoothSubtract", [F, F, F], (a, b, k) => {
|
|
14
15
|
let h;
|
|
15
16
|
return [
|
|
16
17
|
(h = sym(clamp01(fit1101(div(add(b, a), k))))),
|
package/sdf/smooth-union.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 { div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { fit1101 } from "../math/fit.js";
|
|
|
10
11
|
* @param d2 - float
|
|
11
12
|
* @param k - float
|
|
12
13
|
*/
|
|
13
|
-
export const sdfSmoothUnion = defn(
|
|
14
|
+
export const sdfSmoothUnion = defn(F, "sdOpSmoothUnion", [F, F, F], (a, b, k) => {
|
|
14
15
|
let h;
|
|
15
16
|
return [
|
|
16
17
|
(h = sym(clamp01(fit1101(div(sub(b, a), k))))),
|
package/sdf/sphere.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
3
4
|
import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
@@ -7,11 +8,15 @@ import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
|
7
8
|
* @param p - vec2
|
|
8
9
|
* @param r - float
|
|
9
10
|
*/
|
|
10
|
-
export const sdfCircle = defn(
|
|
11
|
+
export const sdfCircle = defn(F, "sdCircle", [V2, F], (p, r) => [
|
|
12
|
+
ret(sub(length(p), r)),
|
|
13
|
+
]);
|
|
11
14
|
/**
|
|
12
15
|
* Returns signed distance from `p` to centered sphere of radius `r`.
|
|
13
16
|
*
|
|
14
17
|
* @param p - vec3
|
|
15
18
|
* @param r - float
|
|
16
19
|
*/
|
|
17
|
-
export const sdfSphere = defn(
|
|
20
|
+
export const sdfSphere = defn(F, "sdSphere", [V3, F], (p, r) => [
|
|
21
|
+
ret(sub(length(p), r)),
|
|
22
|
+
]);
|
package/sdf/torus.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
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 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -11,6 +12,6 @@ import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
|
11
12
|
* @param r1 - float
|
|
12
13
|
* @param r2 - float
|
|
13
14
|
*/
|
|
14
|
-
export const sdfTorus = defn(
|
|
15
|
+
export const sdfTorus = defn(F, "sdTorus", [V3, F, F], (p, r1, r2) => [
|
|
15
16
|
ret(sub(length(vec2(sub(length($(p, "xz")), r2), $y(p))), r1)),
|
|
16
17
|
]);
|
package/sdf/tri.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 { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { div, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -12,7 +13,7 @@ import { cross2 } from "../math/cross2.js";
|
|
|
12
13
|
* @param b - vec2
|
|
13
14
|
* @param c - vec2
|
|
14
15
|
*/
|
|
15
|
-
export const sdfTriangle2 = defn(
|
|
16
|
+
export const sdfTriangle2 = defn(F, "sdTriangle", [V2, V2, V2, V2], (p, a, b, c) => {
|
|
16
17
|
let e0, e1, e2;
|
|
17
18
|
let v0, v1, v2;
|
|
18
19
|
let pq0, pq1, pq2;
|
package/sdf/union.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { V2 } 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 { lt } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -19,6 +20,6 @@ export const sdfUnion = (a, ...terms) => terms.reduce((a, b) => min(a, b), a);
|
|
|
19
20
|
* @param a -
|
|
20
21
|
* @param b -
|
|
21
22
|
*/
|
|
22
|
-
export const sdfUnion2 = defn(
|
|
23
|
+
export const sdfUnion2 = defn(V2, "sdfUnion2", [V2, V2], (a, b) => [
|
|
23
24
|
ret(ternary(lt($x(a), $x(b)), a, b)),
|
|
24
25
|
]);
|
package/tex/blur.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { V2, 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 { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
@@ -26,7 +27,7 @@ const singlePass = (col, tex, uv, off, k) => assign(col, add(col, mul(add(textur
|
|
|
26
27
|
* @param uv -
|
|
27
28
|
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
28
29
|
*/
|
|
29
|
-
export const blur5 = defn(
|
|
30
|
+
export const blur5 = defn(V4, "blur5", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
30
31
|
let col;
|
|
31
32
|
let off;
|
|
32
33
|
const k1 = 0.29411764705882354;
|
|
@@ -49,7 +50,7 @@ export const blur5 = defn("vec4", "blur5", ["sampler2D", "vec2", "vec2", "vec2"]
|
|
|
49
50
|
* @param uv -
|
|
50
51
|
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
51
52
|
*/
|
|
52
|
-
export const blur9 = defn(
|
|
53
|
+
export const blur9 = defn(V4, "blur9", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
53
54
|
let col;
|
|
54
55
|
let off;
|
|
55
56
|
let off2;
|
|
@@ -77,7 +78,7 @@ export const blur9 = defn("vec4", "blur9", ["sampler2D", "vec2", "vec2", "vec2"]
|
|
|
77
78
|
* @param uv -
|
|
78
79
|
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
79
80
|
*/
|
|
80
|
-
export const blur13 = defn(
|
|
81
|
+
export const blur13 = defn(V4, "blur13", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
81
82
|
let col;
|
|
82
83
|
let off;
|
|
83
84
|
let off2;
|