shadow$provide.module$node_modules$pixi_DOT_js$lib$filters$FilterSystem = function(global, require, module, exports) {
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var PassthroughFilter = require("module$node_modules$pixi_DOT_js$lib$filters$defaults$passthrough$PassthroughFilter"), Matrix = require("module$node_modules$pixi_DOT_js$lib$maths$matrix$Matrix"), BindGroup = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$gpu$shader$BindGroup");
  module = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$geometry$Geometry");
  var UniformGroup = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$shader$UniformGroup"), Texture = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$Texture"), TexturePool = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$TexturePool"), types = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$types"), Bounds = require("module$node_modules$pixi_DOT_js$lib$scene$container$bounds$Bounds"), getRenderableBounds = 
  require("module$node_modules$pixi_DOT_js$lib$scene$container$bounds$getRenderableBounds"), warn = require("module$node_modules$pixi_DOT_js$lib$utils$logging$warn");
  "use strict";
  const quadGeometry = new module.Geometry({attributes:{aPosition:{buffer:new Float32Array([0, 0, 1, 0, 1, 1, 0, 1]), format:"float32x2", stride:8, offset:0}}, indexBuffer:new Uint32Array([0, 1, 2, 0, 2, 3])});
  class FilterData {
    constructor() {
      this.skip = !1;
      this.filters = this.backTexture = this.inputTexture = null;
      this.bounds = new Bounds.Bounds();
      this.container = null;
      this.blendRequired = !1;
      this.outputRenderSurface = null;
      this.globalFrame = {x:0, y:0, width:0, height:0};
      this.lastEnabledIndex = this.firstEnabledIndex = -1;
    }
  }
  class FilterSystem {
    constructor(renderer) {
      this._filterStackIndex = 0;
      this._filterStack = [];
      this._filterGlobalUniforms = new UniformGroup.UniformGroup({uInputSize:{value:new Float32Array(4), type:"vec4\x3cf32\x3e"}, uInputPixel:{value:new Float32Array(4), type:"vec4\x3cf32\x3e"}, uInputClamp:{value:new Float32Array(4), type:"vec4\x3cf32\x3e"}, uOutputFrame:{value:new Float32Array(4), type:"vec4\x3cf32\x3e"}, uGlobalFrame:{value:new Float32Array(4), type:"vec4\x3cf32\x3e"}, uOutputTexture:{value:new Float32Array(4), type:"vec4\x3cf32\x3e"}});
      this._globalFilterBindGroup = new BindGroup.BindGroup({});
      this.renderer = renderer;
    }
    get activeBackTexture() {
      return this._activeFilterData?.backTexture;
    }
    push(instruction) {
      const renderer = this.renderer;
      var filters = instruction.filterEffect.filters;
      const filterData = this._pushFilterData();
      filterData.skip = !1;
      filterData.filters = filters;
      filterData.container = instruction.container;
      filterData.outputRenderSurface = renderer.renderTarget.renderSurface;
      const colorTextureSource = renderer.renderTarget.renderTarget.colorTexture.source;
      var rootResolution = colorTextureSource.resolution, rootAntialias = colorTextureSource.antialias;
      if (filters.every(filter => !filter.enabled)) {
        filterData.skip = !0;
      } else {
        if (filters = filterData.bounds, this._calculateFilterArea(instruction, filters), this._calculateFilterBounds(filterData, renderer.renderTarget.rootViewPort, rootAntialias, rootResolution, 1), !filterData.skip) {
          instruction = this._getPreviousFilterData();
          rootResolution = this._findFilterResolution(rootResolution);
          var offsetY = rootAntialias = 0;
          instruction && (rootAntialias = instruction.bounds.minX, offsetY = instruction.bounds.minY);
          this._calculateGlobalFrame(filterData, rootAntialias, offsetY, rootResolution, colorTextureSource.width, colorTextureSource.height);
          this._setupFilterTextures(filterData, filters, renderer, instruction);
        }
      }
    }
    generateFilteredTexture({texture, filters}) {
      const filterData = this._pushFilterData();
      this._activeFilterData = filterData;
      filterData.skip = !1;
      filterData.filters = filters;
      const colorTextureSource = texture.source, rootResolution = colorTextureSource.resolution, rootAntialias = colorTextureSource.antialias;
      if (filters.every(filter => !filter.enabled)) {
        return filterData.skip = !0, texture;
      }
      filters = filterData.bounds;
      filters.addRect(texture.frame);
      this._calculateFilterBounds(filterData, filters.rectangle, rootAntialias, rootResolution, 0);
      if (filterData.skip) {
        return texture;
      }
      this._calculateGlobalFrame(filterData, 0, 0, rootResolution, colorTextureSource.width, colorTextureSource.height);
      filterData.outputRenderSurface = TexturePool.TexturePool.getOptimalTexture(filters.width, filters.height, filterData.resolution, filterData.antialias);
      filterData.backTexture = Texture.Texture.EMPTY;
      filterData.inputTexture = texture;
      this.renderer.renderTarget.finishRenderPass();
      this._applyFiltersToTexture(filterData, !0);
      texture = filterData.outputRenderSurface;
      texture.source.alphaMode = "premultiplied-alpha";
      return texture;
    }
    pop() {
      const renderer = this.renderer, filterData = this._popFilterData();
      filterData.skip || (renderer.globalUniforms.pop(), renderer.renderTarget.finishRenderPass(), this._activeFilterData = filterData, this._applyFiltersToTexture(filterData, !1), filterData.blendRequired && TexturePool.TexturePool.returnTexture(filterData.backTexture), TexturePool.TexturePool.returnTexture(filterData.inputTexture));
    }
    getBackTexture(lastRenderSurface, bounds, previousBounds) {
      const backgroundResolution = lastRenderSurface.colorTexture.source._resolution, backTexture = TexturePool.TexturePool.getOptimalTexture(bounds.width, bounds.height, backgroundResolution, !1);
      let x = bounds.minX, y = bounds.minY;
      previousBounds && (x -= previousBounds.minX, y -= previousBounds.minY);
      x = Math.floor(x * backgroundResolution);
      y = Math.floor(y * backgroundResolution);
      this.renderer.renderTarget.copyToTexture(lastRenderSurface, backTexture, {x, y}, {width:Math.ceil(bounds.width * backgroundResolution), height:Math.ceil(bounds.height * backgroundResolution)}, {x:0, y:0});
      return backTexture;
    }
    applyFilter(filter, input, output, clear) {
      const renderer = this.renderer, filterData = this._activeFilterData, isFinalTarget = filterData.outputRenderSurface === output, resolution = this._findFilterResolution(renderer.renderTarget.rootRenderTarget.colorTexture.source._resolution);
      let offsetX = 0;
      var offsetY = 0;
      isFinalTarget && (offsetY = this._findPreviousFilterOffset(), offsetX = offsetY.x, offsetY = offsetY.y);
      this._updateFilterUniforms(input, output, filterData, offsetX, offsetY, resolution, isFinalTarget, clear);
      filter = filter.enabled ? filter : this._getPassthroughFilter();
      this._setupBindGroupsAndRender(filter, input, renderer);
    }
    calculateSpriteMatrix(outputMatrix, sprite) {
      var data = this._activeFilterData;
      outputMatrix = outputMatrix.set(data.inputTexture._source.width, 0, 0, data.inputTexture._source.height, data.bounds.minX, data.bounds.minY);
      data = sprite.worldTransform.copyTo(Matrix.Matrix.shared);
      const renderGroup = sprite.renderGroup || sprite.parentRenderGroup;
      renderGroup && renderGroup.cacheToLocalTransform && data.prepend(renderGroup.cacheToLocalTransform);
      data.invert();
      outputMatrix.prepend(data);
      outputMatrix.scale(1 / sprite.texture.orig.width, 1 / sprite.texture.orig.height);
      outputMatrix.translate(sprite.anchor.x, sprite.anchor.y);
      return outputMatrix;
    }
    destroy() {
      this._passthroughFilter?.destroy(!0);
      this._passthroughFilter = null;
    }
    _getPassthroughFilter() {
      this._passthroughFilter ?? (this._passthroughFilter = new PassthroughFilter.PassthroughFilter());
      return this._passthroughFilter;
    }
    _setupBindGroupsAndRender(filter, input, renderer) {
      if (renderer.renderPipes.uniformBatch) {
        const batchUniforms = renderer.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);
        this._globalFilterBindGroup.setResource(batchUniforms, 0);
      } else {
        this._globalFilterBindGroup.setResource(this._filterGlobalUniforms, 0);
      }
      this._globalFilterBindGroup.setResource(input.source, 1);
      this._globalFilterBindGroup.setResource(input.source.style, 2);
      filter.groups[0] = this._globalFilterBindGroup;
      renderer.encoder.draw({geometry:quadGeometry, shader:filter, state:filter._state, topology:"triangle-list"});
      renderer.type === types.RendererType.WEBGL && renderer.renderTarget.finishRenderPass();
    }
    _setupFilterTextures(filterData, bounds, renderer, previousFilterData) {
      filterData.backTexture = Texture.Texture.EMPTY;
      filterData.inputTexture = TexturePool.TexturePool.getOptimalTexture(bounds.width, bounds.height, filterData.resolution, filterData.antialias);
      if (filterData.blendRequired) {
        renderer.renderTarget.finishRenderPass();
        const renderTarget = renderer.renderTarget.getRenderTarget(filterData.outputRenderSurface);
        filterData.backTexture = this.getBackTexture(renderTarget, bounds, previousFilterData?.bounds);
      }
      renderer.renderTarget.bind(filterData.inputTexture, !0);
      renderer.globalUniforms.push({offset:bounds});
    }
    _calculateGlobalFrame(filterData, offsetX, offsetY, globalResolution, sourceWidth, sourceHeight) {
      filterData = filterData.globalFrame;
      filterData.x = offsetX * globalResolution;
      filterData.y = offsetY * globalResolution;
      filterData.width = sourceWidth * globalResolution;
      filterData.height = sourceHeight * globalResolution;
    }
    _updateFilterUniforms(input, output, filterData, offsetX, offsetY, resolution, isFinalTarget, clear) {
      var uniforms = this._filterGlobalUniforms.uniforms;
      const outputFrame = uniforms.uOutputFrame, inputSize = uniforms.uInputSize, inputPixel = uniforms.uInputPixel, inputClamp = uniforms.uInputClamp, globalFrame = uniforms.uGlobalFrame;
      uniforms = uniforms.uOutputTexture;
      isFinalTarget ? (outputFrame[0] = filterData.bounds.minX - offsetX, outputFrame[1] = filterData.bounds.minY - offsetY) : (outputFrame[0] = 0, outputFrame[1] = 0);
      outputFrame[2] = input.frame.width;
      outputFrame[3] = input.frame.height;
      inputSize[0] = input.source.width;
      inputSize[1] = input.source.height;
      inputSize[2] = 1 / inputSize[0];
      inputSize[3] = 1 / inputSize[1];
      inputPixel[0] = input.source.pixelWidth;
      inputPixel[1] = input.source.pixelHeight;
      inputPixel[2] = 1 / inputPixel[0];
      inputPixel[3] = 1 / inputPixel[1];
      inputClamp[0] = 0.5 * inputPixel[2];
      inputClamp[1] = 0.5 * inputPixel[3];
      inputClamp[2] = input.frame.width * inputSize[2] - 0.5 * inputPixel[2];
      inputClamp[3] = input.frame.height * inputSize[3] - 0.5 * inputPixel[3];
      input = this.renderer.renderTarget.rootRenderTarget.colorTexture;
      globalFrame[0] = offsetX * resolution;
      globalFrame[1] = offsetY * resolution;
      globalFrame[2] = input.source.width * resolution;
      globalFrame[3] = input.source.height * resolution;
      output instanceof Texture.Texture && (output.source.resource = null);
      offsetX = this.renderer.renderTarget.getRenderTarget(output);
      this.renderer.renderTarget.bind(output, !!clear);
      output instanceof Texture.Texture ? (uniforms[0] = output.frame.width, uniforms[1] = output.frame.height) : (uniforms[0] = offsetX.width, uniforms[1] = offsetX.height);
      uniforms[2] = offsetX.isRoot ? -1 : 1;
      this._filterGlobalUniforms.update();
    }
    _findFilterResolution(rootResolution) {
      let currentIndex = this._filterStackIndex - 1;
      for (; 0 < currentIndex && this._filterStack[currentIndex].skip;) {
        --currentIndex;
      }
      return 0 < currentIndex && this._filterStack[currentIndex].inputTexture ? this._filterStack[currentIndex].inputTexture.source._resolution : rootResolution;
    }
    _findPreviousFilterOffset() {
      let offsetX = 0, offsetY = 0, lastIndex = this._filterStackIndex;
      for (; 0 < lastIndex;) {
        lastIndex--;
        const prevFilterData = this._filterStack[lastIndex];
        if (!prevFilterData.skip) {
          offsetX = prevFilterData.bounds.minX;
          offsetY = prevFilterData.bounds.minY;
          break;
        }
      }
      return {x:offsetX, y:offsetY};
    }
    _calculateFilterArea(instruction, bounds) {
      instruction.renderables ? getRenderableBounds.getGlobalRenderableBounds(instruction.renderables, bounds) : instruction.filterEffect.filterArea ? (bounds.clear(), bounds.addRect(instruction.filterEffect.filterArea), bounds.applyMatrix(instruction.container.worldTransform)) : instruction.container.getFastGlobalBounds(!0, bounds);
      instruction.container && (instruction = (instruction.container.renderGroup || instruction.container.parentRenderGroup).cacheToLocalTransform) && bounds.applyMatrix(instruction);
    }
    _applyFiltersToTexture(filterData, clear) {
      var inputTexture = filterData.inputTexture, bounds = filterData.bounds;
      const filters = filterData.filters;
      var firstEnabled = filterData.firstEnabledIndex;
      const lastEnabled = filterData.lastEnabledIndex;
      this._globalFilterBindGroup.setResource(inputTexture.source.style, 2);
      this._globalFilterBindGroup.setResource(filterData.backTexture.source, 3);
      if (firstEnabled === lastEnabled) {
        filters[firstEnabled].apply(this, inputTexture, filterData.outputRenderSurface, clear);
      } else {
        inputTexture = filterData.inputTexture;
        let flop = bounds = TexturePool.TexturePool.getOptimalTexture(bounds.width, bounds.height, inputTexture.source._resolution, !1);
        for (; firstEnabled < lastEnabled; firstEnabled++) {
          var filter = filters[firstEnabled];
          filter.enabled && (filter.apply(this, inputTexture, flop, !0), filter = inputTexture, inputTexture = flop, flop = filter);
        }
        filters[lastEnabled].apply(this, inputTexture, filterData.outputRenderSurface, clear);
        TexturePool.TexturePool.returnTexture(bounds);
      }
    }
    _calculateFilterBounds(filterData, viewPort, rootAntialias, rootResolution, paddingMultiplier) {
      const renderer = this.renderer, bounds = filterData.bounds, filters = filterData.filters;
      let resolution = Infinity, padding = 0, antialias = !0, blendRequired = !1, enabled = !1, clipToViewport = !0, firstEnabledIndex = -1, lastEnabledIndex = -1;
      for (let i = 0; i < filters.length; i++) {
        const filter = filters[i];
        if (filter.enabled) {
          -1 === firstEnabledIndex && (firstEnabledIndex = i);
          lastEnabledIndex = i;
          resolution = Math.min(resolution, "inherit" === filter.resolution ? rootResolution : filter.resolution);
          padding += filter.padding;
          "off" === filter.antialias ? antialias = !1 : "inherit" === filter.antialias && antialias && (antialias = rootAntialias);
          filter.clipToViewport || (clipToViewport = !1);
          if (!(filter.compatibleRenderers & renderer.type)) {
            enabled = !1;
            break;
          }
          if (filter.blendRequired && !(renderer.backBuffer?.useBackBuffer ?? !0)) {
            warn.warn("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options.");
            enabled = !1;
            break;
          }
          enabled = !0;
          blendRequired || (blendRequired = filter.blendRequired);
        }
      }
      enabled ? (clipToViewport && bounds.fitBounds(0, viewPort.width / rootResolution, 0, viewPort.height / rootResolution), bounds.scale(resolution).ceil().scale(1 / resolution).pad((padding | 0) * paddingMultiplier), bounds.isPositive ? (filterData.antialias = antialias, filterData.resolution = resolution, filterData.blendRequired = blendRequired, filterData.firstEnabledIndex = firstEnabledIndex, filterData.lastEnabledIndex = lastEnabledIndex) : filterData.skip = !0) : filterData.skip = !0;
    }
    _popFilterData() {
      this._filterStackIndex--;
      return this._filterStack[this._filterStackIndex];
    }
    _getPreviousFilterData() {
      let previousFilterData, index = this._filterStackIndex - 1;
      for (; 0 < index && (index--, previousFilterData = this._filterStack[index], previousFilterData.skip);) {
      }
      return previousFilterData;
    }
    _pushFilterData() {
      let filterData = this._filterStack[this._filterStackIndex];
      filterData || (filterData = this._filterStack[this._filterStackIndex] = new FilterData());
      this._filterStackIndex++;
      return filterData;
    }
  }
  FilterSystem.extension = {type:[global.ExtensionType.WebGLSystem, global.ExtensionType.WebGPUSystem], name:"filter"};
  exports.FilterSystem = FilterSystem;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$filters$FilterSystem.js.map
