combinedVertexShader.glsl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. attribute vec2 position;
  11. attribute vec4 extrusion_vectors;
  12. #ifdef USE_VERTEX_COLORS
  13. attribute vec4 vertex_color_in;
  14. #endif
  15. varying float fade_factor; // fade factor for anti-aliasing
  16. varying float multiply;
  17. #ifdef USE_VERTEX_COLORS
  18. varying vec4 vertex_color;
  19. #endif
  20. uniform float line_width;
  21. uniform float feather; // width where we fade the line
  22. uniform mat4 mvp;
  23. #define TYPE_NORMAL 0
  24. #define TYPE_LINE 1
  25. uniform int type;
  26. void main()
  27. {
  28. vec2 extrusion_vector = extrusion_vectors.xy;
  29. float render_thickness = 0.0;
  30. if (type == TYPE_LINE)
  31. {
  32. // miter factor to additionally lengthen the distance of vertex (needed for miter)
  33. // if 1.0 - miter_factor has no effect
  34. float miter_factor = 1.0 / abs(extrusion_vectors.z);
  35. // fade factor is always -1.0 or 1.0 -> we transport that info together with length
  36. fade_factor = sign(extrusion_vectors.z);
  37. #ifdef USE_VERTEX_COLORS
  38. float the_feather = (1.0 + sign(extrusion_vectors.w)) / 4.0;
  39. float the_line_width = abs(extrusion_vectors.w);
  40. #else
  41. float the_feather = feather;
  42. float the_line_width = line_width;
  43. #endif
  44. render_thickness = (the_line_width * miter_factor + the_feather * 2.0 * miter_factor);
  45. // Calculate the multiplier so we can transform the 0->1 fade factor
  46. // to take feather and line width into account.
  47. float start = mix(0.0, (the_line_width / 2.0) - the_feather, the_feather * 2.0);
  48. float end = mix(1.0, (the_line_width / 2.0) + the_feather, the_feather * 2.0);
  49. multiply = 1.0 / (1.0 - (start / end));
  50. }
  51. // lengthen the vertex in direction of the extrusion vector by line width.
  52. vec4 final_position = vec4(position + (extrusion_vector * (render_thickness / 2.0) ), 0.0, 1.0);
  53. gl_Position = mvp * final_position;
  54. #ifdef USE_VERTEX_COLORS
  55. vertex_color = vertex_color_in / 255.0;
  56. #endif
  57. }
  58. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */