@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
28 lines (27 loc) • 773 B
JavaScript
import { M4, V3 } from "@thi.ng/shader-ast/api/types";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { mat4, vec4 } from "@thi.ng/shader-ast/ast/lit";
import { neg, sub } from "@thi.ng/shader-ast/ast/ops";
import { sym } from "@thi.ng/shader-ast/ast/sym";
import { cross, dot, normalize } from "@thi.ng/shader-ast/builtin/math";
const lookat = defn(M4, "lookat", [V3, V3, V3], (eye, target, up) => {
let x;
let y;
let z;
return [
z = sym(normalize(sub(eye, target))),
x = sym(normalize(cross(up, z))),
y = sym(normalize(cross(z, x))),
ret(
mat4(
vec4(x, neg(dot(eye, x))),
vec4(up, neg(dot(eye, y))),
vec4(z, neg(dot(eye, z))),
vec4(0, 0, 0, 1)
)
)
];
});
export {
lookat
};