import { Filter } from '@pixi/core' ; /**
 * This filter uses a backdrop texture to calculate the output colors.
 *
 * A backdrop filter can use existing colors in the destination framebuffer to calculate the
 * output colors. It does not need to rely on in-built  PIXI . BLEND_MODES to
 * do those calculations.
  export class BackdropFilter extends Filter { /**
     * The name of the  Filter . uniforms for the backdrop texture.
     *
     *  pixi backdropUniformName : string = null ; ignore _backdropActive = false ; /** If non-null, @pixi/picture will clear the filter's output framebuffer with this RGBA color. */ clearColor : Float32Array = null ; } /** A shader part for blending source and destination colors. */ export interface IBlendShaderParts { /**
     * (optional) Code that declares any additional uniforms to be accepted by the  BlendFilter .
     *
     * If you do use this, make sure these uniforms are passed in  IBlendShaderParts . uniforms .
      uniformCode ? : string ; /**
     * (optional) Uniforms to pass to the resulting  BlendFilter .
     *
     * Make sure to declare these in  IBlendShaderParts . uniformCode .
      uniforms ? : { [ key ] : any ; } ; /**
     * The blend code that calculates the output color. The following variables are available to
     * this code:
     *
     * | Variable | Type     | Description (colors are usually PMA)       |
     * |----------|----------|--------------------------------------------|
     * | b_src    | vec4     | Source color                               |
     * | b_dst    | vec4     | Destination color                          |
     * | b_res    | vec4     | Output / result color                      |
     */ blendCode : string ; } const filterFrag = `
varying vec2 vTextureCoord;

uniform sampler2D uSampler;
uniform sampler2D uBackdrop;
uniform vec2 uBackdrop_flipY;

%UNIFORM_CODE%

void main(void)
{
   vec2 backdropCoord = vec2(vTextureCoord.x, uBackdrop_flipY.x + uBackdrop_flipY.y * vTextureCoord.y);
   vec4 b_src = texture2D(uSampler, vTextureCoord);
   vec4 b_dest = texture2D(uBackdrop, backdropCoord);
   vec4 b_res = b_dest;
   
   %BLEND_CODE%

   gl_FragColor = b_res;
}` ; /**
 * A blend filter is a special kind of  BackdropFilter that is used to implement additional blend modes.
 *
 * The blend filter takes in a  IBlendShaderParts and integrates that code in its shader template to
 * blend the source and destination colors.
 *
 * The backdrop texture uniform for blend filters is {@code "uBackdrop"}.
  export class BlendFilter extends BackdropFilter { param shaderParts constructor ( shaderParts ) { let fragCode = filterFrag ; fragCode = fragCode . replace ( '%UNIFORM_CODE%' , shaderParts . uniformCode || "" ) ; fragCode = fragCode . replace ( '%BLEND_CODE%' , shaderParts . blendCode || "" ) ; super ( undefined , fragCode , shaderParts . uniforms ) ; this . backdropUniformName = 'uBackdrop' ; } }