Skip to content

e-mateo/ProceduralGeneration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Procedural World Generation - Planet Generation

png

Introduction

Procedural World Generation - Planet Generation is a C# project on the implementation of procedural generation algorithms on Unity3D.
This project started on October 3rd and ended on November 14th.
Made by ERBISTI Matéo and RABINNE Lenny, programming students at Isart Digital Paris.
For this project, we focused ourselves on creating procedural planets, including the creation of the planet mesh and texture, but also the procedural placement of props on its surface.

Usage

Download the .zip file from the repository/portal.
Inside you will find:

  • the build, in Build.
  • screenshots, in Screenshots.
  • videos of the build and of the setup in the editor in Videos.

Spaceship Controls

WS/ZS to move forward and backward.
AD/QD to roll.
The mouse controls both yaw and pitch.
Space bar to ascend.
Shift to descend.

Planet Generation

Planet Sphere Mesh:

The Planet Generator script and PlanetSettings scriptable object are used to generate the planet mesh.
The sphere mesh is generated using a normalized cube. You can set the resolution of the mesh.
The Flat Face script is responsible for creating the vertices and indices of a face cube, as well as normalizing them, resulting in a sphere with 6 face meshes.
drawing

Noises:

To alter the planet's surface, you can create a biome and a noise setting to define multiple noise layers for the planet's surface.
Each noise setting layer has its own parameters such as the noise strength, amplitude, roughness...
We implemented 3 different Noise Types: Perlin Noise, Simplex Noise, and Voronoi Noise.
You can also set multiple octaves per noise, which will be added together, and you also have an option to use the first layer as a mask (meaning that the noise value of future layers will be multiplied by the noise value of the first layer).
At each octave, values such as amplitude and roughness will be multiplied by the multiplierPerOctave.

The Noise Filter is used directly after computing the default Perlin, Simplex, or Voronoi noise to remap the noise value.
Simple type only remaps the noise range from [-1:1] to [0,1]. Rigid type does the same, but uses the 1- Abs(x) formula to make it, and then multiply the result by a weight updated at each octave.

drawing

Biomes:

You can create multiple biomes for your planet.
Each biome has its own list of noise layer settings and gradient for the ground and the ocean.
This allows you to create different areas on your planet.
Biome regions are separated thanks to the start biome height (0 is the bottom point of the planet, 1 is the top point of the planet).
You can also tweak the biome noise layer to have a more realistic and less abrupt transition.

drawing

We also have a biome blend variable to blend the different biomes together and have a smooth transition between the noises and colors.
Here you can have a look at two biomes without and with blending.

drawing

drawing

Planet Material:

When generating the planet, the planet material will be updated, and a texture filled with biome and water gradients is generated and sent to the planet material.
Gradient colors will be applied on the planet based on the unscaled noise value and biome percent stored in the UV coordinates of each vertex used to sample the generated texture.
We also added an ocean gradient used for negative unscaled noise values.
The depth of the ocean is only visual, as when creating the planet mesh, the noise is scaled with planet radius and clamped to 0 for the minimum value.

drawing

Here is the generated texture for those biome/ocean gradients.
png

Random Generation:

You can use the generate random planet/colors buttons to randomize the values of the planet settings, resulting in random planets.
This is useful to quickly generate multiple planets.

drawing

Procedural Props Placement

To randomly spawn meshes on the planet, add the ProceduralPropsPlacement script and create some PropsGenSettings scriptable objects. You can accumulate multiple PropsGenSettings on the same planet, resulting in multiple samplings.

Sampling on unit sphere:

The sampling can be computed with two different methods:

  • Random Offset Spherical Grid: create a uniform grid on the planet and offset the position of each grid point randomly. This method is fast and gives great random results but produces meshes overlapping.
    You can tweak the density of the grid (the density is based on a unit sphere) as well as the random min and max position offsets.
    drawing
    We can see that meshes overlap.

  • Multi Class Spherical Poisson Sampling: The sampling is made using Bridson’s multi-class poisson sampling algorithm, but is applied to a sphere object. With this method, you can set a minimum distance between each point, which will not provide any overlapping.
    With the Multi Class, you can have objects of different sizes in the same sampling. Each class has:

  • a minimum distance from objects of the same class

  • a minimum distance from the objects of other classes.
    To use multiple classes, you need to assign multiple PropsGenSettings scriptable objects in the ProceduralPropsPlacement (one per class).
    Classes that are higher in the PropsGenSettings have priority over classes below, as they are the first ones to spawn.
    The algorithm has been optimized using 3D grids to store the sample points for each class (the cell size is the maximum of the two minimum distances within the class).
    Those grids are used when checking distances of a new sample point from others to only calculate the distance with points in neighboring cells, which makes it way faster.
    drawing
    Thanks to the poisson disc sampling, meshes don't overlap. Trees, Mushrooms, grass and rocks are all different classes with their own minimum distances.

Projection on the planet:

Once the sampling has been made, points will be projected onto the planet surface.
Then you can add more variations with random rotation or scale offsets. You can also align the props to the ground normal or not.
drawing

Point Selection:

Then the selection of the point will happen, and some points will be discarded based on their height, tilt, or even a noise value.
drawing
We can see here some noise on the mushroom props.

Prop Meshes:

You can set a list of meshes that will spawn. For each mesh, you can specify the biome it will spawn in, as well as a spawn probability if multiple objects can be spawned on the point.
The props are drawn with GPU Instancing to optimize the duration of the generation, as 0 gameobject will be created, as well as the rendering thread if the density is huge.
drawing

Results

png
png
png
png
png
png
png

Improvement

Even though our results are quite satifiying, we always have room for improvement!
For example, the planets that are generated have an ocean, but the depths are visuals.
Having pits and rifts would be a great addition to those stars.

Another great idea would be to have custom textures instead of one gradiant for a whole biome.
Being able to draw the limits of new biomes to generate them would also be awesome and allow us to bring ideas alive quicker.

For the procedural props placement, a great improvement could be to have an option to spawn gameobjects instead of using GPU instancing.
That will allow artists to tweak it more easily once the generation has been made.
The Multi-class poisson disc sampling could also be optimized with a better spatial acceleration.
Finally, just like the biomes, it could be really great to have a painting tool to procedurally place props precisely where we want like Unreal Engine with their foliage tool.

Credits

Here are the links for the assets used for the props placement:

About

Procedural planets generation (planet meshes and props placement) on Unity

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors