#version 300 es // highp is required: the SDF works in absolute pixel coordinates, and mediump loses ~2px of // precision past x=2000, which eats the 1px feather on a high-DPI phone precision highp float; in vec4 vColor; in highp vec2 vPos; flat in highp vec4 vSegment; flat in highp float vHalfWidth; out vec4 fragColor; void main() { vec2 pa = vPos - vSegment.xy; vec2 ba = vSegment.zw - vSegment.xy; float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0); float dist = length(pa - (ba * h)); float alpha = 1.0 - smoothstep(vHalfWidth - 1.0, vHalfWidth, dist); if (alpha <= 0.0) discard; fragColor = vec4(vColor.rgb, vColor.a * alpha); }