
Project description:
The Universe Project is a project I plan to work on for a long time. It will be a simulation of planets, solar systems, and galaxies if possible. It will also include various natural phenomena like life, planetary terrain, and asteroids. The project is created in Unity, using C#.
The project is inspired by a youtube series Sebastian Lague made which I was very interested in but the repository for that project hasn’t been updated in 3 years so I decided I was going to make it myself.
It currently has
- A physics simulation of orbits using the real gravitational equation
- Terrain generation for planets (by simplex noise)
- The sphere mesh used is a Fibonacci Sphere using Delaunay Triangulation to find triangles
- Terrain shaders (the colors on the terrain)
Physics
Every celestial body interacts with each other through gravity. This project uses the gravitational acceleration formula

with a modified gravitational constant (using the real gravitational constant [6.674×10−11] would require too large of a space).
In my testing I have just used a topdown view as if the simulation was 2d but it is actually 3d, it just hasn’t been important to add that complexity when testing.
The 3-body Problem
The 3-body problem is a physics problem about predicting the future positions & velocities of a 3 body system given some initial values. Similar to the double-pendulum, the initial values are very sensitive and can significantly influence future positions even in the short term.
I attempted to find 2 dimensional stable orbits for this problem using machine learning. I was unsuccessful in this but I also realized later that I had a part of the sim wrong so I plan to try again.
Coincidentally, a few weeks after I tried this an article named We Just Got 12,000 New Solutions to The Infamous Three-Body Problem was published which is about a finding of 12,409 stable orbits of three bodies with equal mass, which used a similar technique for finding the solutions.



Sphere Mesh Generation
To create good looking terrain the sphere mesh used for the planet needs to have enough well spaced vertices. There are several types of spheres that can accomplish this but I chose the Fibonacci sphere as it has the most control (and it’s more interesting).
Fibonacci Spheres
Fibonacci spheres are a type of sphere that is defined by a number of vertices which allows for much higher control of the mesh definition. The Fibonacci sphere also has fairly well spaced vertices which is important for having consistent terrain.

Stereographic Projection & Delaunay Triangulation
Stereographic projection is a method of representing a 3D sphere on a 2D plane.
Delaunay Triangulation is a method of generating triangulation data for a mesh (it can also be used to generate Voronoi diagrams).
I use stereographic projection and the Delaunay Triangulation library Delaunator Sharp by Patryk Grech, a C# port of the Javascript package Delaunator by Mapbox, to triangulate the points of the sphere. The triangulation data can be used to determine the mesh triangles of the sphere. There is a way to do 3D Delaunay Triangulation but it is significantly slower.
The method of using stereographic projection does result in a hole appearing in the mesh but this can be fixed by creating triangles between a new point in the hole and the points of the convex hull of the projection.

Terrain Generation
The terrain of the planets is generated by simplex noise. The noise inputs are the 3d coordinates of the vertex and it outputs a number between -1 and 1. The outputs are used to create a height value which is added onto the vertex position (which is equal to the vertex normal, because a sphere’s vertices all have a magnitude equal to the radius). Multiple samples of noise are used to generate various terrain features.
There is a “continent” noise, which is generally noise with a low scale, that creates the general shape of the terrain. Continent noise values below zero are divided by an ocean depth variable which sort of defines where the oceans are. The ocean floor variable determines the minimum height value.
There is also “mountain” noise. This noise contributes more to the height but also has a higher scale and more layers which makes it significant in smaller areas.
The last current noise in the sim is “detail” noise. This noise just slightly offsets height values to add some detail. I plan to combine this with tri-planar mapping (used to allow textures without UVs) and normal maps to increase the detail significantly.
I plan to add a lot more detail and noise types to make the terrain more interesting but this is an effective start. The terrain generator will also be moved to a compute shader instead of a normal script which will be much faster.

Terrain Shading
The terrain is colored by a surface shader I wrote in Shaderlab (Unity’s shader language). It currently uses the steepness of the vertices (steepness is 1 minus the dot product of the up direction [sphere normal] and the actual vertex normal) as well as their elevations to generate the colors. The coloring will be made more complicated so it looks more interesting. I also want to introduce biomes into the simulation which would have their own color values and would make life on the planet more diverse when I get to adding that.

Resources:
https://www.redblobgames.com/x/1842-delaunay-voronoi-sphere/
Below are images from various parts of the sim breaking, I think they’re kind of interesting.



