UNPKG

@thi.ng/shader-ast-stdlib

Version:

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

27 lines (26 loc) 692 B
import { V3 } from "@thi.ng/shader-ast/api/types"; import { defn, ret } from "@thi.ng/shader-ast/ast/function"; import { FLOAT0, FLOAT1 } from "@thi.ng/shader-ast/ast/lit"; import { add, mul, neg, sub } from "@thi.ng/shader-ast/ast/ops"; import { sym } from "@thi.ng/shader-ast/ast/sym"; import { abs, dot, max } from "@thi.ng/shader-ast/builtin/math"; const trilight = defn( V3, "trilight", [V3, V3, V3, V3, V3], (n, l, c1, c2, c3) => { let d; return [ d = sym(dot(n, l)), ret( add( add(mul(c1, max(d, FLOAT0)), mul(c2, sub(FLOAT1, abs(d)))), mul(c3, max(dot(neg(n), l), FLOAT0)) ) ) ]; } ); export { trilight };