Apr
3
2012

Diamond Square Algorithm

Converted Diamond Square Algorithm / random midpoint displacement fractal from Processing (original by “Justin Seyster”) to Unity C#.
*See also related forum topic.

Release#1:
– Color32 array with SetPixels32() (instead of plotting each pixel at a time..)
– Replaced “/2” with “*0.5f” (supposed to be bit better??)

Ideas:
– Try to make some terrain height maps? Or just directly displace vertices from the function..?
– Does it work in 3D?
– Use it for drawing clouds? Minecraft map?
– What if you adjust parameters each frame, how it looks animated?
– Use as a shader? Someone has made one here, who would convert to unity..?
– Mix colors with previous layer..?
– LookUpTables?

Webplayer:
nothing to see..it just generates a texture as in screenshot..

Download source:
DiamondSquareAlgorithm1.unityPackage

Or donatebuy source:
0.5 eur [digishop id=”14″] (download link comes to your email)
Includes: Example scene, c# source

Image#2: texture size: 2048×2048, filtermode.Point,

Image#3: deep profiler report (should try to put the colors in array..instead of using single setpixels..also could try using ints? and replace divisions with multipliers?)


(click image to view)

Small update: using array & setpixels, bit faster..


(click image to view)

Image#4: greyscale..heightmaps..


(click image to view)

Image#5 (Terrain with nicer colors.. the grid’ding is quite visible in larger terrains..)


12 Comments + Add Comment

  • This is amazing!Can’t wait for the source

  • Hello!How do i download it?I have installed the toolbar and have java enabled and still says that UnityCoder.com Toolbar must be installed & Javascript enabled! (and these links are personal, use the toolbar to access downloads) yada yada

  • I also was not able to download – after installing shitty toolbar

    • Chrome has problems with the downloads..
      (It might work better now, link doesnt open in a new window anymore)

      • Sorry for calling your toolbar shitty. You are an awesome programmer. I was just frustrated.

        • no problems, havent yet found other solutions for offering free downloads.. (actually google ads are better than the toolbar already)

  • I suppose this is not a “Dianmond-Squere” Algorithm because it looks so linear and “griddy”.
    It looks like a two dimensional “Midpoint-Displacement”. You need to do two steps first create all squares then diamonds

  • Wonderful! You just saved me a few hours of work, thanks a lot!

  • How did you generate the greyscale height map?

    • I think the colors were just set to 0-1 for each (R, G, B), so it becomes grayscale,
      in the terrain colors image, there is some added if’s to set different colors based on the value (like if height is 0.5, then use grass color..)

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.