phaser/src/fx/Bokeh.js

145 lines
4.7 KiB
JavaScript
Raw Normal View History

2023-02-16 15:04:37 +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-16 15:04:37 +00:00
var FX_CONST = require('./const');
/**
* @classdesc
2023-03-21 17:21:45 +00:00
* The Bokeh FX Controller.
*
* This FX controller manages the bokeh effect for a Game Object.
*
* Bokeh refers to a visual effect that mimics the photographic technique of creating a shallow depth of field.
* This effect is used to emphasize the game's main subject or action, by blurring the background or foreground
* elements, resulting in a more immersive and visually appealing experience. It is achieved through rendering
* techniques that simulate the out-of-focus areas, giving a sense of depth and realism to the game's graphics.
*
* This effect can also be used to generate a Tilt Shift effect, which is a technique used to create a miniature
* effect by blurring everything except a small area of the image. This effect is achieved by blurring the
* top and bottom elements, while keeping the center area in focus.
*
* A Bokeh effect is added to a Game Object via the FX component:
*
* ```js
* const sprite = this.add.sprite();
*
* sprite.preFX.addBokeh();
* sprite.postFX.addBokeh();
* ```
2023-02-16 15:04:37 +00:00
*
* @class Bokeh
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-16 15:04:37 +00:00
* @constructor
* @since 3.60.0
*
* @param {Phaser.GameObjects.GameObject} gameObject - A reference to the Game Object that has this fx.
* @param {number} [radius=0.5] - The radius of the bokeh effect.
* @param {number} [amount=1] - The amount of the bokeh effect.
* @param {number} [contrast=0.2] - The color contrast of the bokeh effect.
* @param {boolean} [isTiltShift=false] - Is this a bokeh or Tile Shift effect?
* @param {number} [blurX=1] - If Tilt Shift, the amount of horizontal blur.
* @param {number} [blurY=1] - If Tilt Shift, the amount of vertical blur.
* @param {number} [strength=1] - If Tilt Shift, the strength of the blur.
2023-02-16 15:04:37 +00:00
*/
var Bokeh = new Class({
2023-02-17 01:08:52 +00:00
Extends: Controller,
2023-02-16 15:04:37 +00:00
initialize:
function Bokeh (gameObject, radius, amount, contrast, isTiltShift, blurX, blurY, strength)
2023-02-16 15:04:37 +00:00
{
if (radius === undefined) { radius = 0.5; }
if (amount === undefined) { amount = 1; }
if (contrast === undefined) { contrast = 0.2; }
if (isTiltShift === undefined) { isTiltShift = false; }
if (blurX === undefined) { blurX = 1; }
if (blurY === undefined) { blurY = 1; }
if (strength === undefined) { strength = 1; }
2023-02-17 01:08:52 +00:00
Controller.call(this, FX_CONST.BOKEH, gameObject);
2023-02-16 15:04:37 +00:00
2023-03-21 17:21:45 +00:00
/**
* The radius of the bokeh effect.
*
* This is a float value, where a radius of 0 will result in no effect being applied,
* and a radius of 1 will result in a strong bokeh. However, you can exceed this value
* for even stronger effects.
*
* @name Phaser.FX.Bokeh#radius
* @type {number}
* @since 3.60.0
*/
this.radius = radius;
2023-03-21 17:21:45 +00:00
/**
* The amount, or strength, of the bokeh effect. Defaults to 1.
*
* @name Phaser.FX.Bokeh#amount
* @type {number}
* @since 3.60.0
*/
this.amount = amount;
2023-03-21 17:21:45 +00:00
/**
* The color contrast, or brightness, of the bokeh effect. Defaults to 0.2.
*
* @name Phaser.FX.Bokeh#contrast
* @type {number}
* @since 3.60.0
*/
this.contrast = contrast;
2023-03-21 17:21:45 +00:00
/**
* Is this a Tilt Shift effect or a standard bokeh effect?
*
* @name Phaser.FX.Bokeh#isTiltShift
* @type {boolean}
* @since 3.60.0
*/
this.isTiltShift = isTiltShift;
2023-03-21 17:21:45 +00:00
/**
* If a Tilt Shift effect this controls the strength of the blur.
*
* Setting this value on a non-Tilt Shift effect will have no effect.
*
* @name Phaser.FX.Bokeh#strength
* @type {number}
* @since 3.60.0
*/
this.strength = strength;
2023-03-21 17:21:45 +00:00
/**
* If a Tilt Shift effect this controls the amount of horizontal blur.
*
* Setting this value on a non-Tilt Shift effect will have no effect.
*
* @name Phaser.FX.Bokeh#blurX
* @type {number}
* @since 3.60.0
*/
this.blurX = blurX;
2023-03-21 17:21:45 +00:00
/**
* If a Tilt Shift effect this controls the amount of vertical blur.
*
* Setting this value on a non-Tilt Shift effect will have no effect.
*
* @name Phaser.FX.Bokeh#blurY
* @type {number}
* @since 3.60.0
*/
this.blurY = blurY;
2023-02-16 15:04:37 +00:00
}
});
module.exports = Bokeh;