-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
GlowFXPipeline.js
116 lines (99 loc) · 3.42 KB
/
GlowFXPipeline.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
113
114
115
116
/**
* @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 GetFastValue = require('../../../../utils/object/GetFastValue');
var GlowFrag = require('../../shaders/FXGlow-frag.js');
var PostFXPipeline = require('../PostFXPipeline');
var Utils = require('../../Utils');
/**
* @classdesc
* The Glow FX Pipeline.
*
* The glow effect is a visual technique that creates a soft, luminous halo around game objects,
* characters, or UI elements. This effect is used to emphasize importance, enhance visual appeal,
* or convey a sense of energy, magic, or otherworldly presence. The effect can also be set on
* the inside of the Game Object. The color and strength of the glow can be modified.
*
* A Glow effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.postFX.addGlow();
* ```
*
* @class GlowFXPipeline
* @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.
* @param {object} config - The configuration options for this pipeline.
*/
var GlowFXPipeline = new Class({
Extends: PostFXPipeline,
initialize:
function GlowFXPipeline (game, config)
{
var quality = GetFastValue(config, 'quality', 0.1);
var distance = GetFastValue(config, 'distance', 10);
PostFXPipeline.call(this, {
game: game,
fragShader: Utils.setGlowQuality(GlowFrag, game, quality, distance)
});
/**
* The strength of the glow outward from the edge of the Sprite.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.GlowFXPipeline#outerStrength
* @type {number}
* @since 3.60.0
*/
this.outerStrength = 4;
/**
* The strength of the glow inward from the edge of the Sprite.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.GlowFXPipeline#innerStrength
* @type {number}
* @since 3.60.0
*/
this.innerStrength = 0;
/**
* If `true` only the glow is drawn, not the texture itself.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.GlowFXPipeline#knockout
* @type {number}
* @since 3.60.0
*/
this.knockout = false;
/**
* A 4 element array of gl color values.
*
* @name Phaser.Renderer.WebGL.Pipelines.FX.GlowFXPipeline#glcolor
* @type {number[]}
* @since 3.60.0
*/
this.glcolor = [ 1, 1, 1, 1 ];
},
onPreRender: function (controller, shader, width, height)
{
controller = this.getController(controller);
this.set1f('outerStrength', controller.outerStrength, shader);
this.set1f('innerStrength', controller.innerStrength, shader);
this.set4fv('glowColor', controller.glcolor, shader);
this.setBoolean('knockout', controller.knockout, 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 = GlowFXPipeline;