From 9dda2b0ed52931462e344613d9bcab00a7d0c6b7 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 5 Apr 2022 13:39:14 +0200 Subject: [PATCH] Refactoring in shader dashed_thick_lines --- resources/shaders/140/dashed_thick_lines.fs | 8 +++++--- resources/shaders/140/dashed_thick_lines.gs | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/resources/shaders/140/dashed_thick_lines.fs b/resources/shaders/140/dashed_thick_lines.fs index 4f6c75a2ff..7ea3c6d610 100644 --- a/resources/shaders/140/dashed_thick_lines.fs +++ b/resources/shaders/140/dashed_thick_lines.fs @@ -10,13 +10,15 @@ uniform float gap_size; uniform vec4 uniform_color; in float line_width; +// x = v tex coord, y = s coord in vec2 seg_params; out vec4 out_color; 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; // 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; 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)); - out_color.a *= au; + 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 *= aa; } diff --git a/resources/shaders/140/dashed_thick_lines.gs b/resources/shaders/140/dashed_thick_lines.gs index 5f54f40bef..c4897e9491 100644 --- a/resources/shaders/140/dashed_thick_lines.gs +++ b/resources/shaders/140/dashed_thick_lines.gs @@ -14,6 +14,7 @@ uniform float width; in float coord_s[]; out float line_width; +// x = v tex coord, y = s coord out vec2 seg_params; void main()