scale2x.frag 859 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Scale2x scaler.
  2. uniform sampler2D tex;
  3. uniform sampler2D videoTex;
  4. in vec2 texStep; // could be uniform
  5. in vec2 coord2pi;
  6. in vec2 texCoord;
  7. in vec2 videoCoord;
  8. out vec4 fragColor;
  9. vec4 scaleNx()
  10. {
  11. vec4 delta;
  12. delta.xw = sin(coord2pi) * texStep;
  13. delta.yz = vec2(0.0);
  14. vec4 posLeftTop = texCoord.stst - delta;
  15. vec4 posRightBot = texCoord.stst + delta;
  16. vec4 left = texture(tex, posLeftTop.xy);
  17. vec4 top = texture(tex, posLeftTop.zw);
  18. vec4 right = texture(tex, posRightBot.xy);
  19. vec4 bot = texture(tex, posRightBot.zw);
  20. if (dot(left.rgb - right.rgb, top.rgb - bot.rgb) == 0.0 || left.rgb != top.rgb) {
  21. return texture(tex, texCoord.st);
  22. } else {
  23. return top;
  24. }
  25. }
  26. void main()
  27. {
  28. #if SUPERIMPOSE
  29. vec4 col = scaleNx();
  30. vec4 vid = texture(videoTex, videoCoord);
  31. fragColor = mix(vid, col, col.a);
  32. #else
  33. fragColor = scaleNx();
  34. #endif
  35. }