Jump to content
• Advertisement

Public Group

Help me understanding the diamond square algorithm

Recommended Posts

Hello,

I'm trying to implement in opencv The Diamond Square algorithm, but something is not working. I think I didn't understand exactly the algorithm.
https://en.wikipedia.org/wiki/Diamond-square_algorithm

1. When I initialize first the four corners, they must have the same color ? Or different ones ? In my algorithm they have different colors.
2. Then I calculate the midpoint of the square by averaging the square corners(The diamond step). So the midpoint will have a color...let's say red.
3. After this, the corners from the square step (the third image from the link) will be averaged and the value will be contained by the midpoint. But the midpoint will not be the same for the square and for the diamond ? So the final color will be that one from the square step ? What is the point by performing the diamond step ? I'm very confused to be honestly.

I tried to search on the internet, but I didn't understand from other websites. It would be nice if someone would explain more clearly, what the colors of the pixels would be.

Thank you!

Share this post

Share on other sites
Advertisement

The diamond-square algorithm is not about coloring but about height: It generates a height-map. I.e. it adds the 3rd (height) component in a semi-random fashion to a given 2D grid. You can, of course, do colorization by mapping height values into colors, but currently I don't see a meaning in "inheriting" color from the corners.

So, what exactly is the goal of your attempt? What are the colors you mentioned good for?

E.g., if you want to colorize the heigh-map like a terrain (white for snow on the mountains and such): Make a color ramp, take the resulting height of a grid point, normalize the height, and use the normalized height to address a color in the ramp.

Share this post

Share on other sites

My goal is to create clouds, gases, or nebulas for skyboxes. And I don't want to use any softwares.  I would like to code them by myself.

Share this post

Share on other sites

For terrain a possible outline to start:

1) compute the height field
2) perhaps clamp heights below sea-level to the height of the sea-level
3) use a color ramp

For clouds a possible outline to start:

1) compute the height field
2) clamp the heights below "blue sky level" to that level
3) colorize the sky level to blue and blend other heights with a dark gray, using the blend factor proportional to the relative height

Nevertheless, I don't understand why to inherit colors from corners somehow. I think because the entire area is the first square, using inherited colors would ever give a much too smooth colorization. There may be a sophisticated way I'm currently not aware of, so if you have a reference why inheriting colors please tell us...

Edited by haegarr

Share this post

Share on other sites

You may want to finish implementing the diamond-square algorithm, since you have started it. But you should also consider using Perlin noise instead.

Share this post

Share on other sites

That's what I want to do. I wrote a part from algorithm, but like I said, I'm not sure if I understood it.
About Perlin noise, maybe after this I will try it .

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 21
• 10
• 33
• 20
• 9
• Forum Statistics

• Total Topics
633416
• Total Posts
3011780
• Who's Online (See full list)

There are no registered users currently online

×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!