Wednesday, February 8, 2012

More on Floating Point Precision

I read an interesting article on the excellent #AltDevBlogADay site the other day entitled "dont-store-that-in-a-float" - a brief but clear and informative discussion on the perils of precision with single precision floating point numbers.

I would recommend a read of this to anyone experimenting with projects similar to my own as this is a key issue to the simulation and rendering of planetary and solar bodies due to the combination of immense and tiny distances that need to be represented - at times simultaneously.

Understanding how floats deal with and represent precision certainly pays dividends when trying to work out why things are clipping or popping around the screen when they really ought not to be!

2 comments:

  1. Hi John,

    I went through some experimentation in the same field as you (except that it wasn't a planetary engine) and I wondered if you also have to manage perspective based scaling on your scene objects?

    I mean, if an object, say a planet, is far from the camera, its world matrix (for GPU) scales down proportionally to the camera projection far plane distance.
    I tried to implement such thing so that objects looked ok while moving away from planets but still avoid too much hassle regarding light & shadow computation.

    Philippe
    http://indiefreaks.com

    ReplyDelete
  2. I can't say I've noticed any particular problems with the perspective projection. The near and far planes are computed to tightly bound each planet for rendering and the viewpoint used as the origin to ensure maximum resolution on near objects. As objects get further away I suspect they just get small enough on screen that I don't see the loss of precision they suffer.

    I remember that I certainly did get some pretty crazy effects before my near/far planes were correct - especially when the near plane was unnecessarily close to the viewpoint causing a dramatic loss of float precision on the GPU.

    If you want to share more details of the problems you were experiencing I'm happy to discuss them.

    ReplyDelete

Comments, questions or feedback? Here's your chance...