- 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
import { vertex } from '@tools/fragments';
import fragment from './adjustment.frag';
import { Filter } from '@pixi/core';
import type { FilterSystem, RenderTexture } from '@pixi/core';
import type { CLEAR_MODES } from '@pixi/constants';
interface AdjustmentFilterOptions {
gamma: number;
saturation: number;
contrast: number;
brightness: number;
red: number;
green: number;
blue: number;
alpha: number;
}
/**
* The ability to adjust gamma, contrast, saturation, brightness, alpha or color-channel shift.
* This is a faster and much simpler to use than
* ColorMatrixFilter
* because it does not use a matrix.<br>
* 
*
* @class
* @extends PIXI.Filter
* @memberof PIXI.filters
* @see @pixi/filter-adjustment
* @see pixi-filters
*/
class AdjustmentFilter extends Filter
{
/** The amount of luminance */
public gamma = 1;
/** The amount of saturation */
public saturation = 1;
/** The amount of contrast */
public contrast = 1;
/** The amount of brightness */
public brightness = 1;
/** The amount of red channel */
public red = 1;
/** The amount of green channel */
public green = 1;
/** The amount of blue channel */
public blue = 1;
/** The amount of alpha channel */
public alpha = 1;
/**
* @param {object|number} [options] - The optional parameters of the filter.
* @param {number} [options.gamma=1] - The amount of luminance
* @param {number} [options.saturation=1] - The amount of color saturation
* @param {number} [options.contrast=1] - The amount of contrast
* @param {number} [options.brightness=1] - The overall brightness
* @param {number} [options.red=1] - The multipled red channel
* @param {number} [options.green=1] - The multipled green channel
* @param {number} [options.blue=1] - The multipled blue channel
* @param {number} [options.alpha=1] - The overall alpha amount
*/
constructor(options?: Partial<AdjustmentFilterOptions>)
{
super(vertex, fragment);
Object.assign(this, options);
}
/**
* Override existing apply method in PIXI.Filter
* @ignore
*/
apply(filterManager: FilterSystem, input: RenderTexture, output: RenderTexture, clear: CLEAR_MODES): void
{
this.uniforms.gamma = Math.max(this.gamma, 0.0001);
this.uniforms.saturation = this.saturation;
this.uniforms.contrast = this.contrast;
this.uniforms.brightness = this.brightness;
this.uniforms.red = this.red;
this.uniforms.green = this.green;
this.uniforms.blue = this.blue;
this.uniforms.alpha = this.alpha;
filterManager.applyFilter(this, input, output, clear);
}
}
export { AdjustmentFilter };
export type { AdjustmentFilterOptions };