interlace.fs 962 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 150
  2. /*
  3. Interlacing
  4. Author: hunterk
  5. License: Public domain
  6. Note: This shader is designed to work with the typical interlaced output from an emulator, which displays both even and odd fields twice.
  7. This shader will un-weave the image, resulting in a standard, alternating-field interlacing.
  8. */
  9. uniform sampler2D source[];
  10. uniform vec2 targetSize;
  11. uniform vec4 sourceSize[];
  12. uniform int phase;
  13. in Vertex {
  14. vec2 texCoord;
  15. };
  16. out vec4 fragColor;
  17. // This controls how bright the intermediate lines are; 0.0 = totally black
  18. #define percent 0.0
  19. void main()
  20. {
  21. vec4 res = texture(source[0], texCoord);
  22. float y = 0.0;
  23. // assume anything with a vertical resolution greater than 400 lines is interlaced
  24. if (sourceSize[0].y > 400.0) y = sourceSize[0].y * texCoord.y + phase;
  25. else
  26. y = 2.00001 * sourceSize[0].y * texCoord.y;
  27. if (mod(y, 2.0) > 0.99999) fragColor = res;
  28. else
  29. fragColor = vec4(percent) * res;
  30. }