Skip to content

A (very work in progress) 2D noise API and Terrain Generator.

License

Notifications You must be signed in to change notification settings

ChristopherWMM/Terra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Terra 🌎

Perlin Noise Overview

Perlin noise, while random, is what is referred to as coherent noise meaning there is gradual change between values. This can be clearly visualized by translating sections of a given noise map. When done to random noise, the section blends in immediately after its movement stops. However, when done to a coherent noise, like Perlin, the gradual change between values is interrupted and ends up being plainly obvious as seen below.

White Noise Perlin Noise
white-noise-example perlin-noise-example

Perlin Noise Algorithm

  1. Definition:

    1. Perlin grid generation.

      pixel-grid

    2. Pseudorandom vector generation at each Perlin grid vertex.

      perlin-grid-vectors

  2. Calculation:

    1. Calculate the Dot Product between each pixel position and its four respective Perlin grid vertex vectors. This ensures that each point shares at least one pseudorandom vectors as points in adjacent Perlin grid quadrants.

      perlin-grid-dot-product

  3. Interpolation:

    1. Utilize bilinear interpolation to combine the four dot products.

      perlin-grid-interpolation

    2. Utilize a sigmoid fade function, otherwise known as an ease curve to remove any seams found between Perlin grid quadrants.

      No fading Fading
      fade-function-on fade-function-on
      • Fade function used: Fade Function

        fade-function-graph

    3. Calculate the local minimum and maximum of the given noise map, then rescale the individual noise values back onto the interval of [0-1] through inverse linear interpolation.

Terminology
  • Seed:

    • Definition: The single number utilized to initiate the pseudorandom generation of a noise map.

    • Use: Each pseudorandom noise map can be recreated from scratch through the reuse of its unique seed.

      Seed X Seed Y
      Seed: x Seed: y
  • Frequency:

    • Definition: The scale number of individual peaks and troughs found in each dimension of a single noise map octave.

    • Use: Controls the initial scale along the x and y axes of the Perlin noise map. As seen below, increasing the initial frequency by a factor of two causes the previous noise map to be present, but only represent a quarter of the subsequent grid.

      Frequency: 1 Frequency: 2 Frequency: 4
      Frequency: 1 Frequency: 2 Frequency: 4
      * Note: The sigmoid fade function has been disabled to clearly show the effect of increasing the initial frequency. This causes artifacts to be visible between Perlin grid quadrants.
  • Octave:

    • Definition: A single noise map which can be used independently or in compounding layers.

    • Use: Allows for the compounding of noise layers such that subsequent layers add detail and roughness to the previous noise layers without changing their overall structure.

      Original Noise Layer Noise Layer 1 Noise Layer 2 Resultant Noise Map
      Original Octave Layer 1 Layer 2 Octave Result
  • Persistence:

    • Definition: The amplitude multiplier between subsequently compounded octaves.

    • Amplitude function used: Amplitude Function

    • Use: Controls the intensity and detail of the small features present on the noise map after all octaves have been compounded.

      Low Persistence Moderate Persistence High Persistence
      Low Persistence Moderate Persistence High Persistence
  • Lacunarity:

    • Definition: The frequency multiplier between subsequently compounded octaves.

    • Frequency function used: Frequency Function

    • Use: Controls the number of small features visible on the noise map after all octaves have been compounded.

      Low Lacunarity Moderate Lacunarity High Lacunarity
      Low Lacunarity Moderate Lacunarity High Lacunarity
  • Noise Mask:

    • Definition: A topmost layer added to a noise map meant to conceal its noise values by a variable factor.

    • Use: Allows for specific areas of a noise map to be obscured or completely hidden.

      Noise Mask Raw Noise Masked Noise
      Noise Mask Raw Perlin Masked Perlin

Generating Perlin Noise

Noise perlin = new PerlinNoiseGenerator()
		// The desired (positive, non-zero, integer) height of the generated PerlinNoise object.
    		.height(512)
		// The desired (positive, non-zero, integer) width of the generated PerlinNoise object.
    		.width(512)
		// The desired (long) seed used when generating the PerlinNoise object.
    		.seed(0)
		// The desired (positive, non-zero integer) initial frequency of the generated PerlinNoise object.
    		.frequency(1)
		// The desired (positive, non-zero, integer) number of octaves present in the generated PerlinNoise object.
    		.octaves(10)
		// The desired (positive, non-zero, double) persistence of the generated PerlinNoise object.
    		.persistence(0.5)
		// The desired (positive, non-zero, double) lacunarity of the generated PerlinNoise object.
    		.lacunarity(2.8)
		// The desired (positive, [0-1], double) intensity of the NoiseMask being applied to the generated PerlinNoise object.
    		.noiseMask(0.5)
		.generate();

About

A (very work in progress) 2D noise API and Terrain Generator.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages