- 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
import { vertex } from '@tools/fragments';
import fragment from './convolution.frag';
import { Filter } from '@pixi/core';
/**
* The ConvolutionFilter class applies a matrix convolution filter effect.
* A convolution combines pixels in the input image with neighboring pixels to produce a new image.
* A wide variety of image effects can be achieved through convolutions, including blurring, edge
* detection, sharpening, embossing, and beveling. The matrix should be specified as a 9 point Array.
* See https://docs.gimp.org/2.10/en/gimp-filter-convolution-matrix.html for more info.<br>
* 
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
* @see @pixi/filter-convolution
* @see pixi-filters
*/
class ConvolutionFilter extends Filter
{
/**
* @param {number[]} [matrix=[0,0,0,0,0,0,0,0,0]] - An array of values used for matrix transformation.
* Specified as a 9 point Array.
* @param {number} [width=200] - Width of the object you are transforming
* @param {number} [height=200] - Height of the object you are transforming
*/
constructor(matrix: number[], width = 200, height = 200)
{
super(vertex, fragment);
this.uniforms.texelSize = new Float32Array(2);
this.uniforms.matrix = new Float32Array(9);
if (matrix !== undefined)
{
this.matrix = matrix;
}
this.width = width;
this.height = height;
}
/**
* An array of values used for matrix transformation. Specified as a 9 point Array.
*/
get matrix(): number[]
{
return this.uniforms.matrix;
}
set matrix(matrix: number[])
{
matrix.forEach((v, i) =>
{
this.uniforms.matrix[i] = v;
});
}
/**
* Width of the object you are transforming
*/
get width(): number
{
return 1 / this.uniforms.texelSize[0];
}
set width(value: number)
{
this.uniforms.texelSize[0] = 1 / value;
}
/**
* Height of the object you are transforming
*/
get height(): number
{
return 1 / this.uniforms.texelSize[1];
}
set height(value: number)
{
this.uniforms.texelSize[1] = 1 / value;
}
}
export { ConvolutionFilter };