@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
35 lines (34 loc) • 785 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,
`mixQuadratic${n > 1 ? n : ""}`,
[type, type, type, F],
(a, b, c, t) => {
let s;
return [
s = sym(sub(1, t)),
ret(
add(
add(
mul(a, mul(s, s)),
mul(b, mul(2, mul(s, t)))
),
mul(c, mul(t, t))
)
)
];
}
);
const mixQuadratic = $(1, F);
const mixQuadratic2 = $(2, V2);
const mixQuadratic3 = $(3, V3);
const mixQuadratic4 = $(4, V4);
export {
mixQuadratic,
mixQuadratic2,
mixQuadratic3,
mixQuadratic4
};