{"id":537,"date":"2006-08-07T11:07:57","date_gmt":"2006-08-07T16:07:57","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=537"},"modified":"2009-08-06T14:20:04","modified_gmt":"2009-08-06T18:20:04","slug":"the-procedural-world-part-1","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=537","title":{"rendered":"The Procedural World, Part 1"},"content":{"rendered":"<p>Via <a href=\"http:\/\/www.cineris.org\/blog\/2006\/08\/03\/kkrieger\/\">Augury<\/a> I found out about <a href=\"http:\/\/www.theprodukkt.com\/kkrieger\">.kkrieger<\/a>, a first-person shooter game which is only 97k in size. That means the <em>entire<\/em> game, sound effects, graphics, code, and everything, all within 97k. That is <em>preposterously<\/em> small, yet the game still looks quite good and at first glance it can pass for a cutting-edge shooter.<\/p>\n<p><center><img decoding=\"async\" src=\"images\/krieger4.jpg\" alt=\".kkrieger Screenshot\"\/><\/center><\/p>\n<p><!--more--><br \/>\nRemember these things?<\/p>\n<p><center><img decoding=\"async\" src=\"images\/floppy.jpg\"\/><\/center><\/p>\n<p>Yeah.  That disk holds about 370k, which means this game could fit on this disk <em>three times<\/em> and still have &#8220;plenty&#8221; of space left over.  Unreal Tournament 2004 comes on 6 CDs.  If it came on floppies, you would need a truck loaded with about 10,000 floppy discs.  To put it another way, Unreal Tournament is around <em>Forty Thousand times larger than .kkreiger<\/em>.<\/p>\n<p><center><img decoding=\"async\" src=\"images\/krieger3.jpg\" alt=\".kkrieger Screenshot\"\/><\/center><\/p>\n<p>So this game is small. Ridiculously small.  But what makes games like UT 2004 so big in the first place? Take a look at the gun you see in the screenshot.  <\/p>\n<div class=dmnotes><em>I&#8217;m going to show how I come up with how big the gun would be.  Feel free to skip this bit if you&#8217;d rather cut to the chase.  <\/em><\/p>\n<p>So how big would that gun be if we had to store it on disk?  <\/p>\n<p>Let&#8217;s assume that it&#8217;s not quite as detailed as it looks.  (I think bump-mapping is adding a lot of the surface detail.)  Let&#8217;s say the gun is 100 polygons and 150 verticies. The weapons in today&#8217;s games are much more detailed, but let&#8217;s assume we&#8217;re being frugal: <\/p>\n<p>Each vertex needs at minimum 3 spatial values (x, y, and z), two texture-mapping values, and three normal vector values (for lighting).  That&#8217;s a total of 8 values per vertex. Normally each of those values is 4 bytes, so we need 4 bytes x 8 values x 150 verticies = 4,800 bytes.  Each polygon is a triangle which connects 3 vertices.  So assuming each index is 2 bytes we need 2 bytes x 3 indexes x 100 polygons = 600 bytes.  The texture is made up of two images: the color map and the bump-map.  For a texture on something that close to the camera, you probably can&#8217;t get away with anything less than 128 x 128 pixels.  Each pixel is three values, red, green, and blue.  (for the bump map, these color values are converted into spatial values).   Each value is one byte.  1 byte per value x 3 values per pixel x 128 pixels wide x 128 pixels high x 2 images = 98,304 bytes.<\/p>\n<p>So even if we are very conservative, our total size for the gun is 4,800 + 600 + 98,304 = 103,704 bytes, or 101k!<\/p><\/div>\n<p>So the gun you see there in the screenshot would be about 101k, which is bigger than the entire kkreiger program! And yet within the 97k of the program it has not just one gun but several, plus enemies to fight, rooms to fight in, and music to listen to while you&#8217;re fighting.  All of that plus the code that drives the game fits within a space smaller than the size of just one weapon!<\/p>\n<p><center><img decoding=\"async\" src=\"images\/krieger2.jpg\" alt=\".kkrieger Screenshot\"\/><\/center><\/p>\n<p>As the original article points out, this is done using procedural methods.  Instead of storing the 101k gun and its textures, just come up with some code that can <em>generate<\/em> a gun on the fly.  This takes away a great deal of artist freedom, as you can no longer design a gun just the way you want, you can only control the parameters used to generate it.  Remember <a href=\"http:\/\/www.wordsmith.org\/~anu\/java\/spirograph.html\">spirograph<\/a>?  It&#8217;s a bit like that.  You can&#8217;t just draw anything you want, but you CAN draw pleasing shapes and patterns with a great deal of precision.  In the applet I just linked, you see that I can re-create anything you draw as long as you send me the exact settings you used.  If you want to show me an image you made, instead of sending me a screenshot, you could send the 3 numbers you chose and I would be able to re-create what you made by simply plugging in those same values.  <\/p>\n<p>So, instead of storing a 101k gun with your program, you can write a gun-generating spirograph, find some numbers that look good, and then plug those numbers in when the program runs.  That&#8217;s the tradeoff:  This game has a long loading time, because it&#8217;s sitting there cranking numbers through the various generators, making guns and monsters and rooms.<\/p>\n<p>This is a fun demonstration of what can be done with procedural objects, although it has a lot of implications for the future of game development.  I&#8217;m not talking about saving hard drive space, though.  This sort of thing is far more useful for combating the growing cost of content creation, which I&#8217;ll leave for the next post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Via Augury I found out about .kkrieger, a first-person shooter game which is only 97k in size. That means the entire game, sound effects, graphics, code, and everything, all within 97k. That is preposterously small, yet the game still looks quite good and at first glance it can pass for a cutting-edge shooter.<\/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":[523],"class_list":["post-537","post","type-post","status-publish","format-standard","hentry","category-programming","tag-game-design"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/537","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=537"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/537\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}