Search code examples
androidopengl-esglsljoglantialiasing

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?


Solution

  • The edges of a primitive can be smoothed using anti aliasing.

    OpenGL offers multisample buffers to allow hardware-accelerated aliasing of an image, however this feature is not supported by all platforms due to it's dependence on dedicated hardware buffers on board the GPU. An alternative method is to render your display to a texture using a FrameBuffer, and then pass the rendered texture through Timothy Lottes' Fast Approximate Anti Aliasing (FXAA) shader, which requires a single pass.