Diamond Square Terrain

A few days ago I decided to look into terrain generation. My goal was to create enormous heightmaps to apply to spheres so I could create a randomly generated world. Well, I Googled left and right, I searched these forums, and I thought about it a lot. I couldn’t find any pages that would really help me! Until I found this page:
http://www.gameprogrammer.com/fractal.html
It was the most useful link ever. A few days later, I had a program that could randomly generate a heightmap, then load it into my renderer and actually display it! I’m very excited, and proud to show off my creation. Here’s a video showing it off:

8zgZNuprqzU

(on a side note, I have no idea how to embed youtube! Figured it out!)

On the more technical side of things, I use display lists that are called once when the heightmap is loaded in, and then they are never rebuilt. I use shaders to position and actually texture the triangles. I don’t just color them. I use triangle strips because otherwise I would be using a ton more vertices, and that’s about it!

Here’s the donwload:
goo.gl/g5Cols
(Sorry, I forgot to change the angle in which the player is created. Just turn around and look up and you should see the map)
Press ‘R’ to generate a random map
Press ‘H’ to reload the original heightmap

Currently, this is Windows only, sorry!

The terrain generator is pretty fast; it can generate ~12 million triangles in less than 5 seconds! Feel free to use any of my code, just open it up using JD-GUI!

What libraries are you using for this?

Just LWJGL and my ShaderUtils library, nothing else.

very nice.

I like this alot, good job. I remember reading an article on how the mountains for the Lord of the Rings movie were generated using that triangle breakdown method. That article you supplied reminded me of it :).

If I had a more powerful and a slightly more optimized/Intricate/advanced algorithm, I could totally render out something like that in probably a few days! But this wasn’t that hard to implement!

I know have some (bad) voxel rendering! You can tell that there aren’t any voxels generated to fill in the gaps, but it works nonetheless :slight_smile: Its not optimized as I’m still using display lists to render, I intended to switch to VBOs, but I was too lazy :P!

Haha I like the gaps :slight_smile: It makes it look funny somehow…
If you get into voxels, even if you don’t optimise the code, I think you should check out some other generation algorithms because you can produce some pretty cool looking stuff. I also suggest you look at Marching Cubes generation for non voxel stuff, that way you can make things look more… connected? I dunno how to explain it, but if you use that and per pixel shader lighting combined with other generation methods you have some pretty nice looking stuff just from that!

I’ve already gotten myself into voxels a little, I just took a break to work on little stuff like this, and I’m working on networking now! Honestly, terrain generation would not be high on my to do list, as this algorithm I have right now produces some pretty nice results!

The marching cubes generation idea sounds fun, I might look into that someday! But I’m just proud of myself for learning the Diamond Square algorithm, I’m not going to ruin that feeling with messing around with other algorithms yet :wink:

This is really cool (+1), love your mountain nipples haha.

Haha, I know they really amuse me :slight_smile: Thanks for the medal!

Cool, do you plan on developing this further or was it a test of diamond square algorithm? I would love to see a kind of medieval RTS built out of this like a city builder :smiley:

I want to eventually get back into voxels, and maybe someday create a free roam type of game with this kind of terrain where you complete small missions and kill things. But who knows!

I do want to make use of this program later on, its just I don’t need it right now. I eventually want to simulate planets with procedural terrain and lighting… but that’s far off in the future after a few more years of OpenGL!

This is less hard as you might think.

  1. Create a sphere
  2. For each point, multiply by a noise value (just use the x,y,z as input).

Thats it!.
After less then a hour work you could achieve this:

*However you will need to make some kind of LOD sytem if you want to be able to zoom.

That’s awesome! Could I overlay a height map onto the sphere? I’m guessing its a bunch of math because I’d have to UV map it, which I don’t know how to do yet!

Sure, and not so much:


text.y = 0.5f + (float)Math.asin(point.y) / PI;
text.x = 0.5f + (float)Math.atan2( point.z, point.x ) / (PI*2);

Wow, thank you that’s very helpful, I’ll do that sometime soon :slight_smile:

Good job man! I must say this is pretty epic in my eyes! :wink:

Good work! I’m just trying to draw a simple triangle strip grid and man I can’t imagine how hard this was…

The last couple of replies that were talking about making a procedural planet out of this are really interesting!! I can’t wait to see how that is coming if you plan on going in that direction.