- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
import { vertex } from '@tools/fragments';
import fragment from './bulgePinch.frag';
import { Filter } from '@pixi/core';
import type { Point, Rectangle } from '@pixi/math';
import type { FilterSystem, RenderTexture } from '@pixi/core';
import type { CLEAR_MODES } from '@pixi/constants';
type PointLike = Point | number[];
interface BulgePinchFilterOptions {
center: PointLike;
radius: number;
strength: number;
}
// @author Julien CLEREL @JuloxRox
// original filter https://github.com/evanw/glfx.js/blob/master/src/filters/warp/bulgepinch.js
// by Evan Wallace : http://madebyevan.com/
/**
* Bulges or pinches the image in a circle.<br>
* 
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
* @see @pixi/filter-bulge-pinch
* @see pixi-filters
*/
class BulgePinchFilter extends Filter
{
/** Default constructor options. */
public static readonly defaults: BulgePinchFilterOptions = {
center: [0.5, 0.5],
radius: 100,
strength: 1,
};
/**
* @param {object} [options] - Options to use for filter.
* @param {PIXI.Point|Array<number>} [options.center=[0,0]] - The x and y coordinates of the center
* of the circle of effect.
* @param {number} [options.radius=100] - The radius of the circle of effect.
* @param {number} [options.strength=1] - -1 to 1 (-1 is strong pinch, 0 is no effect, 1 is strong bulge)
*/
constructor(options?: Partial<BulgePinchFilterOptions>)
{
super(vertex, fragment);
this.uniforms.dimensions = new Float32Array(2);
Object.assign(this, BulgePinchFilter.defaults, options);
}
apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
{
const { width, height } = input.filterFrame as Rectangle;
this.uniforms.dimensions[0] = width;
this.uniforms.dimensions[1] = height;
filterManager.applyFilter(this, input, output, clear);
}
/**
* The radius of the circle of effect.
*/
get radius(): number
{
return this.uniforms.radius;
}
set radius(value: number)
{
this.uniforms.radius = value;
}
/**
* The strength of the effect. -1 to 1 (-1 is strong pinch, 0 is no effect, 1 is strong bulge)
*/
get strength(): number
{
return this.uniforms.strength;
}
set strength(value: number)
{
this.uniforms.strength = value;
}
/**
* The x and y coordinates of the center of the circle of effect.
*
* @member {PIXI.Point | Array<number>}
*/
get center(): PointLike
{
return this.uniforms.center;
}
set center(value: PointLike)
{
this.uniforms.center = value;
}
}
export { BulgePinchFilter };
export type { BulgePinchFilterOptions };