@thi.ng/shader-ast-stdlib 0.14.19 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-10-23T07:37:37Z
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,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.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
+
25
+ ### [0.14.20](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.14.20) (2023-10-24)
26
+
27
+ #### ♻️ Refactoring
28
+
29
+ - use hoc function to define easing functions ([2b2c451](https://github.com/thi-ng/umbrella/commit/2b2c451))
30
+
12
31
  ## [0.14.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/shader-ast-stdlib@0.14.0) (2023-07-14)
13
32
 
14
33
  #### 🚀 Features
package/README.md CHANGED
@@ -25,8 +25,10 @@ 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)
31
+ - [Easing functions](#easing-functions)
30
32
  - [Oscillators](#oscillators)
31
33
  - [Matrix operations](#matrix-operations)
32
34
  - [Noise / randomness](#noise--randomness)
@@ -37,6 +39,7 @@ This project is part of the
37
39
  - [Polyhedra](#polyhedra)
38
40
  - [Operators / combinators](#operators--combinators)
39
41
  - [Texture lookups](#texture-lookups)
42
+ - [Visualization](#visualization)
40
43
  - [Authors](#authors)
41
44
  - [License](#license)
42
45
 
@@ -44,7 +47,7 @@ This project is part of the
44
47
 
45
48
  Function collection for modular GPGPU / shader programming with [@thi.ng/shader-ast](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast).
46
49
 
47
- A growing collection (currently ~170) of useful functions & higher order
50
+ A growing collection (currently ~225) of useful functions & higher order
48
51
  constructs (incl. meta programming approaches) for GPU / shader programming,
49
52
  acting as optional standard library for
50
53
  [@thi.ng/shader-ast](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast)
@@ -102,7 +105,7 @@ For Node.js REPL:
102
105
  const shaderAstStdlib = await import("@thi.ng/shader-ast-stdlib");
103
106
  ```
104
107
 
105
- Package sizes (brotli'd, pre-treeshake): ESM: 11.82 KB
108
+ Package sizes (brotli'd, pre-treeshake): ESM: 13.20 KB
106
109
 
107
110
  ## Dependencies
108
111
 
@@ -117,19 +120,20 @@ directory are using this package.
117
120
 
118
121
  A selection:
119
122
 
120
- | Screenshot | Description | Live demo | Source |
121
- |:-----------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------|:----------------------------------------------------------|:---------------------------------------------------------------------------------------|
122
- | <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) |
123
- | <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) |
124
- | <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) |
125
- | <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) |
126
- | <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) |
127
- | <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) |
128
- | <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) |
129
- | <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) |
130
- | | 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) |
131
- | <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) |
132
- | <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) |
133
137
 
134
138
  ## API
135
139
 
@@ -361,6 +365,13 @@ for reference.
361
365
  - `fogExp`
362
366
  - `fogExp2`
363
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
+
364
375
  ### Lighting
365
376
 
366
377
  [/src/light](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/light/)
@@ -391,6 +402,21 @@ for reference.
391
402
  - `smootherStep` / `smootherStep2` / `smootherStep3` / `smootherStep4`
392
403
  - `smootherStep01` / `smootherStep01_2` / `smootherStep01_3` / `smootherStep01_4`
393
404
 
405
+ ### Easing functions
406
+
407
+ [/src/math/easing.ts](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/math/easing.ts)
408
+
409
+ - `easeInBack` / `easeOutBack` / `easeInOutBack`
410
+ - `easeInBounce` / `easeOutBounce` / `easeInOutBounce`
411
+ - `easeInCirc` / `easeOutCirc` / `easeInOutCirc`
412
+ - `easeInCubic` / `easeOutCubic` / `easeInOutCubic`
413
+ - `easeInElastic` / `easeOutElastic` / `easeInOutElastic`
414
+ - `easeInExpo` / `easeOutExpo` / `easeInOutExpo`
415
+ - `easeInQuad` / `easeOutQuad` / `easeInOutQuad`
416
+ - `easeInQuart` / `easeOutQuart` / `easeInOutQuart`
417
+ - `easeInQuint` / `easeOutQuint` / `easeInOutQuint`
418
+ - `easeInSine` / `easeOutSine` / `easeInOutSine`
419
+
394
420
  ### Oscillators
395
421
 
396
422
  [/src/math](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-stdlib/src/math/osc.ts)
@@ -453,6 +479,8 @@ for reference.
453
479
  - `sdfLine3`
454
480
  - `sdfPlane2`
455
481
  - `sdfPlane3`
482
+ - `sdfPolygon2`
483
+ - `sdfPolyline2`
456
484
  - `sdfQuadratic2`
457
485
  - `sdfSphere`
458
486
  - `sdfTorus`
@@ -489,16 +517,24 @@ for reference.
489
517
  - `indexToUV` / `uvToIndex`
490
518
  - `readIndex1` / `readIndex2` / `readIndex3` / `readIndex4`
491
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
+
492
527
  ## Authors
493
528
 
494
- - [Karsten Schmidt](https://thi.ng)
529
+ - [Karsten Schmidt](https://thi.ng) (Main author)
530
+ - [Yury Hantsouski](https://github.com/Hantsouski)
495
531
 
496
532
  If this project contributes to an academic publication, please cite it as:
497
533
 
498
534
  ```bibtex
499
535
  @misc{thing-shader-ast-stdlib,
500
536
  title = "@thi.ng/shader-ast-stdlib",
501
- author = "Karsten Schmidt",
537
+ author = "Karsten Schmidt and others",
502
538
  note = "https://thi.ng/shader-ast-stdlib",
503
539
  year = 2019
504
540
  }
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";
@@ -27,6 +28,7 @@ export * from "./math/osc.js";
27
28
  export * from "./math/polar.js";
28
29
  export * from "./math/sincos.js";
29
30
  export * from "./math/smoother-step.js";
31
+ export * from "./math/easing.js";
30
32
  export * from "./matrix/lookat.js";
31
33
  export * from "./matrix/mvp.js";
32
34
  export * from "./matrix/normal.js";
@@ -58,6 +60,7 @@ export * from "./sdf/mirror.js";
58
60
  export * from "./sdf/plane.js";
59
61
  export * from "./sdf/polyhedra.js";
60
62
  export * from "./sdf/polygon.js";
63
+ export * from "./sdf/polyline.js";
61
64
  export * from "./sdf/repeat.js";
62
65
  export * from "./sdf/repeat-polar.js";
63
66
  export * from "./sdf/round.js";
@@ -73,4 +76,5 @@ export * from "./tex/blur.js";
73
76
  export * from "./tex/index-coord.js";
74
77
  export * from "./tex/index-uv.js";
75
78
  export * from "./tex/read-index.js";
79
+ export * from "./viz/function.js";
76
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";
@@ -27,6 +28,7 @@ export * from "./math/osc.js";
27
28
  export * from "./math/polar.js";
28
29
  export * from "./math/sincos.js";
29
30
  export * from "./math/smoother-step.js";
31
+ export * from "./math/easing.js";
30
32
  export * from "./matrix/lookat.js";
31
33
  export * from "./matrix/mvp.js";
32
34
  export * from "./matrix/normal.js";
@@ -58,6 +60,7 @@ export * from "./sdf/mirror.js";
58
60
  export * from "./sdf/plane.js";
59
61
  export * from "./sdf/polyhedra.js";
60
62
  export * from "./sdf/polygon.js";
63
+ export * from "./sdf/polyline.js";
61
64
  export * from "./sdf/repeat.js";
62
65
  export * from "./sdf/repeat-polar.js";
63
66
  export * from "./sdf/round.js";
@@ -73,3 +76,4 @@ export * from "./tex/blur.js";
73
76
  export * from "./tex/index-coord.js";
74
77
  export * from "./tex/index-uv.js";
75
78
  export * from "./tex/read-index.js";
79
+ export * from "./viz/function.js";
@@ -0,0 +1,39 @@
1
+ import type { FnBody1 } from "@thi.ng/shader-ast";
2
+ /**
3
+ * Higher order helper function to wrap a given easing function body as proper
4
+ * shader-ast function.
5
+ *
6
+ * @param body
7
+ */
8
+ export declare const defEasing: (body: FnBody1<"float">) => import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
9
+ export declare const easeInSine: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
10
+ export declare const easeOutSine: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
11
+ export declare const easeInOutSine: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
12
+ export declare const easeInQuad: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
13
+ export declare const easeOutQuad: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
14
+ export declare const easeInOutQuad: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
15
+ export declare const easeInCubic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
16
+ export declare const easeOutCubic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
17
+ export declare const easeInOutCubic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
18
+ export declare const easeInQuart: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
19
+ export declare const easeOutQuart: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
20
+ export declare const easeInOutQuart: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
21
+ export declare const easeInQuint: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
22
+ export declare const easeOutQuint: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
23
+ export declare const easeInOutQuint: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
24
+ export declare const easeInExpo: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
25
+ export declare const easeOutExpo: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
26
+ export declare const easeInOutExpo: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
27
+ export declare const easeInCirc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
28
+ export declare const easeOutCirc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
29
+ export declare const easeInOutCirc: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
30
+ export declare const easeInBack: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
31
+ export declare const easeOutBack: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
32
+ export declare const easeInOutBack: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
33
+ export declare const easeInElastic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
34
+ export declare const easeOutElastic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
35
+ export declare const easeInOutElastic: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
36
+ export declare const easeOutBounce: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
37
+ export declare const easeInBounce: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
38
+ export declare const easeInOutBounce: import("@thi.ng/shader-ast").TaggedFn1<"float", "float">;
39
+ //# sourceMappingURL=easing.d.ts.map
package/math/easing.js ADDED
@@ -0,0 +1,117 @@
1
+ import { F } from "@thi.ng/shader-ast/api/types";
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, FLOAT1, FLOAT2, HALF_PI, PI, TAU, float, } from "@thi.ng/shader-ast/ast/lit";
5
+ import { add, div, eq, gte, lt, lte, madd, mul, neg, reciprocal, sub, } from "@thi.ng/shader-ast/ast/ops";
6
+ import { cos, exp2, pow, sin, sqrt } from "@thi.ng/shader-ast/builtin/math";
7
+ /**
8
+ * Higher order helper function to wrap a given easing function body as proper
9
+ * shader-ast function.
10
+ *
11
+ * @param body
12
+ */
13
+ export const defEasing = (body) => defn(F, null, [F], body);
14
+ export const easeInSine = defEasing((x) => [
15
+ ret(sub(FLOAT1, cos(mul(x, HALF_PI)))),
16
+ ]);
17
+ export const easeOutSine = defEasing((x) => [ret(sin(mul(x, HALF_PI)))]);
18
+ export const easeInOutSine = defEasing((x) => [
19
+ ret(div(neg(sub(cos(mul(PI, x)), FLOAT1)), FLOAT2)),
20
+ ]);
21
+ export const easeInQuad = defEasing((x) => [ret(pow(x, FLOAT2))]);
22
+ export const easeOutQuad = defEasing((x) => [
23
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), FLOAT2))),
24
+ ]);
25
+ export const easeInOutQuad = defEasing((x) => [
26
+ ret(ternary(lt(x, FLOAT05), mul(FLOAT2, pow(x, FLOAT2)), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2), FLOAT2)))),
27
+ ]);
28
+ export const easeInCubic = defEasing((x) => [ret(pow(x, float(3)))]);
29
+ export const easeOutCubic = defEasing((x) => [
30
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(3)))),
31
+ ]);
32
+ export const easeInOutCubic = defEasing((x) => [
33
+ ret(ternary(lt(x, FLOAT05), mul(float(4), pow(x, float(3))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(3)), FLOAT2)))),
34
+ ]);
35
+ export const easeInQuart = defEasing((x) => [ret(pow(x, float(4)))]);
36
+ export const easeOutQuart = defEasing((x) => [
37
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(4)))),
38
+ ]);
39
+ export const easeInOutQuart = defEasing((x) => [
40
+ ret(ternary(lt(x, FLOAT05), mul(float(8), pow(x, float(4))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(4)), FLOAT2)))),
41
+ ]);
42
+ export const easeInQuint = defEasing((x) => [ret(pow(x, float(5)))]);
43
+ export const easeOutQuint = defEasing((x) => [
44
+ ret(sub(FLOAT1, pow(sub(FLOAT1, x), float(5)))),
45
+ ]);
46
+ export const easeInOutQuint = defEasing((x) => [
47
+ ret(ternary(lt(x, FLOAT05), mul(float(16), pow(x, float(5))), sub(FLOAT1, div(pow(madd(neg(FLOAT2), x, FLOAT2), float(5)), FLOAT2)))),
48
+ ]);
49
+ export const easeInExpo = defEasing((x) => [
50
+ ret(ternary(eq(x, FLOAT0), FLOAT0, exp2(sub(mul(float(10), x), float(10))))),
51
+ ]);
52
+ export const easeOutExpo = defEasing((x) => [
53
+ ret(ternary(eq(x, FLOAT1), FLOAT1, sub(FLOAT1, exp2(mul(neg(float(10)), x))))),
54
+ ]);
55
+ export const easeInOutExpo = defEasing((x) => [
56
+ ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, ternary(lt(x, FLOAT05), div(exp2(sub(mul(float(20), x), float(10))), FLOAT2), div(sub(FLOAT2, exp2(madd(neg(float(20)), x, float(10)))), FLOAT2))))),
57
+ ]);
58
+ export const easeInCirc = defEasing((x) => [
59
+ ret(sub(FLOAT1, sqrt(sub(FLOAT1, pow(x, FLOAT2))))),
60
+ ]);
61
+ export const easeOutCirc = defEasing((x) => [
62
+ ret(sqrt(sub(FLOAT1, pow(sub(x, FLOAT1), FLOAT2)))),
63
+ ]);
64
+ export const easeInOutCirc = defEasing((x) => [
65
+ ret(ternary(lt(x, FLOAT05), div(sub(FLOAT1, sqrt(sub(FLOAT1, pow(mul(FLOAT2, x), FLOAT2)))), FLOAT2), div(add(sqrt(sub(FLOAT1, pow(madd(neg(FLOAT2), x, FLOAT2), FLOAT2))), FLOAT1), FLOAT2))),
66
+ ]);
67
+ export const easeInBack = defEasing((x) => {
68
+ const c1 = 1.70158;
69
+ const c3 = c1 + 1;
70
+ return [ret(sub(mul(c3, pow(x, float(3))), mul(c1, pow(x, FLOAT2))))];
71
+ });
72
+ export const easeOutBack = defEasing((x) => {
73
+ const c1 = 1.70158;
74
+ const c3 = c1 + 1;
75
+ return [
76
+ ret(add(madd(float(c3), pow(sub(x, FLOAT1), float(3)), FLOAT1), mul(c1, pow(sub(x, FLOAT1), FLOAT2)))),
77
+ ];
78
+ });
79
+ export const easeInOutBack = defEasing((x) => {
80
+ const c1 = 1.70158;
81
+ const c2 = c1 * 1.525;
82
+ return [
83
+ ret(ternary(lt(x, FLOAT05), div(mul(pow(mul(FLOAT2, x), FLOAT2), sub(mul(mul(add(c2, FLOAT1), FLOAT2), x), c2)), FLOAT2), div(add(mul(pow(sub(mul(FLOAT2, x), FLOAT2), FLOAT2), add(mul(add(c2, FLOAT1), sub(mul(x, FLOAT2), FLOAT2)), c2)), FLOAT2), FLOAT2))),
84
+ ];
85
+ });
86
+ export const easeInElastic = defEasing((x) => [
87
+ ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, mul(neg(exp2(sub(mul(10, x), 10))), sin(mul(sub(mul(x, 10), 10.75), div(TAU, 3))))))),
88
+ ]);
89
+ export const easeOutElastic = defEasing((x) => [
90
+ ret(ternary(lte(x, FLOAT0), FLOAT0, ternary(gte(x, FLOAT1), FLOAT1, madd(exp2(mul(-10, x)), sin(mul(sub(mul(x, 10), 0.75), div(TAU, 3))), FLOAT1)))),
91
+ ]);
92
+ export const easeInOutElastic = defEasing((x) => {
93
+ const c5 = div(TAU, 4.5);
94
+ return [
95
+ ret(ternary(eq(x, FLOAT0), FLOAT0, ternary(eq(x, FLOAT1), FLOAT1, ternary(lt(x, FLOAT05), div(neg(mul(exp2(sub(mul(20, x), 10)), sin(mul(sub(mul(20, x), 11.125), c5)))), FLOAT2), add(div(mul(exp2(madd(neg(float(20)), x, float(10))), sin(mul(sub(mul(20, x), 11.125), c5))), FLOAT2), FLOAT1))))),
96
+ ];
97
+ });
98
+ export const easeOutBounce = defEasing((x) => {
99
+ const n1 = 7.5625;
100
+ const d1 = float(2.75);
101
+ return [
102
+ ifThen(lt(x, reciprocal(d1)), [ret(mul(n1, pow(x, FLOAT2)))]),
103
+ ifThen(lt(x, div(FLOAT2, d1)), [
104
+ ret(add(mul(mul(n1, sub(x, div(1.5, d1))), sub(x, div(1.5, d1))), 0.75)),
105
+ ]),
106
+ ifThen(lt(x, div(2.5, d1)), [
107
+ ret(add(mul(mul(n1, sub(x, div(2.25, d1))), sub(x, div(2.25, d1))), 0.9375)),
108
+ ]),
109
+ ret(add(mul(mul(n1, sub(x, div(2.625, d1))), sub(x, div(2.625, d1))), 0.984375)),
110
+ ];
111
+ });
112
+ export const easeInBounce = defEasing((x) => [
113
+ ret(sub(FLOAT1, easeOutBounce(sub(FLOAT1, x)))),
114
+ ]);
115
+ export const easeInOutBounce = defEasing((x) => [
116
+ ret(ternary(lt(x, FLOAT05), div(sub(FLOAT1, easeOutBounce(sub(FLOAT1, mul(FLOAT2, x)))), FLOAT2), div(add(FLOAT1, easeOutBounce(sub(mul(FLOAT2, x), FLOAT1))), FLOAT2))),
117
+ ]);
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, div(sub(x, a), sub(b, a)));
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.14.19",
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",
@@ -22,6 +22,9 @@
22
22
  }
23
23
  ],
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
+ "contributors": [
26
+ "Yury Hantsouski (https://github.com/Hantsouski)"
27
+ ],
25
28
  "license": "Apache-2.0",
26
29
  "scripts": {
27
30
  "build": "yarn clean && tsc --declaration",
@@ -35,7 +38,7 @@
35
38
  },
36
39
  "dependencies": {
37
40
  "@thi.ng/api": "^8.9.6",
38
- "@thi.ng/shader-ast": "^0.12.73"
41
+ "@thi.ng/shader-ast": "^0.12.75"
39
42
  },
40
43
  "devDependencies": {
41
44
  "@microsoft/api-extractor": "^7.38.0",
@@ -51,6 +54,7 @@
51
54
  "canvas",
52
55
  "codegen",
53
56
  "dsl",
57
+ "easing",
54
58
  "fog",
55
59
  "functional",
56
60
  "glsl",
@@ -125,6 +129,9 @@
125
129
  "./fog/linear": {
126
130
  "default": "./fog/linear.js"
127
131
  },
132
+ "./isec/point": {
133
+ "default": "./isec/point.js"
134
+ },
128
135
  "./light/lambert": {
129
136
  "default": "./light/lambert.js"
130
137
  },
@@ -149,6 +156,9 @@
149
156
  "./math/dist-manhattan": {
150
157
  "default": "./math/dist-manhattan.js"
151
158
  },
159
+ "./math/easing": {
160
+ "default": "./math/easing.js"
161
+ },
152
162
  "./math/fit": {
153
163
  "default": "./math/fit.js"
154
164
  },
@@ -278,6 +288,9 @@
278
288
  "./sdf/polyhedra": {
279
289
  "default": "./sdf/polyhedra.js"
280
290
  },
291
+ "./sdf/polyline": {
292
+ "default": "./sdf/polyline.js"
293
+ },
281
294
  "./sdf/repeat-polar": {
282
295
  "default": "./sdf/repeat-polar.js"
283
296
  },
@@ -322,6 +335,9 @@
322
335
  },
323
336
  "./tex/read-index": {
324
337
  "default": "./tex/read-index.js"
338
+ },
339
+ "./viz/function": {
340
+ "default": "./viz/function.js"
325
341
  }
326
342
  },
327
343
  "thi.ng": {
@@ -333,5 +349,5 @@
333
349
  ],
334
350
  "year": 2019
335
351
  },
336
- "gitHead": "8d46d9326a9f9b81d65e7e274446f5964f9942ac\n"
352
+ "gitHead": "fc6e14052ed24bf9196896980ceb9f398b6ea6c1\n"
337
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 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
+ });