UNPKG

@thi.ng/shader-ast-stdlib

Version:

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

22 lines (21 loc) 701 B
import { V2, V3 } from "@thi.ng/shader-ast/api/types"; import { defn, ret } from "@thi.ng/shader-ast/ast/function"; import { vec2, vec3 } from "@thi.ng/shader-ast/ast/lit"; import { div } 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 { asin, atan, length } from "@thi.ng/shader-ast/builtin/math"; const polar2 = defn(V2, "polar2", [V2], (v) => [ ret(vec2(length(v), atan(div($y(v), $x(v))))) ]); const polar3 = defn(V3, "polar3", [V3], (v) => { let r; return [ r = sym(length(v)), ret(vec3(r, asin(div($z(v), r)), atan(div($y(v), $x(v))))) ]; }); export { polar2, polar3 };