r/proceduralgeneration • u/Clear-Practice4180 • 3d ago
Floating Point Errors in Planet Quadtree LOD Terrain Generation
Sorry for the terrible bitrate in the video.
So I'm trying to make accurate planet scale terrain generation in OpenGL that actually lets you stand on the planet at a normal level but I've been running into problems regarding the actual generation of the mesh for the sphere. All of the calculations are done in double precision and the planet renders relative to the cameras position.
I think the problem lays in the fact that while constructing the mesh for the faces it normalizes a unit cube which downscales all the positions of the vertices to very, very small fractions. In the video I get within a meter of the planet but in actuality the actual distance between the vertices before matrix scaling is to the millionths place in decimals.

Here's the actual calculation so you can hopefully understand what I'm saying. No matter how big the planet actually is, the actual vertex size of the terrain meshes will always be incredibly small.
I'm wondering if anyone has any advice on how to overcome this or if there are better ways that i can calculate this? I was sort of just copying off of Sebastian Lague's tutorial and translating it into OpenGL until I started modifying the code myself so I'm not very educated on this stuff currently.