@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
25 lines (24 loc) • 720 B
JavaScript
import { V2 } from "@thi.ng/shader-ast/api/types";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { FLOAT05, VEC2_1, VEC2_2 } from "@thi.ng/shader-ast/ast/lit";
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { sym } from "@thi.ng/shader-ast/ast/sym";
import { floor, mod } from "@thi.ng/shader-ast/builtin/math";
const sdfMirror2 = defn(V2, "sdfMirror2", [V2, V2], (p, size) => {
let halfSize;
return [
halfSize = sym(mul(size, FLOAT05)),
ret(
mul(
sub(mod(add(p, halfSize), size), halfSize),
sub(
mul(mod(floor(div(add(p, halfSize), size)), VEC2_2), 2),
VEC2_1
)
)
)
];
});
export {
sdfMirror2
};