{"version":3,"file":"filter-crt.mjs","sources":["../src/CRTFilter.ts"],"sourcesContent":["import { vertex } from '@tools/fragments';\nimport fragment from './crt.frag';\nimport { Filter } from '@pixi/core';\nimport type { Rectangle, CLEAR_MODES, FilterSystem, RenderTexture } from '@pixi/core';\n\ninterface CRTFilterOptions\n{\n    curvature: number;\n    lineWidth: number;\n    lineContrast: number;\n    verticalLine: boolean;\n    noise: number;\n    noiseSize: number;\n    seed: number;\n    vignetting: number;\n    vignettingAlpha: number;\n    vignettingBlur: number;\n    time: number;\n}\n\n/**\n * The CRTFilter applies a CRT effect to an object.<br>\n * ![original](../tools/screenshots/dist/original.png)![filter](../tools/screenshots/dist/crt.gif)\n *\n * @class\n * @extends PIXI.Filter\n * @see {@link https://www.npmjs.com/package/@pixi/filter-crt|@pixi/filter-crt}\n * @see {@link https://www.npmjs.com/package/pixi-filters|pixi-filters}\n */\nclass CRTFilter extends Filter\n{\n    /** Default constructor options */\n    public static readonly defaults: CRTFilterOptions = {\n        curvature: 1.0,\n        lineWidth: 1.0,\n        lineContrast: 0.25,\n        verticalLine: false,\n        noise: 0.0,\n        noiseSize: 1.0,\n        seed: 0.0,\n        vignetting: 0.3,\n        vignettingAlpha: 1.0,\n        vignettingBlur: 0.3,\n        time: 0.0,\n    };\n\n    /** For animating interlaced lines */\n    public time = 0;\n\n    /** A seed value to apply to the random noise generation */\n    public seed = 0;\n\n    /**\n     * @param {object} [options] - The optional parameters of CRT effect\n     * @param {number} [options.curvature=1.0] - Bent of interlaced lines, higher value means more bend\n     * @param {number} [options.lineWidth=1.0] - Width of the interlaced lines\n     * @param {number} [options.lineContrast=0.25] - Contrast of interlaced lines\n     * @param {number} [options.verticalLine=false] - `true` is vertical lines, `false` is horizontal\n     * @param {number} [options.noise=0.3] - Opacity/intensity of the noise effect between `0` and `1`\n     * @param {number} [options.noiseSize=1.0] - The size of the noise particles\n     * @param {number} [options.seed=0] - A seed value to apply to the random noise generation\n     * @param {number} [options.vignetting=0.3] - The radius of the vignette effect, smaller\n     *        values produces a smaller vignette\n     * @param {number} [options.vignettingAlpha=1.0] - Amount of opacity of vignette\n     * @param {number} [options.vignettingBlur=0.3] - Blur intensity of the vignette\n     * @param {number} [options.time=0] - For animating interlaced lines\n     */\n    constructor(options?: Partial<CRTFilterOptions>)\n    {\n        super(vertex, fragment);\n        this.uniforms.dimensions = new Float32Array(2);\n\n        Object.assign(this, CRTFilter.defaults, options);\n    }\n\n    /**\n     * Override existing apply method in PIXI.Filter\n     * @private\n     */\n    apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void\n    {\n        const { width, height } = input.filterFrame as Rectangle;\n\n        this.uniforms.dimensions[0] = width;\n        this.uniforms.dimensions[1] = height;\n\n        this.uniforms.seed = this.seed;\n        this.uniforms.time = this.time;\n\n        filterManager.applyFilter(this, input, output, clear);\n    }\n\n    /**\n     * Bent of interlaced lines, higher value means more bend\n     * @default 1\n     */\n    set curvature(value: number)\n    {\n        this.uniforms.curvature = value;\n    }\n    get curvature(): number\n    {\n        return this.uniforms.curvature;\n    }\n\n    /**\n     * Width of interlaced lines\n     * @default 1\n     */\n    set lineWidth(value: number)\n    {\n        this.uniforms.lineWidth = value;\n    }\n    get lineWidth(): number\n    {\n        return this.uniforms.lineWidth;\n    }\n\n    /**\n     * Contrast of interlaced lines\n     * @default 0.25\n     */\n    set lineContrast(value: number)\n    {\n        this.uniforms.lineContrast = value;\n    }\n    get lineContrast(): number\n    {\n        return this.uniforms.lineContrast;\n    }\n\n    /**\n     * `true` for vertical lines, `false` for horizontal lines\n     * @default false\n     */\n    set verticalLine(value: boolean)\n    {\n        this.uniforms.verticalLine = value;\n    }\n    get verticalLine(): boolean\n    {\n        return this.uniforms.verticalLine;\n    }\n\n    /**\n     * Opacity/intensity of the noise effect between `0` and `1`\n     * @default 0\n     */\n    set noise(value: number)\n    {\n        this.uniforms.noise = value;\n    }\n    get noise(): number\n    {\n        return this.uniforms.noise;\n    }\n\n    /**\n     * The size of the noise particles\n     * @default 0\n     */\n    set noiseSize(value: number)\n    {\n        this.uniforms.noiseSize = value;\n    }\n    get noiseSize(): number\n    {\n        return this.uniforms.noiseSize;\n    }\n\n    /**\n     * The radius of the vignette effect, smaller\n     * values produces a smaller vignette\n     * @default 0\n     */\n    set vignetting(value: number)\n    {\n        this.uniforms.vignetting = value;\n    }\n    get vignetting(): number\n    {\n        return this.uniforms.vignetting;\n    }\n\n    /**\n     * Amount of opacity of vignette\n     * @default 0\n     */\n    set vignettingAlpha(value: number)\n    {\n        this.uniforms.vignettingAlpha = value;\n    }\n    get vignettingAlpha(): number\n    {\n        return this.uniforms.vignettingAlpha;\n    }\n\n    /**\n     * Blur intensity of the vignette\n     * @default 0\n     */\n    set vignettingBlur(value: number)\n    {\n        this.uniforms.vignettingBlur = value;\n    }\n    get vignettingBlur(): number\n    {\n        return this.uniforms.vignettingBlur;\n    }\n}\n\nexport { CRTFilter };\nexport type { CRTFilterOptions };\n"],"names":["_CRTFilter","Filter","options","vertex","fragment","filterManager","input","output","clear","width","height","value","CRTFilter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BA,MAAMA,EAAN,cAAwBC,CACxB,CAqCI,YAAYC,EACZ,CACI,MAAMC,EAAQC,CAAQ,EAtB1B,KAAO,KAAO,EAGd,KAAO,KAAO,EAoBV,KAAK,SAAS,WAAa,IAAI,aAAa,CAAC,EAE7C,OAAO,OAAO,KAAMJ,EAAU,SAAUE,CAAO,CACnD,CAMA,MAAMG,EAA6BC,EAAsBC,EAAuBC,EAChF,CACI,KAAM,CAAE,MAAAC,EAAO,OAAAC,CAAO,EAAIJ,EAAM,YAEhC,KAAK,SAAS,WAAW,GAAKG,EAC9B,KAAK,SAAS,WAAW,GAAKC,EAE9B,KAAK,SAAS,KAAO,KAAK,KAC1B,KAAK,SAAS,KAAO,KAAK,KAE1BL,EAAc,YAAY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