{"id":22825,"date":"2014-05-07T15:16:20","date_gmt":"2014-05-07T20:16:20","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=22825"},"modified":"2014-05-09T09:33:08","modified_gmt":"2014-05-09T14:33:08","slug":"frontier-rebooted-part-1-back-to-school","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=22825","title":{"rendered":"Frontier Rebooted Part 1: Back to School"},"content":{"rendered":"<p><a href=\"?p=21405\">Good Robot<\/a> has been on my mind lately. I keep coming back to the fact that I put a few months into it and didn&#8217;t finish it. But then I remember that on top of <a href=\"?p=21973\" title=\"Project Good Robot #30: Interesting-ness\">gameplay concerns<\/a> I&#8217;ve also got a bunch of annoying technology problems to worry about and I lose my enthusiasm.<\/p>\n<p>The central part of the technology problems come from [my usage of] GLSL &#8211; the OpenGL shader language. The rest of my code &#8211; talking to the filesystem, input devices, AI, and gameplay &#8211; is basically solid, but the shaders are a mess. On one machine robots would strobe, randomly rendering or not from one frame to the next. Another tester reported that walls didn&#8217;t render. Another had the robots and walls render fine, but powerups were invisible. Another person had strange slowdowns that should not have been happening on their given hardware. <\/p>\n<p>The center of the problem is that I&#8217;m not very knowledgeable regarding GLSL. I&#8217;ve only gotten around to messing with it in the last couple of years, and I&#8217;ve only learned enough to accomplish the few simple things I need to do. This leaves great big blind spot in my knowledge where problems can hide. It creates situations where I can do something the wrong way and have it work on my machine, and malfunction a dozen different ways elsewhere. <\/p>\n<p>But to correct this problem I have to deal with another one: <!--more-->The GLSL resources are an absolute mess. The language has undergone sweeping changes at least twice since its inception. Programs that were once valid are now wrong, which means nearly all of the basic &#8220;hello world&#8221; tutorials are now broken to the point where they won&#8217;t even compile. The docs are filled with side-notes about what&#8217;s &#8220;new&#8221; in a version people stopped using five years ago. The simple stuff is out of date, and the advanced stuff is written with the assumption that you already know what you&#8217;re doing and you just need a few pointers on how things have changed. It&#8217;s amazing how many pages of documentation fail to explain how things actually work, but instead explain how things differ from how they <em>used to<\/em> work. It&#8217;s like giving someone directions based on scenery that no longer exists. &#8220;Drive until you get to the place that used to be a drugstore, turn left onto old main street, and turn left when you see the empty lot where the recycling center used to be.&#8221; You&#8217;ll probably be be able to find the place eventually, but those layers of ambiguity and uncertainty are a major hindrance.<\/p>\n<p>Further exacerbating the problem is that the updated and proper way of doing things is a lot more complex. The entire OpenGL matrix stack has been deprecated. In plain language, this means that the built-in systems for managing tables of numbers and performing the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Camera_matrix\">spatial transformations<\/a> needed to take 3D scenery and draw it on a 2D screen are no longer supposed to be used. You&#8217;re supposed to write all of those systems yourself. Now, there are a lot of good reasons for that, but it&#8217;s also a massive undertaking when you&#8217;re just trying to get a handle on the basics. I&#8217;m sure there are open-source tools to do the job, but <a href=\"?p=9557\" title=\"Object-Disoriented Programming\">integrating those is a pain<\/a> and it adds huge levels of complexity to what should otherwise be simple and straightforward learning exercise. (I already have my own matrix code, although it&#8217;s not nearly as well-developed as it could be.) When you get a blank screen you have to wonder: &#8220;Am I still not doing this shader properly, or am I mis-applying this new matrix system?&#8221; You can fall back to using the old matrix stack, but only if you find the directive to do so and only if you can intuit how it works. (It&#8217;s not well documented and I have yet to see it appear in example code.) <\/p>\n<p>If you post some short shader code and ask for help you&#8217;re likely to get immediate dismissal: &#8220;The old matrix stack is deprecated! Don&#8217;t use it!&#8221; Which is like asking someone why your internal combustion engine doesn&#8217;t work and having them give you a hard time because it doesn&#8217;t have a gearbox, a catalytic converter, or a starter motor. <\/p>\n<p>As if this wasn&#8217;t enough of an adventure, the OpenGL pages are somewhat capricious. In the process of working on this project the official docs would vanish for hours or days. You can download the docs as a PDF, but PDFs generally suck and Google can&#8217;t help you find what you&#8217;re looking for if they&#8217;re on your hard drive. And of course snarky <acronym title=\"Read The F**king Manual\">RTFM<\/acronym> forum posts all become <a href=\"?p=21365\" title=\"How to Forum\">that much less helpful as fallback documentation<\/a>, since now they&#8217;re just insults with dead links. <\/p>\n<p>Basically: Learning GLSL is is tough hill to climb, it keeps getting steeper, and the topography keeps changing without anyone updating the maps. The people who reached the top years ago don&#8217;t really have a concept of how convoluted the road has gotten and so they often give unhelpful advice. <\/p>\n<p>But maybe I&#8217;ll have an easier time getting back to Good Robot if I force myself to do something sophisticated with shaders. Right now in Good Robot I&#8217;m just using them for simple stuff: I&#8217;m drawing basic squares and using the GPU (the graphics card, basically) to rotate them, scale them, and adjust the texture mapping so they draw from the proper section of the <a href=\"?p=20671\" title=\"Project Good Robot Part 3: Killer Robots\">sprite sheet<\/a>.  That&#8217;s silly easy. My hope is that by doing a bunch of stuff that&#8217;s far more complex, I&#8217;ll actually get some depth to my GLSL knowledge and be able to spot the mistakes I&#8217;m making in Good Robot.<\/p>\n<p>Goals:<\/p>\n<ol>\n<li>Aside from the shader work, I want to be really comfortable with what I&#8217;m doing. Which means doing something I&#8217;ve done before. Which means heightmap-based terrain. That&#8217;s easy, it&#8217;s familiar, and it looks interesting. (Enough.)<\/li>\n<li>I want to do something that lets me dump a bunch of difficult processing onto the graphics card. Since we&#8217;re working with terrain, I figure erosion is a good choice. I&#8217;ll make some real-time erosion code and have it run on the GPU.\n<li>I want to explore how difficult it is to support Oculus Rift levels of performance. Most games run at 30fps.  If the scene gets crowded or if the player stumbles into some scripted event, it&#8217;s generally acceptable (or tolerated) if the framerate dips down to 20 or so for a few seconds. But if you&#8217;re programming for VR, you need incredible performance. You need 60 frames per second. Worse, you need to render everything twice &#8211; one for each eye. If that&#8217;s not hard enough, it&#8217;s extremely uncomfortable to miss frames, so you can&#8217;t ever dip below 60fps unless you want to risk making people sick.  So now the program has to render twice as much, twice as fast, with no margin for error.\n<p>I can&#8217;t afford (or justify) getting a Rift dev kit right now, but it should be simple to set up a test to see if my program can keep up with the Rift performance demands. <\/li>\n<li>I&#8217;m going to stop being so stubborn and just use the same dang coordinate system everyone else uses. More on this in another post.\n<\/ol>\n<p>So those are our goals. I&#8217;m calling this &#8220;Frontier Rebooted&#8221; just because I&#8217;m re-hashing a lot of the ideas from Project Frontier, although the code is going to be all new. We&#8217;re going to have hills and water and grass and trees like before, but they&#8217;ll all be made using new techniques with shaders.<\/p>\n<p>Step one: Grab the latest version of my various 3D tools (which come from the Good Robot codebase) and drop them into a new project. I set up an empty scene with a one-meter panel drawn at the origin.  Just to make sure I&#8217;ve got the axis all pointing the right way, I build a literal axis arrow at the world origin. Red is X, Y is green, blue is Z. <\/p>\n<p><table width='600'  cellpadding='0' cellspacing='0' border='0' align='center'><tr><td><img src='https:\/\/www.shamusyoung.com\/twentysidedtale\/images\/freboot1.jpg' class='insetimage' width='600' alt='freboot1.jpg' title='freboot1.jpg'\/><\/td><\/tr><\/table><\/p>\n<p>Was that worth reading 1,500 words? I hope it was worth reading 1,500 words to see that. Next time we&#8217;ll actually accomplish something.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Good Robot has been on my mind lately. I keep coming back to the fact that I put a few months into it and didn&#8217;t finish it. But then I remember that on top of gameplay concerns I&#8217;ve also got a bunch of annoying technology problems to worry about and I lose my enthusiasm. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[387,388],"class_list":["post-22825","post","type-post","status-publish","format-standard","hentry","category-programming","tag-glsl","tag-opengl"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/22825","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=22825"}],"version-history":[{"count":0,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/22825\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}