-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
ShineFXPipeline.js
112 lines (95 loc) · 2.91 KB
/
ShineFXPipeline.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
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
/**
* @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 ShineFrag = require('../../shaders/FXShine-frag.js');
var PostFXPipeline = require('../PostFXPipeline');
/**
* @classdesc
* The Shine FX Pipeline.
*
* The shine effect is a visual technique that simulates the appearance of reflective
* or glossy surfaces by passing a light beam across a Game Object. This effect is used to
* enhance visual appeal, emphasize certain features, and create a sense of depth or
* material properties.
*
* A Shine effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.postFX.addShine();
* ```
*
* @class ShineFXPipeline
* @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 ShineFXPipeline = new Class({
Extends: PostFXPipeline,
initialize:
function ShineFXPipeline (game)
{
PostFXPipeline.call(this, {
game: game,
fragShader: ShineFrag
});
/**
* The speed of the Shine effect.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.ShineFXPipeline#speed
* @type {number}
* @since 3.60.0
*/
this.speed = 0.5;
/**
* The line width of the Shine effect.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.ShineFXPipeline#lineWidth
* @type {number}
* @since 3.60.0
*/
this.lineWidth = 0.5;
/**
* The gradient of the Shine effect.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.ShineFXPipeline#gradient
* @type {number}
* @since 3.60.0
*/
this.gradient = 3;
/**
* Does this Shine effect reveal or get added to its target?
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.ShineFXPipeline#reveal
* @type {boolean}
* @since 3.60.0
*/
this.reveal = false;
},
onPreRender: function (controller, shader, width, height)
{
controller = this.getController(controller);
this.setTime('time', shader);
this.set1f('speed', controller.speed, shader);
this.set1f('lineWidth', controller.lineWidth, shader);
this.set1f('gradient', controller.gradient, shader);
this.setBoolean('reveal', controller.reveal, 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 = ShineFXPipeline;