greyscale.frag 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* MegaZeux
  2. *
  3. * Copyright (C) 2008 Joel Bouchard Lamontagne <logicow@gmail.com>
  4. * Copyright (C) 2009 Alistair John Strachan <alistair@devzero.co.uk>
  5. * Copyright (C) 2017 Alice Rowan <petrifiedrowan@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #version 110
  22. /* Greyscale scaling shader based on nearest.frag */
  23. uniform sampler2D baseMap;
  24. varying vec2 vTexcoord;
  25. #define TEX_SCREEN_WIDTH 1024.0
  26. #define TEX_SCREEN_HEIGHT 512.0
  27. #define HALF_PIXEL_X 0.5 / TEX_SCREEN_WIDTH
  28. #define HALF_PIXEL_Y 0.5 / TEX_SCREEN_HEIGHT
  29. void main(void)
  30. {
  31. const vec4 weight = vec4(0.30, 0.59, 0.11, 0);
  32. vec2 src = vec2(
  33. floor(vTexcoord.x * TEX_SCREEN_WIDTH) / TEX_SCREEN_WIDTH + HALF_PIXEL_X,
  34. floor(vTexcoord.y * TEX_SCREEN_HEIGHT) / TEX_SCREEN_HEIGHT + HALF_PIXEL_Y
  35. );
  36. vec4 color = texture2D(baseMap, src);
  37. float lum = dot(color, weight);
  38. gl_FragColor = vec4(lum, lum, lum, 1.0);
  39. }