From 7edc856154b67e29a4c3a0e1d63431e1aab58fd1 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 27 Feb 2023 13:47:33 +0000 Subject: [PATCH] Added setGlowQuality function --- src/renderer/webgl/Utils.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/renderer/webgl/Utils.js b/src/renderer/webgl/Utils.js index b08bec4de..a2c72113d 100644 --- a/src/renderer/webgl/Utils.js +++ b/src/renderer/webgl/Utils.js @@ -169,5 +169,38 @@ module.exports = { fragmentShaderSource = fragmentShaderSource.replace(/%count%/gi, maxTextures.toString()); return fragmentShaderSource.replace(/%forloop%/gi, src); + }, + + /** + * Takes the Glow FX Shader source and parses out the __SIZE__ and __DIST__ + * consts with the configuration values. + * + * @function Phaser.Renderer.WebGL.Utils.setGlowQuality + * @since 3.60.0 + * + * @param {string} shader - The Fragment Shader source code to operate on. + * @param {Phaser.Game} game - The Phaser Game instance. + * @param {number} [quality] - The quality of the glow (defaults to 0.1) + * @param {number} [distance] - The distance of the glow (defaults to 10) + * + * @return {string} The modified Fragment Shader source. + */ + setGlowQuality: function (shader, game, quality, distance) + { + if (quality === undefined) + { + quality = game.config.glowFXQuality; + } + + if (distance === undefined) + { + distance = game.config.glowFXDistance; + } + + shader = shader.replace(/__SIZE__/gi, (1 / quality / distance).toFixed(7)); + shader = shader.replace(/__DIST__/gi, distance.toFixed(0) + '.0'); + + return shader; } + };