# Generating Voxel Planet using 3D Simplex Noise

A

Voxelin 3D space is what aPixelis in 2D space. The term Voxel is short forVolume Elementjust the way Pixel is short form ofPicture Element

# A voxel is the 3D representation of Pixel

A Picture in computer graphics is made up of a grid of Pixels in 2D space. The resolution of an image represents the number of pixels along its length and breadth. Each pixel has it’s color and position in a picture. We can think of pixels as tiny squares perfectly lined in 2D space.

If we use cubes to represent Pixels and add a height Dimension then we get Voxel. You should be familiar with it if you are familiar with the Minecraft game.

# Building Voxel Planet

**Step1: Draw Voxel along 3D axises**

Let’s first fill the entire grid with Voxel blocks

**Result**:

**Step 2: Make it Spherical**

To make it spherical we need to ignore the point if it is located outside the Planet Sphere.

We can do that by calculating the distance of a point from the Center of the Planet and checking if the distance is more than Planet’s Radius.

**Result**:

**Step 3: Noise**

In order to add this smooth randomness in Computer Graphics, we use noise algorithms.

Simplex noiseis a method for constructing ann-dimensional noise function comparable to Perlin Noise(“classic” noise) but with fewer directional artifacts and, in higher dimensions, a lower computational overhead.

Ken Perlin designed the algorithm in 2001 to address the limitations of his classic noise function, especially in higher dimensions.

The advantages of simplex noise over Perlin noise:

- Simplex noise has lower computational complexity and requires fewer multiplications.
- Simplex noise scales to higher dimensions (4D, 5D) with much less computational cost
- Simplex noise has no noticeable directional artifacts, though noise generated for different dimensions is visually distinct (e.g. 2D noise has a different look than slices of 3D noise, and it looks increasingly worse for higher dimensions
- Simplex noise has a well-defined and continuous gradient (almost) everywhere that can be computed quite cheaply.
- Simplex noise is easy to implement in hardware.

**This is a demonstration of Vertex transition using JavaScript Math.random() vs Simplex Noise algorithm on 3D plane:**

If you look at the result then it should be clear by now that the Simplex Noise Algorithm generates a smother random numbers than the Math.random function. More you zoom into the Noise output more smoothly it will appear.

Noise output might appears random but it really is not. If it were really random, then you’d get a different result every time you call it. Instead, it’s “pseudo-random” — it gives the appearance of randomness.

Noise algorithm can take a number of inputs but always returns single value as output

**1 Dimensional Noise:**Input single value as input and it will return a randomized number as output. eg Graph, 2D lightning bolt.

**Path Demo**: http://hiteshsahu.com/Sea

**2 Dimensional Noise:**Input 2 values as input and it will return a randomized single value as output. eg Height Data for Terrain Generation:

**Mountain Demo**: http://hiteshsahu.com/CyberPunk2077

**3 Dimensional Noise:**Input 3 values as input and it will return randomized single value as output. eg Time-varying Volumetric Areas like Caves in 3D (Noise<0 Means Air)

Here I am using 3D noise output to decide if I should draw the Voxel Cube or not.

**It results in tunnels on the planet:**

**Step 4: Texturing**

Now you can apply a different texture on voxels based on its distance from the center. For example, you can say if Voxel is between PLANET_SIZE * 0.5 it will be Lava. beyond that Ocean and somewhere at PLANET_SIZE * 9.5 it will be Land. You can experiment with different textures:

You can even disable Tunneling below Sea level which will result in a solid planet:

You can even change the spacing between blocks:

You can see the final version on this Website:

I hope that was useful to you, till next time. Follow me on Tweeter for weekly new inspiration: https://twitter.com/HiteshSahu_