JavaScript:
/*:
* @target MZ
* @plugindesc Custom filters for map spriteset.
* @url
https://forums.rpgmakerweb.com/index.php?threads/152047/
*
@Help Free to use and/or modify for any project, no credit required.
*
* @param Vertex Shader
* @type multiline_string
*
@desc Custom vertex shader. Leave blank for default.
*
@Default
*
* @param Fragment Shader 1
* @type multiline_string
*
@desc Custom fragment shader. Leave blank for default.
*
@Default
*
* @param Fragment Shader 2
* @type multiline_string
*
@desc Custom fragment shader. Leave blank for default.
*
@Default
*
* @param Fragment Shader 3
* @type multiline_string
*
@desc Custom fragment shader. Leave blank for default.
*
@Default
*
* @param Fragment Shader 4
* @type multiline_string
*
@desc Custom fragment shader. Leave blank for default.
*
@Default
*
* @command toggleMapFilter1
* @text Toggle Map Filter 1
*
@desc Toggles the first map filter on or off.
*
* @command toggleMapFilter2
* @text Toggle Map Filter 2
*
@desc Toggles the second map filter on or off.
*
* @command toggleMapFilter3
* @text Toggle Map Filter 3
*
@desc Toggles the third map filter on or off.
*
* @command toggleMapFilter4
* @text Toggle Map Filter 4
*
@desc Toggles the fourth map filter on or off.
*
*/
void (alias => {
'use strict';
// ===== Read parameters ===== //
const PLUGIN_NAME = 'MapFilter';
const P = PluginManager.parameters(PLUGIN_NAME);
const VERT = P['Vertex Shader'] || null;
const FRAG1 = P['Fragment Shader 1'] || null;
const FRAG2 = P['Fragment Shader 2'] || null;
const FRAG3 = P['Fragment Shader 3'] || null;
const FRAG4 = P['Fragment Shader 4'] || null;
// ===== Define filter ===== //
const F1 = globalThis.DitherFilter1 = function (enabled = true) {
this.initialize(...arguments);
this.enabled = enabled;
};
F1.prototype = Object.create(PIXI.Filter.prototype);
F1.prototype.constructor = F1;
F1.prototype.initialize = function () {
PIXI.Filter.call(this, this._vertexSrc(), this._fragmentSrc1());
};
F1.prototype._vertexSrc = function () {
return VERT;
};
F1.prototype._fragmentSrc1 = function () {
return FRAG1;
};
const F2 = globalThis.DitherFilter2 = function (enabled = true) {
this.initialize(...arguments);
this.enabled = enabled;
};
F2.prototype = Object.create(PIXI.Filter.prototype);
F2.prototype.constructor = F2;
F2.prototype.initialize = function () {
PIXI.Filter.call(this, this._vertexSrc(), this._fragmentSrc2());
};
F2.prototype._vertexSrc = function () {
return VERT;
};
F2.prototype._fragmentSrc2 = function () {
return FRAG2;
};
const F3 = globalThis.DitherFilter3 = function (enabled = true) {
this.initialize(...arguments);
this.enabled = enabled;
};
F3.prototype = Object.create(PIXI.Filter.prototype);
F3.prototype.constructor = F3;
F3.prototype.initialize = function () {
PIXI.Filter.call(this, this._vertexSrc(), this._fragmentSrc3());
};
F3.prototype._vertexSrc = function () {
return VERT;
};
F3.prototype._fragmentSrc3 = function () {
return FRAG3;
};
const F4 = globalThis.DitherFilter4 = function (enabled = true) {
this.initialize(...arguments);
this.enabled = enabled;
};
F4.prototype = Object.create(PIXI.Filter.prototype);
F4.prototype.constructor = F4;
F4.prototype.initialize = function () {
PIXI.Filter.call(this, this._vertexSrc(), this._fragmentSrc4());
};
F4.prototype._vertexSrc = function () {
return VERT;
};
F4.prototype._fragmentSrc4 = function () {
return FRAG4;
};
// === Attach to spriteset === //
Spriteset_Map.prototype.createOverallFilters = function () {
alias.apply(this, arguments);
this.filters.push(this._ditherFilter1 = new F1(false));
this.filters.push(this._ditherFilter2 = new F2(false));
this.filters.push(this._ditherFilter3 = new F3(false));
this.filters.push(this._ditherFilter4 = new F4(false));
};
// === Add plugin commands === //
PluginManager.registerCommand(PLUGIN_NAME, 'toggleMapFilter1', args => {
const spriteset = SceneManager._scene._spriteset;
if (spriteset && spriteset._ditherFilter1) {
spriteset._ditherFilter1.enabled = !(spriteset._ditherFilter1.enabled);
}
});
PluginManager.registerCommand(PLUGIN_NAME, 'toggleMapFilter2', args => {
const spriteset = SceneManager._scene._spriteset;
if (spriteset && spriteset._ditherFilter2) {
spriteset._ditherFilter2.enabled = !(spriteset._ditherFilter2.enabled);
}
});
PluginManager.registerCommand(PLUGIN_NAME, 'toggleMapFilter3', args => {
const spriteset = SceneManager._scene._spriteset;
if (spriteset && spriteset._ditherFilter3) {
spriteset._ditherFilter3.enabled = !(spriteset._ditherFilter3.enabled);
}
});
PluginManager.registerCommand(PLUGIN_NAME, 'toggleMapFilter4', args => {
const spriteset = SceneManager._scene._spriteset;
if (spriteset && spriteset._ditherFilter4) {
spriteset._ditherFilter4.enabled = !(spriteset._ditherFilter4.enabled);
}
});
})(Spriteset_Map.prototype.createOverallFilters);