ntsc-pass1.fs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // NTSC Shader - written by Hans-Kristian Arntzen
  2. // License: GPLv3
  3. // pulled from git://github.com/libretro/common-shaders.git on 01/30/2014
  4. #version 150
  5. uniform sampler2D source[];
  6. uniform vec4 sourceSize[];
  7. uniform vec4 targetSize;
  8. uniform int phase;
  9. // uniforms added for compatibility
  10. out vec3 col;
  11. out float mod_phase;
  12. out float chroma_phase;
  13. #define THREE_PHASE
  14. #define COMPOSITE
  15. // #include "ntsc-param.inc" //
  16. #define PI 3.14159265
  17. #if defined(TWO_PHASE)
  18. #define CHROMA_MOD_FREQ (4.0 * PI / 15.0)
  19. #elif defined(THREE_PHASE)
  20. #define CHROMA_MOD_FREQ (PI / 3.0)
  21. #endif
  22. #if defined(COMPOSITE)
  23. #define SATURATION 1.0
  24. #define BRIGHTNESS 1.0
  25. #define ARTIFACTING 1.0
  26. #define FRINGING 1.0
  27. #elif defined(SVIDEO)
  28. #define SATURATION 1.0
  29. #define BRIGHTNESS 1.0
  30. #define ARTIFACTING 0.0
  31. #define FRINGING 0.0
  32. #endif
  33. #if defined(COMPOSITE) || defined(SVIDEO)
  34. mat3 mix_mat = mat3(
  35. BRIGHTNESS, FRINGING, FRINGING,
  36. ARTIFACTING, 2.0 * SATURATION, 0.0,
  37. ARTIFACTING, 0.0, 2.0 * SATURATION
  38. );
  39. #endif
  40. // END "ntsc-param.inc" //
  41. // moved from vertex
  42. #define pix_no (texCoord.xy * sourceSize[0].xy * (targetSize.xy / sourceSize[0].xy))
  43. in Vertex {
  44. vec2 texCoord;
  45. };
  46. out vec4 fragColor;
  47. mat3 yiq2rgb_mat = mat3(
  48. 1.0, 1.0, 1.0,
  49. 0.956, -0.2720, -1.1060,
  50. 0.6210, -0.6474, 1.7046
  51. );
  52. vec3 yiq2rgb(vec3 yiq)
  53. {
  54. return (yiq * yiq2rgb_mat);
  55. }
  56. mat3 yiq_mat = mat3(
  57. 0.2989, 0.5959, 0.2115,
  58. 0.5870, -0.2744, -0.5229,
  59. 0.1140, -0.3216, 0.3114
  60. );
  61. vec3 rgb2yiq(vec3 col)
  62. {
  63. return (col * yiq_mat);
  64. }
  65. void main() {
  66. // #include "ntsc-pass1-encode-demodulate.inc" //
  67. vec3 col = texture(source[0], texCoord).rgb;
  68. vec3 yiq = rgb2yiq(col);
  69. #if defined(TWO_PHASE)
  70. float chroma_phase = PI * (mod(pix_no.y, 2.0) + phase);
  71. #elif defined(THREE_PHASE)
  72. float chroma_phase = 0.6667 * PI * (mod(pix_no.y, 3.0) + phase);
  73. #endif
  74. float mod_phase = chroma_phase + pix_no.x * CHROMA_MOD_FREQ;
  75. float i_mod = cos(mod_phase);
  76. float q_mod = sin(mod_phase);
  77. yiq.yz *= vec2(i_mod, q_mod); // Modulate
  78. yiq *= mix_mat; // Cross-talk
  79. yiq.yz *= vec2(i_mod, q_mod); // Demodulate
  80. fragColor = vec4(yiq, 1.0);
  81. // END "ntsc-pass1-encode-demodulate.inc" //
  82. }