crt-wave.frag 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* MegaZeux
  2. *
  3. * Copyright (C) 2017 David (astral) Cravens (decravens@gmail.com)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /*
  20. * crt-wave.frag - a fragment shader that generates scanlines with a sine wave
  21. * based on semisoft.frag
  22. *
  23. * settings:
  24. * DARKEN - how dark the gaps get
  25. * BOOST - how bright the scanlines are
  26. * SCAN_FREQUENCY - how rapidly down Y the wave oscillates
  27. */
  28. #version 110
  29. uniform sampler2D baseMap;
  30. varying vec2 vTexcoord;
  31. #define XS 1024.0
  32. #define YS 512.0
  33. #define AX 0.5/XS
  34. #define AY 0.5/YS
  35. #define TS vec2(XS, YS)
  36. // -- settings ---------------
  37. #define DARKEN 0.8
  38. #define BOOST 1.4
  39. #define SCAN_FREQUENCY 3.0
  40. // ---------------------------
  41. #define HALFERS ((BOOST - DARKEN) * 0.5)
  42. float calc_scanline( float y )
  43. {
  44. return DARKEN + HALFERS + sin(2.0*3.14*y/SCAN_FREQUENCY) * HALFERS;
  45. }
  46. void main( void )
  47. {
  48. vec2 tcbase = (floor(vTexcoord * TS + 0.5) + 0.5) / TS;
  49. vec2 tcdiff = vTexcoord - tcbase;
  50. vec2 sdiff = sign(tcdiff);
  51. vec2 adiff = pow(abs(tcdiff) * TS, vec2(3.0));
  52. gl_FragColor = texture2D(baseMap, tcbase + sdiff * adiff / TS) * calc_scanline(gl_FragCoord.y);
  53. }