@thi.ng/shader-ast-stdlib 0.14.20 → 0.15.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 +14 -1
- package/README.md +34 -15
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/math/fit.d.ts +10 -0
- package/math/fit.js +11 -1
- package/package.json +12 -3
- package/screen/uv.d.ts +1 -1
- package/screen/uv.js +6 -14
- package/sdf/polyline.d.ts +2 -0
- package/sdf/polyline.js +20 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2023-10-
|
|
3
|
+
- **Last updated**: 2023-10-25T12:40:55Z
|
|
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.15.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.15.0) (2023-10-25)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- add sdfPolyline2() ([4b6c6b7](https://github.com/thi-ng/umbrella/commit/4b6c6b7))
|
|
17
|
+
- add fitNorm() ([d5f21c5](https://github.com/thi-ng/umbrella/commit/d5f21c5))
|
|
18
|
+
- add isPointInCircle(), isPointInRect() ([de4b1ab](https://github.com/thi-ng/umbrella/commit/de4b1ab))
|
|
19
|
+
- add functionSampler() HOF plotting ([c6140b4](https://github.com/thi-ng/umbrella/commit/c6140b4))
|
|
20
|
+
|
|
21
|
+
#### ⏱ Performance improvements
|
|
22
|
+
|
|
23
|
+
- optimize aspectCorrectedUV2() ([733331a](https://github.com/thi-ng/umbrella/commit/733331a))
|
|
24
|
+
|
|
12
25
|
### [0.14.20](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.14.20) (2023-10-24)
|
|
13
26
|
|
|
14
27
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ This project is part of the
|
|
|
25
25
|
- [Color](#color)
|
|
26
26
|
- [Porter-Duff alpha blending](#porter-duff-alpha-blending)
|
|
27
27
|
- [Fog](#fog)
|
|
28
|
+
- [Intersection tests](#intersection-tests)
|
|
28
29
|
- [Lighting](#lighting)
|
|
29
30
|
- [Math](#math)
|
|
30
31
|
- [Easing functions](#easing-functions)
|
|
@@ -38,6 +39,7 @@ This project is part of the
|
|
|
38
39
|
- [Polyhedra](#polyhedra)
|
|
39
40
|
- [Operators / combinators](#operators--combinators)
|
|
40
41
|
- [Texture lookups](#texture-lookups)
|
|
42
|
+
- [Visualization](#visualization)
|
|
41
43
|
- [Authors](#authors)
|
|
42
44
|
- [License](#license)
|
|
43
45
|
|
|
@@ -45,7 +47,7 @@ This project is part of the
|
|
|
45
47
|
|
|
46
48
|
Function collection for modular GPGPU / shader programming with [@thi.ng/shader-ast](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast).
|
|
47
49
|
|
|
48
|
-
A growing collection (currently ~
|
|
50
|
+
A growing collection (currently ~225) of useful functions & higher order
|
|
49
51
|
constructs (incl. meta programming approaches) for GPU / shader programming,
|
|
50
52
|
acting as optional standard library for
|
|
51
53
|
[@thi.ng/shader-ast](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast)
|
|
@@ -103,7 +105,7 @@ For Node.js REPL:
|
|
|
103
105
|
const shaderAstStdlib = await import("@thi.ng/shader-ast-stdlib");
|
|
104
106
|
```
|
|
105
107
|
|
|
106
|
-
Package sizes (brotli'd, pre-treeshake): ESM:
|
|
108
|
+
Package sizes (brotli'd, pre-treeshake): ESM: 13.20 KB
|
|
107
109
|
|
|
108
110
|
## Dependencies
|
|
109
111
|
|
|
@@ -118,19 +120,20 @@ directory are using this package.
|
|
|
118
120
|
|
|
119
121
|
A selection:
|
|
120
122
|
|
|
121
|
-
| Screenshot | Description
|
|
122
|
-
|
|
123
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ascii-raymarch.jpg" width="240"/> | ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvas
|
|
124
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/shader-ast/shader-ast-01.jpg" width="240"/> | 2D canvas shader emulation
|
|
125
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-
|
|
126
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-
|
|
127
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/
|
|
128
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/
|
|
129
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-
|
|
130
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-
|
|
131
|
-
|
|
|
132
|
-
|
|
|
133
|
-
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-
|
|
123
|
+
| Screenshot | Description | Live demo | Source |
|
|
124
|
+
|:-----------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------|:----------------------------------------------------------|:---------------------------------------------------------------------------------------|
|
|
125
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/ascii-raymarch.jpg" width="240"/> | ASCII art raymarching with thi.ng/shader-ast & thi.ng/text-canvas | [Demo](https://demo.thi.ng/umbrella/ascii-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ascii-raymarch) |
|
|
126
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/shader-ast/shader-ast-01.jpg" width="240"/> | 2D canvas shader emulation | [Demo](https://demo.thi.ng/umbrella/shader-ast-canvas2d/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-canvas2d) |
|
|
127
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-easings.png" width="240"/> | Shader-AST meta-programming techniques for animated function plots | [Demo](https://demo.thi.ng/umbrella/shader-ast-easings/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-easings) |
|
|
128
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-evo.jpg" width="240"/> | Evolutionary shader generation using genetic programming | [Demo](https://demo.thi.ng/umbrella/shader-ast-evo/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-evo) |
|
|
129
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-noise.jpg" width="240"/> | HOF shader procedural noise function composition | [Demo](https://demo.thi.ng/umbrella/shader-ast-noise/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-noise) |
|
|
130
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/shader-ast/shader-ast-raymarch.jpg" width="240"/> | WebGL & JS canvas2D raymarch shader cross-compilation | [Demo](https://demo.thi.ng/umbrella/shader-ast-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-raymarch) |
|
|
131
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-sdf2d.jpg" width="240"/> | WebGL & JS canvas 2D SDF | [Demo](https://demo.thi.ng/umbrella/shader-ast-sdf2d/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-sdf2d) |
|
|
132
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-tunnel.jpg" width="240"/> | WebGL & Canvas2D textured tunnel shader | [Demo](https://demo.thi.ng/umbrella/shader-ast-tunnel/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-tunnel) |
|
|
133
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/shader-ast-workers.jpg" width="240"/> | Fork-join worker-based raymarch renderer (JS/CPU only) | [Demo](https://demo.thi.ng/umbrella/shader-ast-workers/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/shader-ast-workers) |
|
|
134
|
+
| | Minimal multi-pass / GPGPU example | [Demo](https://demo.thi.ng/umbrella/webgl-multipass/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-multipass) |
|
|
135
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-shadertoy.jpg" width="240"/> | Shadertoy-like WebGL setup | [Demo](https://demo.thi.ng/umbrella/webgl-shadertoy/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-shadertoy) |
|
|
136
|
+
| <img src="https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/webgl-ssao.jpg" width="240"/> | WebGL screenspace ambient occlusion | [Demo](https://demo.thi.ng/umbrella/webgl-ssao/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/webgl-ssao) |
|
|
134
137
|
|
|
135
138
|
## API
|
|
136
139
|
|
|
@@ -362,6 +365,13 @@ for reference.
|
|
|
362
365
|
- `fogExp`
|
|
363
366
|
- `fogExp2`
|
|
364
367
|
|
|
368
|
+
### Intersection tests
|
|
369
|
+
|
|
370
|
+
[/src/isec](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/isec/)
|
|
371
|
+
|
|
372
|
+
- `isPointInCircle`
|
|
373
|
+
- `isPointInRect`
|
|
374
|
+
|
|
365
375
|
### Lighting
|
|
366
376
|
|
|
367
377
|
[/src/light](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/light/)
|
|
@@ -469,6 +479,8 @@ for reference.
|
|
|
469
479
|
- `sdfLine3`
|
|
470
480
|
- `sdfPlane2`
|
|
471
481
|
- `sdfPlane3`
|
|
482
|
+
- `sdfPolygon2`
|
|
483
|
+
- `sdfPolyline2`
|
|
472
484
|
- `sdfQuadratic2`
|
|
473
485
|
- `sdfSphere`
|
|
474
486
|
- `sdfTorus`
|
|
@@ -505,6 +517,13 @@ for reference.
|
|
|
505
517
|
- `indexToUV` / `uvToIndex`
|
|
506
518
|
- `readIndex1` / `readIndex2` / `readIndex3` / `readIndex4`
|
|
507
519
|
|
|
520
|
+
### Visualization
|
|
521
|
+
|
|
522
|
+
[/src/viz](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/viz/)
|
|
523
|
+
|
|
524
|
+
- `functionDomainMapper`
|
|
525
|
+
- `functionSampler`
|
|
526
|
+
|
|
508
527
|
## Authors
|
|
509
528
|
|
|
510
529
|
- [Karsten Schmidt](https://thi.ng) (Main author)
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./color/rgbe.js";
|
|
|
8
8
|
export * from "./fog/exp.js";
|
|
9
9
|
export * from "./fog/exp2.js";
|
|
10
10
|
export * from "./fog/linear.js";
|
|
11
|
+
export * from "./isec/point.js";
|
|
11
12
|
export * from "./light/lambert.js";
|
|
12
13
|
export * from "./light/trilight.js";
|
|
13
14
|
export * from "./math/additive.js";
|
|
@@ -59,6 +60,7 @@ export * from "./sdf/mirror.js";
|
|
|
59
60
|
export * from "./sdf/plane.js";
|
|
60
61
|
export * from "./sdf/polyhedra.js";
|
|
61
62
|
export * from "./sdf/polygon.js";
|
|
63
|
+
export * from "./sdf/polyline.js";
|
|
62
64
|
export * from "./sdf/repeat.js";
|
|
63
65
|
export * from "./sdf/repeat-polar.js";
|
|
64
66
|
export * from "./sdf/round.js";
|
|
@@ -74,4 +76,5 @@ export * from "./tex/blur.js";
|
|
|
74
76
|
export * from "./tex/index-coord.js";
|
|
75
77
|
export * from "./tex/index-uv.js";
|
|
76
78
|
export * from "./tex/read-index.js";
|
|
79
|
+
export * from "./viz/function.js";
|
|
77
80
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./color/rgbe.js";
|
|
|
8
8
|
export * from "./fog/exp.js";
|
|
9
9
|
export * from "./fog/exp2.js";
|
|
10
10
|
export * from "./fog/linear.js";
|
|
11
|
+
export * from "./isec/point.js";
|
|
11
12
|
export * from "./light/lambert.js";
|
|
12
13
|
export * from "./light/trilight.js";
|
|
13
14
|
export * from "./math/additive.js";
|
|
@@ -59,6 +60,7 @@ export * from "./sdf/mirror.js";
|
|
|
59
60
|
export * from "./sdf/plane.js";
|
|
60
61
|
export * from "./sdf/polyhedra.js";
|
|
61
62
|
export * from "./sdf/polygon.js";
|
|
63
|
+
export * from "./sdf/polyline.js";
|
|
62
64
|
export * from "./sdf/repeat.js";
|
|
63
65
|
export * from "./sdf/repeat-polar.js";
|
|
64
66
|
export * from "./sdf/round.js";
|
|
@@ -74,3 +76,4 @@ export * from "./tex/blur.js";
|
|
|
74
76
|
export * from "./tex/index-coord.js";
|
|
75
77
|
export * from "./tex/index-uv.js";
|
|
76
78
|
export * from "./tex/read-index.js";
|
|
79
|
+
export * from "./viz/function.js";
|
package/math/fit.d.ts
CHANGED
|
@@ -19,6 +19,16 @@ export declare const fitNorm1: import("@thi.ng/shader-ast").TaggedFn3<"float", "
|
|
|
19
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
|
+
/**
|
|
23
|
+
* Scales value `x` from closed interval [a,b] to closed [0,1] interval. No
|
|
24
|
+
* clamping performed.
|
|
25
|
+
*
|
|
26
|
+
* @param x
|
|
27
|
+
* @param a
|
|
28
|
+
* @param b
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare const fitNorm: <T extends PrimTerm>(x: T, a: T, b: T) => Term<TermType<T>>;
|
|
22
32
|
/**
|
|
23
33
|
* Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
|
|
24
34
|
*
|
package/math/fit.js
CHANGED
|
@@ -26,7 +26,17 @@ export const fitNorm1 = defn(F, "fitNorm1", [F, F, F], (x, a, b) => [
|
|
|
26
26
|
* @param c -
|
|
27
27
|
* @param d -
|
|
28
28
|
*/
|
|
29
|
-
export const fit = (x, a, b, c, d) => mix(c, d,
|
|
29
|
+
export const fit = (x, a, b, c, d) => mix(c, d, fitNorm(x, a, b));
|
|
30
|
+
/**
|
|
31
|
+
* Scales value `x` from closed interval [a,b] to closed [0,1] interval. No
|
|
32
|
+
* clamping performed.
|
|
33
|
+
*
|
|
34
|
+
* @param x
|
|
35
|
+
* @param a
|
|
36
|
+
* @param b
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export const fitNorm = (x, a, b) => div(sub(x, a), sub(b, a));
|
|
30
40
|
/**
|
|
31
41
|
* Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
|
|
32
42
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/shader-ast-stdlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@thi.ng/api": "^8.9.6",
|
|
41
|
-
"@thi.ng/shader-ast": "^0.12.
|
|
41
|
+
"@thi.ng/shader-ast": "^0.12.75"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@microsoft/api-extractor": "^7.38.0",
|
|
@@ -129,6 +129,9 @@
|
|
|
129
129
|
"./fog/linear": {
|
|
130
130
|
"default": "./fog/linear.js"
|
|
131
131
|
},
|
|
132
|
+
"./isec/point": {
|
|
133
|
+
"default": "./isec/point.js"
|
|
134
|
+
},
|
|
132
135
|
"./light/lambert": {
|
|
133
136
|
"default": "./light/lambert.js"
|
|
134
137
|
},
|
|
@@ -285,6 +288,9 @@
|
|
|
285
288
|
"./sdf/polyhedra": {
|
|
286
289
|
"default": "./sdf/polyhedra.js"
|
|
287
290
|
},
|
|
291
|
+
"./sdf/polyline": {
|
|
292
|
+
"default": "./sdf/polyline.js"
|
|
293
|
+
},
|
|
288
294
|
"./sdf/repeat-polar": {
|
|
289
295
|
"default": "./sdf/repeat-polar.js"
|
|
290
296
|
},
|
|
@@ -329,6 +335,9 @@
|
|
|
329
335
|
},
|
|
330
336
|
"./tex/read-index": {
|
|
331
337
|
"default": "./tex/read-index.js"
|
|
338
|
+
},
|
|
339
|
+
"./viz/function": {
|
|
340
|
+
"default": "./viz/function.js"
|
|
332
341
|
}
|
|
333
342
|
},
|
|
334
343
|
"thi.ng": {
|
|
@@ -340,5 +349,5 @@
|
|
|
340
349
|
],
|
|
341
350
|
"year": 2019
|
|
342
351
|
},
|
|
343
|
-
"gitHead": "
|
|
352
|
+
"gitHead": "fc6e14052ed24bf9196896980ceb9f398b6ea6c1\n"
|
|
344
353
|
}
|
package/screen/uv.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare const fragUV: (fragCoord: Vec4Term, res: Vec2Term) => import("@th
|
|
|
12
12
|
* scaled by the aspect ratio `resx / resy`.
|
|
13
13
|
*
|
|
14
14
|
* @param fragCoord - vec2
|
|
15
|
-
* @param
|
|
15
|
+
* @param resolution - vec2
|
|
16
16
|
*/
|
|
17
17
|
export declare const aspectCorrectedUV: import("@thi.ng/shader-ast").TaggedFn2<"vec2", "vec2", "vec2">;
|
|
18
18
|
/**
|
package/screen/uv.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { F, V2 } from "@thi.ng/shader-ast/api/types";
|
|
2
|
-
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
3
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
4
3
|
import { VEC2_1, bvec4, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
5
|
-
import { add, div, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
6
|
-
import { $
|
|
7
|
-
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
4
|
+
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
5
|
+
import { $xy, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
8
6
|
import { _any, greaterThan, lessThan } from "@thi.ng/shader-ast/builtin/bvec";
|
|
9
|
-
import { fit0111 } from "../math/fit.js";
|
|
10
7
|
/**
|
|
11
8
|
* Computes UV coord in [0..1] interval from given `fragCoord` and screen `res`.
|
|
12
9
|
*
|
|
@@ -20,16 +17,11 @@ export const fragUV = (fragCoord, res) => div($xy(fragCoord), res);
|
|
|
20
17
|
* scaled by the aspect ratio `resx / resy`.
|
|
21
18
|
*
|
|
22
19
|
* @param fragCoord - vec2
|
|
23
|
-
* @param
|
|
20
|
+
* @param resolution - vec2
|
|
24
21
|
*/
|
|
25
|
-
export const aspectCorrectedUV = defn(V2, "
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(uv = sym(fit0111(div(pos, res)))),
|
|
29
|
-
assign($x(uv), mul($x(uv), div($x(res), $y(res)))),
|
|
30
|
-
ret(uv),
|
|
31
|
-
];
|
|
32
|
-
});
|
|
22
|
+
export const aspectCorrectedUV = defn(V2, "aspectCorrectedUV2", [V2, V2], (fragCoord, resolution) => [
|
|
23
|
+
ret(div(sub(mul(2, fragCoord), resolution), $y(resolution))),
|
|
24
|
+
]);
|
|
33
25
|
/**
|
|
34
26
|
* Returns true if at least one coordinate of the given point is within the
|
|
35
27
|
* `width` internal border region of UV rect ([0,0] .. [1,1]).
|
package/sdf/polyline.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { F, V2 } from "@thi.ng/shader-ast/api/types";
|
|
2
|
+
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
3
|
+
import { forLoop } from "@thi.ng/shader-ast/ast/controlflow";
|
|
4
|
+
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
5
|
+
import { index } from "@thi.ng/shader-ast/ast/indexed";
|
|
6
|
+
import { INT0, float, int } from "@thi.ng/shader-ast/ast/lit";
|
|
7
|
+
import { add, inc, lt } from "@thi.ng/shader-ast/ast/ops";
|
|
8
|
+
import { sym } from "@thi.ng/shader-ast/ast/sym";
|
|
9
|
+
import { min } from "@thi.ng/shader-ast/builtin/math";
|
|
10
|
+
import { sdfLine2 } from "./line.js";
|
|
11
|
+
export const sdfPolyline2 = (N) => defn(F, `sdfPolyline2_${N}`, [V2, ["vec2[]", "pts", { num: N }]], (p, pts) => {
|
|
12
|
+
let minD;
|
|
13
|
+
return [
|
|
14
|
+
(minD = sym(float(1e6))),
|
|
15
|
+
forLoop(sym(INT0), (i) => lt(i, int(N - 1)), inc, (i) => [
|
|
16
|
+
assign(minD, min(minD, sdfLine2(p, index(pts, i), index(pts, add(i, 1))))),
|
|
17
|
+
]),
|
|
18
|
+
ret(minD),
|
|
19
|
+
];
|
|
20
|
+
});
|