@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
24 lines (23 loc) • 773 B
JavaScript
import { V3 } 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 { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit";
import { gt, neg } from "@thi.ng/shader-ast/ast/ops";
import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle";
import { abs } from "@thi.ng/shader-ast/builtin/math";
const perpendicularCCW = (v) => vec2(neg($y(v)), $x(v));
const perpendicularCW = (v) => vec2($y(v), neg($x(v)));
const orthogonal3 = defn(V3, "orthogonal3", [V3], (v) => [
ret(
ternary(
gt(abs($x(v)), abs($z(v))),
vec3(neg($y(v)), $x(v), 0),
vec3(0, neg($z(v)), $y(v))
)
)
]);
export {
orthogonal3,
perpendicularCCW,
perpendicularCW
};