@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 4.09 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 o=function(e){return e instanceof r},a=function(e,n,t){var i;(i=e,null==i||"object"!=typeof i?null:s(i)?i:s(i.game)?i.game:o(i)?i.sys.game:o(i.scene)?i.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(n,t)};const l=Phaser.Utils.Array.SpliceOne;class p extends Phaser.Plugins.BasePlugin{setPostPipelineClass(e,n){return this.PostFxPipelineClass=e,this.postFxPipelineName=n,this}start(){this.game.events.once("destroy",this.destroy,this),a(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--)(o=s[i])instanceof n&&(o.destroy(),l(s,i));else{i=0;for(var s,r=(s=e.postPipelines).length;i<r;i++){var o;(o=s[i])instanceof n&&o.name===t&&(o.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=(o=e.postPipelines).length;s<r;s++)(a=o[s])instanceof n&&i.push(a);return i}var o;for(s=0,r=(o=e.postPipelines).length;s<r;s++){var a;if((a=o[s])instanceof n&&a.name===t)return a}}(e,this.PostFxPipelineClass,n)}}var h=function(e){return null==e||""===e||0===e.length};return function(e,n,t,i){if(void 0===i&&(i="."),"object"==typeof e)if(h(n)){if(null==t)return;"object"==typeof t&&(e=t)}else{"string"==typeof n&&(n=n.split(i));var s=n.pop(),r=function(e,n,t){var i=e;if(h(n));else{var s;"string"==typeof n&&(n=n.split("."));for(var r=0,o=n.length;r<o;r++){var a;null!=i[s=n[r]]&&"object"==typeof i[s]||(a=r===o-1?void 0===t?{}:t:{},i[s]=a),i=i[s]}}return i}(e,n);r[s]=t}}(window,"RexPlugins.Pipelines.CrtPostFx",t),class extends p{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();