{"id":12113,"date":"2011-06-27T06:39:28","date_gmt":"2011-06-27T11:39:28","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=12113"},"modified":"2011-06-27T09:31:25","modified_gmt":"2011-06-27T14:31:25","slug":"project-frontier-9-happy-little-trees","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=12113","title":{"rendered":"Project Frontier #9: Happy Little Trees"},"content":{"rendered":"<p><table   class=\"\" cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier9_bob_ross.jpg' class='insetimage'   alt='frontier9_bob_ross.jpg' title='frontier9_bob_ross.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>With apologies to the late <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bob_Ross\">Bob Ross<\/a>.  His work has been widely <a href=\"http:\/\/emptyeasel.com\/2007\/01\/29\/helpful-or-harmful-the-bob-ross-method-of-painting\/\">criticized<\/a>, but this project shares a certain kinship with his work:  We&#8217;re not trying to make Great Art, we&#8217;re trying to make &#8220;Pretty Good Art&#8221; in 10% of the time.  I imagine that if paintings could somehow cost as much to produce as videogames, the &#8220;Bob Ross method&#8221; would be the only way to get anything done. <\/p>\n<p>Hopefully my tree-making skills are better than my photoshopping skills.<\/p>\n<p><!--more-->Minecraft has proven that a large number of people are capable of accepting a stack of one-meter cubes as a tree, both visually and as a gameplay conceit.  Perhaps even a <em>majority<\/em> of the people are capable of embracing this sort of abstraction. I imagine there are people who are not like this.  There are those who look at Minecraft and scoff, who refuse to enter a world of such low fidelity.  I am not interested in attempting to entertain those people.  I don&#8217;t think I can.  It&#8217;s too expensive. I&#8217;ll leave them in the hands of id Software and Crytek.  <\/p>\n<p>For those who <em>can<\/em> look at a pile of blocks and see the the emergent cubic beauty, I hope to create something a bit different. Not cubic, but&#8230; chunky. Low poly, colorful, vibrant, and varied. Somewhere between Minecraft and World of Warcraft in its first years.<\/p>\n<p>Now, there are a LOT of techniques for making trees out there.  Check out <a href=\"http:\/\/procworld.blogspot.com\/2011\/05\/mango-sequoia-baobab.html\">this one<\/a>, which does complex maths on&#8230; geeze.  I duuno.  There&#8217;s a lot going on there.  The point is, if those trees are under 10k polygons I&#8217;ll eat my mouse. Still, there is a lot to think about in that post.  (And some of the other things people have linked. Thanks.) <\/p>\n<p>I actually wrote a tree generator way back in the last few months of 2000.  Like a lot of the experimental work I did for my employer at the time, it was met with polite admiration, followed by indifference. &#8220;That&#8217;s really cool, Shamus.  Seriously. Nice work there. But it is completely useless to us. Thanks anyway, though.&#8221;  <\/p>\n<p>The source for it is long gone, but I still have most of the concepts in my head.  That tree builder accepted three pieces of information:<\/p>\n<ol>\n<li><strong>Properties:<\/strong>  This was a huge list of fiddly little details like: How tall is the (fully grown) tree overall? How far between the roots and the lowest branch?  How many branches overall? How straight is the trunk?  How wide is it? What colors are the bark, and the leaves?  How much do the branches lift or sag from their origin?\n<p>And so on.  This list of properties could be thought of as the template for the species as a whole.\n<\/li>\n<li><strong>Seed:<\/strong> Not &#8220;seed&#8221; as in &#8220;plant seed&#8221; but &#8220;seed&#8221; as in &#8220;random number seed&#8221;.  (Although the two concepts overlapped here in a way that greatly amused me.)  Basically, change the seed and you&#8217;ll change a bunch of numbers like the shape of the bending and the branch positioning.  Create two trees with the same properties but with different seeds, and they&#8217;ll look like two different trees of the same species.\n<\/li>\n<li><strong>Age:<\/strong>  On a scale of 0.0 to 1.0, how close is the tree to full grown?  You could manipulate this number to smoothly grow a plant from sprout to full-grown.  Very slick.\n<\/li>\n<\/ol>\n<p>Now, the &#8220;smooth growing&#8221; thing added a lot of complexity.  I don&#8217;t think I&#8217;m going to need that here, so I&#8217;m going to leave that out for now. <\/p>\n<p>My polygon budget in 2000 was somewhere between 50 and 100 polygons.  Now, given the massive increase in computing power since 2000, I&#8217;m sure trees today are many times heavier than that.  I wouldn&#8217;t be surprised to find out the average Crysis tree clocks in at 1,000 triangles.  <\/p>\n<p>However, I need a <em>lot<\/em> of trees. Most games are focused on delivering a highly polished, high-detail scene of very limited size.  I&#8217;m aiming at lower platforms AND trying to extend the view distance at the same time, which is like trying to make a car that burns less fuel <strong>and<\/strong> goes faster.  This is usually an either \/ or arrangement. If you&#8217;re making gains in both of these areas, odds are you&#8217;re making big sacrifices elsewhere.<\/p>\n<p>The thing about view distance is that it gets ridiculously expensive to make even small increases, because it&#8217;s based on area.  If you have a view distance of 100 meters, that means you actually need a 200&#215;200 meter area of viewable stuff, with the player at the center.  (Unless you can persuade the player to never turn around.  Let me know how that works out.) That&#8217;s 40,000 square meters.  Now let&#8217;s say you want to increase your view distance to 150 meters.  That means you need an area of 300&#215;300 meters, for a grand total of 90,000 square meters. A 50% increase in view distance resulted in a <strong>125%<\/strong> increase in resources.  I don&#8217;t care how much computing horsepower you throw at a problem, sooner or later those numbers will kill you. <\/p>\n<p>While a lot of games sprinkle a few trees at the edges of the map and call it a day, I might have hundreds of them in view at once, so I can&#8217;t afford to spend too much on them.  I think 200-300 polygons is a good starting point. <\/p>\n<p>So my trees are dead simple:  When a new map is generated, it creates a selection of trees for various climates.   It actually makes a table of them.  One axis of the table is for moisture, the other for temperature.  So, once the climate is decided for a region, it looks up in the table for the most appropriate tree. Here is an example map:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier9_1.jpg' class='insetimage' width='512' alt='The grey circles are mountains, the blue circles are &#8220;lakes&#8221;.  The light squares are plains. I&#8217;ll be showing these off in a later post.  For now, just note the climate.  The coloring tells us that the arctic climate is to the south, and the tropic climate is to the north.  The land gets drier (more brown and yellow) as you go east, which means the wind is from the west.' title='The grey circles are mountains, the blue circles are &#8220;lakes&#8221;.  The light squares are plains. I&#8217;ll be showing these off in a later post.  For now, just note the climate.  The coloring tells us that the arctic climate is to the south, and the tropic climate is to the north.  The land gets drier (more brown and yellow) as you go east, which means the wind is from the west.'\/><\/td><\/tr><tr><td class='insetcaption'>The grey circles are mountains, the blue circles are &#8220;lakes&#8221;.  The light squares are plains. I&#8217;ll be showing these off in a later post.  For now, just note the climate.  The coloring tells us that the arctic climate is to the south, and the tropic climate is to the north.  The land gets drier (more brown and yellow) as you go east, which means the wind is from the west.<\/td><\/tr><\/table> <\/p>\n<p>For development, I&#8217;m using a 5&#215;5 table of trees.  (5 different moisture settings, times 5 different temperature settings, for a total of 25 different trees.  Er, actually, 24. &#8220;Tree zero&#8221; is for areas with minimum moisture and minimum temperature, and means &#8220;no tree at all&#8221;.  We can argu about whether or not that should count as a &#8220;type of tree&#8221;, but that&#8217;s a problem for a philosopher, not a programmer.)<\/p>\n<p>Here I&#8217;ve given each tree a random unique color.  Areas with the same color will have the same tree type:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier9_2.jpg' class='insetimage' width='512' alt='frontier9_2.jpg' title='frontier9_2.jpg'\/><\/td><\/tr><\/table> <\/p>\n<p>If I up the tree grid to 10&#215;10, I&#8217;ll have 100 species of trees.  It end up looking like this:<\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier9_3.jpg' class='insetimage' width='512' alt='frontier9_3.jpg' title='frontier9_3.jpg'\/><\/td><\/tr><\/table> <\/p>\n<p>I like the complex shapes I&#8217;m seeing here.  That&#8217;s not random.  That&#8217;s emergent, based on the cheapo climate simulation I outlined <a href=\"?p=11923\">before<\/a>.  <\/p>\n<p>You might be worried that these hard lines will look odd, &#8220;You mean you&#8217;re walking along and suddenly you come to an invisible line and all the trees are different?&#8221;  But the trees use the same scattering code that I used on the grass back in <a href=\"?p=11893\">part 3<\/a>, so the change is not instant.  It&#8217;s staggered enough to hide the boundaries, at least.  <\/p>\n<p>The trees draw their foliage color from the same palette as the grass.  So, tropical trees will be deep greens, and desert trees will be pale greens and yellows. Trees in cold climates will have a bit of blue in them.  Similarly, the bark color draws from the dirt palette.  Note that I&#8217;m not forcing the tress to always match the grass.  I&#8217;m just drawing from the same palette. This means trees will still stand out, but the two together will still look like a good thematic match. <\/p>\n<p><table width='512'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><a href='images\/frontier9_4_big.jpg'><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/frontier9_4.jpg' class='insetimage' width='512' alt='frontier9_4.jpg' title='frontier9_4.jpg'\/><\/a><\/td><\/tr><\/table> <\/p>\n<p>Next time I&#8217;ll actually get down to talking about how the trees are constructed. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>With apologies to the late Bob Ross. His work has been widely criticized, but this project shares a certain kinship with his work: We&#8217;re not trying to make Great Art, we&#8217;re trying to make &#8220;Pretty Good Art&#8221; in 10% of the time. I imagine that if paintings could somehow cost as much to produce as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-12113","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/12113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12113"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/12113\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}