Help with understanding perlin noise and implementing modifiers

I am looking for help in understanding how to generate perlin noise based on several different parameters.
I have successfully generated terrain previously by gathering two perlin points (low octave sample and high octave sample) and combining them. Now I wish to do this type of thing :

1210707--49206--$fullnoisediagram.png

that is : creating different ‘modules’ with varying outputs of perlin, and then somehow blending them together.

I have been reading (among many other pages) :

… and my head hurts. I cannot see how to factor in these variables :

var persistence : float = 1.0;
var frequency : float = 1.0;
var amplitude : float = 1.0;
var octaves : int = 1;
var randomSeed : int = 1;

From the libnoise tutorial :

I really cannot see the difference between octave and frequency, nor how to implement these two factors.

Amplitude I have concluded is just a percentage of the returned perlin value.

And with Persistence, well I just do not understand where to implement that at all.

So I tried some experimentation :

#pragma strict

public var terrain : Terrain;
var terrainData : TerrainData;

var heightmapWidth : int;
var heightmapHeight : int;

var persistence : float = 1.0;
var frequency : float = 1.0;
var amplitude : float = 1.0;
var octaves : int = 1;
var randomSeed : int = 1;

function Start() 
{
	GetTerrainData();
}

function Update() 
{
	if ( Input.GetMouseButtonDown(0) )
	{
		GeneratePerlinTerrain();
	}
}

function GeneratePerlinTerrain() 
{
	var heightmapData : float[,] = terrainData.GetHeights( 0, 0, heightmapWidth, heightmapHeight );
	
	for ( var y : int = 0; y < heightmapHeight; y ++ )
	{
		for ( var x : int = 0; x < heightmapWidth; x ++ )
		{
			// calculate percentage of octave
			var pOctave : Vector2 = new Vector2( (parseFloat( octaves ) / heightmapWidth) * x, (parseFloat( octaves ) / heightmapHeight) * y );
			
			// modify with frequency
			pOctave *= frequency;
			
			// read perlin
			var newHeight : float = Mathf.PerlinNoise( pOctave.x, pOctave.y );
			
			// restrict by amplitude
			newHeight *= amplitude;
			
			// apply to height at position x,y
			heightmapData[y,x] = newHeight;
		}
	}
	
	terrainData.SetHeights( 0, 0, heightmapData );
}

function GetTerrainData() 
{
	if ( !terrain )
	{
		terrain = Terrain.activeTerrain;
	}
	
	terrainData = terrain.terrainData;
	
	heightmapWidth = terrain.terrainData.heightmapWidth;
	heightmapHeight = terrain.terrainData.heightmapHeight;
}

But all this is doing is creating a basic perlin output. Is there anyone here who would like to explain and help me understand how I can use all these modifiers before or after reading a perlin noise sample?

You have my thanks just for reading this =]

Mathf perlinnoise and libnoise are completely different stuff.
Try my Libnoise port with visual frontend for textures, terrain and normal maps with artificial lights and tutorials, its on a 50% discount now.

Hi. Your really not using the perlin noise as it intended to be used.

This is how I normally create fractal noise. Dont worry about persistance for the time being. Its just the rate at which the amp changes. This is quite a simple version but is easy to follow. The noise value will be in the range of 0 to 1 so you may need to scale it up to what height you want

I also have a perlin noise plug-in found here

var octaves : int = 8;
var frq : float = 100.0;
var amp : float 1.0;

for ( var y : int = 0; y < heightmapHeight; y ++ )
{

 for ( var x : int = 0; x < heightmapWidth; x ++ )
 {

var noise : float = 0.0;
var gain : float = 1.0;
 for(var i : int = 0; i < octaves; i++)
{

noise +=  Mathf.PerlinNoise(x*gain/frq, y*gain/frq) * amp/gain;
gain *= 2.0;

}

heightmapData[y,x] = noise;

}
}
3 Likes

aubergine : Thanks, but I’m not really interested in a product. For me its about understanding the principles and applying them for myself. I appreciate your response, and I understand there is a clear difference between LibNoise and PerlinNoise. My main interest in LibNoise was how they combined the data sets, but I’m now working on my own code that will blend between data sets.

scrawk : wow, you have a most excellent blog there. I shall indeed take my time and work through each of those subjects, and do my best to absorb the information you have provided. I have worked a bit with perlin, but in a basic limited capacity, just like UVs, merely setting the sample size and the offset. Just like my answer here on combining 2 samples for random terrain : How can I make my algorithm make cloudy heightmaps? - Questions & Answers - Unity Discussions . I wanted to somehow make perlin more flexible, to give a much larger range of outputs like what I reading about in LibNoise with all those parameters. But I realize I have to learn about other things like fractal and browning. I actually just did a conversion of the robot frog hill method, that gives some great results too. Many thanks again for advising me of your blog, all the best.