sai.frag 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. uniform sampler2D tex;
  2. uniform sampler2D videoTex;
  3. in vec4 posABCD;
  4. in vec4 posEL;
  5. in vec4 posGJ;
  6. in vec3 scaled;
  7. in vec2 videoCoord;
  8. out vec4 fragColor;
  9. void swap(inout vec4 a, inout vec4 b)
  10. {
  11. vec4 t = a; a = b; b = t;
  12. }
  13. vec4 sai()
  14. {
  15. vec4 A = texture(tex, posABCD.xy);
  16. vec4 B = texture(tex, posABCD.zy);
  17. vec4 C = texture(tex, posABCD.xw);
  18. vec4 D = texture(tex, posABCD.zw);
  19. vec3 pp = fract(scaled);
  20. bvec2 b1 = bvec2(A.rgb == D.rgb, B.rgb == C.rgb);
  21. bvec2 b2 = b1 && not(b1.yx);
  22. if (b2.x || b2.y) {
  23. vec4 pos1 = posEL.xyzw;
  24. vec4 pos2 = posGJ.xyzw;
  25. vec2 p = pp.xz;
  26. if (b2.y) {
  27. swap(A, B);
  28. swap(C, D);
  29. pos1 = posEL.zyxw;
  30. pos2 = posGJ.zyxw;
  31. p = pp.yz;
  32. }
  33. vec4 E = texture(tex, pos1.xy);
  34. vec4 L = texture(tex, pos1.zw);
  35. vec4 G = texture(tex, pos2.xy);
  36. vec4 J = texture(tex, pos2.zw);
  37. vec2 d = p / 2.0 - 0.25;
  38. float d2 = p.y - p.x;
  39. bvec4 b5 = bvec4(A.rgb == J.rgb, A.rgb == E.rgb,
  40. A.rgb == G.rgb, A.rgb == L.rgb);
  41. bvec4 b7 = b5 && not(b5.yxwz);
  42. bvec4 l;
  43. l.xy = lessThan(vec2(d), vec2(0.0));
  44. l.zw = not(l.xy);
  45. bvec4 b8 = l.ywzx && b7.xzyw;
  46. if (b8.x) {
  47. return mix(A, B, -d.y);
  48. } else if (b8.y) {
  49. return mix(A, C, d.y);
  50. } else if (b8.z) {
  51. return mix(A, B, d.x);
  52. } else if (b8.w) {
  53. return mix(A, C, -d.x);
  54. } else if (d2 < 0.0) {
  55. return mix(A, B, -d2);
  56. } else {
  57. return mix(A, C, d2);
  58. }
  59. } else {
  60. return mix(mix(A, B, pp.x), mix(C, D, pp.x), pp.z);
  61. }
  62. }
  63. void main()
  64. {
  65. #if SUPERIMPOSE
  66. vec4 col = sai();
  67. vec4 vid = texture(videoTex, videoCoord);
  68. fragColor = mix(vid, col, col.a);
  69. #else
  70. fragColor = sai();
  71. #endif
  72. }