phaser3-rex-plugins
Version:
2 lines (1 loc) • 4.13 kB
JavaScript
var e,n;e=void 0,n=function(){const e=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,n=Phaser.Utils.Objects.GetValue;class t extends e{constructor(e){super({name:"rexCrtPostFx",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 warp;\nuniform float scanLineStrength;\nuniform float scanLineWidth;\n\nvoid main (void) {\n // squared distance from center\n vec2 uv = outTexCoord;\n vec2 dc = abs(0.5-uv);\n dc *= dc;\n \n // warp the fragment coordinates\n uv.x -= 0.5; \n uv.x *= 1.0+(dc.y*warp.x);\n uv.x += 0.5;\n\n uv.y -= 0.5; \n uv.y *= 1.0+(dc.x*warp.y); \n uv.y += 0.5;\n\n // sample inside boundaries, otherwise set to black\n if (uv.y > 1.0 || uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0) {\n gl_FragColor = vec4(0.0,0.0,0.0,1.0);\n } else {\n // float apply = abs(sin(outTexCoord.y*scanLineWidth)*scanLineStrength);\n // gl_FragColor = vec4(mix(texture2D(uMainSampler,uv).rgb,vec3(0.0),apply),1.0);\n vec4 color = texture2D(uMainSampler,uv);\n color.rgb *= (1.-scanLineStrength)+(sin(outTexCoord.y*scanLineWidth)*scanLineStrength);\n gl_FragColor = color;\n }\n}\n"}),this.warp=0,this.scanLineStrength=.2,this.scanLineWidth=1024}resetFromJSON(e){return this.setWarp(n(e,"warpX",.75),n(e,"warpY",.75)),this.setScanStrength(n(e,"scanLineStrength",.2)),this.setScanLineWidth(n(e,"scanLineWidth",1024)),this}onPreRender(){this.set2f("warp",this.warpX,this.warpY),this.set1f("scanLineStrength",this.scanLineStrength),this.set1f("scanLineWidth",this.scanLineWidth)}setWarp(e,n){return this.warpX=e,this.warpY=n,this}setScanStrength(e){return this.scanLineStrength=e,this}setScanLineWidth(e){return this.scanLineWidth=e,this}}const i=Phaser.Game;var s=function(e){return e instanceof i};const r=Phaser.Scene;var a=function(e){return e instanceof r},o=function(e,n,t){var i;(i=e,null==i||"object"!=typeof i?null:s(i)?i:s(i.game)?i.game:a(i)?i.sys.game:a(i.scene)?i.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,t)};const l=Phaser.Utils.Array.SpliceOne;class h extends Phaser.Plugins.BasePlugin{setPostPipelineClass(e,n){return this.PostFxPipelineClass=e,this.postFxPipelineName=n,this}start(){this.game.events.once("destroy",this.destroy,this),o(this.game,this.postFxPipelineName,this.PostFxPipelineClass)}add(e,n){return function(e,n,t){void 0===t&&(t={}),e.setPostPipeline(n);var i=e.postPipelines[e.postPipelines.length-1];return i.resetFromJSON(t),t.name&&(i.name=t.name),i}(e,this.PostFxPipelineClass,n)}remove(e,n){return function(e,n,t){if(void 0===t)for(var i=(s=e.postPipelines).length-1;i>=0;i--)(a=s[i])instanceof n&&(a.destroy(),l(s,i));else{i=0;for(var s,r=(s=e.postPipelines).length;i<r;i++){var a;(a=s[i])instanceof n&&a.name===t&&(a.destroy(),l(s,i))}}e.hasPostPipeline=e.postPipelines.length>0}(e,this.PostFxPipelineClass,n),this}get(e,n){return function(e,n,t){if(void 0===t){for(var i=[],s=0,r=(a=e.postPipelines).length;s<r;s++)(o=a[s])instanceof n&&i.push(o);return i}var a;for(s=0,r=(a=e.postPipelines).length;s<r;s++){var o;if((o=a[s])instanceof n&&o.name===t)return o}}(e,this.PostFxPipelineClass,n)}}var c=function(e){return null!==e&&"object"==typeof e};return function(e,n,t,i="."){if(!c(e))return e;if(function(e){return null==e}(n)||""===n||Array.isArray(n)&&0===n.length)return e;if("string"==typeof n&&-1===n.indexOf(i)||"number"==typeof n)return e[n]=t,e;var s=function(e,n){return Array.isArray(e)||(e="string"!=typeof e||""===e.trim()?[]:e.split(n).filter(Boolean)),e}(n,i);if(0===s.length)return e;for(var r=e,a=s.length,o=0;o<a-1;o++){var l=s[o],h=r[l];c(h)||(r[l]={}),r=r[l]}r[s[a-1]]=t}(window,"RexPlugins.Pipelines.CrtPostFx",t),class extends h{constructor(e){super(e),this.setPostPipelineClass(t,"rexCrtPostFx")}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).rexcrtpipelineplugin=n();