Development Log 6 - Perlin Noise and Implementation


Perlin Noise 

This entry shall examine Perlin Noise and how it can be used to creating terrain. Perlin Noise is a gradient noise that contains normalized values. These points can be projected as height maps and allow the production of flowing coherent terrain. 

Michelon de Carli et al. (2014) provide a concise explanation for how Perlin Noise is applied to Terrain Generation; each noise function (Perlin Noise layer) has its own individual amplitudes and differing frequencies and is applied to a single output. 1  

This technique can be referred to as Fractal Perlin Noise. 

Octaves refer to individual layers of noise, each contributing to the overall noise output with varying frequencies and amplitudes. Each octave, or layer, has a decreasing effect on the overall noise output. Subsequent octaves have lesser influence on the final noise output to allow finer details. 

Frequency affects the scale at which a given octave is applied to the final output – a higher frequency allows smaller details to appear in the noise.  

Amplitude determines the level of multiplication that the Octaves values apply to the overall values – a low amplitude value diminishes each subsequent Octaves noise to the final noise output. 

This research helps to inform the project in the practical implementation of Perlin Noise in generating realistic terrain. 


Practical Implementation of Perlin Noise in Unity 

The online video produced by Brackeys (2017) provided guidance on practically implementing Perlin noise to terrain generation. 2 3

Brackey details applying Perlin Noise first onto a texture, followed by a Mesh.  

In the first implementation of Perlin Noise generated terrain, this author determined that Perlin Noise as a single layer will be applied to the height values of the mesh, however it is noted, as outlined in the prior research, multiple layers will be added later. 

The project makes use of Unity’s inbuilt function Mathf.PerlinNoise(), which provided an invaluable tool in accessing the values from a plane of Perlin Noise. 4 

The gradient of values from Mathf.PerlinNoise() allows for the projection of height values onto a mesh with a visual cohesion and flow. 

 

Figure 1: GIF demonstrating mesh grid size changes and height values displaying different colouration. 

 

The project currently provides for the scaling of the height of the mesh with values taken from the Perlin noise map, allowing for the size of the grid, making up the meshes vertices, to be changed without affecting any given points height value. 

 

Figure 2: Code snippet demonstrating mesh height values calculated from X and Z coordinates of the meshes grid, normalised, then passed to PerlinNoise function. 

 

To address the issue from last week regarding stretching textures, a new method to applying texture was engaged. A texture was generated to the mesh that projects the Perlin Noise values into colours applied to each pixel on the texture. This was expanded to change the pixel colours gradient based upon the points in the meshes height in world space. 

This was applied by grabbing reference to the highest point in the terrain and normalizing that value as 1 and referencing any other height points to the highest point to get their normalized value. The colour for that point was then applied via colour interpolation. 

 

Figure Three: Code snippet showing the implementation of applying colour based on height. 

 

References

  1. Michelon de Carli, D., Pozzer, C.T., Bevilacqua, F. and Schetinger, V. (2014) ‘Procedural Generation of 3D Canyons’, 2014 27th SIBGRAPI Conference on Graphics, Patterns and Images, Rio de Janeiro, Brazil, pp. 103–110. doi: 10.1109/SIBGRAPI.2014.41

  2. Brackeys (2017) PERLIN NOISE in Unity - Procedural Generation Tutorial [YouTube video]. Available at: https://www.youtube.com/watch?v=bG0uEXV6aHQ (Accessed: 7 December 2024)

  3. Brackeys (2017) GENERATING TERRAIN in Unity - Procedural Generation Tutorial  [YouTube video]. Available at: https://youtu.be/vFvwyu_ZKfU?feature=shared (Accessed: 7 December 2024)

  4. Unity (n.d.) Mathf.PerlinNoise. Unity Documentation. Available at: https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Mathf.PerlinNoise.html#:~:text=Perlin%20noise%20is%20a%20pseudo,is%20not%20implemented%20in%20Unity (Accessed: 7 December 2024)

Previous
Previous

Development Log 7 - Multiple Terrain Handling

Next
Next

Development Log 5 - Revisiting Terrain Generation with Meshes