I'm struggling to understand the following code, the idea is to draw a simple segment in a fragment shader. I tried to decompose it but I still don't get the ??? line. It would be awesome to have a nice explanation. I couldn't find anything on SO or Google.
float lineSegment(vec2 p, vec2 a, vec2 b) {
float thickness = 1.0/100.0;
vec2 pa = p - a;
vec2 ba = b - a;
float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
// ????????
float idk = length(pa - ba*h);
return smoothstep(0.0, thickness, idk);
}
Original code comes from TheBookOfShaders.