import * as PIXI from "pixi.js";
import RTTShader from "../utils/RTTShader";

//@ts-expect-error Frag file
import filter_src from "./frag/MenuBackground.frag";

export default class MenuBackgroundFilter extends RTTShader {
  private elapsed: number;
  private filter: PIXI.Filter;

  constructor(renderer: PIXI.Renderer, scale: number) {
    const filter = new PIXI.Filter(null, filter_src, {
      iTime: 0,
      iResolution: [renderer.width / scale, renderer.height / scale],
    });
    super(renderer, filter, scale);
    this.elapsed = 0;
    this.filter = filter;
  }

  rescale(scale: number) {
    super.rescale(scale);
    this.filter.uniforms.iResolution = [
      this.renderer.width / scale,
      this.renderer.height / scale,
    ];
  }

  update(delta: number) {
    this.filter.uniforms.iTime = this.elapsed;
    this.elapsed += delta / 60;
  }
}
