{"id":1262,"date":"2016-02-26T19:10:53","date_gmt":"2016-02-26T19:10:53","guid":{"rendered":"http:\/\/theindiestone.com\/binky\/?p=1262"},"modified":"2016-02-27T16:41:49","modified_gmt":"2016-02-27T16:41:49","slug":"simple-landscape-generation","status":"publish","type":"post","link":"https:\/\/theindiestone.com\/binky\/2016\/02\/26\/simple-landscape-generation\/","title":{"rendered":"Simple Landscape Generation"},"content":{"rendered":"<p>Man I love playing around with landscape generators, it&#8217;s the most therapeutic thing ever. I recommend it. It&#8217;s the weekend tomorrow, what are you waiting for?<\/p>\n<p>Anyway, in a break from whinging about games and the games industry I thought I&#8217;d write a few words about some daft experiments I was doing with landscapes&#8230; uhhh&#8230; (checks date modified on these files)&#8230; blimey, was it 2 years ago? Yeah, apparently mid 2014(ish). I had intended to write this blog post then, but it seems I never got around to it \ud83d\ude09<\/p>\n<p>Here&#8217;s an example of one of the landscapes wot I generated:<\/p>\n<p><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landscape.png\" rel=\"attachment wp-att-1264\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1264 \" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landscape.png\" alt=\"landscape\" width=\"700\" height=\"350\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landscape.png 800w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landscape-300x150.png 300w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landscape-768x384.png 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p>A couple of things to note: Firstly, it tiles in both directions which is handy. Secondly, it&#8217;s not very Perlin Noise-y. That&#8217;s because I didn&#8217;t use any kind of noise function to generate it &#8211; well, I sort of did (I&#8217;ll get to that), but not in the conventional way.<\/p>\n<p>Perlin Noise (or more accurately nowadays, Simplex Noise) is probably the world&#8217;s handiest algorithm ever for generating textures. We&#8217;ve all seen it, we all know what it is, so there&#8217;s no reason to go into it beyond this extremely crude example:<\/p>\n<p><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/perlinnoise.png\" rel=\"attachment wp-att-1265\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1265\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/perlinnoise.png\" alt=\"perlinnoise\" width=\"702\" height=\"250\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/perlinnoise.png 702w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/perlinnoise-300x107.png 300w\" sizes=\"auto, (max-width: 702px) 100vw, 702px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">Read more <a href=\"https:\/\/en.wikipedia.org\/wiki\/Perlin_noise\" target=\"_blank\">here<\/a><\/p>\n<p style=\"text-align: left;\">Yeah?\u00a0It&#8217;s basically that except not using regular sine-waves, but instead adding together interpolated random noise &#8211;\u00a0for every iteration the frequency of the noise goes up and the amount it contributes goes down.\u00a0When using Perlin Noise\u00a0to generate your noise values, the result of cumulative additions (each time doubling the frequency and halving the intensity) is\u00a0that classic\u00a0<em>turbulence<\/em> look which is so synonymous with Perlin Noise that we often call the texture <em>itself<\/em> Perlin Noise:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/clouds.png\" rel=\"attachment wp-att-1294\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1294\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/clouds.png\" alt=\"clouds\" width=\"300\" height=\"300\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/clouds.png 300w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/clouds-150x150.png 150w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p style=\"text-align: center;\">(Okay, this is Photoshop&#8217;s Cloud Filter. But it&#8217;s basically the same and, for all I know, might actually be coded using Perlin Noise)<\/p>\n<p style=\"text-align: left;\">Anyway, I bring this up not because of any of this\u00a0specifically, but because the principle it operates on (add together lots of things to build up interesting structured noise) is the principle my landscape generators work on. This principle can generate you really interesting landscapes irrespective of what it is you&#8217;re using to add together to produce your final result. So your source could be an unstructured random mess but the act of adding lots of it together &#8211; each time the input contributing less than the previous iteration &#8211; can produce ordered structure.<\/p>\n<p style=\"text-align: left;\">So for my landscape, what was my input? Well, I just repeatedly added\u00a0sine-wave strips (where each strip&#8217;s orientation &#8211; either horizontal or vertical &#8211; and its position, thickness, amplitude, and frequency were random). So the first iteration would look like this, for example:<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land1.png\" rel=\"attachment wp-att-1270\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1270\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land1.png\" alt=\"land1\" width=\"769\" height=\"274\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land1.png 769w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land1-300x107.png 300w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land1-768x274.png 768w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">And iteration two, could look like this:<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land2.png\" rel=\"attachment wp-att-1271\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1271\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land2.png\" alt=\"land2\" width=\"769\" height=\"274\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land2.png 769w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land2-300x107.png 300w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land2-768x274.png 768w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Keep going, then render it with landscapey colours and you end up with something like my landscape above. It&#8217;s\u00a0dead simple and you can use absolutely anything for your iterative additions &#8211; sine-wave strips, filled circles, filled squares, various pictures of cows &#8211; anything. Because <em>anything<\/em> added together sufficiently, will eventually produce something which looks like structured noise &#8211; which makes playing with your inputs kind of fun \ud83d\ude42<\/p>\n<p style=\"text-align: left;\">So &#8211; now knowing that my landscape is just lots and lots of sine-strips, looking at it again it&#8217;s really really <em>really<\/em> flupping obvious:<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land3.png\" rel=\"attachment wp-att-1273\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1273\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land3.png\" alt=\"land3\" width=\"700\" height=\"350\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land3.png 800w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land3-300x150.png 300w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/land3-768x384.png 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Here&#8217;s a landscape\u00a0where I used filled circles (with random positions, radii, and strength &#8211; where the strength also diminishes with each iteration), where the circles were filled like a crater such that in cross-section they&#8217;d look sorta like this:<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/circlecrosssection.png\" rel=\"attachment wp-att-1304\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1304\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/circlecrosssection.png\" alt=\"circlecrosssection\" width=\"299\" height=\"82\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/circlecrosssection.png 659w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/circlecrosssection-300x82.png 300w\" sizes=\"auto, (max-width: 299px) 100vw, 299px\" \/><\/a><\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landcircles.png\" rel=\"attachment wp-att-1298\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1298\" src=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landcircles.png\" alt=\"landcircles\" width=\"700\" height=\"350\" srcset=\"https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landcircles.png 800w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landcircles-300x150.png 300w, https:\/\/theindiestone.com\/binky\/wp-content\/uploads\/landcircles-768x384.png 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Notice the crater in the central island \ud83d\ude42<\/p>\n<p style=\"text-align: left;\">So anyway. It&#8217;s not rocket science, nor the world&#8217;s most amazing way to generate super-realistic landscapes. But it&#8217;s fun, so I thought I&#8217;d share \ud83d\ude42<\/p>\n<p style=\"text-align: left;\"><strong>edit<\/strong>: This is what I love most about playing with this sort of stuff.\u00a0<em>How<\/em> something actually works isn&#8217;t in the least bit important, all that matters is whether the results are close to what you want. I love it when the underlying nuts and bolts are stupidly simple.\u00a0While I don&#8217;t claim to have invented anything original with this approach, what\u00a0<em>lead<\/em> me to\u00a0this style of height\u00a0generation was thinking about landscapes in terms of plate structure. I\u00a0considered trying to simulate plate tectonics (crudely) but then decided that it wasn&#8217;t really important <em>how<\/em> I got these sorts of structures only that I got them. So the sine-wave wibbles were\u00a0the first toe-dip into this kind of thing. Instead of using smooth noise, using a pattern with a sharp cut-off (you&#8217;re either in the sine-wave ripple (and therefore adding a bit), or you&#8217;re not &#8211; there&#8217;s no interpolation) could yield\u00a0some interesting features &#8211; a curve of a bay where around that curve you may get some little atolls, or dramatic cliff edges. These little features did somewhat end up in the results &#8211; close enough, at least, to be fairly satisfying.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Man I love playing around with landscape generators, it&#8217;s the most therapeutic thing ever. I recommend it. It&#8217;s the weekend tomorrow, what are you waiting for? Anyway, in a break from whinging about games and the games industry I thought I&#8217;d write a few words about some daft experiments I was doing with landscapes&#8230; uhhh&#8230;&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[],"class_list":["post-1262","post","type-post","status-publish","format-standard","hentry","category-stuff"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p326tq-km","_links":{"self":[{"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/posts\/1262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/comments?post=1262"}],"version-history":[{"count":33,"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/posts\/1262\/revisions"}],"predecessor-version":[{"id":1306,"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/posts\/1262\/revisions\/1306"}],"wp:attachment":[{"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/media?parent=1262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/categories?post=1262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theindiestone.com\/binky\/wp-json\/wp\/v2\/tags?post=1262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}