/**
 * The glitch parameters. The first eight are ported verbatim from the WIMVEE GLYTCH
 * prototype — names and semantics are load-bearing: the fragment shader reads `u_<key>`
 * and the prototype's tuning assumes these exact ranges (0..1 each). Their maths is
 * untouched.
 *
 * The last three (round 2) are artifact classes the original eight could not express:
 * they are new shader passes, not new blends of old ones.
 */

export const PARAMS = [
  'mosh',   // macroblock displacement
  'melt',   // vertical pixel drip
  'chroma', // RGB channel split
  'tear',   // scanline horizontal tears
  'roll',   // vertical hold roll
  'burn',   // film burn blotches
  'noise',  // analog snow
  'freeze', // time quantize + dropout
  'block',  // 8x8 quantization: flat blocks, hard seams, posterized colour
  'ring',   // Gibbs ringing: oscillating halos hugging contrast edges
  'moire',  // interference lattice: beat pattern + rainbow sheen
] as const;

export type Param = (typeof PARAMS)[number];
export type ParamSet = Record<Param, number>;

export function zeroParams(): ParamSet {
  return {
    mosh: 0, melt: 0, chroma: 0, tear: 0, roll: 0, burn: 0, noise: 0, freeze: 0,
    block: 0, ring: 0, moire: 0,
  };
}

/** Frame-rate independent approach toward a target. `tau` = seconds to ~63% of the way. */
export function ease(current: number, target: number, dt: number, tau: number): number {
  return current + (target - current) * (1 - Math.exp(-dt / Math.max(1e-4, tau)));
}
