{"version":3,"file":"filter-godray.mjs","sources":["../src/GodrayFilter.ts"],"sourcesContent":["import { vertex } from '@tools/fragments';\nimport perlin from './perlin.frag';\nimport fragment from './gorday.frag';\nimport { Filter, Point, DEG_TO_RAD } from '@pixi/core';\nimport type { Rectangle, CLEAR_MODES, FilterSystem, RenderTexture } from '@pixi/core';\n\ninterface GodrayFilterOptions\n{\n    angle: number;\n    gain: number;\n    lacunarity: number;\n    parallel: boolean;\n    time: number;\n    center: number[] | Point;\n    alpha: number;\n}\n\n/**\n * GordayFilter, {@link https://codepen.io/alaingalvan originally} by Alain Galvan\n *\n *\n *\n * ![original](../tools/screenshots/dist/original.png)![filter](../tools/screenshots/dist/godray.gif)\n * @class\n * @extends PIXI.Filter\n * @see {@link https://www.npmjs.com/package/@pixi/filter-godray|@pixi/filter-godray}\n * @see {@link https://www.npmjs.com/package/pixi-filters|pixi-filters}\n *\n * @example\n *  displayObject.filters = [new GodrayFilter()];\n */\nclass GodrayFilter extends Filter\n{\n    /** Default for constructior options. */\n    public static readonly defaults: GodrayFilterOptions = {\n        angle: 30,\n        gain: 0.5,\n        lacunarity: 2.5,\n        time: 0,\n        parallel: true,\n        center: [0, 0],\n        alpha: 1,\n    };\n\n    /**\n     * `true` if light rays are parallel (uses angle),\n     * `false` to use the focal `center` point\n     */\n    public parallel = true;\n\n    /**\n     * The position of the emitting point for light rays\n     * only used if `parallel` is set to `false`.\n     */\n    public center: number[] | Point;\n\n    /** The current time. */\n    public time = 0;\n\n    private _angleLight: Point;\n    private _angle = 0;\n\n    /**\n     * @param {object} [options] - Filter options\n     * @param {number} [options.angle=30] - Angle/Light-source of the rays.\n     * @param {number} [options.gain=0.5] - General intensity of the effect.\n     * @param {number} [options.lacunarity=2.5] - The density of the fractal noise.\n     * @param {boolean} [options.parallel=true] - `true` to use `angle`, `false` to use `center`\n     * @param {number} [options.time=0] - The current time position.\n     * @param {PIXI.Point|number[]} [options.center=[0,0]] - Focal point for non-parallel rays,\n     *        to use this `parallel` must be set to `false`.\n * @param {number} [options.alpha=1.0] - the alpha, defaults to 1, affects transparency of rays\n     */\n    constructor(options?: Partial<GodrayFilterOptions>)\n    {\n        super(vertex, fragment.replace('${perlin}', perlin));\n\n        this.uniforms.dimensions = new Float32Array(2);\n\n        const opts: GodrayFilterOptions = Object.assign(GodrayFilter.defaults, options);\n\n        this._angleLight = new Point();\n        this.angle = opts.angle;\n        this.gain = opts.gain;\n        this.lacunarity = opts.lacunarity;\n        this.alpha = opts.alpha;\n        this.parallel = opts.parallel;\n        this.center = opts.center;\n        this.time = opts.time;\n    }\n\n    /**\n     * Applies the filter.\n     * @private\n     * @param {PIXI.FilterManager} filterManager - The manager.\n     * @param {PIXI.RenderTarget} input - The input target.\n     * @param {PIXI.RenderTarget} output - The output target.\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.light = this.parallel ? this._angleLight : this.center;\n\n        this.uniforms.parallel = this.parallel;\n        this.uniforms.dimensions[0] = width;\n        this.uniforms.dimensions[1] = height;\n        this.uniforms.aspect = height / width;\n        this.uniforms.time = this.time;\n        this.uniforms.alpha = this.alpha;\n\n        // draw the filter...\n        filterManager.applyFilter(this, input, output, clear);\n    }\n\n    /**\n     * The angle/light-source of the rays in degrees. For instance, a value of 0 is vertical rays,\n     *     values of 90 or -90 produce horizontal rays.\n     * @default 30\n     */\n    get angle(): number\n    {\n        return this._angle;\n    }\n    set angle(value: number)\n    {\n        this._angle = value;\n\n        const radians = value * DEG_TO_RAD;\n\n        this._angleLight.x = Math.cos(radians);\n        this._angleLight.y = Math.sin(radians);\n    }\n\n    /**\n     * General intensity of the effect. A value closer to 1 will produce a more intense effect,\n     * where a value closer to 0 will produce a subtler effect.\n     * @default 0.5\n     */\n    get gain(): number\n    {\n        return this.uniforms.gain;\n    }\n    set gain(value: number)\n    {\n        this.uniforms.gain = value;\n    }\n\n    /**\n     * The density of the fractal noise. A higher amount produces more rays and a smaller amound\n     * produces fewer waves.\n     * @default 2.5\n     */\n    get lacunarity(): number\n    {\n        return this.uniforms.lacunarity;\n    }\n    set lacunarity(value: number)\n    {\n        this.uniforms.lacunarity = value;\n    }\n\n    /**\n     * The alpha (opacity) of the rays.  0 is fully transparent, 1 is fully opaque.\n     * @default 1\n     */\n    get alpha(): number\n    {\n        return this.uniforms.alpha;\n    }\n    set alpha(value: number)\n    {\n        this.uniforms.alpha = value;\n    }\n}\n\nexport { GodrayFilter };\n"],"names":["_GodrayFilter","Filter","options","vertex","fragment","perlin","opts","Point","filterManager","input","output","clear","width","height","value","radians","DEG_TO_RAD","GodrayFilter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BA,MAAMA,EAAN,cAA2BC,CAC3B,CAyCI,YAAYC,EACZ,CACI,MAAMC,EAAQC,EAAS,QAAQ,YAAaC,CAAM,CAAC,EA3BvD,KAAO,SAAW,GASlB,KAAO,KAAO,EAGd,KAAQ,OAAS,EAiBb,KAAK,SAAS,WAAa,IAAI,aAAa,CAAC,EAE7C,MAAMC,EAA4B,OAAO,OAAON,EAAa,SAAUE,CAAO,EAE9E,KAAK,YAAc,IAAIK,EACvB,KAAK,MAAQD,EAAK,MAClB,KAAK,KAAOA,EAAK,KACjB,KAAK,WAAaA,EAAK,WACvB,KAAK,MAAQA,EAAK,MAClB,KAAK,SAAWA,EAAK,SACrB,KAAK,OAASA,EAAK,OACnB,KAAK,KAAOA,EAAK,IACrB,CASA,MAAME,EAA6BC,EAAsBC,EAAuBC,EAChF,CACI,KAAM,CAAE,MAAAC,EAAO,OAAAC,CAAO,EAAIJ,EAAM,YAEhC,KAAK,SAAS,MAAQ,KAAK,SAAW,KAAK,Y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