Hacker News new | ask | show | jobs
by EliasWatson 1807 days ago
I'm not the greatest at explaining things, but I'll give it a shot.

Just so everyone is on the same page, an SDF is a function that simply returns the distance to the closest surface for any input point. If the distance is positive, the point is outside of the geometry. If the distance is negative, the point is inside the geometry. The gradient of the SDF is calculated by sampling the SDF across multiple points, so the SDF itself doesn't return a gradient.

An SDF is no longer a valid SDF if the distance isn't the true distance to the closest surface. This is usually caused by transforming the SDF non-uniformly, such as adding a sine wave. Another way to think about this is that a valid SDF is in euclidean space while an invalid SDF is in non-euclidean space. Applying a displacement function will compress and stretch space non-uniformly.

Imagine you have an SDF function that just represents a sphere. Then you transform the vertical position of the sphere based on the absolute value of the horizontal position of the input point. This will turn the sphere into a V shape. However, the SDF is no longer a valid SDF. If you sampled a point next to one of the inner walls of the V shape, it wouldn't return the distance to the wall, it would return the distance to the point on the shape below it.

The gradient for every possible point in a valid SDF will be a unit vector because space is uniform. A non-valid SDF will contain non-unit-vector gradients between areas of non-uniformity.

Hopefully that made sense. If you are still confused, I would suggest writing a simple raymarcher on Shadertoy and playing around with distorting SDFs yourself. A simple raymarcher is only a couple lines of code (probably less than 20 lines of GLSL).