Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Do you know why my diamond square algorithm is giving me this such "ragged" results? I used to render it in a way that concealed the roughness (basically asigning color ranges instead of fractional values as now), but when made it work for the first time, months ago, it used to work fine!

enter image description here

I want to tear my hair out!

share|improve this question
3  
We don't know what your diamond square algorithm is. So it is quite hard to help. –  DMan Oct 3 '11 at 5:02
2  
Some code or an explanation of your implementation may help (I added a link to the Wikipedia page for the algorithm itself). It's interesting that you have lots of horizontal bands -- perhaps you've got a typo regarding handling/use of X and Y (as in you're only handling X, or handling X twice instead of Y) in some fashion? –  Josh Petrie Oct 3 '11 at 5:08
1  
Is the second step where you use Diamond areas not working anymore? This would cause the "everything looks square" effect. Although, I still wonder why it's banded like that. Can you run the code iteration by iteration and pump out each individual result, this might help to find your problem? –  NetSquirrel Oct 3 '11 at 7:31
    
Why don't you use perlin? –  Dan the Man Oct 3 '11 at 16:16
1  
@DantheMan: Often times beginners start with Diamond Square because it is a little easier to understand if you don't have a strong math background. It can be more easily understood visually, I think. Also, Diamond Square is perfectly fine for any non-infinite map, it just introduces a lot of square/diamond shapes in your landscape if you don't smooth it properly. –  DampeS8N Oct 7 '11 at 19:58
add comment

2 Answers

Diamond Square typically returns very rough results when a basic implementation of it is used. The solution to this is to modify how Diamond Square is creating your values. I'm unsure what you are trying to use it for, but one of the most common is for procedurally generated mountains.

Option 1:

At each step of the Diamond Square process, that is each time the square gets smaller, reduce the amount of new offset you are going to introduce. This will create a more realistic looking mountainous region that is less craggy and more long slopes with variations, if you are trying for that.

This reduction in offset could also come along with randomness along a scale and not just flat. Meaning that it is possible to still have crags, but they are rarer.

Option 2:

If you are intending to create a more weathered looking landscape, and not sharp crags, it would be wise to pass the result from Diamond Square into a Cellular Automata engine that smooths based on neighboring values. One that works well for me is to check if all 8 neighbors are the same height or higher. If 6 or more are, then do nothing, otherwise lower the height by one. Repeat as needed. More repetitions means a smoother landscape. Eventually it will become flat like Florida.

These are by no means the only options. But they are relatively simple ones you should be able to accomplish with a limited understanding of Diamond Square.

share|improve this answer
add comment

Your image reminds me of loading a bitmap with the wrong bit or color depth. When you are outputting (and inputting if you are using your own code for display) make sure you are using the correct number of bits, colors and compression. Even if you think you are doing it correctly try outputting a simple test image to ensure this isn't the source of the issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.