phaser3-rex-plugins
Version:
2 lines (1 loc) • 8.89 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexkawaseblurpipelineplugin=t();}(undefined,(function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,(i=r.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===t?String:Number)(e)}(i,"string"))?o:String(o)),r);}var i,o;}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t);}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return !1}}();return function(){var n,r=o(e);if(t){var i=o(this).constructor;n=Reflect.construct(r,arguments,i);}else n=r.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return l(e)}(this,n)}}function a(e){return function(e){if(Array.isArray(e))return f(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var c=function(e,t,n){void 0===n&&(n=[]),n.length=t;for(var r=t;r>0;r--)n[r]=e*(r/t);return n},p=function(e){i(o,e);var n=s(o);function o(){return t(this,o),n.apply(this,arguments)}return r(o,[{key:"draw",value:function(e,t){for(var n,r,i,o,u=this.postFXPipeline,l=this.shader,s=e,a=this.getAnotherFrame(s),f=u.pixelWidth/u.renderer.width,c=u.pixelHeight/u.renderer.height,p=0,h=u._quality-1;p<=h;p++)i=(r=u._kernels[p]+.5)*f,o=r*c,u.set2f("uOffset",i,o,l),p<h?(u.bindAndDraw(s,a,!0,!0,l),s=a,a=this.getAnotherFrame(s)):t?(u.bindAndDraw(s,a,!0,!0,l),n=a):u.bindAndDraw(s,null,!0,!0,l);return n}}]),o}(function(){function e(n,r){t(this,e),this.postFXPipeline=n,this.shader=r;}return r(e,[{key:"getAnotherFrame",value:function(e){var t=this.postFXPipeline,n=t.fullFrame1,r=t.fullFrame2;return e===n?r:n}},{key:"init",value:function(e,t){var n=this.postFXPipeline;return void 0===t&&(t=n.fullFrame1),n.copyFrame(e,t),t}},{key:"draw",value:function(e,t){}}]),e}()),h=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,y=Phaser.Utils.Objects.GetValue,d=function(e){i(o,e);var n=s(o);function o(e){var r;return t(this,o),(r=n.call(this,{name:"rexKawaseBlurFilterPostFx",game:e,renderTarget:!0,fragShader:"#ifdef GL_FRAGMENT_PRECISION_HIGH\n#define highmedp highp\n#else\n#define highmedp mediump\n#endif\nprecision highmedp float;\n\n// Scene buffer\nuniform sampler2D uMainSampler; \nvarying vec2 outTexCoord;\n\n// Effect parameters\nuniform vec2 uOffset;\n\nvoid main (void) {\n vec4 color = vec4(0.0);\n\n // Sample top left pixel\n color += texture2D(uMainSampler, vec2(outTexCoord.x - uOffset.x, outTexCoord.y + uOffset.y));\n\n // Sample top right pixel\n color += texture2D(uMainSampler, vec2(outTexCoord.x + uOffset.x, outTexCoord.y + uOffset.y));\n\n // Sample bottom right pixel\n color += texture2D(uMainSampler, vec2(outTexCoord.x + uOffset.x, outTexCoord.y - uOffset.y));\n\n // Sample bottom left pixel\n color += texture2D(uMainSampler, vec2(outTexCoord.x - uOffset.x, outTexCoord.y - uOffset.y));\n\n // Average\n color *= 0.25;\n\n gl_FragColor = color;\n}\n"})).drawer=new p(l(r)),r._kernels=[0],r._blur=0,r._quality=1,r.pixelWidth=1,r.pixelHeight=1,r}return r(o,[{key:"resetFromJSON",value:function(e){var t=y(e,"blur",4);return "number"==typeof t?(this.setBlur(t),this.setQuality(y(e,"quality",3))):this.setKernela(t),this.setPixelSize(y(e,"pixelWidth",1),y(e,"pixelHeight",1)),this}},{key:"onPreRender",value:function(){}},{key:"onDraw",value:function(e){this.drawer.draw(this.drawer.init(e));}},{key:"blur",get:function(){return this._blur},set:function(e){this._blur!==e&&(this._blur=e,c(this._blur,this._quality,this._kernels));}},{key:"setBlur",value:function(e){return this.blur=e,this}},{key:"quality",get:function(){return this._quality},set:function(e){this._quality!==e&&(this._quality=e,c(this._blur,this._quality,this._kernels));}},{key:"setQuality",value:function(e){return this.quality=e,this}},{key:"kernels",get:function(){return this._kernels},set:function(e){void 0===e&&(e=[0]),this._kernels=e,this._quality=e.length,this._blur=Math.max.apply(Math,a(e));}},{key:"setKernela",value:function(e){return this.kernels=e,this}},{key:"setPixelWidth",value:function(e){return this.pixelWidth=e,this}},{key:"setPixelHeight",value:function(e){return this.pixelHeight=e,this}},{key:"setPixelSize",value:function(e,t){return void 0===t&&(t=e),this.pixelWidth=e,this.pixelHeight=t,this}}]),o}(h),v=Phaser.Game,m=function(e){return e instanceof v},b=Phaser.Scene,g=function(e){return e instanceof b},P=function(t,n,r){var i;(i=t,null==i||"object"!==e(i)?null:m(i)?i:m(i.game)?i.game:g(i)?i.sys.game:g(i.scene)?i.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,r);},x=Phaser.Utils.Array.SpliceOne,w=function(e){i(o,Phaser.Plugins.BasePlugin);var n=s(o);function o(){return t(this,o),n.apply(this,arguments)}return r(o,[{key:"setPostPipelineClass",value:function(e,t){return this.PostFxPipelineClass=e,this.postFxPipelineName=t,this}},{key:"start",value:function(){this.game.events.once("destroy",this.destroy,this),P(this.game,this.postFxPipelineName,this.PostFxPipelineClass);}},{key:"add",value:function(e,t){return function(e,t,n){void 0===n&&(n={}),e.setPostPipeline(t);var r=e.postPipelines[e.postPipelines.length-1];return r.resetFromJSON(n),n.name&&(r.name=n.name),r}(e,this.PostFxPipelineClass,t)}},{key:"remove",value:function(e,t){return function(e,t,n){if(void 0===n)for(var r=(i=e.postPipelines).length-1;r>=0;r--)(u=i[r])instanceof t&&(u.destroy(),x(i,r));else {r=0;for(var i,o=(i=e.postPipelines).length;r<o;r++){var u;(u=i[r])instanceof t&&u.name===n&&(u.destroy(),x(i,r));}}}(e,this.PostFxPipelineClass,t),this}},{key:"get",value:function(e,t){return function(e,t,n){if(void 0===n){for(var r=[],i=0,o=(u=e.postPipelines).length;i<o;i++)(l=u[i])instanceof t&&r.push(l);return r}var u;for(i=0,o=(u=e.postPipelines).length;i<o;i++){var l;if((l=u[i])instanceof t&&l.name===n)return l}}(e,this.PostFxPipelineClass,t)}}]),o}(),O=function(e){return null==e||""===e||0===e.length};Phaser.Utils.Objects.GetValue;var _=function(e){i(o,e);var n=s(o);function o(e){var r;return t(this,o),(r=n.call(this,e)).setPostPipelineClass(d,"rexKawaseBlurFilterPostFx"),r}return r(o)}(w);return function(t,n,r,i){if(void 0===i&&(i="."),"object"===e(t)){if(O(n)){if(null==r)return;"object"===e(r)&&(t=r);}else {"string"==typeof n&&(n=n.split(i));var o=n.pop(),u=function(t,n,r){var i=t;if(O(n));else {var o;"string"==typeof n&&(n=n.split("."));for(var u=0,l=n.length;u<l;u++){var s;null!=i[o=n[u]]&&"object"===e(i[o])||(s=u===l-1?void 0===r?{}:r:{},i[o]=s),i=i[o];}}return i}(t,n);u[o]=r;}}}(window,"RexPlugins.Pipelines.KawaseBlurFilterPostFx",d),_}));