<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>VectorStorm Blog</title>
	<atom:link href="http://www.vectorstorm.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vectorstorm.org</link>
	<description>Creating games, one brightly glowing line at a time.</description>
	<lastBuildDate>Wed, 16 May 2012 02:58:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Let&#8217;s talk about shadows</title>
		<link>http://www.vectorstorm.org/2012/05/15/lets-talk-about-shadows/</link>
		<comments>http://www.vectorstorm.org/2012/05/15/lets-talk-about-shadows/#comments</comments>
		<pubDate>Tue, 15 May 2012 10:16:13 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine Design]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2524</guid>
		<description><![CDATA[There are a lot of different ways to create shadows in video games. When I entered the game industry fifteen years ago, there were two standard ways to draw shadows:  blob shadows and stencil shadows.  (There was a third option as well:  light maps, as popularised by Quake 2.  But I&#8217;m not going to cover [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of different ways to create shadows in video games.</p>
<p>When I entered the game industry fifteen years ago, there were two standard ways to draw shadows:  blob shadows and stencil shadows.  (There was a third option as well:  light maps, as popularised by Quake 2.  But I&#8217;m not going to cover those since they were used for handling static lighting, not for real-time dynamic effects.)</p>
<h2><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/class-Projector-1.jpg"><img class="alignleft size-medium wp-image-2525" title="class-Projector-1" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/class-Projector-1-300x184.jpg" alt="" width="300" height="184" /></a>Blob Shadows</h2>
<p>Blob shadows are a very simple concept.  If we have a moving object that we want to have appear to cast a shadow, all we have to do is to draw a sprite on the ground beneath it.  This sprite was typically an indistinct, blurry oval, roughly matching the general size of the object it was &#8220;shadowing&#8221;.  Its texture is where the term &#8220;blob&#8221; came from.  In this shot, you can see a robot with a blob shadow.  (That blob shadow is substantially larger than I would ever make it, personally.  At this scale, it&#8217;s far too easy to tell that it&#8217;s just a simple sprite).</p>
<p>A tricky point about implementing blob shadows is making the shadow appear correctly over a ground surface;  making it draw on top of an undulating terrain is a surprisingly tricky problem.  It&#8217;s very easy to end up with a shadow sprite that clips through the ground or floats above it, or is visible through other objects between the shadow and the camera.  Since the shadow is basically just a big flat sprite, you can&#8217;t reliably cast the shadow onto an extremely bumpy surface, or onto another object.  You&#8217;re basically stuck with just a flat circle on a (more or less) flat ground.</p>
<p>Fifteen years ago, these were the usual way of putting dynamic shadows on movable objects in a game.  As games became more sophisticated, we started finding ways to disguise how simplistic these shadows were.  First by scaling the blob as the character animated (so as the character moved his leg forward, the circular shadow would stretch forward into an oval shape), and then by actually giving each character several different blob shadows, each projected down from a different part of the character&#8217;s body.  This made the shadow seem to vaguely move along as the character animated in a much better way than the simple scaling approach.  In <a href="http://en.wikipedia.org/wiki/Transformers_(2004_video_game)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Transformers_2004_video_game?referer=');">Transformers</a>, we gave each enemy robot (I seem to recall) four or five blob shadows, each anchored to a different part of the robot&#8217;s body.  When rendered, these separately circular blob shadows appeared to merge together into a single amorphous blob that moved in a way which didn&#8217;t draw the player&#8217;s attention as being circular and static.</p>
<p>This technique is still around and being used today in new games.  Just a few months ago I implemented it for use in an (unreleased) iPhone racing game, where we used vaguely car-shaped blob shadows under the cars.  With some very sophisticated maths to try to make the shadow mimic the car&#8217;s rotation in mid-air, and projecting down onto the race track surface according to an angled light source and angled track.  But fundamentally, if you ignore the fancy math for scaling and orienting it to the ground surface, it was still just a single blob shadow;  just a flat sprite with a pre-drawn texture on it.</p>
<p>I seriously considered using blob shadows for MMORPG Tycoon 2.  It certainly would have been faster to implement than what I&#8217;ve actually done.  But all the foliage in the game would have caused problems, since the shadows would have sorted underneath the foliage and been almost invisible in many situations.  (Even in modern games you occasionally see this problem, blob shadows vanishing under ground clutter)</p>
<h2>Stencil Shadows<a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/shadow_volume.jpg"><img class="alignleft size-medium wp-image-2526" title="shadow_volume" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/shadow_volume-300x223.jpg" alt="" width="300" height="223" /></a></h2>
<p>Also called &#8220;shadow volumes&#8221;, stencil shadows were the high-quality alternative to blob shadows.  They&#8217;re not used as much today as they used to be, but it&#8217;s still an interesting technique.</p>
<p>The basic idea of stencil shadows is to computationally find the silhouette of an object from the light&#8217;s point of view, and then extrude that silhouette through space.  This extruded object is the shadow cast by the object.</p>
<p>You then render this shadow object using a &#8220;stencil buffer&#8221;, and use the resulting stencil data to determine for each pixel in your screen image whether that pixel is inside or outside of the shadow volume.  I worked on several games which used this sort of system.  Usually this approach was only used for the shadow on the player character, or sometimes large boss enemies;  it was really too CPU intensive for us to be able to afford to do it for all characters on-screen.  And even when we did do it, we would use simplified versions of the visual models;  usually just a series of boxes or elipses roughly approximating the character&#8217;s shape.  Finding the silhouette and building renderable extruded geometry every frame was simply too expensive.</p>
<p>Another interesting point is that because of the way that stencil buffers work, the shadow was always hard-edged;  each pixel was either in-shadow or out-of-shadow, so shadows couldn&#8217;t feather or soften with distance.</p>
<p>To do this, you had to render the shadow volume with a special shader, and you had to render any object which might receive a shadow with another special shader.  This was always more expensive than normal rendering, so quite a lot of effort often went into determining precisely which triangles might receive a shadow, just for the purposes of figuring out which bits of world geometry needed to have the expensive shaders enabled.</p>
<p>Fun note:  The further your shadow geometry is extruded, the longer it takes to render, both because it touches more pixels, because it will more often have to go through the expensive geometry clipping process, and also because it potentially hits more world geometry, thus requiring more stuff to render using the expensive shadow-receiver shader.  But if your renderable geometry didn&#8217;t actually hit a shadow receiver (the ground underneath the character, for example, because the character was high up in the air from a jump or something and the shadow geometry wasn&#8217;t extruded far enough downward to reach the ground), then no shadow would be visible at all;  the shadow would appear to suddenly pop into being as soon as the shadow caster moved within range.  Most games tried to hide this pop-in by making the extruded shadow geometry be built like a spike;  smoothly scaling down into a single point &#8212; kind of the opposite of the shadow volume being extruded from the torus in the image above.  If you look at games from the early 90s, you&#8217;ll occasionally see games which do this;  you can tell because you&#8217;ll see that shadows get smaller as objects move away from their cast shadows, instead of getting larger.</p>
<p>To my knowledge, no modern games use stencil shadows any longer.  And that&#8217;s mostly because they&#8217;ve been completely replaced by the new favoured system(s): shadow maps, which are better in almost every way.</p>
<h2>Shadow Maps</h2>
<p><span id="more-2524"></span></p>
<p>As hardware has advanced, the power of graphic cards and rendering speeds have accelerated far faster than regular CPU processing.  As a result, we&#8217;ve started to push all sorts of processing over to graphic cards whenever possible, since the graphic cards often have a lot more processing time available.  Shadow maps are one of those cases.</p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/WithDepth.png"><img class="alignleft size-medium wp-image-2534" title="WithDepth" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/WithDepth-300x184.png" alt="" width="300" height="184" /></a>The basic idea of shadow maps is to actually render our scene twice:  once from the point of view of the light, and then again from the point of view of the camera.  By comparing what&#8217;s visible in the two shots, we can tell what is in shadow and what is visible from the point of view of the light.</p>
<p>In this screenshot I&#8217;ve put a copy of the light&#8217;s render of the scene in the top right corner.  A few things to point out about it:  the light doesn&#8217;t care about colors or textures;  all it cares about is how far away an object is.  So it&#8217;s drawing its view of the scene with darker colors representing close objects, and lighter ones being further away.  It&#8217;s also worth mentioning that the light doesn&#8217;t turn with the player&#8217;s camera;  it&#8217;s always oriented with north at the top of the image.  In this image, the camera is facing approximately northwest.</p>
<p>In the light&#8217;s view you can (roughly) see the column I&#8217;m standing beside, as well as the trees that are casting the large shadows on the left.    (The more distant objects are not visible in the light&#8217;s rendering of the scene.  I&#8217;ll talk about that in a moment)</p>
<p>So after I&#8217;ve rendered the light&#8217;s view of the scene, I then draw the scene normally, but with a little extra logic running per pixel.  The logic goes like this:  For each pixel I draw on the screen, I figure out where that pixel is in the world, and then where that position would be in the light&#8217;s view.  If the pixel is further away than what the light could see during its render, then I know that that pixel is blocked from the light, and so I should draw that pixel as being in shadow.  If not, then it&#8217;s in the light.  And that&#8217;s pretty much all there is to it!</p>
<h2>I&#8217;m a dirty liar</h2>
<p>Actually, no, there&#8217;s a lot more to it than that.  See, the chief problem with shadow maps is resolution.  When the camera is close to shadows (as in this screenshot, and in almost all first-person perspective games), we really need a lot of pixels in our light&#8217;s view of the scene to keep our shadows from appearing blocky.  But we only need that high resolution for the shadows that are close to the view;  if we drew the light&#8217;s view of the scene at that sort of resolution everywhere, we&#8217;d have a terrible frame rate.</p>
<p>So what almost every modern first-person-view game does is to use a system called cascaded shadow maps.</p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/Cascades.png"><img class="alignleft size-medium wp-image-2537" title="Cascades" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/Cascades-268x300.png" alt="" width="268" height="300" /></a>A simple overhead-view of the player&#8217;s first-person view of a scene looks something like this.  The black trapezoid (&#8220;frustum&#8221;, in 3D) represents the part of the game world which the player will be able to see in a particular frame.  Anything outside of that frustum won&#8217;t be visible to the player, unless the player turns or moves.  The player is at the narrow end of the frustum, looking toward the wide end.</p>
<p>When viewed from the player&#8217;s position (that is, not from an overhead view like this one), an object at the narrow end of the frustum is drawn using a lot more pixels than that same object being drawn at the wide end of the frustum.  And this means that we need a lot more detail on things being rendered at the narrow end than at the wide end.  This is true for everything, and a lot of computer graphic technology is built around dealing with this &#8220;how can we draw high quality stuff close to the player, and lower quality stuff further away&#8221; problem.  For models, we have LODs;  simpler versions of models which can be drawn with fewer triangles, for drawing when models are far away from the player.  For textures, we have mipmaps, pre-filtered textures which are optimised for being displayed at smaller sizes on the screen.</p>
<p>Similarly, for shadows, we use cascaded shadow maps.  The idea is that rather than draw one big shadow map as we discussed above, we instead want to draw several, each covering a different part of the view frustum.  Traditionally, each shadow map (called a &#8220;cascade&#8221; in this context) has the same number of pixels in it;  often 512&#215;512 or 1024&#215;1024.  But one will cover a very small box in front of the player (thus having a very high pixel density), another will cover a larger area past that (thus having a lower pixel density), and there may be several more, each covering larger areas located further away from the player, and having coarser and coarser pixels.  In the screenshot here, I have roughly estimated the positions of three cascades to fit the frustum, and outlined them as grey boxes.</p>
<p>Under this approach, when rendering a pixel, we first check how far forward it is from the camera, and then based on that distance forward, we pick which cascade to look in to decide whether that pixel is in light or in shadow.  Right now, MMORPG Tycoon 2 has three cascades.  One covers the first ten meters in front of the camera, the next covers the next 50 meters, and the last covers the next 800 meters.  Each is rendering a 1024&#215;1024 image from the light&#8217;s point of view.  I&#8217;m not certain that these numbers are the best choices right now;  It may well be that I&#8217;d be better off using more cascades with smaller images for each.  Or maybe the cascades should be spaced differently.  But fundamentally, the technology is in place and working;  it&#8217;s only fiddling with numbers that&#8217;s left to do to tweak the behaviour.</p>
<p>Almost every modern first-person game out there uses exactly this system for rendering their shadows, at least in outdoor scenes.  It&#8217;s easy to spot, once you know what to look for.  Because we&#8217;re rendering several different shadow maps at different resolutions, all you have to do is walk forward in a game, and look for a spot where shadows change their level of detail.  In an FPS, this will ordinarily appear as a horizontal line across the ground, where shadows visibly become more defined as you move forward.</p>
<p>So that&#8217;s cascades.  There are a few other issues to be considered, but they&#8217;re probably too far down into fiddly points to be of much interest to most folks.  I already talked about surface acne in a previous post.  The opposite of that problem is called &#8220;Peter Panning&#8221;, where you&#8217;ve biased the shadows so much that they actually detach from the objects that are casting them, causing the objects to appear to be floating above the ground.</p>
<p>Another common problem is shimmer at the edges of shadows, as the camera moves and rotates.  The trick to solving this is to move the light-view cameras in increments that match the distance between pixels in their shadow map, not rotating the light-view cameras to try to better fill the frustum, and not changing the sizes of the cascades from frame to frame.  Doing these things means that if I move the camera (say) three pixels to the right, it will generate exactly the same shadows as it did before, just three pixels away from where it was generating them before.  By comparison, if I moved the camera by a non-integral number of pixels, the shadows would still look very similar, but the precise pixels at the edges of a shadow shape would change, just based on rounding differently.  And this generates a very distracting shimmer around the edges of shadows.</p>
<p>That&#8217;s really all I have to say on the subject.  If I&#8217;ve forgotten something or if you&#8217;d like more detail on one bit or another, please ask in the comments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/05/15/lets-talk-about-shadows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A couple of shadow shots</title>
		<link>http://www.vectorstorm.org/2012/05/06/a-coupl-of-shadow-shots/</link>
		<comments>http://www.vectorstorm.org/2012/05/06/a-coupl-of-shadow-shots/#comments</comments>
		<pubDate>Sun, 06 May 2012 12:04:47 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2499</guid>
		<description><![CDATA[Shadows, now working on both ATI and NVidia chipsets. Have not yet tested on a device using Intel integrated graphics. Not sure how well these shadows will work in that situation.  But I&#8217;ll definitely want to release MS-2 soon, to hear about performance on more machines.  Hopefully in the next few weeks!]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz002.jpg"><img class="alignleft size-medium wp-image-2500" title="View of a simple playable area" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz002-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz004.jpg"><img class="alignleft size-medium wp-image-2502" title="Seconds after attempting to fight a monster" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz004-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz003.jpg"><img class="alignleft size-medium wp-image-2501" title="Fighting a monster" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz003-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz005.jpg"><img class="alignleft size-medium wp-image-2503" title="Side of a steep hill" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/ScreenSnapz005-300x193.jpg" alt="" width="300" height="193" /></a></p>
<p>Shadows, now working on both ATI and NVidia chipsets. Have not yet tested on a device using Intel integrated graphics.</p>
<p>Not sure how well these shadows will work in that situation.  But I&#8217;ll definitely want to release MS-2 soon, to hear about performance on more machines.  Hopefully in the next few weeks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/05/06/a-coupl-of-shadow-shots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unexpected behaviour</title>
		<link>http://www.vectorstorm.org/2012/05/06/unexpected-behaviour/</link>
		<comments>http://www.vectorstorm.org/2012/05/06/unexpected-behaviour/#comments</comments>
		<pubDate>Sun, 06 May 2012 07:06:14 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2496</guid>
		<description><![CDATA[Ladies and gentlemen, cascading shadow maps are working.  (High-resolution shadows up close, low-resolution in the distance.  In this screenshot, all the visible shadows are low-resolution;  the high-res ones are mostly only visible when you&#8217;re down near the ground) This isn&#8217;t the best shot of the shadows;  I&#8217;ll take another screenshot later tonight which will be [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz004.jpg"><img class="alignleft size-medium wp-image-2497" title="MMORPG2ScreenSnapz004" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz004-300x173.jpg" alt="" width="300" height="173" /></a>Ladies and gentlemen, cascading shadow maps are working.  (High-resolution shadows up close, low-resolution in the distance.  In this screenshot, all the visible shadows are low-resolution;  the high-res ones are mostly only visible when you&#8217;re down near the ground)</p>
<p>This isn&#8217;t the best shot of the shadows;  I&#8217;ll take another screenshot later tonight which will be a bit more dramatic.  But I was sort of startled to see this a moment ago:  AI developer cursors automatically casting shadows.  I probably should disable that, since they&#8217;re not supposed to literally be present inside the game world.  But it&#8217;s neat to see the shadows working.</p>
<p>It&#8217;s looking like I probably need a third shadow distance.  The close one is really needed for when you&#8217;re actually standing on the ground.  But for the shadows visible in the middle-distance here, they look a lot blockier than I&#8217;d really like.  So there&#8217;s still a bit more work to be done.  But overall, I&#8217;m pretty happy with where this is going.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/05/06/unexpected-behaviour/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Progress</title>
		<link>http://www.vectorstorm.org/2012/05/06/progress-3/</link>
		<comments>http://www.vectorstorm.org/2012/05/06/progress-3/#comments</comments>
		<pubDate>Sun, 06 May 2012 05:52:18 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2492</guid>
		<description><![CDATA[Still not there, but getting a lot closer.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz003.jpg"><img class="alignleft size-medium wp-image-2493" title="MMORPG2ScreenSnapz003" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz003-300x173.jpg" alt="" width="300" height="173" /></a>Still not there, but getting a lot closer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/05/06/progress-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Surface acne</title>
		<link>http://www.vectorstorm.org/2012/05/06/surface-acne/</link>
		<comments>http://www.vectorstorm.org/2012/05/06/surface-acne/#comments</comments>
		<pubDate>Sun, 06 May 2012 01:24:57 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2488</guid>
		<description><![CDATA[This is what I&#8217;m struggling with right now. In discussions about shadows, these sorts of odd striations and blemishes are generally referred to as &#8220;self-shadow surface acne&#8221;. They&#8217;re commonly caused by math imprecision when a surface (such as here, the mountain) throws a shadow onto itself.  The shadow-caster and the shadow-receiver are so close together [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz002.jpg"><img class="alignleft size-medium wp-image-2489" title="MMORPG2ScreenSnapz002" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz002-300x173.jpg" alt="" width="300" height="173" /></a>This is what I&#8217;m struggling with right now.</p>
<p>In discussions about shadows, these sorts of odd striations and blemishes are generally referred to as &#8220;self-shadow surface acne&#8221;. They&#8217;re commonly caused by math imprecision when a surface (such as here, the mountain) throws a shadow onto itself.  The shadow-caster and the shadow-receiver are so close together (ie: directly on top of one another), that sometimes the math flips their order around.  This results in these interesting stripe patterns.</p>
<p>Hope it doesn&#8217;t take me too long to sort them out.  I&#8217;d really like to finish shadows today and get back to items.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/05/06/surface-acne/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A different perspective</title>
		<link>http://www.vectorstorm.org/2012/05/05/a-different-perspective/</link>
		<comments>http://www.vectorstorm.org/2012/05/05/a-different-perspective/#comments</comments>
		<pubDate>Sat, 05 May 2012 07:59:04 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2484</guid>
		<description><![CDATA[I was ill for part of last week, so haven&#8217;t made quite the progress on items that I wanted to.  But I&#8217;m starting on the work needed for cascaded shadow maps, for really nice full-world shadow support. The first requirement for this is to be able to render an orthographic projection. Orthographic projections are actually [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz001.jpg"><img class="alignleft size-medium wp-image-2485" title="MMORPG2ScreenSnapz001" src="http://www.vectorstorm.org/wp-content/uploads/2012/05/MMORPG2ScreenSnapz001-300x173.jpg" alt="" width="300" height="173" /></a>I was ill for part of last week, so haven&#8217;t made quite the progress on items that I wanted to.  But I&#8217;m starting on the work needed for cascaded shadow maps, for really nice full-world shadow support.</p>
<p>The first requirement for this is to be able to render an orthographic projection.</p>
<p>Orthographic projections are actually pretty simple;  they&#8217;re a view which has no vanishing point;  objects don&#8217;t appear larger as they get closer to the camera, or smaller as they get further away.  Oddly enough, this is the traditional sort of view used for most &#8220;tycoon&#8221;-genre games.  The screenshot here is of a regular view into the MMORPG game world, taken from an orthographic camera.  And.. I think I kind of like it, once real shadows are in.  I&#8217;m starting to think about using this sort of view for general terrain editing and building placement modes, then going down into first-person perspectives for non-editing modes.</p>
<p>Until now, the VectorStorm library had no native support for orthographic views;  you could either render a flat 2D space, or you could render a perspective projection of a 3D space.  I&#8217;ve now added support for orthographic views to the vsCamera3D.  There are a whole host of changes under the hood which are needed to make use of this.  But the upside is that you can now ask a vsCamera3D for its projection matrix;  that&#8217;s no longer hidden inside the renderer.</p>
<p>To use an orthographic view, set a camera&#8217;s projection type to &#8220;vsCamera3D::PT_Orthographic&#8221;, and set its field of view to the vertical distance you want to be rendering.  The horizontal distance is automatically determined based upon the field of view and the aspect ratio (exactly as we were already doing on the vsCamera2D).</p>
<p>Tomorrow, I&#8217;ll be hooking up a couple of shadow map renders to this sort of view.  With any luck, I&#8217;ll get all the way through and be able to show demos of proper shadowing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/05/05/a-different-perspective/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shadow speed</title>
		<link>http://www.vectorstorm.org/2012/04/30/shadow-speed/</link>
		<comments>http://www.vectorstorm.org/2012/04/30/shadow-speed/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 13:13:08 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2477</guid>
		<description><![CDATA[This post isn&#8217;t actually about shadows.  But after poking around a bit, I&#8217;ve finally got shadows performing nicely.  Look at that timing bar at the bottom left corner of the screenshot, and compare it against any of the recent screenshots (with or without shadows) to see how little a performance difference is being caused by [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/04/MMORPG2ScreenSnapz0012.jpg"><img class="alignleft size-medium wp-image-2478" title="MMORPG2ScreenSnapz001" src="http://www.vectorstorm.org/wp-content/uploads/2012/04/MMORPG2ScreenSnapz0012-300x173.jpg" alt="" width="300" height="173" /></a>This post isn&#8217;t actually about shadows.  But after poking around a bit, I&#8217;ve finally got shadows performing nicely.  Look at that timing bar at the bottom left corner of the screenshot, and compare it against any of the recent screenshots (with or without shadows) to see how little a performance difference is being caused by the shadows, now.</p>
<p>As I mentioned yesterday, there&#8217;s still a lot to do with shadows.  Most notably, right now shadows are only being generated for a single area of the game world (covering about half of the starting region).  Move away from there, and shadows vanish again.  I&#8217;m planning to implement cascaded shadow maps, which will result in shadows being calculated near the player, and with better resolution near the player;  blockier further away.  I&#8217;ll make an attempt at this on the coming weekend.</p>
<p>But what I really want to talk about today is the screenshot from yesterday, with all the red squares in the actionbars.  In a lot of ways, for me, those screenshots are more exciting than these ones with the progress on shadows.  See, what&#8217;s going on is that I&#8217;m in the middle of a massive refactoring of how action bars work.  And here&#8217;s why:</p>
<p>I&#8217;m adding an inventory.  Both for in-game characters, and for the player himself.  &#8220;Items&#8221; are now objects which can be carried around, and optionally perform a function when clicked upon.  And almost everything is now an infinite-use &#8220;Item&#8221;, including all of the terrain editing and building placement tools.  Even the button for stepping off of the graveship is an &#8220;Item&#8221; now.  Similarly, the various combat abilities of mmo classes are now implemented as infinite-use items, too.</p>
<p>Items are stored in various places (inventory, class abilities, etc), and shortcuts to these items can then be dragged into action bar button slots.  I haven&#8217;t yet implemented stacking and depletion of similar items, but that&#8217;s planned;  hopefully should have that working by the end of the week.  This support gives me the ability to (for example) give the player once-off consumable items, such as &#8220;construct a capital city&#8221;, without cluttering his interface with disabled buttons for all the time when he&#8217;s not allowed to do that.  It also opens the door to, for example, the player being able to de-rez a building, pick it up, carry it somewhere else, and then rebuild it elsewhere, at no charge.  I think I like that mechanic a lot more than the current &#8220;drag the building freely around the landscape&#8221; interface.</p>
<p>In a more obviously useful vein, it also allows the MMORPG game to have things like health potions, spell scrolls, and other one-use items, and have the AI players automatically understand how to use them.  These consumable items are all implemented in exactly the same way as class abilities, which means that they should slot straight into the AI action selection logic that already exists.</p>
<p>Originally, the idea for MT2 was to abstract away items, because of all the complexities that surround them (drop tables, loot frequencies, etc), but in the end, I really wanted to be able to give items to the player for the purpose of building the world.  I probably won&#8217;t expose the complexities of drop tables in the first release of MT2;  it&#8217;s not really what I want the game to be about.  I&#8217;ll just have AI game designers fill them out automatically.</p>
<p>So that&#8217;s what I&#8217;m up to at the moment!  Hoping to polish off the item interface this week, and get cascaded shadows over the weekend.  Wish me luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/04/30/shadow-speed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A boring screenshot</title>
		<link>http://www.vectorstorm.org/2012/04/29/a-boring-screenshot/</link>
		<comments>http://www.vectorstorm.org/2012/04/29/a-boring-screenshot/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 11:08:10 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2472</guid>
		<description><![CDATA[Originally, my plan for this weekend was to implement cascaded shadow maps for MMORPG Tycoon 2.  In practice, though, technology had other plans for me. Some background: VectorStorm&#8217;s graphic engine works based on a concept that I call display lists (OpenGL programmers, these are not the same thing as OpenGL&#8217;s display lists).  In VectorStorm, a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/04/MMORPG2ScreenSnapz0011.jpg"><img class="alignleft size-medium wp-image-2473" title="MMORPG2ScreenSnapz001" src="http://www.vectorstorm.org/wp-content/uploads/2012/04/MMORPG2ScreenSnapz0011-300x173.jpg" alt="" width="300" height="173" /></a>Originally, my plan for this weekend was to implement <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee416307(v=vs.85).aspx" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/windows/desktop/ee416307_v=vs.85_.aspx?referer=');">cascaded shadow maps</a> for MMORPG Tycoon 2.  In practice, though, technology had other plans for me.</p>
<p>Some background:</p>
<p>VectorStorm&#8217;s graphic engine works based on a concept that I call <em>display lists</em> (OpenGL programmers, these are not the same thing as OpenGL&#8217;s display lists).  In VectorStorm, a display list is a set of rendering commands, converted into a binary blob of memory.  You can think of them as a small program that is run by the renderer.  Statements in these programs are things along the lines of &#8220;Activate the texture &#8216;grass.png&#8217;&#8221;, &#8220;Draw this list of triangles&#8221;, &#8220;Draw a line between these two positions&#8221;, etc.</p>
<p>Originally, VectorStorm&#8217;s drawing strategy was to create a display list, and pass it around to all the drawable objects in the world, letting each of them put their own drawing commands into that list.  In practice, though, switching from one type of material to another (e.g.: switching from drawing clouds to drawing grass) is much more complicated and time-consuming than almost anything else, and so I added a class which I call a <em>Render Queue</em>.  The Render Queue basically keeps a separate Display List for each material.   So when objects submit their &#8220;here&#8217;s how to draw me&#8221; instructions to the renderer, they&#8217;re added to a render queue for the materials that they&#8217;re using.  This means that, for example, we only need to set up the tree foliage material once, no matter how many trees are visible on the screen.  In the world of graphics technology, this is called <em>batching</em> &#8212; rearranging drawing commands to try to make them run faster.  This made a huge difference to rendering performance.  It also gives me a lot more control over specifying which objects are drawn in front of other objects, for things which don&#8217;t use the z-buffer.</p>
<p>For backwards-compatibility, the Render Queue also keeps a &#8220;Generic Display List&#8221;, which old code can use the same way that it used the original display list.  But that tends to be a lot slower, and has a lot more draw-ordering issues.</p>
<p>Almost every one of the &#8220;Testbeds&#8221; games, for example, still uses the Generic Display List for all their drawing.  But MMORPG Tycoon 2 is attempting to perform a lot more drawing and needs to perform more optimally, so almost everything in MT2 is now rendering using the batching system.  (In the screenshot above, only the MMORPG name, the bars beneath it, and the timing bars in the bottom left corner of the screenshot are still rendering via the generic display list &#8212; absolutely everything else is being rendered using the batching system)</p>
<p>Or at least, that&#8217;s what I thought.</p>
<p>This morning I discovered that absolutely everything in VectorStorm&#8217;s 2D rendering path was still using the Generic Display List, not the batched rendering system, even if the game was requesting the batched rendering system.  I had helpfully left myself a little comment that I should turn on the batched rendering for 2D, which was nice of me.  But there were some technical challenges in getting it up and running.  The largest of these was that I&#8217;m still sticking with VectorStorm&#8217;s weird coordinate system, which required some serious doctoring of matrix math to make it all work with OpenGL.</p>
<p>The long and the short of it, though, is that I now have 2D objects being correctly batched, the same as 3D objects.  This should give a sizeable speed boost for folks on slower GPU processors;  the 2D drawing in MMORPG2 has always been a much bigger drain on GPU performance than the 3D drawing, so anything that can help it out a bit will definitely help a lot.</p>
<p>I&#8217;ve got more stuff to talk about (particularly the reason for the red squares in the picture above), but I&#8217;ll leave that for tomorrow.  I&#8217;ve already babbled for far too long, tonight.</p>
<p>And maybe I&#8217;ll manage to do the cascaded shadow maps next weekend;  it&#8217;s too big a task to really attempt in my spare time during the week.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/04/29/a-boring-screenshot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A techy weekend</title>
		<link>http://www.vectorstorm.org/2012/04/15/a-techy-weekend/</link>
		<comments>http://www.vectorstorm.org/2012/04/15/a-techy-weekend/#comments</comments>
		<pubDate>Sun, 15 Apr 2012 11:44:45 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[Engine]]></category>
		<category><![CDATA[Full Games]]></category>
		<category><![CDATA[MMORPG Tycoon]]></category>
		<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2469</guid>
		<description><![CDATA[So I&#8217;ve spent much of the weekend working on adding to VectorStorm&#8217;s shader support.  Enough that I&#8217;ve managed to implement dynamic shadow maps in MMORPG Tycoon 2. This is all very early stuff, and I&#8217;m sure that I&#8217;m going to want to completely rework the mechanisms by which this works.  But I&#8217;m pretty pleased at [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vectorstorm.org/wp-content/uploads/2012/04/MMORPG2ScreenSnapz001.jpg"><img class="alignleft size-medium wp-image-2470" title="MMORPG2ScreenSnapz001" src="http://www.vectorstorm.org/wp-content/uploads/2012/04/MMORPG2ScreenSnapz001-300x173.jpg" alt="" width="300" height="173" /></a>So I&#8217;ve spent much of the weekend working on adding to VectorStorm&#8217;s shader support.  Enough that I&#8217;ve managed to implement dynamic shadow maps in MMORPG Tycoon 2.</p>
<p>This is all very early stuff, and I&#8217;m sure that I&#8217;m going to want to completely rework the mechanisms by which this works.  But I&#8217;m pretty pleased at having things which are recognisably shadows in the game!  (And interacting nicely with the grass effect, etc!)</p>
<p>This isn&#8217;t ready for prime time yet.  It&#8217;s still very, very glitchy, and is far too computationally expensive for what it is right now (because I&#8217;m rendering into a 2048&#215;2048 shadow texture).  And I&#8217;m not even certain that I really want shadows for the visual style of the game.  But it&#8217;s nice to finally have VectorStorm supporting them!</p>
<p>Also, MMORPG Tycoon 2 is now using my de-facto VectorStorm library development trunk, which is over at <a href="http://www.github.com/vectorstorm/vectorstorm" onclick="pageTracker._trackPageview('/outgoing/www.github.com/vectorstorm/vectorstorm?referer=');">Github</a>.  Which means that if you want to see the changes under the hood, they&#8217;re all publicly visible right now;  no need to wait for me to port them back from the MT2 codebase to the VectorStorm trunk.  (Note that there are no testbeds or samples demonstrating anything using this;  it&#8217;s just source code for the rendering architecture, and therefore probably not of much interest to anyone)</p>
<p>Notable new stuff includes:</p>
<ul>
<li>VectorStorm games can now implement custom frame drawing logic (defaults to old behaviour, if they don&#8217;t).</li>
<li>VectorStorm now supports offscreen render targets, for television screens, shadow buffers, and other purposes.  Render targets support multisampling buffers and depth-only targets, in addition to normal texture targets.</li>
<li>Games can now request individual scenes or groups of scenes be drawn into a special render target.</li>
<li>Games can now override the normal lit/unlit/textured/untextured shaders with their own custom shaders.</li>
<li>Game-provided vsShaders are now able to set uniform variables and otherwise set up their state, when they&#8217;re used.</li>
<li>vsImage can now read back texture data from a vsTexture object (even one inside a render target).</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/04/15/a-techy-weekend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gitorious vs. Github vs VectorStorm</title>
		<link>http://www.vectorstorm.org/2012/04/12/gitorious-vs-github-vs-vectorstorm/</link>
		<comments>http://www.vectorstorm.org/2012/04/12/gitorious-vs-github-vs-vectorstorm/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 11:03:03 +0000</pubDate>
		<dc:creator>trevor</dc:creator>
				<category><![CDATA[VectorStorm]]></category>

		<guid isPermaLink="false">http://www.vectorstorm.org/?p=2466</guid>
		<description><![CDATA[I have a small git repository for the new VectorStorm library.   It&#8217;s about 12 megabytes in total, including all history (and it&#8217;ll be even smaller, once I finish trimming and reset the history). I&#8217;ve just done timing tests from my laptop, here in Australia, sending this repository to freshly created bare repositories at my three [...]]]></description>
			<content:encoded><![CDATA[<p>I have a small git repository for the new VectorStorm library.   It&#8217;s about 12 megabytes in total, including all history (and it&#8217;ll be even smaller, once I finish trimming and reset the history).</p>
<p>I&#8217;ve just done timing tests from my laptop, here in Australia, sending this repository to freshly created bare repositories at my three big hosting options (timing via the standard unix &#8216;time&#8217; command line tool):</p>
<p>Github:  58.588 seconds.</p>
<p>Gitorious:  76.964 seconds.</p>
<p>VectorStorm: 54.316 seconds.</p>
<p>This pretty much validates my subjective feeling that Gitorious felt slow to me from here.  (I suspect that these results would be different if measured from elsewhere in the world)</p>
<p>It does surprise me that VectorStorm outperformed Github, but it was only by about 10%;  not a big improvement.  And Github provides a lot of other features, so that&#8217;d probably be the most sensible place to put the VectorStorm library.</p>
<p>In terms of actually doing it, I&#8217;m still cleaning up the new library structure, particularly the cmake build structure.  But it&#8217;s getting pretty close to final now, I think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vectorstorm.org/2012/04/12/gitorious-vs-github-vs-vectorstorm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

