@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
15 lines (14 loc) • 546 B
JavaScript
import { V2 } from "@thi.ng/shader-ast/api/types";
import { ternary } from "@thi.ng/shader-ast/ast/controlflow";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { lt } from "@thi.ng/shader-ast/ast/ops";
import { $x } from "@thi.ng/shader-ast/ast/swizzle";
import { min } from "@thi.ng/shader-ast/builtin/math";
const sdfUnion = (a, ...terms) => terms.reduce((a2, b) => min(a2, b), a);
const sdfUnion2 = defn(V2, "sdfUnion2", [V2, V2], (a, b) => [
ret(ternary(lt($x(a), $x(b)), a, b))
]);
export {
sdfUnion,
sdfUnion2
};