Is there a cheap and effective way to get the closest point on an SDF? (signed distance field). CodeParade made a video on a game he developed that uses SDF collisions with a sphere, how did he do it? I understand how he was able to detect if a collision occurred, but not how he got the point of collision.
I believe this is the video in question: Marble Marcher - A Fractal Physics Game.
We can find the source code in the description: MarbleMarcher source code.
There we see it uses two relevant methods:
But it does ray marching, right? I expected there would be some code that uses
DE for ray marching, but there isn't. So looked for where does ray marching happen, and - I should have expected this - it happens in the GPU. Futhermore, the
DE code has a counterpart in a shader here. But
NP does not!
Thus, the game is not getting the nearest point from a signed distance field. It is using an alternative field that gives the nearest point (a 3D Vector) instead of the distance (a float value).
The details of this alternative field are specific of the fractal, in a similar fashion that you have dedicated functions for the signed distance field of different shapes.