UNPKG

@petkoneo/phaser3-rex-plugins

Version:
2 lines (1 loc) 5.64 kB
var t,e;t=void 0,e=function(){const t=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,e=Phaser.Utils.Objects.GetValue,i=Phaser.Math.DegToRad,s=Phaser.Math.RadToDeg;class n extends t{constructor(t){super({name:"rexSplitPostFx",game:t,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 texSize;\nuniform vec2 split;\nuniform float spaceLeft;\nuniform float spaceRight;\nuniform float spaceTop;\nuniform float spaceBottom;\nuniform float angle;\nuniform float shiftEnable;\n\nvec2 rotate(vec2 uv, float angle) {\n float s = sin(angle);\n float c = cos(angle);\n return vec2(\n uv.x * c + uv.y * s,\n uv.y * c - uv.x * s\n );\n}\n\nvoid main (void) {\n vec2 tc = outTexCoord * texSize; \n tc -= split;\n tc = rotate(tc, -angle);\n\n if (\n ((tc.x > -spaceLeft) && (tc.x < spaceRight)) ||\n ((tc.y > -spaceTop) && (tc.y < spaceBottom))\n ) {\n gl_FragColor = vec4(0,0,0,0);\n } else {\n if (shiftEnable > 0.0) {\n tc.x += (tc.x < 0.0)? spaceLeft: -spaceRight;\n tc.y += (tc.y < 0.0)? spaceTop: -spaceBottom;\n }\n\n tc = rotate(tc, angle);\n tc += split;\n gl_FragColor = texture2D(uMainSampler, tc / texSize);\n }\n\n}\n"}),this.splitX=0,this.splitY=0,this.spaceLeft=0,this.spaceRight=0,this.spaceTop=0,this.spaceBottom=0,this.rotation=0,this.shiftEnable=!0}resetFromJSON(t){var i=e(t,"width",void 0);void 0===i?(this.spaceLeft=e(t,"left",0),this.spaceRight=e(t,"right",0)):this.splittedWidth=i;var s=e(t,"height",void 0);void 0===s?(this.spaceTop=e(t,"top",0),this.spaceBottom=e(t,"bottom",0)):this.splittedHeight=s,this.splitX=e(t,"x",this.renderer.width/2),this.splitY=e(t,"Y",this.renderer.height/2);var n=e(t,"rotation",void 0);return void 0===n?this.setAngle(e(t,"angle",0)):this.setRotation(n),this.shiftEnable=e(t,"shiftEnable",!0),this}onPreRender(){var t=this.renderer.width,e=this.renderer.height;this.set2f("split",this.splitX,e-this.splitY),this.set1f("angle",this.rotation),this.set2f("texSize",t,e),this.set1f("spaceLeft",this.spaceLeft),this.set1f("spaceRight",this.spaceRight),this.set1f("spaceTop",this.spaceTop),this.set1f("spaceBottom",this.spaceBottom),this.set1f("shiftEnable",this.shiftEnable?1:0)}setSplit(t,e){return void 0===t&&(t=0),void 0===e&&(e=0),this.splitX=t,this.splitY=e,this}splitAtCenter(t,e){return this.setSplit(this.renderer.width/2,this.renderer.height/2),void 0!==t&&this.setSplittedWidth(t),void 0!==e&&this.setSplittedHeight(e),this}setRotation(t){return this.rotation=t,this}get angle(){return s(this.rotation)}set angle(t){this.rotation=i(t)}setAngle(t){return this.angle=t,this}setSpace(t,e,i,s){return void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=0),this.spaceLeft=t,this.spaceRight=e,this.spaceTop=i,this.spaceBottom=s,this}get splittedWidth(){return this.spaceLeft+this.spaceRight}set splittedWidth(t){this.spaceLeft=t/2,this.spaceRight=this.spaceLeft}setSplittedWidth(t){return void 0===t&&(t=0),this.splittedWidth=t,this}get splittedHeight(){return this.spaceTop+this.spaceBottom}set splittedHeight(t){this.spaceTop=t/2,this.spaceBottom=this.spaceTop}setSplittedHeight(t){return void 0===t&&(t=0),this.splittedHeight=t,this}setShiftEnable(t){return void 0===t&&(t=!0),this.shiftEnable=t,!0}}const o=Phaser.Game;var r=function(t){return t instanceof o};const a=Phaser.Scene;var h=function(t){return t instanceof a},p=function(t,e,i){var s;(s=t,null==s||"object"!=typeof s?null:r(s)?s:r(s.game)?s.game:h(s)?s.sys.game:h(s.scene)?s.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(e,i)};const l=Phaser.Utils.Array.SpliceOne;class c extends Phaser.Plugins.BasePlugin{setPostPipelineClass(t,e){return this.PostFxPipelineClass=t,this.postFxPipelineName=e,this}start(){this.game.events.once("destroy",this.destroy,this),p(this.game,this.postFxPipelineName,this.PostFxPipelineClass)}add(t,e){return function(t,e,i){void 0===i&&(i={}),t.setPostPipeline(e);var s=t.postPipelines[t.postPipelines.length-1];return s.resetFromJSON(i),i.name&&(s.name=i.name),s}(t,this.PostFxPipelineClass,e)}remove(t,e){return function(t,e,i){if(void 0===i)for(var s=(n=t.postPipelines).length-1;s>=0;s--)(r=n[s])instanceof e&&(r.destroy(),l(n,s));else{s=0;for(var n,o=(n=t.postPipelines).length;s<o;s++){var r;(r=n[s])instanceof e&&r.name===i&&(r.destroy(),l(n,s))}}t.hasPostPipeline=t.postPipelines.length>0}(t,this.PostFxPipelineClass,e),this}get(t,e){return function(t,e,i){if(void 0===i){for(var s=[],n=0,o=(r=t.postPipelines).length;n<o;n++)(a=r[n])instanceof e&&s.push(a);return s}var r;for(n=0,o=(r=t.postPipelines).length;n<o;n++){var a;if((a=r[n])instanceof e&&a.name===i)return a}}(t,this.PostFxPipelineClass,e)}}var f=function(t){return null==t||""===t||0===t.length};return function(t,e,i,s){if(void 0===s&&(s="."),"object"==typeof t)if(f(e)){if(null==i)return;"object"==typeof i&&(t=i)}else{"string"==typeof e&&(e=e.split(s));var n=e.pop(),o=function(t,e,i){var s=t;if(f(e));else{var n;"string"==typeof e&&(e=e.split("."));for(var o=0,r=e.length;o<r;o++){var a;null!=s[n=e[o]]&&"object"==typeof s[n]||(a=o===r-1?void 0===i?{}:i:{},s[n]=a),s=s[n]}}return s}(t,e);o[n]=i}}(window,"RexPlugins.Pipelines.SplitPostFx",n),class extends c{constructor(t){super(t),this.setPostPipelineClass(n,"rexSplitPostFx")}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexsplitpipelineplugin=e();