@@ -55,7 +55,8 @@ void emit_vertex(vec3 position, vec2 uv, int index)
55
55
f_color = g_color[index];
56
56
gl_Position = vec4 ((position.xy / resolution), position.z, 1.0 );
57
57
f_id = g_id[index];
58
- f_thickness = g_thickness[index];
58
+ // linewidth scaling may shrink the effective linewidth
59
+ f_thickness = abs (uv.y) - AA_THICKNESS;
59
60
EmitVertex();
60
61
}
61
62
@@ -77,7 +78,7 @@ void emit_vertex(vec3 position, vec2 uv, int index, vec4 color)
77
78
f_color = color;
78
79
gl_Position = vec4 ((position.xy / resolution), position.z, 1.0 );
79
80
f_id = g_id[index];
80
- f_thickness = g_thickness[index] ;
81
+ f_thickness = abs (uv.y) - AA_THICKNESS ;
81
82
EmitVertex();
82
83
}
83
84
void emit_vertex(vec3 position, vec2 uv, vec4 color)
@@ -618,10 +619,6 @@ void draw_solid_line(bool isvalid[4])
618
619
vec3 p2 = screen_space(gl_in[2 ].gl_Position ); // end of current segment, start of next segment
619
620
vec3 p3 = screen_space(gl_in[3 ].gl_Position ); // end of next segment
620
621
621
- // linewidth with padding for anti aliasing
622
- float thickness_aa1 = g_thickness[1 ] + AA_THICKNESS;
623
- float thickness_aa2 = g_thickness[2 ] + AA_THICKNESS;
624
-
625
622
// determine the direction of each of the 3 segments (previous, current, next)
626
623
vec3 v1 = p2 - p1;
627
624
float segment_length = length (v1.xy);
@@ -641,6 +638,14 @@ void draw_solid_line(bool isvalid[4])
641
638
vec2 n1 = vec2 (- v1.y, v1.x);
642
639
vec2 n2 = vec2 (- v2.y, v2.x);
643
640
641
+ // determine stretching of AA border due to linewidth change
642
+ float temp = (g_thickness[2 ] - g_thickness[1 ]) / segment_length;
643
+ float edge_scale = sqrt (1 + temp * temp);
644
+
645
+ // linewidth with padding for anti aliasing (used for geometry)
646
+ float thickness_aa1 = g_thickness[1 ] + edge_scale * AA_THICKNESS;
647
+ float thickness_aa2 = g_thickness[2 ] + edge_scale * AA_THICKNESS;
648
+
644
649
// Setup for sharp corners (see above)
645
650
vec2 miter_a = normalize (n0 + n1);
646
651
vec2 miter_b = normalize (n1 + n2);
@@ -717,6 +722,10 @@ void draw_solid_line(bool isvalid[4])
717
722
segment_length += corner_offset;
718
723
}
719
724
725
+ // scaling of uv.y due to different linewidths
726
+ // the padding for AA_THICKNESS should always have AA_THICKNESS width in uv
727
+ thickness_aa1 = g_thickness[1 ] / edge_scale + AA_THICKNESS;
728
+ thickness_aa2 = g_thickness[2 ] / edge_scale + AA_THICKNESS;
720
729
721
730
// Generate line segment
722
731
u1 *= px2uv;
0 commit comments