Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / library / map / src / main / rust / shaders / line_globe.frag

line_globe.frag43 lines · 1.5 KiBRaw
1#version 450
2// Globe line fragment: `line.frag` plus the limb discard.
3//
4// `inZ` is the unit-sphere z from the vertex stage; past the limb the road has
5// bent to the far side and must not draw. Otherwise the edge coverage and dash
6// pattern are exactly `line.frag`'s.
7layout(location = 0) in float inDistancePx;
8layout(location = 1) in float inEdgePx;
9layout(location = 2) in float inZ;
10layout(location = 0) out vec4 outColor;
11layout(push_constant) uniform Push {
12 mat4 tileToClip;
13 vec4 color;
14 vec4 line;
15 vec4 misc;
16 vec4 morph;
17} push;
18
19const float MIN_HALF_WIDTH_PX = 0.5;
20
21void main() {
22 if (inZ < 0.0) discard;
23 float wantHalfPx = push.line.x;
24 float halfWidthPx = max(wantHalfPx, MIN_HALF_WIDTH_PX);
25 float coverage = clamp(wantHalfPx / halfWidthPx, 0.0, 1.0);
26 float box = clamp(halfWidthPx - abs(inEdgePx) + 0.5, 0.0, 1.0);
27 coverage *= mix(1.0, box, push.misc.y);
28 // Limb fade, matching the fill: roads thin out at the edge, not to a wall.
29 coverage *= clamp(inZ * 8.0, 0.0, 1.0);
30 if (coverage <= 0.0) discard;
31
32 float dashOn = push.line.z;
33 float dashOff = push.line.w;
34 if (dashOff > 0.0) {
35 float width = max(halfWidthPx * 2.0, 1.0);
36 float on = dashOn * width;
37 float off = dashOff * width;
38 float period = on + off;
39 float phase = push.misc.w * push.morph.y;
40 if (period > 0.0 && mod(inDistancePx - phase, period) > on) discard;
41 }
42 outColor = vec4(push.color.rgb, push.color.a * coverage);
43}