Refactoring in shader dashed_thick_lines

This commit is contained in:
enricoturri1966 2022-04-05 13:39:14 +02:00
parent 6cb860ba50
commit 9dda2b0ed5
2 changed files with 6 additions and 3 deletions

View File

@ -10,13 +10,15 @@ uniform float gap_size;
uniform vec4 uniform_color; uniform vec4 uniform_color;
in float line_width; in float line_width;
// x = v tex coord, y = s coord
in vec2 seg_params; in vec2 seg_params;
out vec4 out_color; out vec4 out_color;
void main() void main()
{ {
if (gap_size > 0.0 && fract(seg_params.y / (dash_size + gap_size)) > dash_size / (dash_size + gap_size)) float inv_stride = 1.0 / (dash_size + gap_size);
if (gap_size > 0.0 && fract(seg_params.y * inv_stride) > dash_size * inv_stride)
discard; discard;
// We render a quad that is fattened by r, giving total width of the line to be w+r. We want smoothing to happen // We render a quad that is fattened by r, giving total width of the line to be w+r. We want smoothing to happen
@ -27,6 +29,6 @@ void main()
out_color = uniform_color; out_color = uniform_color;
float inv_line_width = 1.0 / line_width; float inv_line_width = 1.0 / line_width;
float au = 1.0 - smoothstep(1.0 - (2.0 * aa_radius * inv_line_width), 1.0, abs(seg_params.x * inv_line_width)); float aa = 1.0 - smoothstep(1.0 - (2.0 * aa_radius * inv_line_width), 1.0, abs(seg_params.x * inv_line_width));
out_color.a *= au; out_color.a *= aa;
} }

View File

@ -14,6 +14,7 @@ uniform float width;
in float coord_s[]; in float coord_s[];
out float line_width; out float line_width;
// x = v tex coord, y = s coord
out vec2 seg_params; out vec2 seg_params;
void main() void main()