Zylann / godot_voxel

Voxel module for Godot Engine
MIT License
2.64k stars 248 forks source link

Technical feasibility of having chunks saved as triangles instead of squares and having chunks render at a progressively slanted angle from player? #328

Open ravennst opened 2 years ago

ravennst commented 2 years ago

I was thinking of a way to render/generate a true Earth-sized planet and I may have come up with a solution but I'm currently unware of the technical limitations that might go into it.

Using Earth as an example, you wouldn't need to generate at most 5 km below the surface as it would get too hot. The diameter of Earth is 12,742 km, that means that 99.76% of the "planet" doesn't need to be rendered or generated at all and the scale at the player level is generally flat. A 20 m line at the surface, maintaining the same lat/long for the end points would only vary by ~ 1 cm at 3km of depth and 5.5 cm at 15 km of depth.

That said, if the surface of the "sphere" were subdivided into an icosahedron which would then be further subdivided into smaller triangles at a reasonable distance for the engine, each triangle could be rotated away from the player at something like .00020797 degrees per 20 m triangle on an Earth sized planet. You could use flat plane generation methods including 3D noise for caves and overhangs without having to generate the ENTIRE planet like the tutorial does. (tiny asteroid comparatively speaking), have LOD generation, all the benefits of flat plane generation, etc. without generating the entire planet at once.

The hurdle then, would it be technically feasible to have triangle "chunks" and have them progressively angled from the player? I'm aware that this would require some code alteration but I'm trying to gauge how much of a change this would require. #

Zylann commented 2 years ago

Using triangular chunks seems like a hassle. The entire stack of data structures need to be rethought, because every chunk, every data block, every mesh, the LOD system, generators, are all built to use box chunks.

If your concern is that a generator would have to generate the entire planet, this is actually only true if you write a naive generator. I'll take the example of the Solar System demo:

An alternative to triangular chunks would be to use a method similar to what No Man Sky does: to consider only a thin layer of voxels above bedrock. That layer is represented as 6 faces of a cube, which is spherified. That still works with box chunks. The catch is, every operation done on voxels must convert between sphere and chunk coordinates, and some special cases need care at the edges. Still, I don't plan on doing these changes or introducing more terrain classes in this module at the moment.