combinedTextureFragmentShader.glsl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /*
  3. * This file is part of the LibreOffice project.
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  8. */
  9. #version 130
  10. varying vec2 tex_coord;
  11. varying vec2 alpha_coord;
  12. varying vec2 mask_coord;
  13. #ifdef USE_VERTEX_COLORS
  14. varying vec4 vertex_color;
  15. #endif
  16. uniform sampler2D texture;
  17. uniform sampler2D mask;
  18. uniform sampler2D alpha;
  19. uniform vec4 color;
  20. uniform int type;
  21. #define TYPE_NORMAL 0
  22. #define TYPE_BLEND 1
  23. #define TYPE_MASKED 2
  24. #define TYPE_DIFF 3
  25. #define TYPE_MASKED_COLOR 4
  26. void main()
  27. {
  28. vec4 texelTexture = texture2D(texture, tex_coord);
  29. if (type == TYPE_NORMAL)
  30. {
  31. gl_FragColor = texelTexture;
  32. }
  33. else if (type == TYPE_BLEND)
  34. {
  35. vec4 texelMask = texture2D(mask, mask_coord);
  36. vec4 texelAlpha = texture2D(alpha, alpha_coord);
  37. gl_FragColor = texelTexture;
  38. gl_FragColor.a = 1.0 - (1.0 - floor(texelAlpha.r)) * texelMask.r;
  39. }
  40. else if (type == TYPE_MASKED)
  41. {
  42. vec4 texelMask = texture2D(mask, mask_coord);
  43. gl_FragColor = texelTexture;
  44. gl_FragColor.a = 1.0 - texelMask.r;
  45. }
  46. else if (type == TYPE_DIFF)
  47. {
  48. vec4 texelMask = texture2D(mask, mask_coord);
  49. float alpha = 1.0 - abs(texelTexture.r - texelMask.r);
  50. if (alpha > 0.0)
  51. gl_FragColor = texelMask / alpha;
  52. gl_FragColor.a = alpha;
  53. }
  54. else if (type == TYPE_MASKED_COLOR)
  55. {
  56. #ifdef USE_VERTEX_COLORS
  57. gl_FragColor = vertex_color;
  58. #else
  59. gl_FragColor = color;
  60. #endif
  61. gl_FragColor.a = 1.0 - texelTexture.r;
  62. }
  63. }
  64. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */