{"id":171,"date":"2006-02-15T17:44:12","date_gmt":"2006-02-15T22:44:12","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=171"},"modified":"2011-04-10T05:43:47","modified_gmt":"2011-04-10T10:43:47","slug":"terrain-part-8","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=171","title":{"rendered":"Terrain, Part 8"},"content":{"rendered":"<p>If you recall back in <a href=\"?p=146\">Part 6<\/a> I introduced shadowing, and then I did some tests on the terrain to see how it looks at various resolutions.    I&#8217;ve noticed that most of the problem with the lower resolutions is not that the hills look undefined or blocky, but that the lighting looks bad.  The light and dark side of hills get blurred, and shadows become big dark blobs.<\/p>\n<p><center><img src='http:\/\/www.shamusyoung.com\/twentysidedtale\/images\/terrain21.jpg'\/><br \/><em> Notice how the shadows are kind of vague blobs of darkness.  I&#8217;ve turned down the the resolution on the terrain, and the result was that the shadows became undefined. <\/em><\/center><\/p>\n<p><!--more--><br \/>\nBut keeping the high polygon count just to preserve the lighting just doesn&#8217;t make any sense.   Polygons are there to give the thing shape, and if you&#8217;re adding polygons just so you can have little areas of light and dark, you&#8217;re probably doing something wrong.  That&#8217;s a job for textures.<\/p>\n<p>You remember in Part 7 I added zone textures.  I can very easily add the lighting and shadows to these textures as well.  The results are very nice:<\/p>\n<p><center><img src='http:\/\/www.shamusyoung.com\/twentysidedtale\/images\/terrain22.jpg'\/><\/center><\/p>\n<p>Amazingly, this image and the previous are of the same scene from the same point of view, and they even <em>have  exactly the same polygon count<\/em>.  This is a 2 million polygon terrain that has been reduced to a mere 12,000 polygons!  Back in part 7 I concluded polygon counts this low were unworkable because the terrain looked too simple.  This sidesteps the problem by drawing a texture with lots of subtle lighting and shadowing effects.  Nothing is left out.  So what we have are 12,000 polygons being drawn with a texture generated with 2 million polygons worth of detail.   All of the smaller hills you see are just shading: the surface itself is totally flat at this distance.  As you get closer, polygons will be added that will make those areas more detailed.  Here is the same view again, only showing the polygons that make up the terrain:<\/p>\n<p><center><img src='http:\/\/www.shamusyoung.com\/twentysidedtale\/images\/terrain23.jpg'\/><br \/><em>The circled area is a large quad (a pair of triangles).  See how that area still has little shadows and lighting changes?  Those would have been turned into a big &#8216;ol hazy dark blob using the old system. <\/em><\/center><\/p>\n<p>With this feature in place, I can afford to keep the polygon count low. Also, remember how I was crying about sending vertex data back in <a href=\"?p=144\">part 4<\/a>?  Well, now I don&#8217;t have to send the lighting data with each vertex.  As far As OpenGL is concerened, I&#8217;m drawing a flat white unlit terrain with a texture on it.  This is about the fastest way you <em>can<\/em> draw textured polygons.  <\/p>\n<p>Let&#8217;s look at another before and after:<\/p>\n<p><center><img src='http:\/\/www.shamusyoung.com\/twentysidedtale\/images\/terrain25.jpg'\/><\/center><br \/>\n<center><img src='http:\/\/www.shamusyoung.com\/twentysidedtale\/images\/terrain26.jpg'\/><\/center><\/p>\n<p>But of course, as <a href=\"http:\/\/kaedrin.com\/weblog\/\">Mark<\/a> would tell you, <a href=\"http:\/\/kaedrin.com\/weblog\/archive\/001020.html\">we don&#8217;t so much solve problems as we trade one set of problems for another with the hope that the new set of problems is more favorable than the old<\/a>.  The drawback is this:  The lighting goes on the texture, so if I change the lighting (like, sunset, sunrise, etc) it will have no effect whatsoever on the terrain unless I rebuild all of the terrain textures.  However, these improvements are so great that I intend to keep them, even if it means I have to give up on smooth day\/night changes.<\/p>\n<p><center><img src='http:\/\/www.shamusyoung.com\/twentysidedtale\/images\/terrain24.jpg'\/><br \/><em>Here is a view of the same scene, only from ground level. Just a few years ago this would have been passable as a first-person view, although the ground looks a little blurry by today&#8217;s standards.  Still, this looks very nice.  Makes me want to replace the &#8220;fly around&#8221; style movement with standard first-person movement so I can run around and jump on these hills.  :)<\/em><\/center> <\/p>\n<p>My test machine is a 1Ghz with 512MB of memory.  My video card is a GeForce 5200.  So far, the engine runs nice and smooth on this system.  I think we&#8217;re nearing the end of the project.  There are only a few items left on my goal list at this point.   <\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you recall back in Part 6 I introduced shadowing, and then I did some tests on the terrain to see how it looks at various resolutions. I&#8217;ve noticed that most of the problem with the lower resolutions is not that the hills look undefined or blocky, but that the lighting looks bad. The light [&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-171","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\/171","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=171"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}