@thi.ng/shader-ast-stdlib 0.14.20 → 0.16.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-10-24T08:38:23Z
3
+ - **Last updated**: 2023-10-27T16:56:24Z
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,25 @@ 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.16.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.16.0) (2023-10-27)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add trunc(), modulo(), foldback01() ([d3ab3e6](https://github.com/thi-ng/umbrella/commit/d3ab3e6))
17
+
18
+ ## [0.15.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.15.0) (2023-10-25)
19
+
20
+ #### 🚀 Features
21
+
22
+ - add sdfPolyline2() ([4b6c6b7](https://github.com/thi-ng/umbrella/commit/4b6c6b7))
23
+ - add fitNorm() ([d5f21c5](https://github.com/thi-ng/umbrella/commit/d5f21c5))
24
+ - add isPointInCircle(), isPointInRect() ([de4b1ab](https://github.com/thi-ng/umbrella/commit/de4b1ab))
25
+ - add functionSampler() HOF plotting ([c6140b4](https://github.com/thi-ng/umbrella/commit/c6140b4))
26
+
27
+ #### ⏱ Performance improvements
28
+
29
+ - optimize aspectCorrectedUV2() ([733331a](https://github.com/thi-ng/umbrella/commit/733331a))
30
+
12
31
  ### [0.14.20](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.14.20) (2023-10-24)
13
32
 
14
33
  #### ♻️ 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 ~170) of useful functions & higher order
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: 12.62 KB
108
+ Package sizes (brotli'd, pre-treeshake): ESM: 13.42 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 | Live demo | Source |
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 | [Demo](https://demo.thi.ng/umbrella/ascii-raymarch/) | [Source](https://github.com/thi-ng/umbrella/tree/develop/examples/ascii-raymarch) |
124
- | <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) |
125
- | <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) |
126
- | <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) |
127
- | <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) |
128
- | <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) |
129
- | <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) |
130
- | <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) |
131
- | | 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) |
132
- | <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) |
133
- | <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) |
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";
@@ -17,6 +18,7 @@ export * from "./math/cross2.js";
17
18
  export * from "./math/dist-chebyshev.js";
18
19
  export * from "./math/dist-manhattan.js";
19
20
  export * from "./math/fit.js";
21
+ export * from "./math/interval.js";
20
22
  export * from "./math/magsq.js";
21
23
  export * from "./math/maxcomp.js";
22
24
  export * from "./math/mincomp.js";
@@ -59,6 +61,7 @@ export * from "./sdf/mirror.js";
59
61
  export * from "./sdf/plane.js";
60
62
  export * from "./sdf/polyhedra.js";
61
63
  export * from "./sdf/polygon.js";
64
+ export * from "./sdf/polyline.js";
62
65
  export * from "./sdf/repeat.js";
63
66
  export * from "./sdf/repeat-polar.js";
64
67
  export * from "./sdf/round.js";
@@ -74,4 +77,5 @@ export * from "./tex/blur.js";
74
77
  export * from "./tex/index-coord.js";
75
78
  export * from "./tex/index-uv.js";
76
79
  export * from "./tex/read-index.js";
80
+ export * from "./viz/function.js";
77
81
  //# 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";
@@ -17,6 +18,7 @@ export * from "./math/cross2.js";
17
18
  export * from "./math/dist-chebyshev.js";
18
19
  export * from "./math/dist-manhattan.js";
19
20
  export * from "./math/fit.js";
21
+ export * from "./math/interval.js";
20
22
  export * from "./math/magsq.js";
21
23
  export * from "./math/maxcomp.js";
22
24
  export * from "./math/mincomp.js";
@@ -59,6 +61,7 @@ export * from "./sdf/mirror.js";
59
61
  export * from "./sdf/plane.js";
60
62
  export * from "./sdf/polyhedra.js";
61
63
  export * from "./sdf/polygon.js";
64
+ export * from "./sdf/polyline.js";
62
65
  export * from "./sdf/repeat.js";
63
66
  export * from "./sdf/repeat-polar.js";
64
67
  export * from "./sdf/round.js";
@@ -74,3 +77,4 @@ export * from "./tex/blur.js";
74
77
  export * from "./tex/index-coord.js";
75
78
  export * from "./tex/index-uv.js";
76
79
  export * from "./tex/read-index.js";
80
+ export * from "./viz/function.js";
package/math/fit.d.ts CHANGED
@@ -8,6 +8,17 @@ import type { PrimTerm, Term, TermType } from "@thi.ng/shader-ast";
8
8
  * @param b -
9
9
  */
10
10
  export declare const fitNorm1: import("@thi.ng/shader-ast").TaggedFn3<"float", "float", "float", "float">;
11
+ /**
12
+ * Similar to {@link fitNorm1} but also for vector types and without checking if
13
+ * `a == b`. Scales value `x` from closed interval [a,b] to closed [0,1]
14
+ * interval. No clamping performed.
15
+ *
16
+ * @param x
17
+ * @param a
18
+ * @param b
19
+ * @returns
20
+ */
21
+ export declare const fitNorm: <T extends PrimTerm>(x: T, a: T, b: T) => Term<TermType<T>>;
11
22
  /**
12
23
  * Fits value `x` from closed interval [a,b] to closed interval [c,d]. No
13
24
  * clamping performed.
package/math/fit.js CHANGED
@@ -16,6 +16,17 @@ import { clamp01 } from "./clamp.js";
16
16
  export const fitNorm1 = defn(F, "fitNorm1", [F, F, F], (x, a, b) => [
17
17
  ret(ternary(neq(a, b), div(sub(x, a), sub(b, a)), FLOAT0)),
18
18
  ]);
19
+ /**
20
+ * Similar to {@link fitNorm1} but also for vector types and without checking if
21
+ * `a == b`. Scales value `x` from closed interval [a,b] to closed [0,1]
22
+ * interval. No clamping performed.
23
+ *
24
+ * @param x
25
+ * @param a
26
+ * @param b
27
+ * @returns
28
+ */
29
+ export const fitNorm = (x, a, b) => div(sub(x, a), sub(b, a));
19
30
  /**
20
31
  * Fits value `x` from closed interval [a,b] to closed interval [c,d]. No
21
32
  * clamping performed.
@@ -26,7 +37,7 @@ export const fitNorm1 = defn(F, "fitNorm1", [F, F, F], (x, a, b) => [
26
37
  * @param c -
27
38
  * @param d -
28
39
  */
29
- export const fit = (x, a, b, c, d) => mix(c, d, div(sub(x, a), sub(b, a)));
40
+ export const fit = (x, a, b, c, d) => mix(c, d, fitNorm(x, a, b));
30
41
  /**
31
42
  * Same as {@link fit}, but first clamps `x` to closed [a,b] interval.
32
43
  *
@@ -0,0 +1,17 @@
1
+ /**
2
+ * GLSL 100 trunc() polyfill.
3
+ */
4
+ export declare const trunc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
5
+ /**
6
+ * Returns `x - y * trunc(x / y)`, i.e. essentially the same as JS `%` operator.
7
+ * Result will always have the sign of `x`.
8
+ */
9
+ export declare const modulo: import("@thi.ng/shader-ast").TaggedFn2<"float", "float", "float">;
10
+ /**
11
+ * Same as thi.ng/math foldback01(). Folds `x` into the closed [0..1] interval,
12
+ * using infinite internal reflection on either side of the interval.
13
+ *
14
+ * @param x
15
+ */
16
+ export declare const foldback01: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
17
+ //# sourceMappingURL=interval.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
2
+ import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
3
+ import { defn, ret } from "@thi.ng/shader-ast/ast/function";
4
+ import { FLOAT0, FLOAT1, FLOAT2 } from "@thi.ng/shader-ast/ast/lit";
5
+ import { div, lt, mul, sub } from "@thi.ng/shader-ast/ast/ops";
6
+ import { sym } from "@thi.ng/shader-ast/ast/sym";
7
+ import { abs, ceil, floor, mix, mod, step, } from "@thi.ng/shader-ast/builtin/math";
8
+ /**
9
+ * GLSL 100 trunc() polyfill.
10
+ */
11
+ export const trunc = defn(F, null, [F], (x) => [
12
+ ret(ternary(lt(x, FLOAT0), ceil(x), floor(x))),
13
+ ]);
14
+ /**
15
+ * Returns `x - y * trunc(x / y)`, i.e. essentially the same as JS `%` operator.
16
+ * Result will always have the sign of `x`.
17
+ */
18
+ export const modulo = defn(F, null, [F, F], (x, y) => [
19
+ ret(sub(x, mul(y, trunc(div(x, y))))),
20
+ ]);
21
+ /**
22
+ * Same as thi.ng/math foldback01(). Folds `x` into the closed [0..1] interval,
23
+ * using infinite internal reflection on either side of the interval.
24
+ *
25
+ * @param x
26
+ */
27
+ export const foldback01 = defn(F, null, [F], (x) => {
28
+ let y;
29
+ return [
30
+ (y = sym(mod(abs(x), FLOAT2))),
31
+ ret(mix(y, sub(FLOAT2, y), step(FLOAT1, y))),
32
+ ];
33
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/shader-ast-stdlib",
3
- "version": "0.14.20",
3
+ "version": "0.16.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.74"
41
+ "@thi.ng/shader-ast": "^0.12.76"
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
  },
@@ -159,6 +162,9 @@
159
162
  "./math/fit": {
160
163
  "default": "./math/fit.js"
161
164
  },
165
+ "./math/interval": {
166
+ "default": "./math/interval.js"
167
+ },
162
168
  "./math/magsq": {
163
169
  "default": "./math/magsq.js"
164
170
  },
@@ -285,6 +291,9 @@
285
291
  "./sdf/polyhedra": {
286
292
  "default": "./sdf/polyhedra.js"
287
293
  },
294
+ "./sdf/polyline": {
295
+ "default": "./sdf/polyline.js"
296
+ },
288
297
  "./sdf/repeat-polar": {
289
298
  "default": "./sdf/repeat-polar.js"
290
299
  },
@@ -329,6 +338,9 @@
329
338
  },
330
339
  "./tex/read-index": {
331
340
  "default": "./tex/read-index.js"
341
+ },
342
+ "./viz/function": {
343
+ "default": "./viz/function.js"
332
344
  }
333
345
  },
334
346
  "thi.ng": {
@@ -340,5 +352,5 @@
340
352
  ],
341
353
  "year": 2019
342
354
  },
343
- "gitHead": "dc7eeaba72f3c3977f2d6cc201e595ed6d68e2ad\n"
355
+ "gitHead": "502e8fa937677ff7bc4fbd0906d8c8b4b0b471e5\n"
344
356
  }
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 res - vec2
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 { $x, $xy, $y } from "@thi.ng/shader-ast/ast/swizzle";
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 res - vec2
20
+ * @param resolution - vec2
24
21
  */
25
- export const aspectCorrectedUV = defn(V2, "aspectCorrectedUV", [V2, V2], (pos, res) => {
26
- let uv;
27
- return [
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]).
@@ -0,0 +1,2 @@
1
+ export declare const sdfPolyline2: (N: number) => import("@thi.ng/shader-ast").TaggedFn2<"vec2", "vec2[]", "float">;
2
+ //# sourceMappingURL=polyline.d.ts.map
@@ -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
+ });