@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
42 lines (41 loc) • 914 B
JavaScript
import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { add, mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { sym } from "@thi.ng/shader-ast/ast/sym";
const $ = (n, type) => defn(
type,
`mixCubic${n > 1 ? n : ""}`,
[type, type, type, type, F],
(a, b, c, d, t) => {
let s;
let s2;
let t2;
return [
t2 = sym(mul(t, t)),
s = sym(sub(1, t)),
s2 = sym(mul(s, s)),
ret(
add(
add(
add(
mul(a, mul(s, s2)),
mul(b, mul(3, mul(s2, t)))
),
mul(c, mul(3, mul(t2, s)))
),
mul(d, mul(t, t2))
)
)
];
}
);
const mixCubic = $(1, F);
const mixCubic2 = $(2, V2);
const mixCubic3 = $(3, V3);
const mixCubic4 = $(4, V4);
export {
mixCubic,
mixCubic2,
mixCubic3,
mixCubic4
};