@thi.ng/shader-ast-stdlib 0.13.13 → 0.13.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/README.md +1 -1
- package/color/aces-film.js +2 -1
- package/color/levels.js +5 -4
- package/color/porter-duff.js +2 -1
- package/color/rgbe.js +3 -2
- package/fog/exp.js +4 -1
- package/fog/exp2.js +2 -1
- package/fog/linear.js +4 -1
- package/light/trilight.js +2 -1
- package/math/additive.js +4 -2
- package/math/cartesian.js +2 -1
- package/math/clamp.js +4 -3
- package/math/cross2.js +2 -1
- package/math/fit.js +4 -1
- package/math/magsq.js +2 -1
- package/math/mix-cubic.js +6 -5
- package/math/mix-quadratic.js +6 -5
- package/math/orthogonal.js +2 -1
- package/math/polar.js +3 -2
- package/matrix/convert.js +4 -3
- package/matrix/lookat.js +2 -1
- package/matrix/rotation.js +10 -9
- package/noise/curl3.js +2 -1
- package/noise/hash.js +16 -15
- package/noise/permute.js +6 -5
- package/noise/simplex2.js +3 -2
- package/noise/simplex3.d.ts +1 -0
- package/noise/simplex3.js +9 -3
- package/noise/voronoi2.js +3 -2
- package/noise/worley2.d.ts +12 -7
- package/noise/worley2.js +18 -9
- package/package.json +8 -8
- package/raymarch/ao.d.ts +2 -1
- package/raymarch/ao.js +5 -2
- package/raymarch/direction.js +2 -1
- package/raymarch/normal.js +3 -1
- package/raymarch/scene.js +6 -4
- package/screen/uv.js +5 -4
- package/sdf/arc.js +2 -1
- package/sdf/bezier.js +3 -2
- package/sdf/box-rounded.js +2 -1
- package/sdf/box.js +3 -2
- package/sdf/cross.js +4 -3
- package/sdf/cylinder.js +3 -2
- package/sdf/hex.js +2 -1
- package/sdf/line.js +4 -3
- package/sdf/mirror.js +2 -1
- package/sdf/plane.js +7 -2
- package/sdf/polygon.js +4 -3
- package/sdf/polyhedra.js +3 -2
- package/sdf/repeat-polar.js +2 -1
- package/sdf/repeat.js +3 -2
- package/sdf/smooth-isec.js +2 -1
- package/sdf/smooth-sub.js +2 -1
- package/sdf/smooth-union.js +2 -1
- package/sdf/sphere.js +7 -2
- package/sdf/torus.js +2 -1
- package/sdf/tri.js +2 -1
- package/sdf/union.js +2 -1
- package/tex/blur.js +4 -3
- package/tex/index-uv.js +3 -2
package/sdf/smooth-sub.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, div, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { fit1101 } from "../math/fit.js";
|
|
|
10
11
|
* @param d2 - float
|
|
11
12
|
* @param k - float
|
|
12
13
|
*/
|
|
13
|
-
export const sdfSmoothSubtract = defn(
|
|
14
|
+
export const sdfSmoothSubtract = defn(F, "sdOpSmoothSubtract", [F, F, F], (a, b, k) => {
|
|
14
15
|
let h;
|
|
15
16
|
return [
|
|
16
17
|
(h = sym(clamp01(fit1101(div(add(b, a), k))))),
|
package/sdf/smooth-union.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { FLOAT1 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -10,7 +11,7 @@ import { fit1101 } from "../math/fit.js";
|
|
|
10
11
|
* @param d2 - float
|
|
11
12
|
* @param k - float
|
|
12
13
|
*/
|
|
13
|
-
export const sdfSmoothUnion = defn(
|
|
14
|
+
export const sdfSmoothUnion = defn(F, "sdOpSmoothUnion", [F, F, F], (a, b, k) => {
|
|
14
15
|
let h;
|
|
15
16
|
return [
|
|
16
17
|
(h = sym(clamp01(fit1101(div(sub(b, a), k))))),
|
package/sdf/sphere.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
3
4
|
import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
@@ -7,11 +8,15 @@ import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
|
7
8
|
* @param p - vec2
|
|
8
9
|
* @param r - float
|
|
9
10
|
*/
|
|
10
|
-
export const sdfCircle = defn(
|
|
11
|
+
export const sdfCircle = defn(F, "sdCircle", [V2, F], (p, r) => [
|
|
12
|
+
ret(sub(length(p), r)),
|
|
13
|
+
]);
|
|
11
14
|
/**
|
|
12
15
|
* Returns signed distance from `p` to centered sphere of radius `r`.
|
|
13
16
|
*
|
|
14
17
|
* @param p - vec3
|
|
15
18
|
* @param r - float
|
|
16
19
|
*/
|
|
17
|
-
export const sdfSphere = defn(
|
|
20
|
+
export const sdfSphere = defn(F, "sdSphere", [V3, F], (p, r) => [
|
|
21
|
+
ret(sub(length(p), r)),
|
|
22
|
+
]);
|
package/sdf/torus.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V3 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -11,6 +12,6 @@ import { length } from "@thi.ng/shader-ast/builtin/math";
|
|
|
11
12
|
* @param r1 - float
|
|
12
13
|
* @param r2 - float
|
|
13
14
|
*/
|
|
14
|
-
export const sdfTorus = defn(
|
|
15
|
+
export const sdfTorus = defn(F, "sdTorus", [V3, F, F], (p, r1, r2) => [
|
|
15
16
|
ret(sub(length(vec2(sub(length($(p, "xz")), r2), $y(p))), r1)),
|
|
16
17
|
]);
|
package/sdf/tri.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { F, V2 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { div, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -12,7 +13,7 @@ import { cross2 } from "../math/cross2.js";
|
|
|
12
13
|
* @param b - vec2
|
|
13
14
|
* @param c - vec2
|
|
14
15
|
*/
|
|
15
|
-
export const sdfTriangle2 = defn(
|
|
16
|
+
export const sdfTriangle2 = defn(F, "sdTriangle", [V2, V2, V2, V2], (p, a, b, c) => {
|
|
16
17
|
let e0, e1, e2;
|
|
17
18
|
let v0, v1, v2;
|
|
18
19
|
let pq0, pq1, pq2;
|
package/sdf/union.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { V2 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
|
|
2
3
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
4
|
import { lt } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -19,6 +20,6 @@ export const sdfUnion = (a, ...terms) => terms.reduce((a, b) => min(a, b), a);
|
|
|
19
20
|
* @param a -
|
|
20
21
|
* @param b -
|
|
21
22
|
*/
|
|
22
|
-
export const sdfUnion2 = defn(
|
|
23
|
+
export const sdfUnion2 = defn(V2, "sdfUnion2", [V2, V2], (a, b) => [
|
|
23
24
|
ret(ternary(lt($x(a), $x(b)), a, b)),
|
|
24
25
|
]);
|
package/tex/blur.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { V2, V4 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { assign } from "@thi.ng/shader-ast/ast/assign";
|
|
2
3
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
3
4
|
import { vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
@@ -26,7 +27,7 @@ const singlePass = (col, tex, uv, off, k) => assign(col, add(col, mul(add(textur
|
|
|
26
27
|
* @param uv -
|
|
27
28
|
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
28
29
|
*/
|
|
29
|
-
export const blur5 = defn(
|
|
30
|
+
export const blur5 = defn(V4, "blur5", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
30
31
|
let col;
|
|
31
32
|
let off;
|
|
32
33
|
const k1 = 0.29411764705882354;
|
|
@@ -49,7 +50,7 @@ export const blur5 = defn("vec4", "blur5", ["sampler2D", "vec2", "vec2", "vec2"]
|
|
|
49
50
|
* @param uv -
|
|
50
51
|
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
51
52
|
*/
|
|
52
|
-
export const blur9 = defn(
|
|
53
|
+
export const blur9 = defn(V4, "blur9", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
53
54
|
let col;
|
|
54
55
|
let off;
|
|
55
56
|
let off2;
|
|
@@ -77,7 +78,7 @@ export const blur9 = defn("vec4", "blur9", ["sampler2D", "vec2", "vec2", "vec2"]
|
|
|
77
78
|
* @param uv -
|
|
78
79
|
* @param dir - blur pass direction (`vec2(1,0)` or `vec2(0,1)`)
|
|
79
80
|
*/
|
|
80
|
-
export const blur13 = defn(
|
|
81
|
+
export const blur13 = defn(V4, "blur13", ["sampler2D", V2, V2, V2], (tex, res, uv, dir) => {
|
|
81
82
|
let col;
|
|
82
83
|
let off;
|
|
83
84
|
let off2;
|
package/tex/index-uv.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { I, V2 } from "@thi.ng/shader-ast/api/types";
|
|
1
2
|
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
|
|
2
3
|
import { float, int, vec2 } from "@thi.ng/shader-ast/ast/lit";
|
|
3
4
|
import { add, div, modi, mul } from "@thi.ng/shader-ast/ast/ops";
|
|
@@ -9,7 +10,7 @@ import { $x, $y } from "@thi.ng/shader-ast/ast/swizzle";
|
|
|
9
10
|
* @param i -
|
|
10
11
|
* @param size -
|
|
11
12
|
*/
|
|
12
|
-
export const indexToUV = defn(
|
|
13
|
+
export const indexToUV = defn(V2, "indexToUV", [[I, "i", { prec: "highp" }], ["ivec2"]], (i, size) => [
|
|
13
14
|
ret(vec2(div(float(modi(i, $x(size))), float($x(size))), div(float(div(i, $x(size))), float($y(size))))),
|
|
14
15
|
]);
|
|
15
16
|
/**
|
|
@@ -19,6 +20,6 @@ export const indexToUV = defn("vec2", "indexToUV", [["int", "i", { prec: "highp"
|
|
|
19
20
|
* @param i -
|
|
20
21
|
* @param width -
|
|
21
22
|
*/
|
|
22
|
-
export const uvToIndex = defn(
|
|
23
|
+
export const uvToIndex = defn(I, "uvToIndex", [V2, [I, "width", { prec: "highp" }]], (uv, width) => [
|
|
23
24
|
ret(add(int(mul($x(uv), float(width))), int(mul($y(uv), float(mul(width, width)))))),
|
|
24
25
|
]);
|