Hacker News new | ask | show | jobs
by bun_terminator 537 days ago
> some of the established practice on generating SDFs from masks is incorrect

SDFs are for some reason riddled with false beliefs. Earlier this year it drove me nuts to learn that boolean operations for SDFs are not correct

4 comments

What do you mean by "boolean operations for SDFs are not correct"?
Most of them are approximations instead of exact, so they can produce incorrect SDFs.
How would you even do a boolean operation over two distances ?
Inigo Quilez (who is basically the CEO of SDFs in my book) has a page on this: https://iquilezles.org/articles/interiordistance/.

The goal isn't boolean operations over distances themselves, because as you point out that makes no sense. What you often want though is boolean operations over the surfaces the functions are returning the distance to. For example, you have one function that gives the distance to the surface of a sphere, and another that gives the distance to the surface of a cube, and you want to AND them, to get a function that gives you the distance to whichever surface is closer. That explanation probably doesn't make any sense, so just check out the page I linked which has some great visualizations.

It's important to use the correct names for things. Using the boolean lingo AND/OR/XOR to describe distance function operations just creates confusion. For example in this case, getting the distance to whichever closer surface is not an AND operation. It's a UNION operation, including the surfaces from both objects. Even if using the boolean lingo, it's more like the OR operation, cube OR sphere. It's best to use the set lingo UNION/INTERSECTION/DIFFERENCE.
That makes much more sense indeed
> boolean operations for SDFs are not correct

They're not?

I mentioned it in another comment, but Inigo Quilez has a page on this: https://iquilezles.org/articles/sdfxor/.
They return approximations which can be very slow to iterate over depending on how far off of the actual value they are.
I believe the "boolean" operations is really set operations - union, intersection, subtraction, etc.