scalefx-pass0.fs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #version 150
  2. /*
  3. ScaleFX - Pass 0
  4. by Sp00kyFox, 2016-03-30
  5. Filter: Nearest
  6. Scale: 1x
  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 0 prepares metric data for the next pass.
  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. // Reference: http://www.compuphase.com/cmetric.htm
  39. float eq(vec3 A, vec3 B)
  40. {
  41. float r = 0.5 * (A.r + B.r);
  42. vec3 d = A - B;
  43. vec3 c = vec3(2 + r, 4, 3 - r);
  44. return 1 - sqrt(dot(c*d, d)) / 3;
  45. }
  46. #define TEX(x, y) textureOffset(source[0], vTexCoord, ivec2(x, y))
  47. void main()
  48. {
  49. /* grid metric
  50. A B C x y z
  51. E F o w
  52. */
  53. // read texels
  54. vec3 A = TEX(-1,-1).rgb;
  55. vec3 B = TEX( 0,-1).rgb;
  56. vec3 C = TEX( 1,-1).rgb;
  57. vec3 E = TEX( 0, 0).rgb;
  58. vec3 F = TEX( 1, 0).rgb;
  59. // output
  60. FragColor = vec4(eq(E,A), eq(E,B), eq(E,C), eq(E,F));
  61. }