Created as part of a university project on shaders using Unity's Shader Graphs.

The project specifications required the creation of a terrain featuring mountains, water, various colors based on altitude, a day/night cycle, clouds, and diffuse and specular lighting. As a bonus, students were allowed to apply the shader to a sphere.

I decided to take on the challenge by generating a planet right from the start.

Work Completed

The foundation of the planet is the creation of a spherical mesh. Using a script, I generate 6 faces forming a cube that I inflate into a sphere. I can adjust the radius and resolution of each sphere, allowing me to create each layer with the desired precision.

custom sphere editor

Triplanar Noises

Procedural generation is based on manipulating noises to achieve natural-looking reliefs and patterns. The drawback is that these noises are produced in two dimensions, causing significant texture distortion at the poles when projected onto the planet.

To solve this issue, I created a triplanar variant of the main noise types (gradient, voronoi, and simple). This involves generating a noise on the planes of the x, y, and z axes, then combining them to form a kind of 3D noise.

Convert 2d noises to triplanar noises

These 3D noises work perfectly when projected onto a sphere and form the foundation of my procedural generations.

Planet Construction

The planet is composed of several layers:

  • The terrain
  • The ocean
  • The atmosphere
  • The starry sky

Timelapse of the planet shader

The terrain is the most complex shader. It defines the detailed continents, with biomes changing based on altitude. Additional relief is added to a portion of the green biome to give the appearance of a pine forest.

The terrain layer is also the most detailed. To achieve this level of detail, the sphere must have an extremely high resolution. I didn’t have time to implement a tessellation algorithm to optimize the rendering, making the scene very GPU-intensive.

The ocean serves to properly delineate the continents. I intentionally did not implement diffuse lighting for stylistic reasons. The water includes wave movements, dynamic foam textures, and horizon lighting.

The atmosphere aims to give a more realistic look of a planet in space. It was also intended to serve as the base for clouds, which I didn’t have time to implement.

Finally, the starry sky is created using a sphere with a negative radius, so its faces are turned inward.

The scene also includes a static moon with a crystalline rock material.

Parameters

The shaders have numerous parameters that can greatly alter the planet's appearance:

  • The strength, scale, and blending of the noises allow changes to the planet's geography.Noises parameters visualization


  • The distribution, color, and blending of the biomes can modify its appearance and make it look like an entirely different planet.
    Biomes parameters visualization


Github page :
https://github.com/Mr-Sim/Unity-Planet-Shader

Published 20 hours ago
StatusReleased
PlatformsHTML5
AuthorMr-Sim
Made withUnity
TagsProcedural Generation, Shaders, Space, Unity

Leave a comment

Log in with itch.io to leave a comment.