Phaser API Documentation

  Version: 
Filter

The ColorMatrix class creates a 5x4 matrix that can be used in shaders and graphics operations. It provides methods required to modify the color values, such as adjusting the brightness, setting a sepia tone, hue rotation and more.

Use the method getData to return a Float32Array containing the current color values.

Constructor:

new ColorMatrix()
Since: 3.50.0

Members

<static, constant> BLACK_WHITE: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for black_white operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> BROWN: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for brown operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> DESATURATE_LUMINANCE: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for desatured luminance operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> KODACHROME: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for kodachrome operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> LSD: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for lsd operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> NEGATIVE: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for negative operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> POLAROID: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for polaroid shift operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> SEPIA: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for sepia operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> SHIFT_BGR: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for shift BGR operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> TECHNICOLOR: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for technicolor operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<static, constant> VINTAGE: Array.<number>
Focus
Focus

Description:

A constant array used by the ColorMatrix class for vintage pinhole operations.

Type:
Array.<number>
Since: 3.60.0
Focus
Focus
<private> _dirty: boolean
Focus
Focus

Description:

Is the ColorMatrix array dirty?

Type:
boolean
Since: 3.50.0
Focus
Focus
<private> _matrix: Float32Array
Focus
Focus

Description:

Internal ColorMatrix array.

Type:
Float32Array
Since: 3.50.0
Focus
Focus
alpha: number
Focus
Focus

Description:

The value that determines how much of the original color is used when mixing the colors. A value between 0 (all original) and 1 (all final)

Type:
number
Since: 3.50.0
Focus
Focus
<private> data: Float32Array
Focus
Focus

Description:

The matrix data as a Float32Array.

Returned by the getData method.

Type:
Float32Array
Since: 3.50.0
Focus
Focus

Methods

blackWhite([multiply])
Focus
Focus

Description:

Sets this ColorMatrix to be black and white.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
brightness([value], [multiply])
Focus
Focus

Description:

Changes the brightness of this ColorMatrix by the given amount.

Parameters:

name type arguments Default description
value number <optional> 0

The amount of brightness to apply to this ColorMatrix. Between 0 (black) and 1.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
brown([multiply])
Focus
Focus

Description:

Applies a brown tone to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
contrast([value], [multiply])
Focus
Focus

Description:

Change the contrast of this ColorMatrix by the amount given.

Parameters:

name type arguments Default description
value number <optional> 0

The amount of contrast to apply to this ColorMatrix.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
desaturateLuminance([multiply])
Focus
Focus

Description:

Apply a desaturated luminance to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
getData()
Focus
Focus

Description:

Gets the ColorMatrix as a Float32Array.

Can be used directly as a 1fv shader uniform value.

Returns:
Description:

The ColorMatrix as a Float32Array.

Type:
  • Float32Array
Since: 3.50.0
Focus
Focus
grayscale([value], [multiply])
Focus
Focus

Description:

Sets this ColorMatrix to be grayscale.

Parameters:

name type arguments Default description
value number <optional> 1

The grayscale scale (0 is black).

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
hue([rotation], [multiply])
Focus
Focus

Description:

Rotates the hues of this ColorMatrix by the value given.

Parameters:

name type arguments Default description
rotation number <optional> 0

The amount of hue rotation to apply to this ColorMatrix, in degrees.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
kodachrome([multiply])
Focus
Focus

Description:

Applies a kodachrome color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
lsd([multiply])
Focus
Focus

Description:

Applies a trippy color tone to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
multiply(a, [multiply])
Focus
Focus

Description:

Multiplies the two given matrices.

Parameters:

name type arguments Default description
a Array.<number>

The 5x4 array to multiply with ColorMatrix._matrix.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
negative([multiply])
Focus
Focus

Description:

Converts this ColorMatrix to have negative values.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
night([intensity], [multiply])
Focus
Focus

Description:

Applies a night vision tone to this ColorMatrix.

Parameters:

name type arguments Default description
intensity number <optional> 0.1

The intensity of this effect.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
polaroid([multiply])
Focus
Focus

Description:

Applies a polaroid color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
reset()
Focus
Focus

Description:

Resets the ColorMatrix to default values and also resets the alpha property back to 1.

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
saturate([value], [multiply])
Focus
Focus

Description:

Changes the saturation of this ColorMatrix by the given amount.

Parameters:

name type arguments Default description
value number <optional> 0

The amount of saturation to apply to this ColorMatrix.

multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
saturation([multiply])
Focus
Focus

Description:

Desaturates this ColorMatrix (removes color from it).

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
sepia([multiply])
Focus
Focus

Description:

Applies a sepia tone to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
set(value)
Focus
Focus

Description:

Sets this ColorMatrix from the given array of color values.

Parameters:

name type description
value Array.<number> | Float32Array

The ColorMatrix values to set. Must have 20 elements.

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
shiftToBGR([multiply])
Focus
Focus

Description:

Shifts the values of this ColorMatrix into BGR order.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
technicolor([multiply])
Focus
Focus

Description:

Applies a technicolor color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus
vintagePinhole([multiply])
Focus
Focus

Description:

Applies a vintage pinhole color effect to this ColorMatrix.

Parameters:

name type arguments Default description
multiply boolean <optional> false

Multiply the resulting ColorMatrix (true), or set it (false) ?

Returns:
Description:

This ColorMatrix instance.

Since: 3.50.0
Focus
Focus