lineFragmentShader.glsl 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 float fade_factor; // 0->1 fade factor used for AA
  11. uniform vec4 color;
  12. uniform float line_width;
  13. uniform float feather;
  14. void main()
  15. {
  16. float start = (line_width / 2.0) - feather; // where we start to apply alpha
  17. float end = (line_width / 2.0) + feather; // where we end to apply alpha
  18. // Calculate the multiplier so we can transform the 0->1 fade factor
  19. // to take feather and line width into account.
  20. float multiplied = 1.0 / (1.0 - (start / end));
  21. float dist = (1.0 - abs(fade_factor)) * multiplied;
  22. float alpha = clamp(dist, 0.0, 1.0);
  23. // modify the alpha channel only
  24. vec4 result_color = color;
  25. result_color.a = result_color.a * alpha;
  26. gl_FragColor = result_color;
  27. }
  28. /* vim:set shiftwidth=4 softtabstop=4 expandtab: */