-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
PixelateFXPipeline.js
80 lines (67 loc) · 2.1 KB
/
PixelateFXPipeline.js
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
/**
* @author Richard Davey <rich@phaser.io>
* @copyright 2013-2024 Phaser Studio Inc.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../../../utils/Class');
var PixelateFrag = require('../../shaders/FXPixelate-frag.js');
var PostFXPipeline = require('../PostFXPipeline');
/**
* @classdesc
* The Pixelate FX Pipeline.
*
* The pixelate effect is a visual technique that deliberately reduces the resolution or detail of an image,
* creating a blocky or mosaic appearance composed of large, visible pixels. This effect can be used for stylistic
* purposes, as a homage to retro gaming, or as a means to obscure certain elements within the game, such as
* during a transition or to censor specific content.
*
* A Pixelate effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.postFX.addPixelate();
* ```
*
* @class PixelateFXPipeline
* @extends Phaser.Renderer.WebGL.Pipelines.PostFXPipeline
* @memberof Phaser.Renderer.WebGL.Pipelines.FX
* @constructor
* @since 3.60.0
*
* @param {Phaser.Game} game - A reference to the Phaser Game instance.
*/
var PixelateFXPipeline = new Class({
Extends: PostFXPipeline,
initialize:
function PixelateFXPipeline (game)
{
PostFXPipeline.call(this, {
game: game,
fragShader: PixelateFrag
});
/**
* The amount of pixelation to apply.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.PixelateFXPipeline#amount
* @type {number}
* @since 3.60.0
*/
this.amount = 1;
},
onPreRender: function (controller, shader, width, height)
{
controller = this.getController(controller);
this.set1f('amount', controller.amount, shader);
if (width && height)
{
this.set2f('resolution', width, height, shader);
}
},
onDraw: function (target)
{
this.set2f('resolution', target.width, target.height);
this.bindAndDraw(target);
}
});
module.exports = PixelateFXPipeline;