UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 4.47 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 n 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 s=Phaser.Game;var r=function(e){return e instanceof s};const o=Phaser.Scene;var h=function(e){return e instanceof o},l=function(e,t,i){var n;(n=e,null==n||"object"!=typeof n?null:r(n)?n:r(n.game)?n.game:h(n)?n.sys.game:h(n.scene)?n.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 n=e.postPipelines[e.postPipelines.length-1];return n.resetFromJSON(i),i.name&&(n.name=i.name),n}(e,this.PostFxPipelineClass,t)}remove(e,t){return function(e,t,i){if(void 0===i)for(var n=(s=e.postPipelines).length-1;n>=0;n--)(o=s[n])instanceof t&&(o.destroy(),c(s,n));else{n=0;for(var s,r=(s=e.postPipelines).length;n<r;n++){var o;(o=s[n])instanceof t&&o.name===i&&(o.destroy(),c(s,n))}}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 n=[],s=0,r=(o=e.postPipelines).length;s<r;s++)(h=o[s])instanceof t&&n.push(h);return n}var o;for(s=0,r=(o=e.postPipelines).length;s<r;s++){var h;if((h=o[s])instanceof t&&h.name===i)return h}}(e,this.PostFxPipelineClass,t)}}var g=function(e){return null!==e&&"object"==typeof e};return function(e,t,i,n="."){if(!g(e))return e;if(function(e){return null==e}(t)||""===t||Array.isArray(t)&&0===t.length)return e;if("string"==typeof t&&-1===t.indexOf(n)||"number"==typeof t)return e[t]=i,e;var s=function(e,t){return Array.isArray(e)||(e="string"!=typeof e||""===e.trim()?[]:e.split(t).filter(Boolean)),e}(t,n);if(0===s.length)return e;for(var r=e,o=s.length,h=0;h<o-1;h++){var l=s[h],c=r[l];g(c)||(r[l]={}),r=r[l]}r[s[o-1]]=i}(window,"RexPlugins.Pipelines.CrossStitchingPostFx",n),class extends a{constructor(e){super(e),this.setPostPipelineClass(n,"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();