@thi.ng/shader-ast-stdlib
Version:
Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast
33 lines (32 loc) • 1.07 kB
JavaScript
import { F, V2, V3, V4 } from "@thi.ng/shader-ast/api/types";
import { defn, ret } from "@thi.ng/shader-ast/ast/function";
import { add, div, mul, sub } from "@thi.ng/shader-ast/ast/ops";
import { clamp01 } from "./clamp.js";
const $ = (n, type) => defn(type, `smootherStep01${n > 1 ? "_" + n : ""}`, [type], (x) => [
// @ts-ignore
ret(mul(x, mul(x, mul(x, add(mul(x, sub(mul(x, 6), 15)), 10)))))
]);
const smootherStep01 = $(1, F);
const smootherStep01_2 = $(2, V2);
const smootherStep01_3 = $(3, V3);
const smootherStep01_4 = $(4, V4);
const $$ = (n, type, fn) => defn(
type,
`smootherStep${n > 1 ? n : ""}`,
[type, type, type],
(e0, e1, x) => [ret(fn(clamp01(div(sub(x, e0), sub(e1, e0)))))]
);
const smootherStep = $$(1, F, smootherStep01);
const smootherStep2 = $$(2, V2, smootherStep01_2);
const smootherStep3 = $$(3, V3, smootherStep01_3);
const smootherStep4 = $$(4, V4, smootherStep01_4);
export {
smootherStep,
smootherStep01,
smootherStep01_2,
smootherStep01_3,
smootherStep01_4,
smootherStep2,
smootherStep3,
smootherStep4
};