4

I’m interested in generating 3D height maps for a 2D game I am working on. I am using this to create land masses like in Minecraft or Dwarf Fortress.

I've created 2D heightmaps before, but I used a very rudimentary algorithm that just interpolated between points of a fully random noise array to create a fixed size map. This doesn't tile however since if I try to add a new map next to it, it doesn't account for the height of the existing map.

I have read about Perlin and Simplex noise, but I’m now confused on how to apply Perlin or Simplex noise to a 2D array of height values.

Any help with this would be greatly appreciated. I have no idea what to do anymore. The term 'octaves' not on sheet music scares me.

Jay_PC
  • 51
  • 1
  • 5
  • Look at the answer which suggests using 4d noise functions: http://gamedev.stackexchange.com/questions/23625/how-do-you-generate-tileable-perlin-noise – Christophe Roussy Mar 18 '12 at 13:19

2 Answers2

2

Exactly, you have to look for Perlin/Simplex noise. Think of it as a function f(x,y,...) (as many variable as you wish) that will output random-looking noise. The difference with pure noise is that it acts on gradients, so it will look more natural since it "draws" gradients instead of plain noise with high local variability. Simplex noise is pretty much the same as Perlin's but it divides space in simplexes instead of operating in n-dimensional grids like Perlin does. This alleviates computational cost and has some more benefits.

It might seem scary, but it's simple actually. You're scared about octaves, but they're pretty much the same as octaves in music: just higher (or lower) frequency noise mixed with the original output. Talking about sheet music, it's like playing C4 and C5 at the same time. It's still C but it has some flavor added (little spikes in the waveform.) Don't be afraid and keep researching, it's not that hard.

Regarding tiling:

If you mean linear tiling (like Minecraft does) you just have to use the same seed for the noise algorithm. As soon as you approach your new boundaries, just generate the new chunk of data and it will tile perfectly (just like it does if you infinitely fill with noise.)

If you mean torus tiling (repeating tiles, think Pacman for instance) I found the best solution is to generate your noise tile and then interpolating near the borders as if it were tiled. The noise will deform to match sides and it will be completely tileable.

kaoD
  • 1,534
  • 14
  • 25
  • My current simple explanation for octaves is like layering sand in a sandbox, but each "Octave" you use a smaller and smaller shovel. You start with large round piles but by the end you're dotting the sandbox with lots of tiny spots. Also I suggest to anyone looking at this now to look at how sine waves of different frequencies add together and it could possibly help A decade later I finally come back to this and accepted it because someone really hated that 20 year old me Capitalized Words A Lot. – Jay_PC Jun 02 '21 at 11:26
1

I think that your question might be phrased incorrectly. A heightmap is 2D, inherently, and you use it to generate 3D terrain (mesh).

http://en.wikipedia.org/wiki/Heightmap

If that is the case... then you can use the Perlin noise function to create a 2D image and use it for a heightmap. If you are unsure of what is created, you can use GIMP or Photoshop or a similar tool to create Perlin noise on a 2D Canvas for an example.

Minecraft makes use of the Perlin noise function to create a 3D cube of noise. So where a heightmap is 2D Perlin noise, Minecraft is 3D Perlin noise. You can also generate 1D Perlin noise.

What is nice about the Perlin noise function is that you can control the "resolution" and "offsets" of the texture through the mathematics and hence create seamless environments. I believe that Minecraft makes use of Perlin noise as a base and then moves on to some cellular automata for finishing touches.

I am unfamiliar with simplex noise.

EDIT: here is a link to test some math functions (in processing) http://processing.org/learning/basics/noise2d.html

avanderw
  • 675
  • 1
  • 7
  • 22
  • I'm familiar with generating the Noise itself but my issue has been creating it on the fly. Minecraft only generates chunks as you approach them but the seamlessly tile. this is the effect im going for. The link goes to a image of my program running, it has 2 128x128 tiles but they don't tile. [link](http://i1178.photobucket.com/albums/x379/Jay_PC000/Durr2.png) – Jay_PC Jul 12 '11 at 02:39
  • I know this is not the language you are looking into, but if you can replicate the method functionality from AS3 BitmapData class. They allow for stitching (create it as best as it can to be tile-able texture) but I find that baseX and baseY can give me that "tiling" effect. However, you have to regen the texture each call then. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#perlinNoise() – avanderw Jul 20 '11 at 08:11