2022-03-24 13:45:59 +00:00
|
|
|
#version 150
|
|
|
|
|
|
|
|
// see as reference: https://github.com/mhalber/Lines/blob/master/geometry_shader_lines.h
|
2022-03-25 13:33:11 +00:00
|
|
|
// https://stackoverflow.com/questions/52928678/dashed-line-in-opengl3
|
2022-03-24 13:45:59 +00:00
|
|
|
|
|
|
|
layout(lines) in;
|
|
|
|
layout(triangle_strip, max_vertices = 4) out;
|
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
const float aa_radius = 0.5;
|
2022-03-24 13:45:59 +00:00
|
|
|
|
|
|
|
uniform vec2 viewport_size;
|
|
|
|
uniform float width;
|
|
|
|
|
2022-03-25 13:33:11 +00:00
|
|
|
in float coord_s[];
|
|
|
|
|
2022-03-24 13:45:59 +00:00
|
|
|
out float line_width;
|
2022-04-05 11:39:14 +00:00
|
|
|
// x = v tex coord, y = s coord
|
2022-04-05 10:14:01 +00:00
|
|
|
out vec2 seg_params;
|
2022-03-24 13:45:59 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2022-03-25 07:57:25 +00:00
|
|
|
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;
|
2022-03-24 13:45:59 +00:00
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
vec2 dir = normalize((ndc_1 - ndc_0) * viewport_size);
|
2022-03-24 13:45:59 +00:00
|
|
|
vec2 normal_dir = vec2(-dir.y, dir.x);
|
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
line_width = max(1.0, width) + 2.0 * aa_radius;
|
2022-03-25 10:05:01 +00:00
|
|
|
float half_line_width = 0.5 * line_width;
|
2022-04-05 10:14:01 +00:00
|
|
|
|
|
|
|
vec2 normal = vec2(line_width / viewport_size[0], line_width / viewport_size[1]) * normal_dir;
|
2022-03-24 13:45:59 +00:00
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
seg_params = vec2(-half_line_width, coord_s[0]);
|
|
|
|
gl_Position = vec4((ndc_0 + normal) * gl_in[0].gl_Position.w, gl_in[0].gl_Position.zw);
|
2022-03-24 13:45:59 +00:00
|
|
|
EmitVertex();
|
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
seg_params = vec2(-half_line_width, coord_s[0]);
|
|
|
|
gl_Position = vec4((ndc_0 - normal) * gl_in[0].gl_Position.w, gl_in[0].gl_Position.zw);
|
2022-03-24 13:45:59 +00:00
|
|
|
EmitVertex();
|
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
seg_params = vec2(half_line_width, coord_s[1]);
|
|
|
|
gl_Position = vec4((ndc_1 + normal) * gl_in[1].gl_Position.w, gl_in[1].gl_Position.zw);
|
2022-03-24 13:45:59 +00:00
|
|
|
EmitVertex();
|
|
|
|
|
2022-04-05 10:14:01 +00:00
|
|
|
seg_params = vec2(half_line_width, coord_s[1]);
|
|
|
|
gl_Position = vec4((ndc_1 - normal) * gl_in[1].gl_Position.w, gl_in[1].gl_Position.zw);
|
2022-03-24 13:45:59 +00:00
|
|
|
EmitVertex();
|
|
|
|
|
|
|
|
EndPrimitive();
|
|
|
|
}
|