Fixes into thick_lines shader

This commit is contained in:
enricoturri1966 2022-03-25 11:05:01 +01:00
parent 8d8a5b4b41
commit 94305e5912
2 changed files with 10 additions and 12 deletions

View File

@ -2,7 +2,7 @@
// see as reference: https://github.com/mhalber/Lines/blob/master/geometry_shader_lines.h // see as reference: https://github.com/mhalber/Lines/blob/master/geometry_shader_lines.h
const vec2 aa_radius = vec2(1.0); const vec2 aa_radius = vec2(0.5);
uniform vec4 uniform_color; uniform vec4 uniform_color;
@ -21,7 +21,7 @@ void main()
// This way the smoothing is centered around 'w'. // This way the smoothing is centered around 'w'.
out_color = uniform_color; out_color = uniform_color;
float au = 1.0 - smoothstep( 1.0 - ((2.0 * aa_radius[0]) / line_width), 1.0, abs(uv.x / line_width) ); float au = 1.0 - smoothstep(1.0 - (2.0 * aa_radius[0] / line_width), 1.0, abs(uv.x / line_width));
float av = 1.0 - smoothstep( 1.0 - ((2.0 * aa_radius[1]) / line_length), 1.0, abs(uv.y / line_length) ); float av = 1.0 - smoothstep(1.0 - (2.0 * aa_radius[1] / line_length), 1.0, abs(uv.y / line_length));
out_color.a *= min(av, au); out_color.a *= min(av, au);
} }

View File

@ -5,7 +5,7 @@
layout(lines) in; layout(lines) in;
layout(triangle_strip, max_vertices = 4) out; layout(triangle_strip, max_vertices = 4) out;
const vec2 aa_radius = vec2(1.0); const vec2 aa_radius = vec2(0.5);
uniform vec2 viewport_size; uniform vec2 viewport_size;
uniform float width; uniform float width;
@ -18,24 +18,22 @@ void main()
{ {
float u_width = viewport_size[0]; float u_width = viewport_size[0];
float u_height = viewport_size[1]; float u_height = viewport_size[1];
float u_aspect_ratio = u_height / u_width;
vec2 ndc_0 = gl_in[0].gl_Position.xy / gl_in[0].gl_Position.w; vec2 ndc_0 = gl_in[0].gl_Position.xy / gl_in[0].gl_Position.w;
vec2 ndc_1 = gl_in[1].gl_Position.xy / gl_in[1].gl_Position.w; vec2 ndc_1 = gl_in[1].gl_Position.xy / gl_in[1].gl_Position.w;
vec2 line_vector = ndc_1 - ndc_0; vec2 viewport_line_vector = 0.5 * (ndc_1 - ndc_0) * viewport_size;
vec2 viewport_line_vector = line_vector * viewport_size;
vec2 dir = normalize(viewport_line_vector); vec2 dir = normalize(viewport_line_vector);
vec2 normal_dir = vec2(-dir.y, dir.x); vec2 normal_dir = vec2(-dir.y, dir.x);
line_width = max(1.0, width) + aa_radius[0]; line_width = max(1.0, width) + 2.0 * aa_radius[0];
line_length = length(viewport_line_vector) + 2.0 * aa_radius[1]; line_length = length(viewport_line_vector) + 2.0 * aa_radius[1];
vec2 normal = vec2(line_width / u_width, line_width / u_height) * normal_dir; vec2 normal = vec2(line_width / u_width, line_width / u_height) * normal_dir;
vec2 extension = vec2(aa_radius[1] / u_width, aa_radius[1] / u_height) * dir; vec2 extension = vec2(aa_radius[1] / u_width, aa_radius[1] / u_height) * dir;
float half_line_width = line_width * 0.5; float half_line_width = 0.5 * line_width;
float half_line_length = line_length * 0.5; float half_line_length = 0.5 * line_length;
uv = vec2(-half_line_width, half_line_length); uv = vec2(-half_line_width, half_line_length);
gl_Position = vec4((ndc_0 + normal - extension) * gl_in[0].gl_Position.w, gl_in[0].gl_Position.zw); gl_Position = vec4((ndc_0 + normal - extension) * gl_in[0].gl_Position.w, gl_in[0].gl_Position.zw);