UNPKG

@thi.ng/shader-ast-stdlib

Version:

Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast

30 lines (29 loc) 756 B
import { V3 } from "@thi.ng/shader-ast/api/types"; import { defn, ret } from "@thi.ng/shader-ast/ast/function"; import { vec3 } from "@thi.ng/shader-ast/ast/lit"; import { mul } from "@thi.ng/shader-ast/ast/ops"; import { $x, $y, $z } from "@thi.ng/shader-ast/ast/swizzle"; import { sym } from "@thi.ng/shader-ast/ast/sym"; import { cossin } from "./sincos.js"; const cartesian2 = (v) => cossin($y(v), $x(v)); const cartesian3 = defn(V3, "cartesian3", [V3], (v) => { let r; let t; let p; return [ r = sym($x(v)), t = sym(cossin($y(v))), p = sym(cossin($z(v))), ret( vec3( mul(mul(r, $x(t)), $x(p)), mul(mul(r, $x(t)), $y(p)), mul(r, $y(t)) ) ) ]; }); export { cartesian2, cartesian3 };