@thi.ng/shader-ast
Version:
DSL to define shader code in TypeScript and cross-compile to GLSL, JS and other targets
36 lines (35 loc) • 629 B
JavaScript
import {
B,
F,
I,
U
} from "../api/types.js";
function $(val, id) {
const type = val.type[0];
const rtype = (a, b) => id.length === 1 ? a : b + id.length;
return {
tag: "swizzle",
type: type === "i" ? rtype(I, "ivec") : type === "u" ? rtype(U, "uvec") : type === "b" ? rtype(B, "bvec") : rtype(F, "vec"),
val,
id
};
}
const $x = (val) => $(val, "x");
const $y = (val) => $(val, "y");
const $z = (val) => $(val, "z");
const $w = (val) => $(val, "w");
function $xy(val) {
return $(val, "xy");
}
function $xyz(val) {
return $(val, "xyz");
}
export {
$,
$w,
$x,
$xy,
$xyz,
$y,
$z
};