My goal is to make a space exploration sandbox game, with ~20%-scale planets, real physics, and a small colony/factory layer.
This teaches real orbital mechanics skills, like:
How do you efficiently turn a rocket sideways as it gets into orbit?
How do you reach the moon?
How do you safely get a huge gravity assist off a binary black hole pair (without being ripped apart by extreme tidal forces)? spoiler:
very flat spacecraft
The factory layer can also teach people about the promise of space industry:
What does it take to build a Kevlar space elevator on the moon?
How many orbital solar panels does it take to meet all of humanityβs energy needs?
Why are huge rockets like Sea Dragon or Starship economically exciting?
This is an outrageously ambitious technical project. Kerbal Space Program 2 spent six years in development with an informally estimated cost of 40 to 60 million USD, never left early access, and ended when its publisher shut down the studio that made it.
To do this, one thing I need is an earth worth returning to.
That earth begins as a few-hundred-million-year whole-planet sim, written in Rust, which simulates plate tectonics, orogeny, volcanoes and lava flows, meteor impacts, glacial erosion (Cordonnier et al. 2023), post-glacial rebound as the earthβs crust regains isostasy, ocean evaporation, rain shadows, rivers, lakes, erosion, and movement of sand in the ocean. (This might be the subject of a future blog post π, but for now weβll skip over it to some other interesting bits about neural networks. The moon, pictured at the beginning of this post and rendered in Unreal Engine, comes from the same terrain Rust sim, with more emphasis on craters, ejecta, and lava flows.)
That sim takes a few hours to run on my RTX 3080 Ti, and gets us down to ~500-meter resolution for my earth stand-in. But thatβs not enough detail, and using first-principles physics sims to get to a finer resolution was too difficult. Rock breaks and erodes in complicated ways, rivers and soil have incredibly complex dynamics; capturing all of that detail was hard.
So, letβs use neural networks to just learn all those complicated dynamics!
Terrain detail with diffusion models ποΈ
First, we teach a diffusion model to understand fine erosion detail, by training it (from scratch on my gaming PC!) on real earth terrain data. (Thanks ESA!)
aiAI-generated:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ1. Coarse heightsββββ2. Exact baseββββ3. U-Net denoiserββββ4. 57 m terrainββββββββββββββββββββ Input from the ββββ A quadratic spline ββββ Predicts the ββββ Base + detail, ββββ full-planet ββββ through the means ββββ detail below the ββββ 8 Γ 8 cells a ββββ erosion sim, one ββββ (histopolation): ββββ base, starting ββββ texel, means still ββββ mean height per ββββ smooth, and texel ββββ from noise: ββββ exact: Nanite ββββ ~460 m texel, ββββΆβ means held exactly ββββΆβ 32 Heun steps ββββΆβ meshes + ββββ 4096 Γ 4096 texels ββββββββ (EDM), 30 M ββββ displacement for ββββ a cube face ββββββββ weights, 4 levels, ββββ the game ββββββββββββ 64β384 ch βββββββββββββββββββββββββββββββββββββββββββββββββββΓ 32 β βΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ²βββββββββββββββββββββββββββββββββββββweightsββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββReal elevation modelsββββTraining dataββββTrainββββββββββββββββ Copernicus GLO-30 ββββ Resampled to 57 m cells; ββββ Denoise at random noise ββββ worldwide, USGS 3DEP (bare ββββ random 14.6 km patches, ββββ levels (EDM loss), ββββ earth) in the US: 57 ββββΆβ rotated and mirrored; the ββββΆβ 20k steps, 81 minutes on ββββ regions from Himalaya to ββββ input is their own texel ββββ one RTX 3080 Ti ββββ deltas, dunes and ice caps ββββ means. 6 regions held out βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Inspired by recent work like Elucidating the Design Space of Diffusion-Based Generative Models (Karras et al. 2022). This takes nine hours to add detail to a tiled cube-sphere heightmap representation of the earth, which is the output from the first erosion sim. It runs over the tiles in raster order, using RePaint (Lugmayr et al. 2022) and a few other tricks to avoid seams.
Sounds good in theory, but how does it look in practice?
Thank goodness for Unreal Engineβs Nanite renderer - between an ~8 GB mesh and further tessellation heightmaps for residual detail, the earthβs geometry data alone is over 9 GB. (These are still just flat-color renders - grey for rock, white for snow, green spheres for trees, be forgiving π ). Unlike a procedural quad-sphere (the usual solution here, as well as my since-replaced v1), thereβs no inefficient subdivision of flat planes or expensive geometry smoothing over heightmaps; thereβs just a giant efficient mesh, baked offline. This also lets us do caves, tunnels, and overhangs! Collision might deserve its own little write-up - basically, Nanite renders the planet on the GPU (with tessellation), but we also have an efficiently queryable CPU representation, which matches what Nanite draws exactly, so we can dynamically generate surface colliders around physics objects.
You might also notice these odd fluffy white things hanging volumetrically in the sky. Another perfect candidate for tiny neural networks!
Radiance-predicting neural networks for volumetric cloud rendering βοΈ
This work is based on MRPNN (Hu et al. 2023) and tiled-MRPNN (multi-feature radiance-predicting neural networks), but is trained from scratch.
Generating training data is usually quite difficult, but weβre saved once again by Unreal Engine - we generate training data for the neural network in-engine by running Unrealβs path tracer through the same volumetric clouds, in the same game world, and then we train a tiny (~10k weights) neural network to approximate the path-traced reference by more efficiently representing visually important features using sparse, cheap input data.
aiAI-generated:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ1. March into the cloudββββ2. Look aroundββββ3. Small neural netββββ4. Light outββββββββββββββββββββ Follow each pixel's ray ββββ 52 density ββββ About 10,000 ββββ How much sun ββββ and stop where the ββββ samples around ββββ weights, run on the ββββ and sky light ββββ cloud has blocked ββββΆβ each stop: rings ββββΆβ GPU for each ββββΆβ reaches the ββββ 40% and 70% of it ββββ out to 13 km and ββββ traced pixel ββββ camera: the ββββββββ a line toward ββββββββ pixel's ββββββββ the sun ββββββββ color βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ²ββββββββββββββββββββββββββweightsββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββGround truthββββTraining dataββββTrainββββββββββββββββ An expensive path-tracer ββββ ~360 views across the ββββ A few minutes in PyTorch; ββββ in the engine simulates ββββΆβ planet, ~1 million pixels ββββΆβ the weights are written ββββ light bouncing through the ββββ of inputs and true light ββββ into the shader ββββ same clouds βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Costs 0.3β1.9 ms a frame at 1440p on an RTX 3080 Ti. On views it never trained on: typical error about 15% against the path tracer, with no bias from dark to bright.
Hereβs a held-out example of what the network is using as input:
Putting it all together (terrain, atmosphere, and clouds) in-game:
(Again, please be forgiving, this is an early prototype - this version of the network was trained on just a few hundred clouds!)
Beauty shots π
After several months of work, (now) three total re-implementations of volumetric cloud rendering, and ~four total re-architectures of the planet rendering (I started with a procedural quad-sphere before pivoting to Nanite) and generation sims, the game is finally starting to look⦠kinda good? Let me show this off for a moment. Screenshots are running in real-time on my gaming PC: