- 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
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
import { vertex } from '@tools/fragments';
import fragment from './shockwave.frag';
import { Filter } from '@pixi/core';
import type { FilterSystem, RenderTexture } from '@pixi/core';
import type { Point } from '@pixi/math';
import type { CLEAR_MODES } from '@pixi/constants';
type PointLike = Point|number[];
interface ShockwaveFilterOptions {
amplitude: number;
wavelength: number;
speed: number;
brightness: number;
radius: number;
}
/**
* The ShockwaveFilter class lets you apply a shockwave effect.<br>
* 
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
* @see @pixi/filter-shockwave
* @see pixi-filters
*/
class ShockwaveFilter extends Filter
{
/** Default constructor options. */
public static readonly defaults: ShockwaveFilterOptions = {
amplitude: 30.0,
wavelength: 160.0,
brightness: 1.0,
speed: 500.0,
radius: -1.0,
};
/**
* Sets the elapsed time of the shockwave.
* It could control the current size of shockwave.
*/
public time: number;
/**
* @param {PIXI.Point|number[]} [center=[0.5, 0.5]] - See `center` property.
* @param {object} [options] - The optional parameters of shockwave filter.
* @param {number} [options.amplitude=0.5] - See `amplitude`` property.
* @param {number} [options.wavelength=1.0] - See `wavelength` property.
* @param {number} [options.speed=500.0] - See `speed` property.
* @param {number} [options.brightness=8] - See `brightness` property.
* @param {number} [options.radius=4] - See `radius` property.
* @param {number} [time=0] - See `time` property.
*/
constructor(center: PointLike = [0, 0], options?: Partial<ShockwaveFilterOptions>, time = 0)
{
super(vertex, fragment);
this.center = center;
Object.assign(this, ShockwaveFilter.defaults, options);
this.time = time;
}
apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
{
// There is no set/get of `time`, for performance.
// Because in the most real cases, `time` will be changed in ever game tick.
// Use set/get will take more function-call.
this.uniforms.time = this.time;
filterManager.applyFilter(this, input, output, clear);
}
/**
* Sets the center of the shockwave in normalized screen coords. That is
* (0,0) is the top-left and (1,1) is the bottom right.
*
* @member {PIXI.Point|number[]}
*/
get center(): PointLike
{
return this.uniforms.center;
}
set center(value: PointLike)
{
this.uniforms.center = value;
}
/**
* The amplitude of the shockwave.
*/
get amplitude(): number
{
return this.uniforms.amplitude;
}
set amplitude(value: number)
{
this.uniforms.amplitude = value;
}
/**
* The wavelength of the shockwave.
*/
get wavelength(): number
{
return this.uniforms.wavelength;
}
set wavelength(value: number)
{
this.uniforms.wavelength = value;
}
/**
* The brightness of the shockwave.
*/
get brightness(): number
{
return this.uniforms.brightness;
}
set brightness(value: number)
{
this.uniforms.brightness = value;
}
/**
* The speed about the shockwave ripples out.
* The unit is `pixel/second`
*/
get speed(): number
{
return this.uniforms.speed;
}
set speed(value: number)
{
this.uniforms.speed = value;
}
/**
* The maximum radius of shockwave.
* `< 0.0` means it's infinity.
*/
get radius(): number
{
return this.uniforms.radius;
}
set radius(value: number)
{
this.uniforms.radius = value;
}
}
export { ShockwaveFilter };