{"version":3,"file":"ShockwaveFilter.mjs","sources":["../../src/shockwave/ShockwaveFilter.ts"],"sourcesContent":["import {\n    deprecation,\n    Filter,\n    FilterSystem,\n    GlProgram,\n    GpuProgram,\n    PointData,\n    RenderSurface,\n    Texture,\n} from 'pixi.js';\nimport { vertex, wgslVertex } from '../defaults';\nimport fragment from './shockwave.frag';\nimport source from './shockwave.wgsl';\n\n/** Options for the ShockwaveFilter constructor. */\nexport interface ShockwaveFilterOptions\n{\n    /**\n     * The `x` and `y` center coordinates to change the position of the center of the circle of effect.\n     * @default {x:0,y:0}\n     */\n    center?: PointData;\n    /**\n     * The speed about the shockwave ripples out. The unit is `pixel-per-second`\n     * @default 500\n     */\n    speed?: number;\n    /**\n     * The amplitude of the shockwave\n     * @default 30\n     */\n    amplitude?: number;\n    /**\n     * The wavelength of the shockwave\n     * @default 160\n     */\n    wavelength?: number;\n    /**\n     * The brightness of the shockwave\n     * @default 1\n     */\n    brightness?: number;\n    /**\n     * The maximum radius of shockwave. less than `0` means the max is an infinite distance\n     * @default -1\n     */\n    radius?: number;\n    /**\n     * Sets the elapsed time of the shockwave.\n     * @default 0\n     */\n    time?: number;\n}\n\n/**\n * Create a visual wrinkle effect by like a pond or blast wave.<br />\n * ![original](../screenshots/original.png)![filter](../screenshots/shockwave.gif)\n *\n * {@link https://github.com/evanw/glfx.js/blob/master/src/filters/adjust/noise.js original filter}\n * @author Vico @vicocotea\n */\nexport class ShockwaveFilter extends Filter\n{\n    /** Default shockwave filter options */\n    public static readonly DEFAULT_OPTIONS: ShockwaveFilterOptions = {\n        /** The `x` and `y` center coordinates to change the position of the center of the circle of effect. */\n        center: { x: 0, y: 0 },\n        /** The speed about the shockwave ripples out. The unit is `pixel-per-second` */\n        speed: 500,\n        /** The amplitude of the shockwave */\n        amplitude: 30,\n        /** The wavelength of the shockwave */\n        wavelength: 160,\n        /** The brightness of the shockwave */\n        brightness: 1,\n        /** The maximum radius of shockwave. less than `0` means the max is an infinite distance */\n        radius: -1,\n    };\n\n    public uniforms: {\n        uTime: number;\n        uCenter: PointData;\n        uSpeed: number;\n        uWave: Float32Array;\n    };\n\n    /** Sets the elapsed time of the shockwave. It could control the current size of shockwave. */\n    public time: number;\n\n    /**\n     * @param options - Options for the ShockwaveFilter constructor.\n     */\n    constructor(options?: ShockwaveFilterOptions);\n    /**\n     * @deprecated since 6.0.0\n     *\n     * @param {PIXI.PointData|number[]} [center=[0.5, 0.5]] - See `center` property.\n     * @param {object} [options] - The optional parameters of shockwave filter.\n     * @param {number} [options.amplitude=0.5] - See `amplitude`` property.\n     * @param {number} [options.wavelength=1.0] - See `wavelength` property.\n     * @param {number} [options.speed=500.0] - See `speed` property.\n     * @param {number} [options.brightness=8] - See `brightness` property.\n     * @param {number} [options.radius=4] - See `radius` property.\n     * @param {number} [time=0] - See `time` property.\n     */\n    constructor(center?: PointData | number[], options?: Omit<ShockwaveFilterOptions, 'time' | 'center'>, time?: number);\n    /** @ignore */\n    // eslint-disable-next-line max-len\n    constructor(...args: [ShockwaveFilterOptions?] | [(PointData | number[])?, Omit<ShockwaveFilterOptions, 'time' | 'center'>?, number?])\n    {\n        let options = args[0] ?? {};\n\n        if (Array.isArray(options) || ('x' in options && 'y' in options))\n        {\n            // eslint-disable-next-line max-len\n            deprecation('6.0.0', 'ShockwaveFilter constructor params are now options object. See params: { center, speed, amplitude, wavelength, brightness, radius, time }');\n\n            options = { center: options, ...args[1] } as ShockwaveFilterOptions;\n\n            if (args[2] !== undefined) options.time = args[2];\n        }\n\n        options = { ...ShockwaveFilter.DEFAULT_OPTIONS, ...options };\n\n        const gpuProgram = GpuProgram.from({\n            vertex: {\n                source: wgslVertex,\n                entryPoint: 'mainVertex',\n            },\n            fragment: {\n                source,\n                entryPoint: 'mainFragment',\n            },\n        });\n\n        const glProgram = GlProgram.from({\n            vertex,\n            fragment,\n            name: 'shockwave-filter'\n        });\n\n        super({\n            gpuProgram,\n            glProgram,\n            resources: {\n                shockwaveUniforms: {\n                    uTime: { value: options.time, type: 'f32' },\n                    uCenter: { value: options.center, type: 'vec2<f32>' },\n                    uSpeed: { value: options.speed, type: 'f32' },\n                    uWave: { value: new Float32Array(4), type: 'vec4<f32>' },\n                },\n            },\n        });\n\n        this.time = 0;\n\n        this.uniforms = this.resources.shockwaveUniforms.uniforms;\n\n        Object.assign(this, options);\n    }\n\n    public override apply(\n        filterManager: FilterSystem,\n        input: Texture,\n        output: RenderSurface,\n        clearMode: boolean\n    ): void\n    {\n        // There is no set/get of `time`, for performance.\n        // Because in the most real cases, `time` will be changed in ever game tick.\n        // Use set/get will take more function-call.\n        this.uniforms.uTime = this.time;\n        filterManager.applyFilter(this, input, output, clearMode);\n    }\n\n    /**\n     * The `x` and `y` center coordinates to change the position of the center of the circle of effect.\n     * @default [0,0]\n     */\n    get center(): PointData { return this.uniforms.uCenter; }\n    set center(value: PointData | number[])\n    {\n        if (Array.isArray(value))\n        {\n            value = { x: value[0], y: value[1] };\n        }\n\n        this.uniforms.uCenter = value;\n    }\n\n    /**\n     * Sets the center of the effect in normalized screen coords on the `x` axis\n     * @default 0\n     */\n    get centerX(): number { return this.uniforms.uCenter.x; }\n    set centerX(value: number) { this.uniforms.uCenter.x = value; }\n\n    /**\n     * Sets the center of the effect in normalized screen coords on the `y` axis\n     * @default 0\n     */\n    get centerY(): number { return this.uniforms.uCenter.y; }\n    set centerY(value: number) { this.uniforms.uCenter.y = value; }\n\n    /**\n     * The speed about the shockwave ripples out. The unit is `pixel-per-second`\n     * @default 500\n     */\n    get speed(): number { return this.uniforms.uSpeed; }\n    set speed(value: number) { this.uniforms.uSpeed = value; }\n\n    /**\n     * The amplitude of the shockwave\n     * @default 30\n     */\n    get amplitude(): number { return this.uniforms.uWave[0]; }\n    set amplitude(value: number) { this.uniforms.uWave[0] = value; }\n\n    /**\n     * The wavelength of the shockwave\n     * @default 160\n     */\n    get wavelength(): number { return this.uniforms.uWave[1]; }\n    set wavelength(value: number) { this.uniforms.uWave[1] = value; }\n\n    /**\n     * The brightness of the shockwave\n     * @default 1\n     */\n    get brightness(): number { return this.uniforms.uWave[2]; }\n    set brightness(value: number) { this.uniforms.uWave[2] = value; }\n\n    /**\n     * The maximum radius of shockwave. less than `0` means the max is an infinite distance\n     * @default -1\n     */\n    get radius(): number { return this.uniforms.uWave[3]; }\n    set radius(value: number) { this.uniforms.uWave[3] = value; }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AA6DO,MAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwB,MACrC,CAAA;AAAA;AAAA;AAAA,EA8CI,eAAe,IACf,EAAA;AACI,IAAA,IAAI,OAAU,GAAA,IAAA,CAAK,CAAC,CAAA,IAAK,EAAC,CAAA;AAE1B,IAAA,IAAI,MAAM,OAAQ,CAAA,OAAO,KAAM,GAAO,IAAA,OAAA,IAAW,OAAO,OACxD,EAAA;AAEI,MAAA,WAAA,CAAY,SAAS,2IAA2I,CAAA,CAAA;AAEhK,MAAA,OAAA,GAAU,EAAE,MAAQ,EAAA,OAAA,EAAS,GAAG,IAAA,CAAK,CAAC,CAAE,EAAA,CAAA;AAExC,MAAI,IAAA,IAAA,CAAK,CAAC,CAAM,KAAA,KAAA,CAAA;AAAW,QAAQ,OAAA,CAAA,IAAA,GAAO,KAAK,CAAC,CAAA,CAAA;AAAA,KACpD;AAEA,IAAA,OAAA,GAAU,EAAE,GAAG,gBAAgB,CAAA,eAAA,EAAiB,GAAG,OAAQ,EAAA,CAAA;AAE3D,IAAM,MAAA,UAAA,GAAa,WAAW,IAAK,CAAA;AAAA,MAC/B,MAAQ,EAAA;AAAA,QACJ,MAAQ,EAAA,UAAA;AAAA,QACR,UAAY,EAAA,YAAA;AAAA,OAChB;AAAA,MACA,QAAU,EAAA;AAAA,QACN,MAAA;AAAA,QACA,UAAY,EAAA,cAAA;AAAA,OAChB;AAAA,KACH,CAAA,CAAA;AAED,IAAM,MAAA,SAAA,GAAY,UAAU,IAAK,CAAA;AAAA,MAC7B,MAAA;AAAA,MACA,QAAA;AAAA,MACA,IA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