'How do you smooth the edges a primitive using a shader?

What is the simplest technique used to soften the edges of a simple primitive such as GL_TRIANGLES in OpenGL using a fragment shader?

I've read that within a GL_BLEND context, we can modulate the alpha values of a fragment depending on it's proximity to an edge; but how is this achieved efficiently in practice?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source