epx.frag 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* MegaZeux
  2. *
  3. * Copyright (C) 2017 GreaseMonkey
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #version 110
  20. // vim:syntax=c:sts=3:sw=3:et:
  21. // EPX scaler by GreaseMonkey
  22. uniform sampler2D baseMap;
  23. varying vec2 vTexcoord;
  24. #define XS 1024.0
  25. #define YS 512.0
  26. void main(void)
  27. {
  28. vec2 tcstepx = vec2(1.0/XS, 0.0);
  29. vec2 tcstepy = vec2(0.0, 1.0/YS);
  30. vec2 tcbase = (floor(vTexcoord*vec2(XS, YS)) + vec2(0.5, 0.5))/vec2(XS, YS);
  31. vec4 c0 = texture2D(baseMap, tcbase);
  32. vec4 c1 = texture2D(baseMap, tcbase-tcstepy);
  33. vec4 c2 = texture2D(baseMap, tcbase-tcstepx);
  34. vec4 c3 = texture2D(baseMap, tcbase+tcstepy);
  35. vec4 c4 = texture2D(baseMap, tcbase+tcstepx);
  36. vec4 final = c0;
  37. ivec2 subpos = ivec2(mod(vTexcoord*vec2(XS, YS)*2.0, 2.0));
  38. int subpos_i = subpos.x + (subpos.y*2);
  39. if(subpos_i == 0)
  40. {
  41. if(c1 == c2 && c1 != c3 && c1 != c4)
  42. final = c1;
  43. }
  44. else
  45. if(subpos_i == 2)
  46. {
  47. if(c2 == c3 && c2 != c4 && c2 != c1)
  48. final = c2;
  49. }
  50. else
  51. if(subpos_i == 3)
  52. {
  53. if(c3 == c4 && c3 != c1 && c3 != c2)
  54. final = c3;
  55. }
  56. else
  57. if(subpos_i == 1)
  58. {
  59. if(c4 == c1 && c4 != c2 && c4 != c3)
  60. final = c4;
  61. }
  62. gl_FragColor = final;
  63. }