Calculating signed distance fields #Math #Modeling

From the Almost Looks Like Work blog, signed distance fields (SDFs) is a fancy name for something very simple. An SDF is just a function which takes a position as an input, and outputs the distance from that position to the nearest part of a shape.

The question is, how are the individual SDFs combined to make a new, global SDF representing the joined object (the boolean union)?

Thinking about it for a second, we should first calculate the SDF for each circle individually – S_1(\mathbf{x}) and S_2(\mathbf{x}). We should then return whichever circle edge is the closest, i.e.

\displaystyle{S_{\text{union}}(\mathbf{x}) = \text{min}(S_1( \mathbf{x} ), S_2( \mathbf{x} ))}

This is cool, and there is a great list of SDFs for different primitive shapes listed here, but how do we actually draw the result of an SDF?

Check out the enjoyable rabbit hole here.