Tech ENABLE_GL_CORE_PROFILE - Thick lines shader enhanced to render dashed lines
Fixed conflicts while rebase with master
This commit is contained in:
parent
94305e5912
commit
914a66e2c3
17 changed files with 169 additions and 27 deletions
|
@ -1,19 +1,25 @@
|
|||
#version 150
|
||||
|
||||
// see as reference: https://github.com/mhalber/Lines/blob/master/geometry_shader_lines.h
|
||||
// https://stackoverflow.com/questions/52928678/dashed-line-in-opengl3
|
||||
|
||||
const vec2 aa_radius = vec2(0.5);
|
||||
|
||||
uniform float dash_size;
|
||||
uniform float gap_size;
|
||||
uniform vec4 uniform_color;
|
||||
|
||||
in float line_width;
|
||||
in float line_length;
|
||||
in vec2 uv;
|
||||
in vec3 uvs;
|
||||
|
||||
out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
if (gap_size > 0.0 && fract(uvs.z / (dash_size + gap_size)) > dash_size / (dash_size + gap_size))
|
||||
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
|
||||
// around w, so that the edge is properly smoothed out. As such, in the smoothstep function we have:
|
||||
// Far edge : 1.0 = (w+r) / (w+r)
|
||||
|
@ -21,7 +27,7 @@ void main()
|
|||
// This way the smoothing is centered around 'w'.
|
||||
|
||||
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 av = 1.0 - smoothstep(1.0 - (2.0 * aa_radius[1] / line_length), 1.0, abs(uv.y / line_length));
|
||||
float au = 1.0 - smoothstep(1.0 - (2.0 * aa_radius[0] / line_width), 1.0, abs(uvs.x / line_width));
|
||||
float av = 1.0 - smoothstep(1.0 - (2.0 * aa_radius[1] / line_length), 1.0, abs(uvs.y / line_length));
|
||||
out_color.a *= min(av, au);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#version 150
|
||||
|
||||
// see as reference: https://github.com/mhalber/Lines/blob/master/geometry_shader_lines.h
|
||||
// https://stackoverflow.com/questions/52928678/dashed-line-in-opengl3
|
||||
|
||||
layout(lines) in;
|
||||
layout(triangle_strip, max_vertices = 4) out;
|
||||
|
@ -10,9 +11,11 @@ const vec2 aa_radius = vec2(0.5);
|
|||
uniform vec2 viewport_size;
|
||||
uniform float width;
|
||||
|
||||
in float coord_s[];
|
||||
|
||||
out float line_width;
|
||||
out float line_length;
|
||||
out vec2 uv;
|
||||
out vec3 uvs;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
@ -35,19 +38,19 @@ void main()
|
|||
float half_line_width = 0.5 * line_width;
|
||||
float half_line_length = 0.5 * line_length;
|
||||
|
||||
uv = vec2(-half_line_width, half_line_length);
|
||||
uvs = vec3(-half_line_width, half_line_length, coord_s[0]);
|
||||
gl_Position = vec4((ndc_0 + normal - extension) * gl_in[0].gl_Position.w, gl_in[0].gl_Position.zw);
|
||||
EmitVertex();
|
||||
|
||||
uv = vec2(-half_line_width, -half_line_length);
|
||||
uvs = vec3(-half_line_width, -half_line_length, coord_s[0]);
|
||||
gl_Position = vec4((ndc_0 - normal - extension) * gl_in[0].gl_Position.w, gl_in[0].gl_Position.zw);
|
||||
EmitVertex();
|
||||
|
||||
uv = vec2(half_line_width, half_line_length);
|
||||
uvs = vec3(half_line_width, half_line_length, coord_s[1]);
|
||||
gl_Position = vec4((ndc_1 + normal + extension) * gl_in[1].gl_Position.w, gl_in[1].gl_Position.zw);
|
||||
EmitVertex();
|
||||
|
||||
uv = vec2(half_line_width, -half_line_length);
|
||||
uvs = vec3(half_line_width, -half_line_length, coord_s[1]);
|
||||
gl_Position = vec4((ndc_1 - normal + extension) * gl_in[1].gl_Position.w, gl_in[1].gl_Position.zw);
|
||||
EmitVertex();
|
||||
|
|
@ -1,13 +1,18 @@
|
|||
#version 150
|
||||
|
||||
// see as reference: https://github.com/mhalber/Lines/blob/master/geometry_shader_lines.h
|
||||
// https://stackoverflow.com/questions/52928678/dashed-line-in-opengl3
|
||||
|
||||
uniform mat4 view_model_matrix;
|
||||
uniform mat4 projection_matrix;
|
||||
|
||||
in vec3 v_position;
|
||||
// v_position.w = coordinate along the line
|
||||
in vec4 v_position;
|
||||
|
||||
out float coord_s;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0);
|
||||
coord_s = v_position.w;
|
||||
gl_Position = projection_matrix * view_model_matrix * vec4(v_position.xyz, 1.0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue