Skip to content

Commit 2314a85

Browse files
endankegithub-actions[bot]
authored andcommitted
Use variable width as offset for line border width
GitOrigin-RevId: 16b898d5fbc2d31963c0aa07253cf43a029bdb53
1 parent 6baa1bc commit 2314a85

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/shaders/line.fragment.glsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ void main() {
7979
// Calculate the antialiasing fade factor. This is either when fading in
8080
// the line in case of an offset line (v_width2.t) or when fading out
8181
// (v_width2.s)
82+
#ifdef VARIABLE_LINE_WIDTH
83+
blur = mix(blur, 0.0, stub_side);
84+
#endif
8285
float blur2 = (u_width_scale * blur + 1.0 / u_device_pixel_ratio) * v_gamma_scale;
8386
float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0);
8487
#ifdef VARIABLE_LINE_WIDTH
@@ -133,6 +136,7 @@ void main() {
133136
}
134137

135138
#ifdef RENDER_LINE_BORDER
139+
#ifndef VARIABLE_LINE_WIDTH
136140
float edgeBlur = ((border_width * u_width_scale) + 1.0 / u_device_pixel_ratio);
137141
float alpha2 = clamp(min(dist - (v_width2.t - edgeBlur), v_width2.s - dist) / edgeBlur, 0.0, 1.0);
138142
if (alpha2 < 1.) {
@@ -151,6 +155,7 @@ void main() {
151155
}
152156
}
153157
#endif
158+
#endif
154159

155160
#ifdef LIGHTING_3D_MODE
156161
out_color = apply_lighting_with_emission_ground(out_color, emissive_strength);

src/shaders/line.vertex.glsl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ void main() {
128128
normal.y = normal.y * 2.0 - 1.0;
129129
v_normal = normal;
130130

131+
offset = -1.0 * offset * u_width_scale;
132+
131133
// these transformations used to be applied in the JS and native code bases.
132134
// moved them into the shader for clarity and simplicity.
133135
gapwidth = gapwidth / 2.0;
@@ -136,10 +138,17 @@ void main() {
136138
bool left = normal.y == 1.0;
137139
float left_width = a_z_offset_width.y;
138140
float right_width = a_z_offset_width.z;
139-
bool zero_right_width = right_width == 0.0 ;
140141
halfwidth = (u_width_scale * (left ? left_width : right_width)) / 2.0;
141142
a_z_offset += left ? side_z_offset : 0.0;
142143
v_normal = side_z_offset > 0.0 && left ? vec2(0.0) : v_normal;
144+
145+
// Variable width is used as an offset for non-zero border_widths case.
146+
// Then the width of the visible part is defined by border_width.
147+
offset = border_width > 0.0 ? (left_width + right_width) * u_width_scale * 0.5 : offset;
148+
halfwidth = border_width > 0.0 ? border_width * u_width_scale * 0.5 : halfwidth;
149+
150+
bool zero_right_width = border_width == 0.0 && right_width == 0.0;
151+
143152
// If the right width is 0, we are rendering an asymmetric line with a stub side
144153
// We should disable antialiasing and blur on this side to be able to stich two lines together
145154
stub_side = zero_right_width ? -normal.y : 0.0;
@@ -148,7 +157,6 @@ void main() {
148157
#else
149158
halfwidth = (u_width_scale * width) / 2.0;
150159
#endif
151-
offset = -1.0 * offset * u_width_scale;
152160

153161
float inset = gapwidth + (gapwidth > 0.0 ? ANTIALIASING : 0.0);
154162
float outset = gapwidth + halfwidth * (gapwidth > 0.0 ? 2.0 : 1.0) + (halfwidth == 0.0 ? 0.0 : ANTIALIASING);

0 commit comments

Comments
 (0)