{"id":842,"date":"2010-12-14T19:17:34","date_gmt":"2010-12-14T09:17:34","guid":{"rendered":"http:\/\/brnz.org\/hbr\/?p=842"},"modified":"2010-12-14T19:36:43","modified_gmt":"2010-12-14T09:36:43","slug":"diamond-square-%e2%80%94-tiled-rendering-and-space","status":"publish","type":"post","link":"https:\/\/brnz.org\/hbr\/?p=842","title":{"rendered":"Diamond-Square \u2014 Tiled rendering and space"},"content":{"rendered":"<p>I started with the assumption of 128\u00d7128 pixel diamond-square tiles &#8212; they&#8217;re a power of two big (which makes them simpler to calculate), 512 bytes wide, 128 lines tall and 64KB in total size, which means two will fit in local store.<\/p>\n<p>So, questions: What points outside this area are required to calculate all the points within?\u00a0 How much space is required to render one of these tiles?<\/p>\n<p><img loading=\"lazy\" class=\"alignright size-full wp-image-845\" title=\"3x3x5\" src=\"https:\/\/brnz.org\/hbr\/wp-content\/uploads\/2010\/12\/3x3x5.png\" alt=\"\" width=\"131\" height=\"131\" \/>(There&#8217;s a smaller example pictured, again with a different colour for each iteration of the calculation)<\/p>\n<p>If the tile is to be 4\u00d74, the centre area is 5\u00d75 with overlap between tiles.\u00a0 Additionally, to calculate a 4\u00d74 tile, fully calculating a 7\u00d77 area is required, not counting the sparsely calculated pixels around the outside.<\/p>\n<p>Scaling this up to 128\u00d7128 pixel tiles and it should be clear that at least 131\u00d7131 pixel area is required, not counting those extras around the outside.\u00a0 How to deal with those?<\/p>\n<p>One thing that is clear is that they&#8217;re sparsely filled, and that calculated values only appear on certain lines.\u00a0 In fact, the number of lines required around the outside of a tile is (1+log<sub>2<\/sub><em>n<\/em>) where <em>n<\/em> is the tile width.\u00a0 For the 4\u00d74 tile pictured, three extra lines are needed on each side of the tile.\u00a0 For a tile 128 lines across, 8 extra lines are needed.<\/p>\n<p>So all the values to calculate a given tile can be stored in in (129+8+8)\u00d7(129+8+8) = 145\u00d7145 pixels.\u00a0 Rounding up to get quadword aligned storage gives a total of 148\u00d7145\u00d74 bytes &#8212; 85,840 <img loading=\"lazy\" class=\"alignright size-full wp-image-875\" title=\"3x3x5p\" src=\"https:\/\/brnz.org\/hbr\/wp-content\/uploads\/2010\/12\/3x3x5p1.png\" alt=\"\" width=\"111\" height=\"111\" \/>bytes per tile.\u00a0 171,680 bytes is a big chunk of local store, but it&#8217;s probably better to be using it for <em>something<\/em>&#8230;<\/p>\n<p>Based on that, it&#8217;s not particularly difficult to generate the data for a tile.\u00a0 Start the tile with its starting values (more on those in another post) in the corners of the squares (the blue ones in the picture), and then calculate the remaining points.\u00a0 There&#8217;s some special cases required for each of the sides, but it&#8217;s nothing particularly tricky, just keeping track of row\/column indexes for particular iterations.<\/p>\n<p>The outer points make up only a very small percentage of the total points that need to be calculated &#8212; more than 50% of the points are calculated in the last diamond and square iterations, and due to the proximity and alignment of the points accessed, their calculation can be usefully optimised.\u00a0 (I might write a post about that sometime&#8230;)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I started with the assumption of 128\u00d7128 pixel diamond-square tiles &#8212; they&#8217;re a power of two big (which makes them simpler to calculate), 512 bytes wide, 128 lines tall and 64KB in total size, which means two will fit in local store. So, questions: What points outside this area are required to calculate all the &hellip; <a href=\"https:\/\/brnz.org\/hbr\/?p=842\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Diamond-Square \u2014 Tiled rendering and space&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,26],"tags":[36,40],"_links":{"self":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/842"}],"collection":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=842"}],"version-history":[{"count":12,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/842\/revisions"}],"predecessor-version":[{"id":904,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=\/wp\/v2\/posts\/842\/revisions\/904"}],"wp:attachment":[{"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=842"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brnz.org\/hbr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}