scalefx-pass1.fs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #version 150
  2. /*
  3. ScaleFX - Pass 1
  4. by Sp00kyFox, 2017-03-01
  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 1 calculates the strength of interpolation candidates.
  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. #define SFX_CLR 0.5
  32. #define SFX_SAA 1.0
  33. uniform sampler2D source[];
  34. uniform vec4 sourceSize[];
  35. uniform vec4 targetSize;
  36. in Vertex {
  37. vec2 vTexCoord;
  38. };
  39. out vec4 FragColor;
  40. // corner strength
  41. float str(float d, vec2 a, vec2 b){
  42. float diff = a.x - a.y;
  43. float wght1 = max(SFX_CLR - d, 0) / SFX_CLR;
  44. float wght2 = clamp((1-d) + (min(a.x, b.x) + a.x > min(a.y, b.y) + a.y ? diff : -diff), 0, 1);
  45. return (SFX_SAA == 1 || 2*d < a.x + a.y) ? (wght1 * wght2) * (a.x * a.y) : 0;
  46. }
  47. void main() {
  48. /* grid metric pattern
  49. A B x y z x y
  50. D E F o w w z
  51. G H I
  52. */
  53. #define TEX(x, y) textureOffset(source[0], vTexCoord, ivec2(x, y))
  54. // metric data
  55. vec4 A = TEX(-1,-1), B = TEX( 0,-1);
  56. vec4 D = TEX(-1, 0), E = TEX( 0, 0), F = TEX( 1, 0);
  57. vec4 G = TEX(-1, 1), H = TEX( 0, 1), I = TEX( 1, 1);
  58. // corner strength
  59. vec4 res;
  60. res.x = str(D.z, vec2(D.w, E.y), vec2(A.w, D.y));
  61. res.y = str(F.x, vec2(E.w, E.y), vec2(B.w, F.y));
  62. res.z = str(H.z, vec2(E.w, H.y), vec2(H.w, I.y));
  63. res.w = str(H.x, vec2(D.w, H.y), vec2(G.w, G.y));
  64. FragColor = res;
  65. }