phaser3-rex-plugins
Version:
2 lines (1 loc) • 5.38 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 r=Phaser.Scene;var l=function(t){return t instanceof r},o=function(t,e,n){var s;(s=t,null==s||"object"!=typeof s?null:i(s)?s:i(s.game)?s.game:l(s)?s.sys.game:l(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),o(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--)(l=i[s])instanceof e&&(l.destroy(),a(i,s));else{s=0;for(var i,r=(i=t.postPipelines).length;s<r;s++){var l;(l=i[s])instanceof e&&l.name===n&&(l.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,r=(l=t.postPipelines).length;i<r;i++)(o=l[i])instanceof e&&s.push(o);return s}var l;for(i=0,r=(l=t.postPipelines).length;i<r;i++){var o;if((o=l[i])instanceof e&&o.name===n)return o}}(t,this.PostFxPipelineClass,e)}}var u=function(t){return null!==t&&"object"==typeof t};return function(t,e,n,s="."){if(!u(t))return t;if(function(t){return null==t}(e)||""===e||Array.isArray(e)&&0===e.length)return t;if("string"==typeof e&&-1===e.indexOf(s)||"number"==typeof e)return t[e]=n,t;var i=function(t,e){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(e).filter(Boolean)),t}(e,s);if(0===i.length)return t;for(var r=t,l=i.length,o=0;o<l-1;o++){var a=i[o],f=r[a];u(f)||(r[a]={}),r=r[a]}r[i[l-1]]=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();