phaser/src/fx/Bloom.js

142 lines
3.8 KiB
JavaScript
Raw Normal View History

2023-02-15 00:50:26 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
2023-02-16 23:49:14 +00:00
var Class = require('../utils/Class');
2023-02-17 01:08:52 +00:00
var Controller = require('./Controller');
2023-02-15 00:50:26 +00:00
var FX_CONST = require('./const');
/**
* @classdesc
*
* @class Bloom
2023-02-17 01:08:52 +00:00
* @extends Phaser.FX.Controller
2023-02-16 23:49:14 +00:00
* @memberof Phaser.FX
2023-02-15 00:50:26 +00:00
* @constructor
* @since 3.60.0
*
* @param {Phaser.GameObjects.GameObject} gameObject - A reference to the Game Object that has this fx.
* @param {number} [color] - The color of the Bloom, as a hex value.
* @param {number} [offsetX=1] - The horizontal offset of the bloom effect.
* @param {number} [offsetY=1] - The vertical offset of the bloom effect.
* @param {number} [blurStrength=1] - The strength of the blur process of the bloom effect.
* @param {number} [strength=1] - The strength of the blend process of the bloom effect.
* @param {number} [steps=4] - The number of steps to run the Bloom effect for. This value should always be an integer.
2023-02-15 00:50:26 +00:00
*/
var Bloom = new Class({
2023-02-17 01:08:52 +00:00
Extends: Controller,
2023-02-15 00:50:26 +00:00
initialize:
2023-02-16 22:15:22 +00:00
function Bloom (gameObject, color, offsetX, offsetY, blurStrength, strength, steps)
2023-02-15 00:50:26 +00:00
{
2023-02-16 22:15:22 +00:00
if (offsetX === undefined) { offsetX = 1; }
if (offsetY === undefined) { offsetY = 1; }
if (blurStrength === undefined) { blurStrength = 1; }
if (strength === undefined) { strength = 1; }
if (steps === undefined) { steps = 4; }
2023-02-17 01:08:52 +00:00
Controller.call(this, FX_CONST.BLOOM, gameObject);
2023-02-15 00:50:26 +00:00
2023-02-16 22:15:22 +00:00
/**
* The number of steps to run the Bloom effect for.
*
* This value should always be an integer.
*
* It defaults to 4. The higher the value, the smoother the Bloom,
* but at the cost of exponentially more gl operations.
*
* Keep this to the lowest possible number you can have it, while
* still looking correct for your game.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#steps
2023-02-16 22:15:22 +00:00
* @type {number}
* @since 3.60.0
*/
this.steps = steps;
/**
* The horizontal offset of the bloom effect.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#offsetX
2023-02-16 22:15:22 +00:00
* @type {number}
* @since 3.60.0
*/
this.offsetX = offsetX;
/**
* The vertical offset of the bloom effect.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#offsetY
2023-02-16 22:15:22 +00:00
* @type {number}
* @since 3.60.0
*/
this.offsetY = offsetY;
/**
* The strength of the blur process of the bloom effect.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#blurStrength
2023-02-16 22:15:22 +00:00
* @type {number}
* @since 3.60.0
*/
this.blurStrength = blurStrength;
/**
* The strength of the blend process of the bloom effect.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#strength
2023-02-16 22:15:22 +00:00
* @type {number}
* @since 3.60.0
*/
this.strength = strength;
/**
* The internal gl color array.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#glcolor
2023-02-16 22:15:22 +00:00
* @type {number[]}
* @since 3.60.0
*/
2023-02-15 00:50:26 +00:00
this.glcolor = [ 1, 1, 1 ];
2023-02-16 22:15:22 +00:00
if (color !== undefined && color !== null)
{
this.color = color;
}
},
/**
* The color of the bloom as a number value.
*
2023-02-16 23:49:14 +00:00
* @name Phaser.FX.Bloom#color
2023-02-16 22:15:22 +00:00
* @type {number}
* @since 3.60.0
*/
color: {
get: function ()
{
var color = this.glcolor;
return (((color[0] * 255) << 16) + ((color[1] * 255) << 8) + (color[2] * 255 | 0));
},
set: function (value)
{
var color = this.glcolor;
color[0] = ((value >> 16) & 0xFF) / 255;
color[1] = ((value >> 8) & 0xFF) / 255;
color[2] = (value & 0xFF) / 255;
}
2023-02-15 00:50:26 +00:00
}
});
module.exports = Bloom;