• Add Review
  • Subscribe
  • Nominate
  • Submit Media
  • RSS

Implicit Surface Shenanigans

  • Kazesui
  • 05/15/2021 10:56 PM

I'm still playing around a little bit with things which I would like to see in the game. In particular I wanted to be able to have the ray tracer animate a collapsing floor as can be seen in the gif above.

What's happening there is that I'm tracing something referred to as an implicit surface, in particular one in the form of something to the tune of
-1 / (x² + y²) + z = 0

Initially I was thinking I could just spline together two 2nd degree polynomials, but when I thought I little bit about it, I realized it wouldn't really be depressing in a circular fashion if I'd go for that, so I had to go for something more like described above... which unfortunately leads to a third degree polynomial and needing to solve it for its roots.

There is an analytical formula for solving a cubic equation, but it generally involves messing about with complex numbers. That's fine enough in itself, but it can quickly lead to a bunch of numerical issues due to the imperfect accuracy of such numbers on a computer. You only want to consider the solutions with real numbers, but there will often be a tiny little something left in the imaginary part which you need to ignore. I needed to set the thresholds surprisingly high to avoid artifacts from popping up.

I could have chosen an iterative solution for this as well. Would have avoided complex numbers, but comes with it's own set of issues. I've never really used the cubic formula before, so it was interesting to mess around a little bit with it, and I'm happy with the end result