gb-pass-1.fs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // This is a port of the original CG shader to the quark format
  2. // the original shader can be found here :
  3. // https://github.com/libretro/common-shaders/tree/master/handheld/gameboy
  4. ///////////////////////////////////////////////////////////////////////////
  5. // //
  6. // Gameboy Classic Shader v0.2.2 //
  7. // //
  8. // Copyright (C) 2013 Harlequin : unknown92835@gmail.com //
  9. // //
  10. // This program is free software: you can redistribute it and/or modify //
  11. // it under the terms of the GNU General Public License as published by //
  12. // the Free Software Foundation, either version 3 of the License, or //
  13. // (at your option) any later version. //
  14. // //
  15. // This program is distributed in the hope that it will be useful, //
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  18. // GNU General Public License for more details. //
  19. // //
  20. // You should have received a copy of the GNU General Public License //
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>. //
  22. // //
  23. ///////////////////////////////////////////////////////////////////////////
  24. #version 150
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26. //config //
  27. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  28. #define blending_mode 0 //0 - only the space between dots is blending, 1 - all texels are blended
  29. #define adjacent_texel_alpha_blending 0.1755 //the amount of alpha swapped between neighboring texels
  30. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  31. //fragment definitions/declarations //
  32. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. #define blending_modifier(color) clamp(float(color.a == 0) + blending_mode,0.0,1.0)
  34. uniform sampler2D source[];
  35. uniform sampler2D frame[];
  36. uniform sampler2D pixmap[];
  37. uniform vec4 sourceSize[];
  38. uniform vec4 targetSize;
  39. in Vertex {
  40. vec2 texCoord;
  41. vec2 tex_coord_1;
  42. vec2 tex_coord_2;
  43. vec2 tex_coord_3;
  44. vec2 tex_coord_4;
  45. vec2 lower_bound;
  46. vec2 upper_bound;
  47. };
  48. out vec4 fragColor;
  49. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. //fragment functions //
  51. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. //a simple blur technique that softens harsh color transitions
  53. //specialized to only blur alpha values and limited to only blurring texels lying in the spaces between two or more texels
  54. float simple_blur(vec4 COLOR)
  55. {
  56. //clamp the blur coords to the input texture size so it doesn't attempt to sample off the texture (it'll retrieve float4(0.0) and darken the edges otherwise)
  57. vec2 coord_1 = clamp(tex_coord_1, lower_bound, upper_bound);
  58. vec2 coord_2 = clamp(tex_coord_2, lower_bound, upper_bound);
  59. vec2 coord_3 = clamp(tex_coord_3, lower_bound, upper_bound);
  60. vec2 coord_4 = clamp(tex_coord_4, lower_bound, upper_bound);
  61. //sample adjacent texels based on the coordinates above
  62. vec4 adjacent_texel_1 = texture(source[0], coord_1);
  63. vec4 adjacent_texel_2 = texture(source[0], coord_2);
  64. vec4 adjacent_texel_3 = texture(source[0], coord_3);
  65. vec4 adjacent_texel_4 = texture(source[0], coord_4);
  66. //sum the alpha differences between neighboring texels, apply modifiers, then subtract the result from the current fragment alpha value
  67. COLOR.a -= ( (COLOR.a - adjacent_texel_1.a) +
  68. (COLOR.a - adjacent_texel_2.a) +
  69. (COLOR.a - adjacent_texel_3.a) +
  70. (COLOR.a - adjacent_texel_4.a) ) * adjacent_texel_alpha_blending * blending_modifier(COLOR);
  71. //return new alpha value
  72. return COLOR.a;
  73. }
  74. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  75. //fragment shader //
  76. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  77. void main(void) {
  78. //sample the input textures
  79. vec4 out_color = texture(source[0], texCoord);
  80. //apply the blur effect
  81. out_color.a = simple_blur(out_color);
  82. //return
  83. fragColor=out_color;
  84. }