← index
Doing anti-aliasing on SDF is not as straightforward as it seems. Most of the time, we see people use a smoothstep with hardcoded constants, sometimes with screen space information, sometimes cryptic or convoluted formulas. Even if SDFs have the perfect mathematical properties needed for a clean anti-aliasing, the whole issue has a scope larger than it appears at first glance. And even when trivial solutions exist, it's not always clear why they are a good fit. Let's study that together.
SDF
The article assumes that you are at least a bit familiar with what an SDF is, but if I had to provide a quick and informal definition, I would say something like:
"It's a function (or lookup-table of said function, usually stored in a texture) which returns the signed distance from the specified coordinates to a given shape, where the sign indicates whether you're inside or outside the shape."
A common visualization of it looks like this:
SDF of a moving pie/pacman, using Inigo Quilez formula and colorscheme for visualization
The distance is fancily colored here for illustrative purpose, and the shape is animated to see how it affects the field.
Another way of seeing it is to switch to a 3D view:
SDF of a moving pie/pacman, as seen in 3D
... continue reading