UNPKG

@petkoneo/phaser3-rex-plugins

Version:
2 lines (1 loc) 4.43 kB
var e,t;e=void 0,t=function(){const e=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,t=Phaser.Utils.Objects.GetValue,i=Phaser.Math.Clamp;class s extends e{constructor(e){super({name:"rexCrossStitchingPostFx",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 texSize;\nuniform vec2 stitchingSize;\nuniform float brightness;\n\nvoid main (void) {\n vec2 cPos = outTexCoord * texSize;\n int remX = int(mod(cPos.x, stitchingSize.x));\n int remY = int(mod(cPos.y, stitchingSize.y));\n vec2 tlPos;\n if (remX == 0 && remY == 0) {\n tlPos = cPos;\n } else {\n tlPos = floor(cPos / stitchingSize);\n tlPos.x = tlPos.x * stitchingSize.x;\n tlPos.y = tlPos.y * stitchingSize.y;\n }\n vec2 blPos = tlPos;\n blPos.y += (stitchingSize.y - 1.0);\n\n vec4 color0, color1;\n if (\n (remX == remY) || \n (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))\n ) {\n color0 = texture2D(uMainSampler, tlPos * vec2(1.0/texSize.x, 1.0/texSize.y)) * 1.4;\n color1 = vec4(0.2, 0.15, 0.05, 1.0);\n } else {\n color0 = vec4(0.0, 0.0, 0.0, 1.0);\n color1 = texture2D(uMainSampler, tlPos * vec2(1.0/texSize.x, 1.0/texSize.y)) * 1.4; \n }\n gl_FragColor = mix(color0, color1, brightness);\n}\n"}),this.stitchingWidth=6,this.stitchingHeight=6,this._brightness=0}resetFromJSON(e){return this.setStitchingSize(t(e,"stitchingWidth",6),t(e,"stitchingHeight",6)),this.setBrightness(t(e,"brightness",0)),this}onPreRender(){this.set2f("stitchingSize",this.stitchingWidth,this.stitchingHeight),this.set2f("texSize",this.renderer.width,this.renderer.height),this.set1f("brightness",this._brightness)}setStitchingWidth(e){return this.stitchingWidth=e,this}setStitchingHeight(e){return this.stitchingHeight=e,this}setStitchingSize(e,t){return void 0===t&&(t=e),this.stitchingWidth=e,this.stitchingHeight=t,this}get brightness(){return this._brightness}set brightness(e){this._brightness=i(e,0,1)}setBrightness(e){return this.brightness=e,this}}const n=Phaser.Game;var r=function(e){return e instanceof n};const o=Phaser.Scene;var h=function(e){return e instanceof o},l=function(e,t,i){var s;(s=e,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(t,i)};const c=Phaser.Utils.Array.SpliceOne;class a extends Phaser.Plugins.BasePlugin{setPostPipelineClass(e,t){return this.PostFxPipelineClass=e,this.postFxPipelineName=t,this}start(){this.game.events.once("destroy",this.destroy,this),l(this.game,this.postFxPipelineName,this.PostFxPipelineClass)}add(e,t){return function(e,t,i){void 0===i&&(i={}),e.setPostPipeline(t);var s=e.postPipelines[e.postPipelines.length-1];return s.resetFromJSON(i),i.name&&(s.name=i.name),s}(e,this.PostFxPipelineClass,t)}remove(e,t){return function(e,t,i){if(void 0===i)for(var s=(n=e.postPipelines).length-1;s>=0;s--)(o=n[s])instanceof t&&(o.destroy(),c(n,s));else{s=0;for(var n,r=(n=e.postPipelines).length;s<r;s++){var o;(o=n[s])instanceof t&&o.name===i&&(o.destroy(),c(n,s))}}e.hasPostPipeline=e.postPipelines.length>0}(e,this.PostFxPipelineClass,t),this}get(e,t){return function(e,t,i){if(void 0===i){for(var s=[],n=0,r=(o=e.postPipelines).length;n<r;n++)(h=o[n])instanceof t&&s.push(h);return s}var o;for(n=0,r=(o=e.postPipelines).length;n<r;n++){var h;if((h=o[n])instanceof t&&h.name===i)return h}}(e,this.PostFxPipelineClass,t)}}var g=function(e){return null==e||""===e||0===e.length};return function(e,t,i,s){if(void 0===s&&(s="."),"object"==typeof e)if(g(t)){if(null==i)return;"object"==typeof i&&(e=i)}else{"string"==typeof t&&(t=t.split(s));var n=t.pop(),r=function(e,t,i){var s=e;if(g(t));else{var n;"string"==typeof t&&(t=t.split("."));for(var r=0,o=t.length;r<o;r++){var h;null!=s[n=t[r]]&&"object"==typeof s[n]||(h=r===o-1?void 0===i?{}:i:{},s[n]=h),s=s[n]}}return s}(e,t);r[n]=i}}(window,"RexPlugins.Pipelines.CrossStitchingPostFx",s),class extends a{constructor(e){super(e),this.setPostPipelineClass(s,"rexCrossStitchingPostFx")}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexcrossstitchingpipelineplugin=t();