#version 300 es
precision highp float;
uniform vec2 uResolution;
uniform vec2 uMouse;
out vec4 outColor;
float segment(vec2 xy, vec2 from, vec2 to) {
vec2 v1 = xy - from;
vec2 v2 = to - from;
float orthlen = dot(v1, v2) / dot(v2, v2);
orthlen = clamp(orthlen, 0.0, 1.0);
vec2 orth = orthlen * v2;
return length(v1 - orth);
}
void main() {
vec2 pos = (2.0 * gl_FragCoord.xy - uResolution.xy) / min(uResolution.x, uResolution.y);
vec2 mouse = (2.0 * uMouse.xy - uResolution.xy) / min(uResolution.x, uResolution.y);
mouse.y *= -1.0;
float sdf = segment(pos, vec2(0.0), mouse);
outColor.rgb = vec3(step(0.005, sdf));
outColor.a = 1.0;
}