@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
11 lines (10 loc) • 498 B
JavaScript
import { F, V2, V3 } from "@thi.ng/shader-ast/api/types";
import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit";
import { clamp } from "@thi.ng/shader-ast/builtin/math";
const __clamp = (min, max) => (x) => x.type === F ? clamp(x, float(min), float(max)) : x.type === V2 ? clamp(x, vec2(min), vec2(max)) : x.type === V3 ? clamp(x, vec3(min), vec3(max)) : clamp(x, vec4(min), vec4(max));
const clamp01 = __clamp(0, 1);
const clamp11 = __clamp(-1, 1);
export {
clamp01,
clamp11
};