Skip to content

Commit 73c5671

Browse files
endankegithub-actions[bot]
authored andcommitted
Render zero width asymmetric lines as stubs
GitOrigin-RevId: da560082fcfa6aea37366e2552b93da6a9cf0f85
1 parent 9fa8566 commit 73c5671

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/shaders/line.fragment.glsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ in highp vec3 v_uv;
1717
#ifdef ELEVATED_ROADS
1818
in highp float v_road_z_offset;
1919
#endif
20+
#ifdef VARIABLE_LINE_WIDTH
21+
in float stub_side;
22+
#endif
23+
2024
#ifdef RENDER_LINE_DASH
2125
uniform sampler2D u_dash_image;
2226

@@ -77,7 +81,11 @@ void main() {
7781
// (v_width2.s)
7882
float blur2 = (u_width_scale * blur + 1.0 / u_device_pixel_ratio) * v_gamma_scale;
7983
float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0);
84+
#ifdef VARIABLE_LINE_WIDTH
85+
alpha = mix(alpha, 1.0, stub_side);
86+
#endif
8087
alpha = side_z_offset > 0.0 ? 1.0 - alpha : alpha;
88+
8189
#ifdef RENDER_LINE_DASH
8290
float sdfdist = texture(u_dash_image, v_tex).r;
8391
float sdfgamma = 1.0 / (2.0 * u_device_pixel_ratio) / dash.z;

src/shaders/line.vertex.glsl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ out highp vec3 v_uv;
5454
#ifdef ELEVATED_ROADS
5555
out highp float v_road_z_offset;
5656
#endif
57+
#ifdef VARIABLE_LINE_WIDTH
58+
out float stub_side;
59+
#endif
5760

5861
#ifdef RENDER_LINE_DASH
5962
uniform vec2 u_texsize;
@@ -131,9 +134,17 @@ void main() {
131134
float halfwidth;
132135
#ifdef VARIABLE_LINE_WIDTH
133136
bool left = normal.y == 1.0;
134-
halfwidth = (u_width_scale * (left ? a_z_offset_width.y : a_z_offset_width.z)) / 2.0;
137+
float left_width = a_z_offset_width.y;
138+
float right_width = a_z_offset_width.z;
139+
bool zero_right_width = right_width == 0.0 ;
140+
halfwidth = (u_width_scale * (left ? left_width : right_width)) / 2.0;
135141
a_z_offset += left ? side_z_offset : 0.0;
136142
v_normal = side_z_offset > 0.0 && left ? vec2(0.0) : v_normal;
143+
// If the right width is 0, we are rendering an asymmetric line with a stub side
144+
// We should disable antialiasing and blur on this side to be able to stich two lines together
145+
stub_side = zero_right_width ? -normal.y : 0.0;
146+
v_normal = !left && zero_right_width ? vec2(0.0) : v_normal;
147+
ANTIALIASING = !left && zero_right_width ? 0.0 : ANTIALIASING;
137148
#else
138149
halfwidth = (u_width_scale * width) / 2.0;
139150
#endif

0 commit comments

Comments
 (0)