{"id":845,"date":"2012-04-03T22:40:10","date_gmt":"2012-04-03T19:40:10","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=845"},"modified":"2013-10-28T21:09:00","modified_gmt":"2013-10-28T18:09:00","slug":"diamond-square-algorithm","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/","title":{"rendered":"Diamond Square Algorithm"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"846\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/diamond_square_algorithm_unity\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity.jpg?fit=680%2C511&amp;ssl=1\" data-orig-size=\"680,511\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Diamond_Square_Algorithm_unity\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity.jpg?fit=680%2C511&amp;ssl=1\" class=\"alignnone size-full wp-image-846\" title=\"Diamond_Square_Algorithm_unity\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity.jpg?resize=680%2C511\" width=\"680\" height=\"511\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity.jpg?resize=300%2C225&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Converted <a title=\"http:\/\/en.wikipedia.org\/wiki\/Diamond-square_algorithm\" href=\"http:\/\/en.wikipedia.org\/wiki\/Diamond-square_algorithm\" target=\"_blank\">Diamond Square Algorithm<\/a> \/ random midpoint displacement fractal from Processing (original by &#8220;Justin Seyster&#8221;) to Unity C#.<br \/>\n*See also related <a title=\"http:\/\/forum.unity3d.com\/threads\/130688-Diamond-Square-Algorithm\" href=\"http:\/\/forum.unity3d.com\/threads\/130688-Diamond-Square-Algorithm\" target=\"_blank\">forum topic<\/a>.<\/p>\n<p><strong>Release#1:<\/strong><br \/>\n&#8211; Color32 array with SetPixels32() (instead of plotting each pixel at a time..)<br \/>\n&#8211; Replaced &#8220;\/2&#8221; with &#8220;*0.5f&#8221; (supposed to be bit better??)<\/p>\n<p><strong>Ideas:<\/strong><br \/>\n&#8211; Try to make some terrain height maps? Or just directly displace vertices from the function..?<br \/>\n&#8211; Does it work in 3D?<br \/>\n&#8211; Use it for drawing clouds? Minecraft map?<br \/>\n&#8211; What if you adjust parameters each frame, how it looks animated?<br \/>\n&#8211; Use as a shader? Someone has made <a title=\"http:\/\/goanna.cs.rmit.edu.au\/~pknowles\/shaders\/src\/terrain.frag\" href=\"http:\/\/goanna.cs.rmit.edu.au\/~pknowles\/shaders\/src\/terrain.frag\" target=\"_blank\">one here<\/a>, who would convert to unity..?<br \/>\n&#8211; Mix colors with previous layer..?<br \/>\n&#8211; LookUpTables?<\/p>\n<p><strong>Webplayer:<\/strong><br \/>\nnothing to see..it just generates a texture as in screenshot..<\/p>\n<p><strong>Download source:<\/strong><br \/>\n<a title=\"Download Source\" href=\"http:\/\/unitycoder.com\/download\/index2.php?link=211&amp;uid=un1t3c0d5r\" target=\"_blank\"> DiamondSquareAlgorithm1.unityPackage<\/a><\/p>\n<p><strong>Or donatebuy source:<\/strong><br \/>\n0.5 eur [digishop id=&#8221;14&#8243;] (download link comes to your email)<br \/>\nIncludes: Example scene, c# source<\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#2<\/strong>: texture size: 2048&#215;2048, filtermode.Point,<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"854\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/diamond_square_algorithm_unity_2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity_2.jpg?fit=680%2C635&amp;ssl=1\" data-orig-size=\"680,635\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Diamond_Square_Algorithm_unity_2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity_2.jpg?fit=680%2C635&amp;ssl=1\" class=\"alignnone size-full wp-image-854\" title=\"Diamond_Square_Algorithm_unity_2\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity_2.jpg?resize=680%2C635\" width=\"680\" height=\"635\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity_2.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity_2.jpg?resize=300%2C280&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#3<\/strong>: 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?)<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1.jpg\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"857\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/diamond_square_profiler1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1.jpg?fit=1115%2C763&amp;ssl=1\" data-orig-size=\"1115,763\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"diamond_square_profiler1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1.jpg?fit=1024%2C700&amp;ssl=1\" class=\"alignnone size-medium wp-image-857\" title=\"diamond_square_profiler1\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1-300x205.jpg?resize=300%2C205\" width=\"300\" height=\"205\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1.jpg?resize=300%2C205&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1.jpg?resize=1024%2C700&amp;ssl=1 1024w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler1.jpg?w=1115&amp;ssl=1 1115w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n(click image to view)<\/p>\n<p>Small update: using array &amp; setpixel<strong>s<\/strong>, bit faster..<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2.jpg\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"862\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/diamond_square_profiler2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2.jpg?fit=1100%2C367&amp;ssl=1\" data-orig-size=\"1100,367\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"diamond_square_profiler2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2.jpg?fit=1024%2C341&amp;ssl=1\" class=\"alignnone size-medium wp-image-862\" title=\"diamond_square_profiler2\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2-300x100.jpg?resize=300%2C100\" width=\"300\" height=\"100\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2.jpg?resize=300%2C100&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2.jpg?resize=1024%2C341&amp;ssl=1 1024w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/diamond_square_profiler2.jpg?w=1100&amp;ssl=1 1100w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n(click image to view)<\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#4<\/strong>: greyscale..heightmaps..<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/plasma_terrain_heightmap_1.jpg\" target=\"_blank\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"859\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/plasma_terrain_heightmap_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/plasma_terrain_heightmap_1.jpg?fit=680%2C666&amp;ssl=1\" data-orig-size=\"680,666\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"plasma_terrain_heightmap_1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/plasma_terrain_heightmap_1.jpg?fit=680%2C666&amp;ssl=1\" class=\"alignnone size-medium wp-image-859\" title=\"plasma_terrain_heightmap_1\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/plasma_terrain_heightmap_1-300x293.jpg?resize=300%2C293\" width=\"300\" height=\"293\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/plasma_terrain_heightmap_1.jpg?resize=300%2C293&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/plasma_terrain_heightmap_1.jpg?w=680&amp;ssl=1 680w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n(click image to view)<\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#5<\/strong> (Terrain with nicer colors.. the grid&#8217;ding is quite visible in larger terrains..)<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"879\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/04\/03\/diamond-square-algorithm\/terrain_map_unity1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/terrain_map_unity1.jpg?fit=680%2C537&amp;ssl=1\" data-orig-size=\"680,537\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"terrain_map_unity1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/terrain_map_unity1.jpg?fit=680%2C537&amp;ssl=1\" class=\"alignnone size-full wp-image-879\" title=\"terrain_map_unity1\" alt=\"\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/terrain_map_unity1.jpg?resize=680%2C537\" width=\"680\" height=\"537\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/terrain_map_unity1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/terrain_map_unity1.jpg?resize=300%2C236&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Converted Diamond Square Algorithm \/ random midpoint displacement fractal from Processing (original by &#8220;Justin Seyster&#8221;) to Unity C#. *See also related forum topic. Release#1: &#8211; Color32 array with SetPixels32() (instead of plotting each pixel at a time..) &#8211; Replaced &#8220;\/2&#8221; with &#8220;*0.5f&#8221; (supposed to be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":846,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,3],"tags":[93,221,16,223,80,222,168,142],"class_list":["post-845","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-algorithm","tag-diamond-square","tag-fractal","tag-generator","tag-plasma","tag-random-midpoint-displacement-fractal","tag-terrain","tag-texture"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/04\/Diamond_Square_Algorithm_unity.jpg?fit=680%2C511&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-dD","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/845","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=845"}],"version-history":[{"count":22,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/845\/revisions"}],"predecessor-version":[{"id":2496,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/845\/revisions\/2496"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/846"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}