@thi.ng/shader-ast-stdlib 0.11.4 → 0.12.0
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 +12 -1
- package/README.md +4 -2
- package/color/aces-film.d.ts +1 -1
- package/color/aces-film.js +1 -1
- package/color/levels.d.ts +5 -5
- package/color/levels.js +5 -5
- package/index.d.ts +6 -0
- package/index.js +6 -0
- package/math/cross2.d.ts +3 -3
- package/math/cross2.js +5 -2
- package/math/fit.d.ts +10 -10
- package/math/fit.js +10 -10
- package/package.json +96 -78
- package/sdf/arc.d.ts +13 -0
- package/sdf/arc.js +27 -0
- package/sdf/bezier.d.ts +12 -0
- package/sdf/bezier.js +72 -0
- package/sdf/box-rounded.d.ts +14 -0
- package/sdf/box-rounded.js +29 -0
- package/sdf/cross.d.ts +30 -0
- package/sdf/cross.js +55 -0
- package/sdf/hex.d.ts +9 -0
- package/sdf/hex.js +26 -0
- package/sdf/polygon.d.ts +12 -0
- package/sdf/polygon.js +46 -0
- package/sdf/polyhedra.js +2 -2
- package/sdf/smooth-isec.d.ts +2 -2
- package/sdf/smooth-isec.js +2 -2
- package/sdf/smooth-sub.d.ts +2 -2
- package/sdf/smooth-sub.js +2 -2
- package/sdf/smooth-union.d.ts +2 -2
- package/sdf/smooth-union.js +2 -2
- package/sdf/union.d.ts +2 -1
- package/sdf/union.js +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**:
|
|
3
|
+
- **Last updated**: 2022-05-07T11:33:35Z
|
|
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,17 @@ 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.12.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.12.0) (2022-05-07)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add more 2D SDF prims ([2672e75](https://github.com/thi-ng/umbrella/commit/2672e75))
|
|
17
|
+
- add 2D SDF arc/bezier fns ([07bd445](https://github.com/thi-ng/umbrella/commit/07bd445))
|
|
18
|
+
|
|
19
|
+
#### ♻️ Refactoring
|
|
20
|
+
|
|
21
|
+
- update cross2() as non-inline fn ([59d631a](https://github.com/thi-ng/umbrella/commit/59d631a))
|
|
22
|
+
|
|
12
23
|
## [0.11.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.11.0) (2021-11-17)
|
|
13
24
|
|
|
14
25
|
#### 🚀 Features
|
package/README.md
CHANGED
|
@@ -104,7 +104,7 @@ node --experimental-repl-await
|
|
|
104
104
|
> const shaderAstStdlib = await import("@thi.ng/shader-ast-stdlib");
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
-
Package sizes (gzipped, pre-treeshake): ESM:
|
|
107
|
+
Package sizes (gzipped, pre-treeshake): ESM: 12.82 KB
|
|
108
108
|
|
|
109
109
|
## Dependencies
|
|
110
110
|
|
|
@@ -443,6 +443,7 @@ for reference.
|
|
|
443
443
|
|
|
444
444
|
#### Primitives
|
|
445
445
|
|
|
446
|
+
- `sdfArc2`
|
|
446
447
|
- `sdfBox2`
|
|
447
448
|
- `sdfBox3`
|
|
448
449
|
- `sdfCircle`
|
|
@@ -451,6 +452,7 @@ for reference.
|
|
|
451
452
|
- `sdfLine3`
|
|
452
453
|
- `sdfPlane2`
|
|
453
454
|
- `sdfPlane3`
|
|
455
|
+
- `sdfQuadratic2`
|
|
454
456
|
- `sdfSphere`
|
|
455
457
|
- `sdfTorus`
|
|
456
458
|
- `sdfTriangle2`
|
|
@@ -503,4 +505,4 @@ If this project contributes to an academic publication, please cite it as:
|
|
|
503
505
|
|
|
504
506
|
## License
|
|
505
507
|
|
|
506
|
-
© 2019 -
|
|
508
|
+
© 2019 - 2022 Karsten Schmidt // Apache Software License 2.0
|
package/color/aces-film.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Reference:
|
|
5
5
|
* https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
|
|
6
6
|
*
|
|
7
|
-
* @param col
|
|
7
|
+
* @param col -
|
|
8
8
|
*/
|
|
9
9
|
export declare const ACESFilm: import("@thi.ng/shader-ast").TaggedFn1<"vec3", "vec3">;
|
|
10
10
|
//# sourceMappingURL=aces-film.d.ts.map
|
package/color/aces-film.js
CHANGED
|
@@ -7,7 +7,7 @@ import { clamp01 } from "../math/clamp.js";
|
|
|
7
7
|
* Reference:
|
|
8
8
|
* https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
|
|
9
9
|
*
|
|
10
|
-
* @param col
|
|
10
|
+
* @param col -
|
|
11
11
|
*/
|
|
12
12
|
export const ACESFilm = defn("vec3", "ACESFilm", ["vec3"], (col) => [
|
|
13
13
|
ret(clamp01(div(mul(col, add(mul(col, 2.51), 0.03)), add(mul(col, add(mul(col, 2.43), 0.59)), 0.14)))),
|
package/color/levels.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const midLevelGamma: import("@thi.ng/shader-ast").TaggedFn1<"floa
|
|
|
12
12
|
* potentially varying settings per channel). To be used with
|
|
13
13
|
* {@link levelAdjustGammaRGB}.
|
|
14
14
|
*
|
|
15
|
-
* @param mid
|
|
15
|
+
* @param mid -
|
|
16
16
|
*/
|
|
17
17
|
export declare const midLevelGammaRGB: (mid: Vec3Term) => import("@thi.ng/shader-ast").Lit<"vec3">;
|
|
18
18
|
/**
|
|
@@ -53,10 +53,10 @@ export declare const levelAdjustMid: (x: FloatTerm, mid: FloatTerm, input: Vec2T
|
|
|
53
53
|
* @remarks
|
|
54
54
|
* Also see {@link levelAdjustGammaRGB}, {@link midLevelGammaRGB}.
|
|
55
55
|
*
|
|
56
|
-
* @param x
|
|
57
|
-
* @param mid
|
|
58
|
-
* @param input
|
|
59
|
-
* @param output
|
|
56
|
+
* @param x -
|
|
57
|
+
* @param mid -
|
|
58
|
+
* @param input -
|
|
59
|
+
* @param output -
|
|
60
60
|
*/
|
|
61
61
|
export declare const levelAdjustMidRGB: (x: Vec3Term, mid: Vec3Term, input: Mat3Term, output: Mat3Term) => import("@thi.ng/shader-ast").FnCall<"vec3">;
|
|
62
62
|
//# sourceMappingURL=levels.d.ts.map
|
package/color/levels.js
CHANGED
|
@@ -21,7 +21,7 @@ export const midLevelGamma = defn("float", "midLevelGamma", ["float"], (mid) =>
|
|
|
21
21
|
* potentially varying settings per channel). To be used with
|
|
22
22
|
* {@link levelAdjustGammaRGB}.
|
|
23
23
|
*
|
|
24
|
-
* @param mid
|
|
24
|
+
* @param mid -
|
|
25
25
|
*/
|
|
26
26
|
export const midLevelGammaRGB = (mid) => vec3(midLevelGamma($x(mid)), midLevelGamma($y(mid)), midLevelGamma($z(mid)));
|
|
27
27
|
/**
|
|
@@ -66,9 +66,9 @@ export const levelAdjustMid = (x, mid, input, output) => levelAdjustGamma(x, mid
|
|
|
66
66
|
* @remarks
|
|
67
67
|
* Also see {@link levelAdjustGammaRGB}, {@link midLevelGammaRGB}.
|
|
68
68
|
*
|
|
69
|
-
* @param x
|
|
70
|
-
* @param mid
|
|
71
|
-
* @param input
|
|
72
|
-
* @param output
|
|
69
|
+
* @param x -
|
|
70
|
+
* @param mid -
|
|
71
|
+
* @param input -
|
|
72
|
+
* @param output -
|
|
73
73
|
*/
|
|
74
74
|
export const levelAdjustMidRGB = (x, mid, input, output) => levelAdjustGammaRGB(x, midLevelGammaRGB(mid), input, output);
|
package/index.d.ts
CHANGED
|
@@ -44,13 +44,19 @@ export * from "./raymarch/point-at.js";
|
|
|
44
44
|
export * from "./raymarch/scene.js";
|
|
45
45
|
export * from "./screen/uv.js";
|
|
46
46
|
export * from "./sdf/annular.js";
|
|
47
|
+
export * from "./sdf/arc.js";
|
|
48
|
+
export * from "./sdf/bezier.js";
|
|
47
49
|
export * from "./sdf/box.js";
|
|
50
|
+
export * from "./sdf/box-rounded.js";
|
|
51
|
+
export * from "./sdf/cross.js";
|
|
48
52
|
export * from "./sdf/cylinder.js";
|
|
53
|
+
export * from "./sdf/hex.js";
|
|
49
54
|
export * from "./sdf/isec.js";
|
|
50
55
|
export * from "./sdf/line.js";
|
|
51
56
|
export * from "./sdf/mirror.js";
|
|
52
57
|
export * from "./sdf/plane.js";
|
|
53
58
|
export * from "./sdf/polyhedra.js";
|
|
59
|
+
export * from "./sdf/polygon.js";
|
|
54
60
|
export * from "./sdf/repeat.js";
|
|
55
61
|
export * from "./sdf/repeat-polar.js";
|
|
56
62
|
export * from "./sdf/round.js";
|
package/index.js
CHANGED
|
@@ -44,13 +44,19 @@ export * from "./raymarch/point-at.js";
|
|
|
44
44
|
export * from "./raymarch/scene.js";
|
|
45
45
|
export * from "./screen/uv.js";
|
|
46
46
|
export * from "./sdf/annular.js";
|
|
47
|
+
export * from "./sdf/arc.js";
|
|
48
|
+
export * from "./sdf/bezier.js";
|
|
47
49
|
export * from "./sdf/box.js";
|
|
50
|
+
export * from "./sdf/box-rounded.js";
|
|
51
|
+
export * from "./sdf/cross.js";
|
|
48
52
|
export * from "./sdf/cylinder.js";
|
|
53
|
+
export * from "./sdf/hex.js";
|
|
49
54
|
export * from "./sdf/isec.js";
|
|
50
55
|
export * from "./sdf/line.js";
|
|
51
56
|
export * from "./sdf/mirror.js";
|
|
52
57
|
export * from "./sdf/plane.js";
|
|
53
58
|
export * from "./sdf/polyhedra.js";
|
|
59
|
+
export * from "./sdf/polygon.js";
|
|
54
60
|
export * from "./sdf/repeat.js";
|
|
55
61
|
export * from "./sdf/repeat-polar.js";
|
|
56
62
|
export * from "./sdf/round.js";
|
package/math/cross2.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { FloatTerm
|
|
1
|
+
import type { FloatTerm } from "@thi.ng/shader-ast";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Computes 2D "cross product" of given vectors. Also see
|
|
4
4
|
* {@link crossC2}.
|
|
5
5
|
*
|
|
6
6
|
* @param a -
|
|
7
7
|
* @param b -
|
|
8
8
|
*/
|
|
9
|
-
export declare const cross2:
|
|
9
|
+
export declare const cross2: import("@thi.ng/shader-ast").TaggedFn2<"vec2", "vec2", "float">;
|
|
10
10
|
/**
|
|
11
11
|
* Inline function. Computes 2D cross product of given individual
|
|
12
12
|
* components: ax * by - ay * bx
|
package/math/cross2.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
1
2
|
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
2
3
|
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Computes 2D "cross product" of given vectors. Also see
|
|
5
6
|
* {@link crossC2}.
|
|
6
7
|
*
|
|
7
8
|
* @param a -
|
|
8
9
|
* @param b -
|
|
9
10
|
*/
|
|
10
|
-
export const cross2 = (
|
|
11
|
+
export const cross2 = defn("float", "cross2", ["vec2", "vec2"], (a, b) => [
|
|
12
|
+
ret(sub(mul($x(a), $y(b)), mul($y(a), $x(b)))),
|
|
13
|
+
]);
|
|
11
14
|
/**
|
|
12
15
|
* Inline function. Computes 2D cross product of given individual
|
|
13
16
|
* components: ax * by - ay * bx
|
package/math/fit.d.ts
CHANGED
|
@@ -12,21 +12,21 @@ export declare const fitNorm1: import("@thi.ng/shader-ast").TaggedFn3<"float", "
|
|
|
12
12
|
* Fits value `x` from closed interval [a,b] to closed interval [c,d]. No
|
|
13
13
|
* clamping performed.
|
|
14
14
|
*
|
|
15
|
-
* @param x
|
|
16
|
-
* @param a
|
|
17
|
-
* @param b
|
|
18
|
-
* @param c
|
|
19
|
-
* @param d
|
|
15
|
+
* @param x -
|
|
16
|
+
* @param a -
|
|
17
|
+
* @param b -
|
|
18
|
+
* @param c -
|
|
19
|
+
* @param d -
|
|
20
20
|
*/
|
|
21
21
|
export declare const fit: <T extends PrimTerm>(x: T, a: T, b: T, c: T, d: T) => Term<TermType<T>>;
|
|
22
22
|
/**
|
|
23
23
|
* Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
|
|
24
24
|
*
|
|
25
|
-
* @param x
|
|
26
|
-
* @param a
|
|
27
|
-
* @param b
|
|
28
|
-
* @param c
|
|
29
|
-
* @param d
|
|
25
|
+
* @param x -
|
|
26
|
+
* @param a -
|
|
27
|
+
* @param b -
|
|
28
|
+
* @param c -
|
|
29
|
+
* @param d -
|
|
30
30
|
*/
|
|
31
31
|
export declare const fitClamped: <T extends PrimTerm>(x: T, a: T, b: T, c: T, d: T) => Term<TermType<T>>;
|
|
32
32
|
/**
|
package/math/fit.js
CHANGED
|
@@ -17,21 +17,21 @@ export const fitNorm1 = defn("float", "fitNorm1", ["float", "float", "float"], (
|
|
|
17
17
|
* Fits value `x` from closed interval [a,b] to closed interval [c,d]. No
|
|
18
18
|
* clamping performed.
|
|
19
19
|
*
|
|
20
|
-
* @param x
|
|
21
|
-
* @param a
|
|
22
|
-
* @param b
|
|
23
|
-
* @param c
|
|
24
|
-
* @param d
|
|
20
|
+
* @param x -
|
|
21
|
+
* @param a -
|
|
22
|
+
* @param b -
|
|
23
|
+
* @param c -
|
|
24
|
+
* @param d -
|
|
25
25
|
*/
|
|
26
26
|
export const fit = (x, a, b, c, d) => mix(c, d, div(sub(x, a), sub(b, a)));
|
|
27
27
|
/**
|
|
28
28
|
* Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
|
|
29
29
|
*
|
|
30
|
-
* @param x
|
|
31
|
-
* @param a
|
|
32
|
-
* @param b
|
|
33
|
-
* @param c
|
|
34
|
-
* @param d
|
|
30
|
+
* @param x -
|
|
31
|
+
* @param a -
|
|
32
|
+
* @param b -
|
|
33
|
+
* @param c -
|
|
34
|
+
* @param d -
|
|
35
35
|
*/
|
|
36
36
|
export const fitClamped = (x, a, b, c, d) => mix(c, d, clamp01(div(sub(x, a), sub(b, a))));
|
|
37
37
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-stdlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
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,16 +34,16 @@
|
|
|
34
34
|
"test": "testament test"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@thi.ng/api": "^8.3.
|
|
38
|
-
"@thi.ng/shader-ast": "^0.12.
|
|
37
|
+
"@thi.ng/api": "^8.3.6",
|
|
38
|
+
"@thi.ng/shader-ast": "^0.12.7"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@microsoft/api-extractor": "^7.
|
|
42
|
-
"@thi.ng/testament": "^0.2.
|
|
41
|
+
"@microsoft/api-extractor": "^7.23.1",
|
|
42
|
+
"@thi.ng/testament": "^0.2.6",
|
|
43
43
|
"rimraf": "^3.0.2",
|
|
44
44
|
"tools": "^0.0.1",
|
|
45
|
-
"typedoc": "^0.22.
|
|
46
|
-
"typescript": "^4.
|
|
45
|
+
"typedoc": "^0.22.15",
|
|
46
|
+
"typescript": "^4.6.4"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
|
49
49
|
"ast",
|
|
@@ -93,214 +93,232 @@
|
|
|
93
93
|
],
|
|
94
94
|
"exports": {
|
|
95
95
|
".": {
|
|
96
|
-
"
|
|
96
|
+
"default": "./index.js"
|
|
97
97
|
},
|
|
98
98
|
"./api": {
|
|
99
|
-
"
|
|
99
|
+
"default": "./api.js"
|
|
100
100
|
},
|
|
101
101
|
"./color/aces-film": {
|
|
102
|
-
"
|
|
102
|
+
"default": "./color/aces-film.js"
|
|
103
103
|
},
|
|
104
104
|
"./color/levels": {
|
|
105
|
-
"
|
|
105
|
+
"default": "./color/levels.js"
|
|
106
106
|
},
|
|
107
107
|
"./color/linear-srgb": {
|
|
108
|
-
"
|
|
108
|
+
"default": "./color/linear-srgb.js"
|
|
109
109
|
},
|
|
110
110
|
"./color/luminance": {
|
|
111
|
-
"
|
|
111
|
+
"default": "./color/luminance.js"
|
|
112
112
|
},
|
|
113
113
|
"./color/porter-duff": {
|
|
114
|
-
"
|
|
114
|
+
"default": "./color/porter-duff.js"
|
|
115
115
|
},
|
|
116
116
|
"./color/rgbe": {
|
|
117
|
-
"
|
|
117
|
+
"default": "./color/rgbe.js"
|
|
118
118
|
},
|
|
119
119
|
"./fog/exp": {
|
|
120
|
-
"
|
|
120
|
+
"default": "./fog/exp.js"
|
|
121
121
|
},
|
|
122
122
|
"./fog/exp2": {
|
|
123
|
-
"
|
|
123
|
+
"default": "./fog/exp2.js"
|
|
124
124
|
},
|
|
125
125
|
"./fog/linear": {
|
|
126
|
-
"
|
|
126
|
+
"default": "./fog/linear.js"
|
|
127
127
|
},
|
|
128
128
|
"./light/lambert": {
|
|
129
|
-
"
|
|
129
|
+
"default": "./light/lambert.js"
|
|
130
130
|
},
|
|
131
131
|
"./light/trilight": {
|
|
132
|
-
"
|
|
132
|
+
"default": "./light/trilight.js"
|
|
133
133
|
},
|
|
134
134
|
"./math/additive": {
|
|
135
|
-
"
|
|
135
|
+
"default": "./math/additive.js"
|
|
136
136
|
},
|
|
137
137
|
"./math/cartesian": {
|
|
138
|
-
"
|
|
138
|
+
"default": "./math/cartesian.js"
|
|
139
139
|
},
|
|
140
140
|
"./math/clamp": {
|
|
141
|
-
"
|
|
141
|
+
"default": "./math/clamp.js"
|
|
142
142
|
},
|
|
143
143
|
"./math/cross2": {
|
|
144
|
-
"
|
|
144
|
+
"default": "./math/cross2.js"
|
|
145
145
|
},
|
|
146
146
|
"./math/dist-chebyshev": {
|
|
147
|
-
"
|
|
147
|
+
"default": "./math/dist-chebyshev.js"
|
|
148
148
|
},
|
|
149
149
|
"./math/dist-manhattan": {
|
|
150
|
-
"
|
|
150
|
+
"default": "./math/dist-manhattan.js"
|
|
151
151
|
},
|
|
152
152
|
"./math/fit": {
|
|
153
|
-
"
|
|
153
|
+
"default": "./math/fit.js"
|
|
154
154
|
},
|
|
155
155
|
"./math/magsq": {
|
|
156
|
-
"
|
|
156
|
+
"default": "./math/magsq.js"
|
|
157
157
|
},
|
|
158
158
|
"./math/maxcomp": {
|
|
159
|
-
"
|
|
159
|
+
"default": "./math/maxcomp.js"
|
|
160
160
|
},
|
|
161
161
|
"./math/mincomp": {
|
|
162
|
-
"
|
|
162
|
+
"default": "./math/mincomp.js"
|
|
163
163
|
},
|
|
164
164
|
"./math/mix-cubic": {
|
|
165
|
-
"
|
|
165
|
+
"default": "./math/mix-cubic.js"
|
|
166
166
|
},
|
|
167
167
|
"./math/mix-quadratic": {
|
|
168
|
-
"
|
|
168
|
+
"default": "./math/mix-quadratic.js"
|
|
169
169
|
},
|
|
170
170
|
"./math/orthogonal": {
|
|
171
|
-
"
|
|
171
|
+
"default": "./math/orthogonal.js"
|
|
172
172
|
},
|
|
173
173
|
"./math/osc": {
|
|
174
|
-
"
|
|
174
|
+
"default": "./math/osc.js"
|
|
175
175
|
},
|
|
176
176
|
"./math/polar": {
|
|
177
|
-
"
|
|
177
|
+
"default": "./math/polar.js"
|
|
178
178
|
},
|
|
179
179
|
"./math/sincos": {
|
|
180
|
-
"
|
|
180
|
+
"default": "./math/sincos.js"
|
|
181
181
|
},
|
|
182
182
|
"./matrix/convert": {
|
|
183
|
-
"
|
|
183
|
+
"default": "./matrix/convert.js"
|
|
184
184
|
},
|
|
185
185
|
"./matrix/lookat": {
|
|
186
|
-
"
|
|
186
|
+
"default": "./matrix/lookat.js"
|
|
187
187
|
},
|
|
188
188
|
"./matrix/mvp": {
|
|
189
|
-
"
|
|
189
|
+
"default": "./matrix/mvp.js"
|
|
190
190
|
},
|
|
191
191
|
"./matrix/normal": {
|
|
192
|
-
"
|
|
192
|
+
"default": "./matrix/normal.js"
|
|
193
193
|
},
|
|
194
194
|
"./matrix/rotation": {
|
|
195
|
-
"
|
|
195
|
+
"default": "./matrix/rotation.js"
|
|
196
196
|
},
|
|
197
197
|
"./noise/curl3": {
|
|
198
|
-
"
|
|
198
|
+
"default": "./noise/curl3.js"
|
|
199
199
|
},
|
|
200
200
|
"./noise/hash": {
|
|
201
|
-
"
|
|
201
|
+
"default": "./noise/hash.js"
|
|
202
202
|
},
|
|
203
203
|
"./noise/permute": {
|
|
204
|
-
"
|
|
204
|
+
"default": "./noise/permute.js"
|
|
205
205
|
},
|
|
206
206
|
"./noise/simplex2": {
|
|
207
|
-
"
|
|
207
|
+
"default": "./noise/simplex2.js"
|
|
208
208
|
},
|
|
209
209
|
"./noise/simplex3": {
|
|
210
|
-
"
|
|
210
|
+
"default": "./noise/simplex3.js"
|
|
211
211
|
},
|
|
212
212
|
"./noise/voronoi2": {
|
|
213
|
-
"
|
|
213
|
+
"default": "./noise/voronoi2.js"
|
|
214
214
|
},
|
|
215
215
|
"./noise/worley2": {
|
|
216
|
-
"
|
|
216
|
+
"default": "./noise/worley2.js"
|
|
217
217
|
},
|
|
218
218
|
"./raymarch/ao": {
|
|
219
|
-
"
|
|
219
|
+
"default": "./raymarch/ao.js"
|
|
220
220
|
},
|
|
221
221
|
"./raymarch/direction": {
|
|
222
|
-
"
|
|
222
|
+
"default": "./raymarch/direction.js"
|
|
223
223
|
},
|
|
224
224
|
"./raymarch/normal": {
|
|
225
|
-
"
|
|
225
|
+
"default": "./raymarch/normal.js"
|
|
226
226
|
},
|
|
227
227
|
"./raymarch/point-at": {
|
|
228
|
-
"
|
|
228
|
+
"default": "./raymarch/point-at.js"
|
|
229
229
|
},
|
|
230
230
|
"./raymarch/scene": {
|
|
231
|
-
"
|
|
231
|
+
"default": "./raymarch/scene.js"
|
|
232
232
|
},
|
|
233
233
|
"./screen/uv": {
|
|
234
|
-
"
|
|
234
|
+
"default": "./screen/uv.js"
|
|
235
235
|
},
|
|
236
236
|
"./sdf/annular": {
|
|
237
|
-
"
|
|
237
|
+
"default": "./sdf/annular.js"
|
|
238
|
+
},
|
|
239
|
+
"./sdf/arc": {
|
|
240
|
+
"default": "./sdf/arc.js"
|
|
241
|
+
},
|
|
242
|
+
"./sdf/bezier": {
|
|
243
|
+
"default": "./sdf/bezier.js"
|
|
244
|
+
},
|
|
245
|
+
"./sdf/box-rounded": {
|
|
246
|
+
"default": "./sdf/box-rounded.js"
|
|
238
247
|
},
|
|
239
248
|
"./sdf/box": {
|
|
240
|
-
"
|
|
249
|
+
"default": "./sdf/box.js"
|
|
250
|
+
},
|
|
251
|
+
"./sdf/cross": {
|
|
252
|
+
"default": "./sdf/cross.js"
|
|
241
253
|
},
|
|
242
254
|
"./sdf/cylinder": {
|
|
243
|
-
"
|
|
255
|
+
"default": "./sdf/cylinder.js"
|
|
256
|
+
},
|
|
257
|
+
"./sdf/hex": {
|
|
258
|
+
"default": "./sdf/hex.js"
|
|
244
259
|
},
|
|
245
260
|
"./sdf/isec": {
|
|
246
|
-
"
|
|
261
|
+
"default": "./sdf/isec.js"
|
|
247
262
|
},
|
|
248
263
|
"./sdf/line": {
|
|
249
|
-
"
|
|
264
|
+
"default": "./sdf/line.js"
|
|
250
265
|
},
|
|
251
266
|
"./sdf/mirror": {
|
|
252
|
-
"
|
|
267
|
+
"default": "./sdf/mirror.js"
|
|
253
268
|
},
|
|
254
269
|
"./sdf/plane": {
|
|
255
|
-
"
|
|
270
|
+
"default": "./sdf/plane.js"
|
|
271
|
+
},
|
|
272
|
+
"./sdf/polygon": {
|
|
273
|
+
"default": "./sdf/polygon.js"
|
|
256
274
|
},
|
|
257
275
|
"./sdf/polyhedra": {
|
|
258
|
-
"
|
|
276
|
+
"default": "./sdf/polyhedra.js"
|
|
259
277
|
},
|
|
260
278
|
"./sdf/repeat-polar": {
|
|
261
|
-
"
|
|
279
|
+
"default": "./sdf/repeat-polar.js"
|
|
262
280
|
},
|
|
263
281
|
"./sdf/repeat": {
|
|
264
|
-
"
|
|
282
|
+
"default": "./sdf/repeat.js"
|
|
265
283
|
},
|
|
266
284
|
"./sdf/round": {
|
|
267
|
-
"
|
|
285
|
+
"default": "./sdf/round.js"
|
|
268
286
|
},
|
|
269
287
|
"./sdf/smooth-isec": {
|
|
270
|
-
"
|
|
288
|
+
"default": "./sdf/smooth-isec.js"
|
|
271
289
|
},
|
|
272
290
|
"./sdf/smooth-sub": {
|
|
273
|
-
"
|
|
291
|
+
"default": "./sdf/smooth-sub.js"
|
|
274
292
|
},
|
|
275
293
|
"./sdf/smooth-union": {
|
|
276
|
-
"
|
|
294
|
+
"default": "./sdf/smooth-union.js"
|
|
277
295
|
},
|
|
278
296
|
"./sdf/sphere": {
|
|
279
|
-
"
|
|
297
|
+
"default": "./sdf/sphere.js"
|
|
280
298
|
},
|
|
281
299
|
"./sdf/sub": {
|
|
282
|
-
"
|
|
300
|
+
"default": "./sdf/sub.js"
|
|
283
301
|
},
|
|
284
302
|
"./sdf/torus": {
|
|
285
|
-
"
|
|
303
|
+
"default": "./sdf/torus.js"
|
|
286
304
|
},
|
|
287
305
|
"./sdf/tri": {
|
|
288
|
-
"
|
|
306
|
+
"default": "./sdf/tri.js"
|
|
289
307
|
},
|
|
290
308
|
"./sdf/union": {
|
|
291
|
-
"
|
|
309
|
+
"default": "./sdf/union.js"
|
|
292
310
|
},
|
|
293
311
|
"./tex/blur": {
|
|
294
|
-
"
|
|
312
|
+
"default": "./tex/blur.js"
|
|
295
313
|
},
|
|
296
314
|
"./tex/index-coord": {
|
|
297
|
-
"
|
|
315
|
+
"default": "./tex/index-coord.js"
|
|
298
316
|
},
|
|
299
317
|
"./tex/index-uv": {
|
|
300
|
-
"
|
|
318
|
+
"default": "./tex/index-uv.js"
|
|
301
319
|
},
|
|
302
320
|
"./tex/read-index": {
|
|
303
|
-
"
|
|
321
|
+
"default": "./tex/read-index.js"
|
|
304
322
|
}
|
|
305
323
|
},
|
|
306
324
|
"thi.ng": {
|
|
@@ -312,5 +330,5 @@
|
|
|
312
330
|
],
|
|
313
331
|
"year": 2019
|
|
314
332
|
},
|
|
315
|
-
"gitHead": "
|
|
333
|
+
"gitHead": "cf084be5fd5932226054d2dd32bad35481379f5d\n"
|
|
316
334
|
}
|
package/sdf/arc.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns signed distance from `p` to 2D circular arc with `aperture` (in
|
|
3
|
+
* [0..π] interval), radius `ra` and `thickness`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Slightly modified version (easier to use aperture control) of original GLSL
|
|
7
|
+
* impl by Inigo Quilez:
|
|
8
|
+
*
|
|
9
|
+
* - https://www.shadertoy.com/view/wl23RK
|
|
10
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
11
|
+
*/
|
|
12
|
+
export declare const sdfArc2: import("@thi.ng/shader-ast").TaggedFn4<"vec2", "float", "float", "float", "float">;
|
|
13
|
+
//# sourceMappingURL=arc.d.ts.map
|
package/sdf/arc.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
2
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
|
+
import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
|
+
import { gt, madd, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
|
+
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
|
+
import { abs, cos, length, sin } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
+
/**
|
|
9
|
+
* Returns signed distance from `p` to 2D circular arc with `aperture` (in
|
|
10
|
+
* [0..π] interval), radius `ra` and `thickness`.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* Slightly modified version (easier to use aperture control) of original GLSL
|
|
14
|
+
* impl by Inigo Quilez:
|
|
15
|
+
*
|
|
16
|
+
* - https://www.shadertoy.com/view/wl23RK
|
|
17
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
18
|
+
*/
|
|
19
|
+
export const sdfArc2 = defn("float", "sdfArc", ["vec2", "float", "float", "float"], (p, apert, ra, rb) => {
|
|
20
|
+
let q;
|
|
21
|
+
let sc;
|
|
22
|
+
return [
|
|
23
|
+
(q = sym(vec2(abs($x(p)), $y(p)))),
|
|
24
|
+
(sc = sym(vec2(sin(apert), cos(apert)))),
|
|
25
|
+
ret(sub(ternary(gt(mul($y(sc), $x(q)), mul($x(sc), $y(q))), length(madd(sc, neg(ra), q)), abs(sub(length(q), ra))), rb)),
|
|
26
|
+
];
|
|
27
|
+
});
|
package/sdf/bezier.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns signed distance from `p` to 2D quadratic bezier (given by points A,
|
|
3
|
+
* B, C).
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
7
|
+
*
|
|
8
|
+
* - https://www.shadertoy.com/view/MlKcDD
|
|
9
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
10
|
+
*/
|
|
11
|
+
export declare const sdfQuadratic2: import("@thi.ng/shader-ast").TaggedFn4<"vec2", "vec2", "vec2", "vec2", "float">;
|
|
12
|
+
//# sourceMappingURL=bezier.d.ts.map
|
package/sdf/bezier.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
|
+
import { ifThen } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
+
import { float, FLOAT0, FLOAT1, FLOAT2, vec2, } from "@thi.ng/shader-ast/ast/lit";
|
|
5
|
+
import { add, div, gte, lt, madd, mul, neg, sub, } from "@thi.ng/shader-ast/ast/ops";
|
|
6
|
+
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
8
|
+
import { abs, acos, cos, dot, powf, sign, sin, sqrt, } from "@thi.ng/shader-ast/builtin/math";
|
|
9
|
+
import { clamp01 } from "../math/clamp.js";
|
|
10
|
+
import { cross2 } from "../math/cross2.js";
|
|
11
|
+
/**
|
|
12
|
+
* Returns signed distance from `p` to 2D quadratic bezier (given by points A,
|
|
13
|
+
* B, C).
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
17
|
+
*
|
|
18
|
+
* - https://www.shadertoy.com/view/MlKcDD
|
|
19
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
20
|
+
*/
|
|
21
|
+
export const sdfQuadratic2 = defn("float", "sdfQuadratic2", ["vec2", "vec2", "vec2", "vec2"], (pos, A, B, C) => {
|
|
22
|
+
let a, b, c, d;
|
|
23
|
+
let kk, kx, ky, kz;
|
|
24
|
+
let p, q, p3, q2, h;
|
|
25
|
+
let m, n, t, v, z;
|
|
26
|
+
let res, sgn;
|
|
27
|
+
let x, y, uv;
|
|
28
|
+
return [
|
|
29
|
+
(a = sym(sub(B, A))),
|
|
30
|
+
(b = sym(add(madd(B, -2, A), C))),
|
|
31
|
+
(c = sym(mul(a, 2))),
|
|
32
|
+
(d = sym(sub(A, pos))),
|
|
33
|
+
(kk = sym(div(FLOAT1, dot(b, b)))),
|
|
34
|
+
(kx = sym(mul(kk, dot(a, b)))),
|
|
35
|
+
(ky = sym(mul(kk, div(madd(FLOAT2, dot(a, a), dot(d, b)), 3)))),
|
|
36
|
+
(kz = sym(mul(kk, dot(d, a)))),
|
|
37
|
+
(res = sym(FLOAT0)),
|
|
38
|
+
(sgn = sym(FLOAT0)),
|
|
39
|
+
(p = sym(sub(ky, mul(kx, kx)))),
|
|
40
|
+
(q = sym(madd(sub(mul(mul(FLOAT2, kx), kx), mul(3, ky)), kx, kz))),
|
|
41
|
+
(p3 = sym(mul(mul(p, p), p))),
|
|
42
|
+
(q2 = sym(mul(q, q))),
|
|
43
|
+
(h = sym(madd(p3, 4, q2))),
|
|
44
|
+
ifThen(gte(h, FLOAT0), [
|
|
45
|
+
assign(h, sqrt(h)),
|
|
46
|
+
(x = sym(div(sub(vec2(h, neg(h)), q), FLOAT2))),
|
|
47
|
+
(uv = sym(mul(sign(x), powf(abs(x), float(1 / 3))))),
|
|
48
|
+
(t = sym(clamp01(sub(add($x(uv), $y(uv)), kx)))),
|
|
49
|
+
assign(x, madd(madd(b, t, c), t, d)),
|
|
50
|
+
assign(res, dot(x, x)),
|
|
51
|
+
assign(sgn, cross2(madd(b, mul(t, FLOAT2), c), x)),
|
|
52
|
+
], [
|
|
53
|
+
(z = sym(sqrt(neg(p)))),
|
|
54
|
+
(v = sym(div(acos(div(q, mul(mul(p, z), FLOAT2))), float(3)))),
|
|
55
|
+
(m = sym(cos(v))),
|
|
56
|
+
(n = sym(mul(sin(v), 1.732050808))),
|
|
57
|
+
(uv = sym(clamp01(sub(mul(vec2(add(m, m), sub(neg(n), m)), z), kx)))),
|
|
58
|
+
(x = sym(madd(madd(b, $x(uv), c), $x(uv), d))),
|
|
59
|
+
(y = sym(madd(madd(b, $y(uv), c), $y(uv), d))),
|
|
60
|
+
assign(m, dot(x, x)),
|
|
61
|
+
assign(n, dot(y, y)),
|
|
62
|
+
ifThen(lt(m, n), [
|
|
63
|
+
assign(res, m),
|
|
64
|
+
assign(sgn, cross2(madd(b, mul($x(uv), 2), c), x)),
|
|
65
|
+
], [
|
|
66
|
+
assign(res, n),
|
|
67
|
+
assign(sgn, cross2(madd(b, mul($y(uv), 2), c), y)),
|
|
68
|
+
]),
|
|
69
|
+
]),
|
|
70
|
+
ret(mul(sign(sgn), sqrt(res))),
|
|
71
|
+
];
|
|
72
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns signed distance from `p` to centered 2D rect of `size` and corner
|
|
3
|
+
* radii defined by given vec4 `r`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
7
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
8
|
+
*
|
|
9
|
+
* @param p - vec2
|
|
10
|
+
* @param size - vec2
|
|
11
|
+
* @param r - vec4
|
|
12
|
+
*/
|
|
13
|
+
export declare const sdfBoxRounded: import("@thi.ng/shader-ast").TaggedFn3<"vec2", "vec2", "vec4", "float">;
|
|
14
|
+
//# sourceMappingURL=box-rounded.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
2
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
|
+
import { FLOAT0, VEC2_0 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
|
+
import { add, gt, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
|
+
import { $, $x, $xy, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
|
+
import { abs, length, max, min } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
+
import { maxComp2 } from "../math/maxcomp.js";
|
|
9
|
+
/**
|
|
10
|
+
* Returns signed distance from `p` to centered 2D rect of `size` and corner
|
|
11
|
+
* radii defined by given vec4 `r`.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
15
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
16
|
+
*
|
|
17
|
+
* @param p - vec2
|
|
18
|
+
* @param size - vec2
|
|
19
|
+
* @param r - vec4
|
|
20
|
+
*/
|
|
21
|
+
export const sdfBoxRounded = defn("float", "sdfBoxRounded", ["vec2", "vec2", "vec4"], (p, size, r) => {
|
|
22
|
+
let q, t, d;
|
|
23
|
+
return [
|
|
24
|
+
(t = sym(ternary(gt($x(p), FLOAT0), $xy(r), $(r, "zw")))),
|
|
25
|
+
(d = sym(ternary(gt($y(p), FLOAT0), $x(t), $y(t)))),
|
|
26
|
+
(q = sym(add(sub(abs(p), size), d))),
|
|
27
|
+
ret(sub(add(min(maxComp2(q), FLOAT0), length(max(q, VEC2_0))), d)),
|
|
28
|
+
];
|
|
29
|
+
});
|
package/sdf/cross.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns signed distance from `p` to 2D cross/plus of given `size` and corner
|
|
3
|
+
* radius `r`.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* - `size` consist of overall width/size (in x) and thickness (in y component)
|
|
7
|
+
* - corner radius can also be negative
|
|
8
|
+
*
|
|
9
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
10
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
11
|
+
*
|
|
12
|
+
* @param p -
|
|
13
|
+
* @param size -
|
|
14
|
+
* @param r -
|
|
15
|
+
*/
|
|
16
|
+
export declare const sdfCross2: import("@thi.ng/shader-ast").TaggedFn3<"vec2", "vec2", "float", "float">;
|
|
17
|
+
/**
|
|
18
|
+
* Returns signed distance from `p` to 2D "X-sign" of given `size` and stroke
|
|
19
|
+
* weight `r`.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
23
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
24
|
+
*
|
|
25
|
+
* @param p -
|
|
26
|
+
* @param size -
|
|
27
|
+
* @param r -
|
|
28
|
+
*/
|
|
29
|
+
export declare const sdfRoundedX2: import("@thi.ng/shader-ast").TaggedFn3<"vec2", "float", "float", "float">;
|
|
30
|
+
//# sourceMappingURL=cross.d.ts.map
|
package/sdf/cross.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
|
+
import { ifThen, ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
+
import { FLOAT0, FLOAT05, vec2, VEC2_0 } from "@thi.ng/shader-ast/ast/lit";
|
|
5
|
+
import { add, gt, madd, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
6
|
+
import { $, $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
7
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
8
|
+
import { abs, length, max, min, sign } from "@thi.ng/shader-ast/builtin/math";
|
|
9
|
+
import { maxComp2 } from "../math/maxcomp.js";
|
|
10
|
+
/**
|
|
11
|
+
* Returns signed distance from `p` to 2D cross/plus of given `size` and corner
|
|
12
|
+
* radius `r`.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* - `size` consist of overall width/size (in x) and thickness (in y component)
|
|
16
|
+
* - corner radius can also be negative
|
|
17
|
+
*
|
|
18
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
19
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
20
|
+
*
|
|
21
|
+
* @param p -
|
|
22
|
+
* @param size -
|
|
23
|
+
* @param r -
|
|
24
|
+
*/
|
|
25
|
+
export const sdfCross2 = defn("float", "sdfCross2", ["vec2", "vec2", "float"], (p, size, r) => {
|
|
26
|
+
let a, q, w;
|
|
27
|
+
let k;
|
|
28
|
+
return [
|
|
29
|
+
(a = sym(abs(p))),
|
|
30
|
+
ifThen(gt($y(a), $x(a)), [assign(a, $(a, "yx"))]),
|
|
31
|
+
(q = sym(sub(a, size))),
|
|
32
|
+
(k = sym(maxComp2(q))),
|
|
33
|
+
(w = sym(ternary(gt(k, FLOAT0), q, vec2(sub($y(size), $x(a)), neg(k))))),
|
|
34
|
+
ret(madd(sign(k), length(max(w, VEC2_0)), r)),
|
|
35
|
+
];
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Returns signed distance from `p` to 2D "X-sign" of given `size` and stroke
|
|
39
|
+
* weight `r`.
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
43
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
44
|
+
*
|
|
45
|
+
* @param p -
|
|
46
|
+
* @param size -
|
|
47
|
+
* @param r -
|
|
48
|
+
*/
|
|
49
|
+
export const sdfRoundedX2 = defn("float", "sdfRoundedX", ["vec2", "float", "float"], (p, size, r) => {
|
|
50
|
+
let q;
|
|
51
|
+
return [
|
|
52
|
+
(q = sym(abs(p))),
|
|
53
|
+
ret(sub(length(sub(q, mul(min(add($x(q), $y(q)), size), FLOAT05))), r)),
|
|
54
|
+
];
|
|
55
|
+
});
|
package/sdf/hex.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns signed distance from `p` to 2D hexagon of given radius `r`.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
6
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
7
|
+
*/
|
|
8
|
+
export declare const sdfHexagon2: import("@thi.ng/shader-ast").TaggedFn2<"vec2", "float", "float">;
|
|
9
|
+
//# sourceMappingURL=hex.d.ts.map
|
package/sdf/hex.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
|
+
import { FLOAT0, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
4
|
+
import { mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
|
+
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
6
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
7
|
+
import { abs, clamp, dot, length, min, sign, } from "@thi.ng/shader-ast/builtin/math";
|
|
8
|
+
/**
|
|
9
|
+
* Returns signed distance from `p` to 2D hexagon of given radius `r`.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Ported from original GLSL impl by Inigo Quilez:
|
|
13
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
14
|
+
*/
|
|
15
|
+
export const sdfHexagon2 = defn("float", "sdfHexagon2", ["vec2", "float"], (p, r) => {
|
|
16
|
+
const TAN30 = 0.5773502691896257;
|
|
17
|
+
let k, q;
|
|
18
|
+
return [
|
|
19
|
+
// sin/cos @ 60deg
|
|
20
|
+
(k = sym(vec2(-0.8660254037844386, 0.5))),
|
|
21
|
+
(q = sym(abs(p))),
|
|
22
|
+
assign(q, sub(q, mul(k, mul(2, min(dot(k, q), FLOAT0))))),
|
|
23
|
+
assign(q, sub(q, vec2(clamp($x(q), mul(r, -TAN30), mul(r, TAN30)), r))),
|
|
24
|
+
ret(mul(length(q), sign($y(q)))),
|
|
25
|
+
];
|
|
26
|
+
});
|
package/sdf/polygon.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-order function. Returns specialized function to compute signed
|
|
3
|
+
* distance for 2D polygons of `N` vertices.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Based on original GLSL impl by Inigo Quilez:
|
|
7
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
8
|
+
*
|
|
9
|
+
* @param N
|
|
10
|
+
*/
|
|
11
|
+
export declare const sdfPolygon2: (N: number) => import("@thi.ng/shader-ast").TaggedFn2<"vec2", "vec2[]", "float">;
|
|
12
|
+
//# sourceMappingURL=polygon.d.ts.map
|
package/sdf/polygon.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
|
+
import { forLoop, ifThen } from "@thi.ng/shader-ast/ast/controlflow";
|
|
3
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
|
+
import { index } from "@thi.ng/shader-ast/ast/indexed";
|
|
5
|
+
import { bvec3, FLOAT1, int, INT0 } from "@thi.ng/shader-ast/ast/lit";
|
|
6
|
+
import { div, gt, gte, inc, lt, mul, neg, not, or, sub, } from "@thi.ng/shader-ast/ast/ops";
|
|
7
|
+
import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
8
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
9
|
+
import { all, _any } from "@thi.ng/shader-ast/builtin/bvec";
|
|
10
|
+
import { dot, min, sqrt } from "@thi.ng/shader-ast/builtin/math";
|
|
11
|
+
import { clamp01 } from "../math/clamp.js";
|
|
12
|
+
/**
|
|
13
|
+
* Higher-order function. Returns specialized function to compute signed
|
|
14
|
+
* distance for 2D polygons of `N` vertices.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Based on original GLSL impl by Inigo Quilez:
|
|
18
|
+
* - https://iquilezles.org/articles/distfunctions2d/
|
|
19
|
+
*
|
|
20
|
+
* @param N
|
|
21
|
+
*/
|
|
22
|
+
export const sdfPolygon2 = (N) => defn("float", `sdfPolygon2_${N}`, ["vec2", ["vec2[]", "pts", { num: N }]], (p, pts) => {
|
|
23
|
+
let d, s;
|
|
24
|
+
let b, e, w, t;
|
|
25
|
+
let pi, pj;
|
|
26
|
+
let c;
|
|
27
|
+
let j;
|
|
28
|
+
return [
|
|
29
|
+
(t = sym(sub(p, index(pts, 0)))),
|
|
30
|
+
(d = sym(dot(t, t))),
|
|
31
|
+
(s = sym(FLOAT1)),
|
|
32
|
+
(j = sym(int(N - 1))),
|
|
33
|
+
forLoop(sym(INT0), (i) => lt(i, int(N)), inc, (i) => [
|
|
34
|
+
(pi = sym(index(pts, i))),
|
|
35
|
+
(pj = sym(index(pts, j))),
|
|
36
|
+
(e = sym(sub(pj, pi))),
|
|
37
|
+
(w = sym(sub(p, pi))),
|
|
38
|
+
(b = sym(sub(w, mul(e, clamp01(div(dot(w, e), dot(e, e))))))),
|
|
39
|
+
assign(d, min(d, dot(b, b))),
|
|
40
|
+
(c = sym(bvec3(gte($y(p), $y(pi)), lt($y(p), $y(pj)), gt(mul($x(e), $y(w)), mul($y(e), $x(w)))))),
|
|
41
|
+
ifThen(or(all(c), not(_any(c))), [assign(s, neg(s))]),
|
|
42
|
+
assign(j, i),
|
|
43
|
+
]),
|
|
44
|
+
ret(mul(s, sqrt(d))),
|
|
45
|
+
];
|
|
46
|
+
});
|
package/sdf/polyhedra.js
CHANGED
package/sdf/smooth-isec.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare const sdfSmoothIntersect: import("@thi.ng/shader-ast").TaggedFn3<
|
|
|
9
9
|
* Variadic compiletime macro for {@link sdfSmoothIntersect}. Takes smooth factor
|
|
10
10
|
* `k`, followed by any number (at least 1 required) of SDF terms.
|
|
11
11
|
*
|
|
12
|
-
* @param k
|
|
13
|
-
* @param terms
|
|
12
|
+
* @param k -
|
|
13
|
+
* @param terms -
|
|
14
14
|
*/
|
|
15
15
|
export declare const sdfSmoothIntersectAll: (k: FloatTerm, ...terms: FloatTerm[]) => FloatTerm;
|
|
16
16
|
//# sourceMappingURL=smooth-isec.d.ts.map
|
package/sdf/smooth-isec.js
CHANGED
|
@@ -21,7 +21,7 @@ export const sdfSmoothIntersect = defn("float", "sdOpSmoothIntersect", ["float",
|
|
|
21
21
|
* Variadic compiletime macro for {@link sdfSmoothIntersect}. Takes smooth factor
|
|
22
22
|
* `k`, followed by any number (at least 1 required) of SDF terms.
|
|
23
23
|
*
|
|
24
|
-
* @param k
|
|
25
|
-
* @param terms
|
|
24
|
+
* @param k -
|
|
25
|
+
* @param terms -
|
|
26
26
|
*/
|
|
27
27
|
export const sdfSmoothIntersectAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothIntersect(acc, x, k));
|
package/sdf/smooth-sub.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare const sdfSmoothSubtract: import("@thi.ng/shader-ast").TaggedFn3<"
|
|
|
9
9
|
* Variadic compiletime macro for {@link sdfSmoothSubtract}. Takes smooth factor
|
|
10
10
|
* `k`, followed by any number (at least 1 required) of SDF terms.
|
|
11
11
|
*
|
|
12
|
-
* @param k
|
|
13
|
-
* @param terms
|
|
12
|
+
* @param k -
|
|
13
|
+
* @param terms -
|
|
14
14
|
*/
|
|
15
15
|
export declare const sdfSmoothSubtractAll: (k: FloatTerm, ...terms: FloatTerm[]) => FloatTerm;
|
|
16
16
|
//# sourceMappingURL=smooth-sub.d.ts.map
|
package/sdf/smooth-sub.js
CHANGED
|
@@ -21,7 +21,7 @@ export const sdfSmoothSubtract = defn("float", "sdOpSmoothSubtract", ["float", "
|
|
|
21
21
|
* Variadic compiletime macro for {@link sdfSmoothSubtract}. Takes smooth factor
|
|
22
22
|
* `k`, followed by any number (at least 1 required) of SDF terms.
|
|
23
23
|
*
|
|
24
|
-
* @param k
|
|
25
|
-
* @param terms
|
|
24
|
+
* @param k -
|
|
25
|
+
* @param terms -
|
|
26
26
|
*/
|
|
27
27
|
export const sdfSmoothSubtractAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothSubtract(acc, x, k));
|
package/sdf/smooth-union.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare const sdfSmoothUnion: import("@thi.ng/shader-ast").TaggedFn3<"flo
|
|
|
9
9
|
* Variadic compiletime macro for {@link sdfSmoothUnion}. Takes smooth factor
|
|
10
10
|
* `k`, followed by any number (at least 1 required) of SDF terms.
|
|
11
11
|
*
|
|
12
|
-
* @param k
|
|
13
|
-
* @param terms
|
|
12
|
+
* @param k -
|
|
13
|
+
* @param terms -
|
|
14
14
|
*/
|
|
15
15
|
export declare const sdfSmoothUnionAll: (k: FloatTerm, ...terms: FloatTerm[]) => FloatTerm;
|
|
16
16
|
//# sourceMappingURL=smooth-union.d.ts.map
|
package/sdf/smooth-union.js
CHANGED
|
@@ -21,7 +21,7 @@ export const sdfSmoothUnion = defn("float", "sdOpSmoothUnion", ["float", "float"
|
|
|
21
21
|
* Variadic compiletime macro for {@link sdfSmoothUnion}. Takes smooth factor
|
|
22
22
|
* `k`, followed by any number (at least 1 required) of SDF terms.
|
|
23
23
|
*
|
|
24
|
-
* @param k
|
|
25
|
-
* @param terms
|
|
24
|
+
* @param k -
|
|
25
|
+
* @param terms -
|
|
26
26
|
*/
|
|
27
27
|
export const sdfSmoothUnionAll = (k, ...terms) => terms.reduce((acc, x) => sdfSmoothUnion(acc, x, k));
|
package/sdf/union.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ import type { FloatTerm } from "@thi.ng/shader-ast";
|
|
|
9
9
|
export declare const sdfUnion: (a: FloatTerm, ...terms: FloatTerm[]) => FloatTerm;
|
|
10
10
|
/**
|
|
11
11
|
* SDF shape union for vec2 terms, i.e. the common form where the X coord
|
|
12
|
-
* defines distance and Y an object or material ID.
|
|
12
|
+
* defines distance and Y an object or material ID. Returns `a` or `b`,
|
|
13
|
+
* depending whose x-coord (dist) is smaller.
|
|
13
14
|
*
|
|
14
15
|
* @param a -
|
|
15
16
|
* @param b -
|
package/sdf/union.js
CHANGED
|
@@ -13,7 +13,8 @@ import { min } from "@thi.ng/shader-ast/builtin/math";
|
|
|
13
13
|
export const sdfUnion = (a, ...terms) => terms.reduce((a, b) => min(a, b), a);
|
|
14
14
|
/**
|
|
15
15
|
* SDF shape union for vec2 terms, i.e. the common form where the X coord
|
|
16
|
-
* defines distance and Y an object or material ID.
|
|
16
|
+
* defines distance and Y an object or material ID. Returns `a` or `b`,
|
|
17
|
+
* depending whose x-coord (dist) is smaller.
|
|
17
18
|
*
|
|
18
19
|
* @param a -
|
|
19
20
|
* @param b -
|