1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
12 attribute vec2 position;
13 attribute vec4 extrusion_vectors;
14 #ifdef USE_VERTEX_COLORS
15 attribute vec4 vertex_color_in;
18 varying float fade_factor; // fade factor for anti-aliasing
19 varying float multiply;
21 #ifdef USE_VERTEX_COLORS
22 varying vec4 vertex_color;
25 uniform float line_width;
26 uniform float feather; // width where we fade the line
37 vec2 extrusion_vector = extrusion_vectors.xy;
39 float render_thickness = 0.0;
41 if (type == TYPE_LINE)
43 // miter factor to additionally lengthen the distance of vertex (needed for miter)
44 // if 1.0 - miter_factor has no effect
45 float miter_factor = 1.0 / abs(extrusion_vectors.z);
46 // fade factor is always -1.0 or 1.0 -> we transport that info together with length
47 fade_factor = sign(extrusion_vectors.z);
48 #ifdef USE_VERTEX_COLORS
49 float the_feather = (1.0 + sign(extrusion_vectors.w)) / 4.0;
50 float the_line_width = abs(extrusion_vectors.w);
52 float the_feather = feather;
53 float the_line_width = line_width;
55 render_thickness = (the_line_width * miter_factor + the_feather * 2.0 * miter_factor);
57 // Calculate the multiplier so we can transform the 0->1 fade factor
58 // to take feather and line width into account.
60 float start = mix(0.0, (the_line_width / 2.0) - the_feather, the_feather * 2.0);
61 float end = mix(1.0, (the_line_width / 2.0) + the_feather, the_feather * 2.0);
63 multiply = 1.0 / (1.0 - (start / end));
66 // lengthen the vertex in directon of the extrusion vector by line width.
67 vec4 final_position = vec4(position + (extrusion_vector * (render_thickness / 2.0) ), 0.0, 1.0);
69 gl_Position = mvp * final_position;
71 #ifdef USE_VERTEX_COLORS
72 vertex_color = vertex_color_in / 255.0;
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */