- 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
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
import { vertex } from '@tools/fragments';
import fragment from './old-film.frag';
import { Filter } from '@pixi/core';
import type { FilterSystem, RenderTexture } from '@pixi/core';
import type { CLEAR_MODES } from '@pixi/constants';
interface OldFilmFilterOptions {
sepia: number;
noise: number;
noiseSize: number;
scratch: number;
scratchDensity: number;
scratchWidth: number;
vignetting: number;
vignettingAlpha: number;
vignettingBlur: number;
}
/**
* The OldFilmFilter applies a Old film effect to an object.<br>
* 
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
* @see @pixi/filter-old-film
* @see pixi-filters
*/
class OldFilmFilter extends Filter
{
/** Default constructor options */
public static readonly defaults: OldFilmFilterOptions = {
sepia: 0.3,
noise: 0.3,
noiseSize: 1.0,
scratch: 0.5,
scratchDensity: 0.3,
scratchWidth: 1.0,
vignetting: 0.3,
vignettingAlpha: 1.0,
vignettingBlur: 0.3,
};
/** A see value to apply to the random noise generation */
public seed = 0;
/**
* @param {object|number} [options] - The optional parameters of old film effect.
* When options is a number , it will be `seed`
* @param {number} [options.sepia=0.3] - The amount of saturation of sepia effect,
* a value of `1` is more saturation and closer to `0` is less, and a value of
* `0` produces no sepia effect
* @param {number} [options.noise=0.3] - Opacity/intensity of the noise effect between `0` and `1`
* @param {number} [options.noiseSize=1.0] - The size of the noise particles
* @param {number} [options.scratch=0.5] - How often scratches appear
* @param {number} [options.scratchDensity=0.3] - The density of the number of scratches
* @param {number} [options.scratchWidth=1.0] - The width of the scratches
* @param {number} [options.vignetting=0.3] - The radius of the vignette effect, smaller
* values produces a smaller vignette
* @param {number} [options.vignettingAlpha=1.0] - Amount of opacity of vignette
* @param {number} [options.vignettingBlur=0.3] - Blur intensity of the vignette
* @param {number} [seed=0] - A see value to apply to the random noise generation
*/
constructor(options?: Partial<OldFilmFilterOptions>, seed = 0)
{
super(vertex, fragment);
this.uniforms.dimensions = new Float32Array(2);
if (typeof options === 'number')
{
this.seed = options;
options = undefined;
}
else
{
this.seed = seed;
}
Object.assign(this, OldFilmFilter.defaults, options);
}
/**
* Override existing apply method in PIXI.Filter
* @private
*/
apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
{
this.uniforms.dimensions[0] = input.filterFrame?.width;
this.uniforms.dimensions[1] = input.filterFrame?.height;
// named `seed` because in the most programming languages,
// `random` used for "the function for generating random value".
this.uniforms.seed = this.seed;
filterManager.applyFilter(this, input, output, clear);
}
/**
* The amount of saturation of sepia effect,
* a value of `1` is more saturation and closer to `0` is less,
* and a value of `0` produces no sepia effect
* @default 0
*/
set sepia(value: number)
{
this.uniforms.sepia = value;
}
get sepia(): number
{
return this.uniforms.sepia;
}
/**
* Opacity/intensity of the noise effect between `0` and `1`
* @default 0
*/
set noise(value: number)
{
this.uniforms.noise = value;
}
get noise(): number
{
return this.uniforms.noise;
}
/**
* The size of the noise particles
* @default 0
*/
set noiseSize(value: number)
{
this.uniforms.noiseSize = value;
}
get noiseSize(): number
{
return this.uniforms.noiseSize;
}
/**
* How often scratches appear
* @default 0
*/
set scratch(value: number)
{
this.uniforms.scratch = value;
}
get scratch(): number
{
return this.uniforms.scratch;
}
/**
* The density of the number of scratches
* @default 0
*/
set scratchDensity(value: number)
{
this.uniforms.scratchDensity = value;
}
get scratchDensity(): number
{
return this.uniforms.scratchDensity;
}
/**
* The width of the scratches
* @default 0
*/
set scratchWidth(value: number)
{
this.uniforms.scratchWidth = value;
}
get scratchWidth(): number
{
return this.uniforms.scratchWidth;
}
/**
* The radius of the vignette effect, smaller
* values produces a smaller vignette
* @default 0
*/
set vignetting(value: number)
{
this.uniforms.vignetting = value;
}
get vignetting(): number
{
return this.uniforms.vignetting;
}
/**
* Amount of opacity of vignette
* @default 0
*/
set vignettingAlpha(value: number)
{
this.uniforms.vignettingAlpha = value;
}
get vignettingAlpha(): number
{
return this.uniforms.vignettingAlpha;
}
/**
* Blur intensity of the vignette
* @default 0
*/
set vignettingBlur(value: number)
{
this.uniforms.vignettingBlur = value;
}
get vignettingBlur(): number
{
return this.uniforms.vignettingBlur;
}
}
export { OldFilmFilter };
export type { OldFilmFilterOptions };