scalefx-pass3.fs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #version 150
  2. /*
  3. ScaleFX - Pass 3
  4. by Sp00kyFox, 2016-03-30
  5. Filter: Nearest
  6. Scale: 3x
  7. ScaleFX is an edge interpolation algorithm specialized in pixel art. It was
  8. originally intended as an improvement upon Scale3x but became a new filter in
  9. its own right.
  10. ScaleFX interpolates edges up to level 6 and makes smooth transitions between
  11. different slopes. The filtered picture will only consist of colours present
  12. in the original.
  13. Pass 3 outputs subpixels based on previously calculated tags.
  14. Copyright (c) 2016 Sp00kyFox - ScaleFX@web.de
  15. Permission is hereby granted, free of charge, to any person obtaining a copy
  16. of this software and associated documentation files (the "Software"), to deal
  17. in the Software without restriction, including without limitation the rights
  18. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  19. copies of the Software, and to permit persons to whom the Software is
  20. furnished to do so, subject to the following conditions:
  21. The above copyright notice and this permission notice shall be included in
  22. all copies or substantial portions of the Software.
  23. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. THE SOFTWARE.
  30. */
  31. uniform sampler2D source[];
  32. uniform vec4 sourceSize[];
  33. uniform vec4 targetSize;
  34. in Vertex {
  35. vec2 vTexCoord;
  36. };
  37. out vec4 FragColor;
  38. // extract corners
  39. vec4 loadCrn(vec4 x){
  40. return floor(mod(x*80.0 + 0.5, 9.0));
  41. }
  42. // extract mids
  43. vec4 loadMid(vec4 x){
  44. return floor(mod(x*8.888888 + 0.055555, 9.0));
  45. }
  46. void main() {
  47. /* grid corners mids
  48. B x y x
  49. D E F w y
  50. H w z z
  51. */
  52. // read data
  53. vec4 E = texture(source[0], vTexCoord);
  54. // extract data
  55. vec4 crn = loadCrn(E);
  56. vec4 mid = loadMid(E);
  57. // determine subpixel
  58. vec2 fp = floor(3.0 * fract(vTexCoord*sourceSize[0].xy));
  59. float sp = fp.y == 0 ? (fp.x == 0 ? crn.x : fp.x == 1 ? mid.x : crn.y) : (fp.y == 1 ? (fp.x == 0 ? mid.w : fp.x == 1 ? 0 : mid.y) : (fp.x == 0 ? crn.w : fp.x == 1 ? mid.z : crn.z));
  60. // output coordinate - 0 = E, 1 = D, 2 = D0, 3 = F, 4 = F0, 5 = B, 6 = B0, 7 = H, 8 = H0
  61. vec2 res = sp == 0 ? vec2(0,0) : sp == 1 ? vec2(-1,0) : sp == 2 ? vec2(-2,0) : sp == 3 ? vec2(1,0) : sp == 4 ? vec2(2,0) : sp == 5 ? vec2(0,-1) : sp == 6 ? vec2(0,-2) : sp == 7 ? vec2(0,1) : vec2(0,2);
  62. // ouput
  63. FragColor = texture(source[3], vTexCoord + 1/sourceSize[0].xy * res);
  64. }