gaussian-scanlines.fs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Gaussian Scanlines
  2. //
  3. // adapted from NTSC Shader - written by Hans-Kristian Arntzen
  4. // License: GPLv3
  5. // pulled from git://github.com/libretro/common-shaders.git on 08/05/2013
  6. #version 150
  7. uniform sampler2D source[];
  8. uniform vec4 sourceSize[];
  9. uniform vec4 targetSize;
  10. uniform int phase;
  11. #define DISPLAY_GAMMA 2.1
  12. #define CRT_GAMMA 2.5
  13. #define one (sourceSize[0]) //this is set to 1.0 / sourceSize[0] in the original version, but I think this looks better
  14. #define pix_no texCoord.y * sourceSize[0]
  15. #define TEX(off) pow(texture(source[0], texCoord - vec2(0.0, (off) * one.y)).rgb, vec3(CRT_GAMMA))
  16. in Vertex {
  17. vec2 texCoord;
  18. };
  19. out vec4 fragColor;
  20. void main() {
  21. vec3 frame0 = TEX(-2.0);
  22. vec3 frame1 = TEX(-1.0);
  23. vec3 frame2 = TEX(0.0);
  24. vec3 frame3 = TEX(1.0);
  25. vec3 frame4 = TEX(2.0);
  26. float offset_dist = fract(pix_no.y) - 0.5;
  27. float dist0 = 2.0 + offset_dist;
  28. float dist1 = 1.0 + offset_dist;
  29. float dist2 = 0.0 + offset_dist;
  30. float dist3 = -1.0 + offset_dist;
  31. float dist4 = -2.0 + offset_dist;
  32. vec3 scanline = frame0 * exp(-5.0 * dist0 * dist0);
  33. scanline += frame1 * exp(-5.0 * dist1 * dist1);
  34. scanline += frame2 * exp(-5.0 * dist2 * dist2);
  35. scanline += frame3 * exp(-5.0 * dist3 * dist3);
  36. scanline += frame4 * exp(-5.0 * dist4 * dist4);
  37. fragColor = vec4(pow(1.15 * scanline, vec3(1.0 / DISPLAY_GAMMA)), 1.0);
  38. }