UNPKG

@thi.ng/shader-ast-stdlib

Version:

Function collection for modular GPGPU / shader programming with @thi.ng/shader-ast

17 lines (16 loc) 416 B
import { float, vec2, vec3, vec4 } from "@thi.ng/shader-ast/ast/lit"; import { pow } from "@thi.ng/shader-ast/builtin/math"; const GAMMA = float(2.2); const INV_GAMMA = float(1 / 2.2); const $ = (t, x) => ({ float: x, vec2: vec2(x), vec3: vec3(x), vec4: vec4(x, x, x, 1) })[t.type]; const toLinear = (x) => pow(x, $(x, GAMMA)); const toSRGB = (x) => pow(x, $(x, INV_GAMMA)); export { toLinear, toSRGB };