@thi.ng/shader-ast
Version:
DSL to define shader code in TypeScript and cross-compile to GLSL, JS and other targets
39 lines (38 loc) • 691 B
JavaScript
import { isNumber } from "@thi.ng/checks/is-number";
import {
F,
V2,
V3,
V4
} from "../api/types.js";
import { int } from "./lit.js";
const index = (val, id) => ({
tag: "idx",
type: val.type.substring(0, val.type.length - 2),
id: isNumber(id) ? int(id) : id,
val
});
const MAT_VEC = {
mat2: V2,
mat3: V3,
mat4: V4
// mat23: "vec3",
// mat24: "vec4",
// mat32: "vec2",
// mat34: "vec4",
// mat42: "vec2",
// mat43: "vec3",
};
function indexMat(m, a, b) {
const idx = {
tag: "idxm",
type: MAT_VEC[m.type],
id: int(a),
val: m
};
return b !== void 0 ? { tag: "idx", type: F, id: int(b), val: idx } : idx;
}
export {
index,
indexMat
};