Generating tile noise maps "on the fly"
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 ma开发者_如何学Cp.
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.
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.
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
精彩评论