Advertisement
Diamonite

pipelineFxOutlineTest

Apr 30th, 2025 (edited)
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function core() {
  2.     function t() {
  3.         const e = "#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 float thickness;\nuniform vec3 outlineColor;\n\nconst float DOUBLE_PI = 3.14159265358979323846264 * 2.;\n\nvoid main() {\n  vec4 front = texture2D(uMainSampler, outTexCoord);\n\n  if (thickness > 0.0) {\n    vec2 mag = vec2(thickness/texSize.x, thickness/texSize.y);\n    vec4 curColor;\n    float maxAlpha = front.a;\n    vec2 offset;\n    for (float angle = 0.; angle < DOUBLE_PI; angle += #{angleStep}) {\n        offset = vec2(mag.x * cos(angle), mag.y * sin(angle));        \n        curColor = texture2D(uMainSampler, outTexCoord + offset);\n        maxAlpha = max(maxAlpha, curColor.a);\n    }\n    vec3 resultColor = front.rgb + (outlineColor.rgb * (1. - front.a)) * maxAlpha;\n    gl_FragColor = vec4(resultColor, maxAlpha);\n  } else {\n    gl_FragColor = front;\n  }\n}\n";
  4.         var t = function(t) {
  5.             void 0 === t && (t = .1);
  6.             var n = Math.max(100 * t, 1),
  7.                 i = (2 * Math.PI / n).toFixed(7);
  8.             return e.replace(/\#\{angleStep\}/, i)
  9.         };
  10.         const n = Phaser.Renderer.WebGL.Pipelines.PostFXPipeline,
  11.             i = Phaser.Utils.Objects.GetValue,
  12.             s = Phaser.Display.Color.IntegerToRGB,
  13.             o = Phaser.Display.Color;
  14.         var r = .1,
  15.             l = t(r);
  16.         class a extends n {
  17.             constructor(e) {
  18.                 super({
  19.                     name: "rexOutlinePostFx",
  20.                     game: e,
  21.                     renderTarget: !0,
  22.                     fragShader: l
  23.                 }), this.thickness = 0, this._outlineColor = new o
  24.             }
  25.             resetFromJSON(e) {
  26.                 return this.setThickness(i(e, "thickness", 3)), this.setOutlineColor(i(e, "outlineColor", 16777215)), this
  27.             }
  28.             onPreRender() {
  29.                 this.set1f("thickness", this.thickness), this.set3f("outlineColor", this._outlineColor.redGL, this._outlineColor.greenGL, this._outlineColor.blueGL), this.set2f("texSize", this.renderer.width, this.renderer.height)
  30.             }
  31.             setThickness(e) {
  32.                 return this.thickness = e, this
  33.             }
  34.             get outlineColor() {
  35.                 return this._outlineColor
  36.             }
  37.             set outlineColor(e) {
  38.                 "number" == typeof e && (e = s(e)), this._outlineColor.setFromRGB(e)
  39.             }
  40.             setOutlineColor(e) {
  41.                 return this.outlineColor = e, this
  42.             }
  43.             static setQuality(e) {
  44.                 r !== e && (r = e, l = t(e))
  45.             }
  46.             static getQuality() {
  47.                 return r
  48.             }
  49.         }
  50.         const u = Phaser.Game;
  51.         var h = function(e) {
  52.             return e instanceof u
  53.         };
  54.         const f = Phaser.Scene;
  55.         var p = function(e) {
  56.                 return e instanceof f
  57.             },
  58.             c = function(e, t, n) {
  59.                 var i;
  60.                 (i = e, null == i || "object" != typeof i ? null : h(i) ? i : h(i.game) ? i.game : p(i) ? i.sys.game : p(i.scene) ? i.scene.sys.game : void 0).renderer.pipelines.addPostPipeline(t, n)
  61.             };
  62.         const d = Phaser.Utils.Array.SpliceOne;
  63.         class g extends Phaser.Plugins.BasePlugin {
  64.             setPostPipelineClass(e, t) {
  65.                 return this.PostFxPipelineClass = e, this.postFxPipelineName = t, this
  66.             }
  67.             start() {
  68.                 this.game.events.once("destroy", this.destroy, this), c(this.game, this.postFxPipelineName, this.PostFxPipelineClass)
  69.             }
  70.             add(e, t) {
  71.                 return function(e, t, n) {
  72.                     void 0 === n && (n = {}), e.setPostPipeline(t);
  73.                     var i = e.postPipelines[e.postPipelines.length - 1];
  74.                     return i.resetFromJSON(n), n.name && (i.name = n.name), i
  75.                 }(e, this.PostFxPipelineClass, t)
  76.             }
  77.             remove(e, t) {
  78.                 return function(e, t, n) {
  79.                     if (void 0 === n)
  80.                         for (var i = (s = e.postPipelines).length - 1; i >= 0; i--)(r = s[i]) instanceof t && (r.destroy(), d(s, i));
  81.                     else {
  82.                         i = 0;
  83.                         for (var s, o = (s = e.postPipelines).length; i < o; i++) {
  84.                             var r;
  85.                             (r = s[i]) instanceof t && r.name === n && (r.destroy(), d(s, i))
  86.                         }
  87.                     }
  88.                     e.hasPostPipeline = e.postPipelines.length > 0
  89.                 }(e, this.PostFxPipelineClass, t), this
  90.             }
  91.             get(e, t) {
  92.                 return function(e, t, n) {
  93.                     if (void 0 === n) {
  94.                         for (var i = [], s = 0, o = (r = e.postPipelines).length; s < o; s++)(l = r[s]) instanceof t && i.push(l);
  95.                         return i
  96.                     }
  97.                     var r;
  98.                     for (s = 0, o = (r = e.postPipelines).length; s < o; s++) {
  99.                         var l;
  100.                         if ((l = r[s]) instanceof t && l.name === n) return l
  101.                     }
  102.                 }(e, this.PostFxPipelineClass, t)
  103.             }
  104.         }
  105.         var P = function(e) {
  106.             return null == e || "" === e || 0 === e.length
  107.         };
  108.         const m = Phaser.Utils.Objects.GetValue;
  109.         return function(e, t, n, i) {
  110.             if (void 0 === i && (i = "."), "object" == typeof e)
  111.                 if (P(t)) {
  112.                     if (null == n) return;
  113.                     "object" == typeof n && (e = n)
  114.                 } else {
  115.                     "string" == typeof t && (t = t.split(i));
  116.                     var s = t.pop(),
  117.                         o = function(e, t, n) {
  118.                             var i = e;
  119.                             if (P(t));
  120.                             else {
  121.                                 var s;
  122.                                 "string" == typeof t && (t = t.split("."));
  123.                                 for (var o = 0, r = t.length; o < r; o++) {
  124.                                     var l;
  125.                                     null != i[s = t[o]] && "object" == typeof i[s] || (l = o === r - 1 ? void 0 === n ? {} : n : {}, i[s] = l), i = i[s]
  126.                                 }
  127.                             }
  128.                             return i
  129.                         }(e, t);
  130.                     o[s] = n
  131.                 }
  132.         }(window, "RexPlugins.Pipelines.OutlinePostFx", a), class extends g {
  133.             constructor(e) {
  134.                 super(e), this.setPostPipelineClass(a, "rexOutlinePostFx")
  135.             }
  136.             add(e, t) {
  137.                 return this.setQuality(m(t, "quality", this.quality)), super.add(e, t)
  138.             }
  139.             setQuality(e) {
  140.                 return a.setQuality(e), this
  141.             }
  142.             set quality(e) {
  143.                 this.setQuality(e)
  144.             }
  145.             get quality() {
  146.                 return a.getQuality()
  147.             }
  148.         }
  149.     }, "object" == typeof exports && "undefined" != typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define(t) : (e = "undefined" != typeof globalThis ? globalThis : e || self).rexoutlinepipelineplugin = t();
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement