import AbstractBaseMaskFilter from "./base-mask-filter.mjs";

export default class VisionMaskFilter extends AbstractBaseMaskFilter {
  /** @override */
  static _createFragmentShader() {
    return `
    precision ${PIXI.Program.defaultFragmentPrecision} float;
    varying vec2 vTextureCoord;
    varying vec2 vMaskTextureCoord;
    uniform sampler2D uSampler;
    uniform sampler2D uMaskSampler;
    void main() {
      float mask = texture2D(uMaskSampler, vMaskTextureCoord).r;
      gl_FragColor = texture2D(uSampler, vTextureCoord) * mask;
    }`;
  }

  /** @override */
  static defaultUniforms = {
    uMaskSampler: null
  };

  /** @override */
  static create() {
    return super.create({
      uMaskSampler: canvas.masks.vision.renderTexture
    });
  }

  /**
   * Is this filter currently suppressed?
   * @type {boolean}
   */
  suppressed = false;

  /**
   * This filter is enabled if and only if it is not suppressed and `canvas.visibility.visible` is true.
   * This property cannot be set. Set {@link VisionMaskFilter#suppressed} to disable this filter.
   * @override
   */
  get enabled() {
    return !this.suppressed && canvas.visibility.visible;
  }

  set enabled(value) {}
}
