r/proceduralgeneration • u/Backbone_Labs • 14h ago
467M stars, billions of planets, all from one seed and every one of them can be visited. How I generate the galaxy for my space game
I'm making a space game about exploration, resources and combat, and the galaxy it all happens in is fully procedural. I've spent most of the last months on it so I figured this sub would be the right place to show it and explain a bit how it works.
Everything comes from one seed. From there you get 467,561,373 stars, about 4.9 billion planets and 8.2 billion moons, with their orbits, atmospheres, chemistry, geology and terrain. Nothing is stored on disk. It's not a skybox with a few handmade systems either, you can fly to any star, go into its system and visit any planet or moon, it gets generated when you arrive and anyone who goes there sees exactly the same thing, bit for bit. I ran a full census walking the whole galaxy star by star with the same code the client uses (no extrapolating from a sample) so those numbers are the real ones. Only about 1 star in 100 has no planets at all, around 185 million planets have liquid water oceans, 1,852,531 have life, and theres 281,081 neutron stars and 186,578 black holes, because a galaxy without weird stuff to hunt for is boring.
Planets aren't random rolls. The chemistry comes from the rock/metal/ice mix the planet formed from, and its calibrated so Earth comes out within about a point of its measured composition. The first version had something like 16% nonsense planets, frozen oceans at 200 °C and that kind of thing. Now the generator works out the final state for every candidate surface and throws away the ones that contradict themselves. Zero contradictions in the census, which honestly took way longer than I'd like to admit.
Terrain height at any point is just a function of its 3D position: improved Perlin plus a ridged multifractal (Musgrave style), with every octave rotated so the mountains don't line up with the noise axes. Because it's a function, zoom is basically free, the whole globe and a bit of coastline are the same function sampled at different resolution. Small moons aren't spheres either, there are nine shape families based on real bodies like Phobos or Arrokoth.
Determinism was the hardest part by far. Same algorithm isn't enough, it has to be the same bits. Mono in the editor does float math at double precision and rounds whenever it feels like it, IL2CPP and .NET round after every operation, so roughly 7 in 25,000 stars had a different temperature depending on where it ran. The fix is ugly but it works: an explicit (float) cast after every single operation in the generator, no Math.Pow or any library function whose last bit depends on the platform. I also reimplemented Unity's RNG and checked it draw by draw against the real one, and the density maps are read with my own PNG decoder because Unity was compressing them on import and changing 36% of the pixels.
Rendering was the other big one. The first version had a GameObject per star and flying around ran at about 19 fps. Now all loaded stars live in a single GPU buffer drawn with one draw call per camera, a background thread sorts them back to front, and new sectors get generated in the background while you fly. When you travel to a star the camera doesn't actually move, the universe moves around it, so everything stays close to the origin where floats keep their precision. From 19 to around 400 fps.
On the game side every world gets a 0-10 rating for minerals, rare earths, energy, water, food and jump fuel, plus hostility, all from its actual data. The world map at the end of the video splits the surface into 32 cells and each one gives resources based on the real terrain under it, coast gives water, a volcanic slope gives geothermal, an icy moon over an ocean gives water and not much else.
The video is captured straight from Unity, still in development. I'd really like to hear what you think, and if you've built something similar, how did you approach it and what gave you the most headaches?