@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 5.34 kB
JavaScript
var t,e;t=void 0,e=function(){const t=Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,e=Phaser.Utils.Objects.GetValue;class n extends t{constructor(t){super({name:"rexHslAdjustPostFx",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 float hueRotate;\nuniform float satAdjust;\nuniform float lumAdjust;\nvec3 RGBToHSL(vec3 color) {\n vec3 hsl = vec3(0.0, 0.0, 0.0);\n\t\n float fmin = min(min(color.r, color.g), color.b);\n float fmax = max(max(color.r, color.g), color.b);\n float delta = fmax - fmin;\n\n hsl.z = (fmax + fmin) / 2.0;\n\n if (delta == 0.0) {\n\t\thsl.x = 0.0;\n\t\thsl.y = 0.0;\n\t} else {\n\t\tif (hsl.z < 0.5) {\n\t\t\thsl.y = delta / (fmax + fmin);\n } else {\n hsl.y = delta / (2.0 - fmax - fmin);\n }\n\t\t\n\t\tfloat dR = (((fmax - color.r) / 6.0) + (delta / 2.0)) / delta;\n\t\tfloat dG = (((fmax - color.g) / 6.0) + (delta / 2.0)) / delta;\n\t\tfloat dB = (((fmax - color.b) / 6.0) + (delta / 2.0)) / delta;\n\n\t\tif (color.r == fmax) {\n\t\t\thsl.x = dB - dG;\n } else if (color.g == fmax) {\n\t\t\thsl.x = (1.0 / 3.0) + dR - dB;\n\t\t} else if (color.b == fmax) {\n hsl.x = (2.0 / 3.0) + dG - dR;\n }\n\n\t\tif (hsl.x < 0.0) {\n\t\t\thsl.x += 1.0;\n } else if (hsl.x > 1.0) {\n hsl.x -= 1.0;\n }\n\t}\n\n\treturn hsl;\n}\nfloat HUEToRGB(float f1, float f2, float hue) {\n if (hue < 0.0) {\n hue += 1.0;\n } else if (hue > 1.0) {\n hue -= 1.0;\n }\n \t\n float ret;\n\t\n\tif ((6.0 * hue) < 1.0) {\n\t\tret = f1 + (f2 - f1) * 6.0 * hue;\n } else if ((2.0 * hue) < 1.0) {\n\t\tret = f2;\n\t} else if ((3.0 * hue) < 2.0) {\n\t\tret = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;\n } else {\n ret = f1;\n }\n\t\n return ret;\n}\nvec3 HSLToRGB(vec3 hsl) {\n\tvec3 rgb = vec3(hsl.z);\n\t\n\tif (hsl.y != 0.0) {\n\t\tfloat f2;\n\t\t\n\t\tif (hsl.z < 0.5) {\n\t\t f2 = hsl.z * (1.0 + hsl.y);\n } else {\n f2 = (hsl.z + hsl.y) - (hsl.y * hsl.z);\n }\n\t\t\t\n\t\tfloat f1 = 2.0 * hsl.z - f2;\n\t\t\n\t\trgb.r = HUEToRGB(f1, f2, hsl.x + (1.0 / 3.0));\n\t\trgb.g = HUEToRGB(f1, f2, hsl.x);\n\t\trgb.b = HUEToRGB(f1, f2, hsl.x - (1.0 / 3.0));\n }\n \n return rgb;\n}\nvoid main(void) {\n\tvec4 front = texture2D(uMainSampler, outTexCoord);\n\tvec3 hsl = RGBToHSL(front.rgb);\n\thsl.x -= hueRotate;\n\thsl.y *= satAdjust;\n\thsl.z += (lumAdjust - 0.5) * front.a;\n\tvec3 rgb = HSLToRGB(hsl);\n\tgl_FragColor = vec4(rgb, front.a);\n}\n"}),this.hueRotate=0,this.satAdjust=1,this.lumAdjust=.5}resetFromJSON(t){return this.setHueRotate(e(t,"hueRotate",0)),this.setSatAdjust(e(t,"satAdjust",1)),this.setLumAdjust(e(t,"lumAdjust",.5)),this}onPreRender(){this.set1f("hueRotate",this.hueRotate%1),this.set1f("satAdjust",this.satAdjust),this.set1f("lumAdjust",this.lumAdjust)}setHueRotate(t){return this.hueRotate=t,this}setSatAdjust(t){return this.satAdjust=t,this}setLumAdjust(t){return this.lumAdjust=t,this}}const s=Phaser.Game;var i=function(t){return t instanceof s};const l=Phaser.Scene;var o=function(t){return t instanceof l},r=function(t,e,n){var s;(s=t,null==s||"object"!=typeof s?null:i(s)?s:i(s.game)?s.game:o(s)?s.sys.game:o(s.scene)?s.scene.sys.game:void 0).renderer.pipelines.addPostPipeline(e,n)};const a=Phaser.Utils.Array.SpliceOne;class f extends Phaser.Plugins.BasePlugin{setPostPipelineClass(t,e){return this.PostFxPipelineClass=t,this.postFxPipelineName=e,this}start(){this.game.events.once("destroy",this.destroy,this),r(this.game,this.postFxPipelineName,this.PostFxPipelineClass)}add(t,e){return function(t,e,n){void 0===n&&(n={}),t.setPostPipeline(e);var s=t.postPipelines[t.postPipelines.length-1];return s.resetFromJSON(n),n.name&&(s.name=n.name),s}(t,this.PostFxPipelineClass,e)}remove(t,e){return function(t,e,n){if(void 0===n)for(var s=(i=t.postPipelines).length-1;s>=0;s--)(o=i[s])instanceof e&&(o.destroy(),a(i,s));else{s=0;for(var i,l=(i=t.postPipelines).length;s<l;s++){var o;(o=i[s])instanceof e&&o.name===n&&(o.destroy(),a(i,s))}}t.hasPostPipeline=t.postPipelines.length>0}(t,this.PostFxPipelineClass,e),this}get(t,e){return function(t,e,n){if(void 0===n){for(var s=[],i=0,l=(o=t.postPipelines).length;i<l;i++)(r=o[i])instanceof e&&s.push(r);return s}var o;for(i=0,l=(o=t.postPipelines).length;i<l;i++){var r;if((r=o[i])instanceof e&&r.name===n)return r}}(t,this.PostFxPipelineClass,e)}}var h=function(t){return null==t||""===t||0===t.length};return function(t,e,n,s){if(void 0===s&&(s="."),"object"==typeof t)if(h(e)){if(null==n)return;"object"==typeof n&&(t=n)}else{"string"==typeof e&&(e=e.split(s));var i=e.pop(),l=function(t,e,n){var s=t;if(h(e));else{var i;"string"==typeof e&&(e=e.split("."));for(var l=0,o=e.length;l<o;l++){var r;null!=s[i=e[l]]&&"object"==typeof s[i]||(r=l===o-1?void 0===n?{}:n:{},s[i]=r),s=s[i]}}return s}(t,e);l[i]=n}}(window,"RexPlugins.Pipelines.HslAdjustPostFx",n),class extends f{constructor(t){super(t),this.setPostPipelineClass(n,"rexHslAdjustPostFx")}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexhsladjustpipelineplugin=e();