Creating Heightmaps

Hey guys, I’ve been working on a voxel terrain of late and its been going well.

But now i must ask of you, how is the best way to generate a heightmap from a series of values?

Would perlin noise be the best way to achieve this?

Creating the values ----> Applying them to a texture --------> Grayscaling it -----------> My reading code
^That is my train of thought right now

What I have right now is the ability to read the pixels in a heightmap and build a voxel terrain from it, all I need to do now is to make the heightmap randomly.

Any help/starting points is appreciated, thanks.

Myhijim

I think you dont need to apply it on a texture or grayscale them,
just create “grayscaled” values on the fly for the terrain (or put the values into array first and read from there)

I want to apply to a texture, so the level can be extremely easily loaded again.

Any ideas where to start on generatin the values?

Actually this diamond square thing might be useful also (just would have to fix those visible sharp “corners” / grids or make a new better version of it)
Diamond Square Algorithm « Unity Coding – Unity3D (see image#4)

Quick test for basic perlin (js), put this script to plane object:

#pragma strict
private var size:int=128;
private var noiseScale:float = 0.02;

function Start () 
{
	// create texture image
    var texture = new Texture2D (size, size);
    renderer.material.mainTexture = texture;
	
	// draw heighmap
	for (var y:int=0;y<size;y++)
	{
		for (var x:int=0;x<size;x++)
		{
			var value:float = Mathf.PerlinNoise(x*noiseScale,y*noiseScale);
			texture.SetPixel(x,y,new Color(value,value,value,1));
		}
	}
	texture.Apply();
}

Edit: See this for noises,
http://forum.unity3d.com/threads/68764-LibNoise-Ported-to-Unity

Thank you very much, shall try in a min

Works perfectly thanks