blob: 43f259671fa6138e15d3e9dc68e53a324601ce60 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*
* Fragment Shader for dashed lines, with uniform multi-color(s),
* or any single-color, and any thickness.
*
* Dashed is performed in screen space.
*/
uniform float dash_width;
/* Simple mode, discarding non-dash parts (so no need for blending at all). */
uniform float dash_factor; /* if > 1.0, solid line. */
/* More advanced mode, allowing for complex, multi-colored patterns.
* Enabled when colors_len > 0. */
/* NOTE: max number of steps/colors in pattern is 32! */
uniform int colors_len; /* Enabled if > 0, 1 for solid line. */
uniform vec4 colors[32];
flat in vec4 color_vert;
noperspective in vec2 stipple_pos;
flat in vec2 stipple_start;
out vec4 fragColor;
void main()
{
float distance_along_line = distance(stipple_pos, stipple_start);
/* Multi-color option. */
if (colors_len > 0) {
/* Solid line case, simple. */
if (colors_len == 1) {
fragColor = colors[0];
}
/* Actually dashed line... */
else {
float normalized_distance = fract(distance_along_line / dash_width);
fragColor = colors[int(normalized_distance * colors_len)];
}
}
/* Single color option. */
else {
/* Solid line case, simple. */
if (dash_factor >= 1.0f) {
fragColor = color_vert;
}
/* Actually dashed line... */
else {
float normalized_distance = fract(distance_along_line / dash_width);
if (normalized_distance <= dash_factor) {
fragColor = color_vert;
}
else {
discard;
}
}
}
}
|