|
|
|
@ -16,10 +16,36 @@ const sdf_vs_src = `#version 300 es
@@ -16,10 +16,36 @@ const sdf_vs_src = `#version 300 es
|
|
|
|
|
void main() { |
|
|
|
|
vec2 screen01 = (a_pos.xy * u_scale + u_translation) / u_res; |
|
|
|
|
vec2 screen02 = screen01 * 2.0; |
|
|
|
|
|
|
|
|
|
// Inflate quad by 1 pixel
|
|
|
|
|
float apron = 1.0; |
|
|
|
|
vec2 line_dir = normalize(a_line.zw - a_line.xy); |
|
|
|
|
vec2 up_dir = vec2(line_dir.y, -line_dir.x); |
|
|
|
|
vec2 pixel = vec2(2.0) / u_res * apron; |
|
|
|
|
|
|
|
|
|
int vertex_index = gl_VertexID % 6; |
|
|
|
|
|
|
|
|
|
if (vertex_index == 0) { |
|
|
|
|
// "top left" aka "p1"
|
|
|
|
|
screen02 += up_dir * pixel - line_dir * pixel; |
|
|
|
|
v_texcoord = a_pos.xy + up_dir * 1.0 / u_scale - line_dir * 1.0 / u_scale; |
|
|
|
|
} else if (vertex_index == 1 || vertex_index == 5) { |
|
|
|
|
// "top right" aka "p2"
|
|
|
|
|
screen02 += up_dir * pixel + line_dir * pixel; |
|
|
|
|
v_texcoord = a_pos.xy + up_dir * 1.0 / u_scale + line_dir * 1.0 / u_scale; |
|
|
|
|
} else if (vertex_index == 2 || vertex_index == 4) { |
|
|
|
|
// "bottom left" aka "p3"
|
|
|
|
|
screen02 += -up_dir * pixel - line_dir * pixel; |
|
|
|
|
v_texcoord = a_pos.xy - up_dir * 1.0 / u_scale - line_dir * 1.0 / u_scale; |
|
|
|
|
} else { |
|
|
|
|
// "bottom right" aka "p4"
|
|
|
|
|
screen02 += -up_dir * pixel + line_dir * pixel; |
|
|
|
|
v_texcoord = a_pos.xy - up_dir * 1.0 / u_scale + line_dir * 1.0 / u_scale; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
screen02.y = 2.0 - screen02.y; |
|
|
|
|
|
|
|
|
|
v_line = a_line; |
|
|
|
|
v_texcoord = a_pos.xy; |
|
|
|
|
v_color = a_color; |
|
|
|
|
v_thickness = a_pos.z; |
|
|
|
|
|
|
|
|
@ -51,6 +77,8 @@ const sdf_fs_src = `#version 300 es
@@ -51,6 +77,8 @@ const sdf_fs_src = `#version 300 es
|
|
|
|
|
float fade = 0.5 * length(fwidth(v_texcoord)); |
|
|
|
|
float alpha = 1.0 - smoothstep(-fade, fade, dist); |
|
|
|
|
|
|
|
|
|
// float alpha = 1.0 - step(0.0, dist);
|
|
|
|
|
|
|
|
|
|
if (u_debug_mode == 1) { |
|
|
|
|
FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
|
|
|
|
} else { |
|
|
|
|