1
\$\begingroup\$

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.

\$\endgroup\$
1

1 Answer 1

2
\$\begingroup\$

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.

Looking around in main, I see here there is an UpdateMarble method of the Scene class here. Which in turn calls MarbleCollision.

There we see it uses two relevant methods:

  • DE: distance estimator.
  • NP: Nearest point.

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.

\$\endgroup\$
2
  • \$\begingroup\$ where can I learn about these collision fields? \$\endgroup\$ Commented Nov 5, 2022 at 1:29
  • \$\begingroup\$ @CreeperCloud No idea. I want to point out that the distance estimator is not exactly a signed distance field. On a similar fashion there is something that is similar to the nearest point: support points. Perhaps learn that. See: GJK Algorithm Explanation & Implementation. - Constructing the nearest point field for simple shapes does not seem hard anyway. It might be worth exploring. \$\endgroup\$
    – Theraot
    Commented Nov 5, 2022 at 2:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .