<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>David&#039;s Blog</title>
	<atom:link href="http://therealdblack.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://therealdblack.wordpress.com</link>
	<description>Mostly Hobby Stuff</description>
	<lastBuildDate>Sat, 14 May 2011 21:05:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='therealdblack.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>David&#039;s Blog</title>
		<link>http://therealdblack.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://therealdblack.wordpress.com/osd.xml" title="David&#039;s Blog" />
	<atom:link rel='hub' href='http://therealdblack.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Fluid Integration and Smoke</title>
		<link>http://therealdblack.wordpress.com/2011/03/20/fluid-integration-and-smoke/</link>
		<comments>http://therealdblack.wordpress.com/2011/03/20/fluid-integration-and-smoke/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 23:00:42 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Hobby Game]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=132</guid>
		<description><![CDATA[Over the last few days I have been adding support for PhysX fluids to my particle engine, in addition to a few enhancement+fixes to the particle engine itself. The big advantage of the fluid integration is not that it provides SPH(which is nice), but that it provides fast and robust collision detection and interaction with physical [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=132&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Over the last few days I have been adding support for PhysX fluids to my particle engine, in addition to a few enhancement+fixes to the particle engine itself. The big advantage of the fluid integration is not that it provides SPH(which is nice), but that it provides fast and robust collision detection and interaction with physical objects.</p>
<p>Anyway below I show a couple of screen shots of a small demo level I made, the first is the demo running(it runs at 60 to 30fps depending on resolution) and the second shows the editor with my node based particle editor. With respect to performance, it is mostly fill rate limited(unsurprisingly), I really should investigate using a low resolution render target for low frequency objects.</p>
<p>Some things I added to improve the quality of the results:</p>
<ul>
<li>I rotate the billboard normals away from the centre of the particle, to create a fake volumetric effect. This vastly improves the quality of the lighting for particles. (not sure where this idea came from, I think I read about it somewhere, I just can&#8217;t remember where&#8230;:-(</li>
<li>I added particle sorting, surprisingly, most of the time this is not even needed for many smoke like effects(partly due to the implicit sorting due to emission order perhaps).</li>
<li>I used the relative screen space depth to fade the edges of the particles near intersection. This is done with a bunch of shader nodes, I really should combine these into one node since it is quite a common operation.</li>
<li>I use my own emitter, not the one built into PhysX, this allows detailed control of the emission parameters(eg distribution of particles within the emission cone etc)</li>
<li>I expose more or less all of the fluid settings, however I havent gotten around to sorting them and allowing distributions to be assigned to appropriate parameters.</li>
</ul>
<p><a href="http://therealdblack.files.wordpress.com/2011/03/smoking.jpg"><img class="alignnone size-medium wp-image-133" title="smoking" src="http://therealdblack.files.wordpress.com/2011/03/smoking.jpg?w=300&#038;h=168" alt="" width="300" height="168" /></a></p>
<p><a href="http://therealdblack.files.wordpress.com/2011/03/smoking_editor.jpg"><img class="alignnone size-medium wp-image-134" title="smoking_editor" src="http://therealdblack.files.wordpress.com/2011/03/smoking_editor.jpg?w=300&#038;h=168" alt="" width="300" height="168" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/132/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/132/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/132/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=132&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2011/03/20/fluid-integration-and-smoke/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2011/03/smoking.jpg?w=300" medium="image">
			<media:title type="html">smoking</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2011/03/smoking_editor.jpg?w=300" medium="image">
			<media:title type="html">smoking_editor</media:title>
		</media:content>
	</item>
		<item>
		<title>Shallow Water Simulator, OpenCL + Rigid Body Interaction</title>
		<link>http://therealdblack.wordpress.com/2011/03/06/shallow-water-simulator-opencl-rigid-body-interaction/</link>
		<comments>http://therealdblack.wordpress.com/2011/03/06/shallow-water-simulator-opencl-rigid-body-interaction/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 17:51:26 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Heightfield Fluids]]></category>
		<category><![CDATA[Hobby Game]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=126</guid>
		<description><![CDATA[Just a quick update to post a video of my current progress on my shallow water simulator. Recently I converted the simulator to OpenCL(from plain C# code) and added rigid body to water and water to rigid body interaction. The conversion to run in parallel was very straightforward, for the rigid body interaction I subdivide the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=126&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just a quick update to post a video of my current progress on my shallow water simulator.</p>
<p>Recently I converted the simulator to OpenCL(from plain C# code) and added rigid body to water and water to rigid body interaction. The conversion to run in parallel was very straightforward, for the rigid body interaction I subdivide the collision shapes into triangles when they first touch the waters bounding box, then just process each triangle separately using atomic operations to update the height and velocity fields. I need to investigate the performance in more detail and generally optimize things, but the initial conversion seems quite fast(the ducks scene runs at 45+fps when not recording video).</p>
<p>I have also added FFT wave simulation for small scale details and/or providing a nice water effect when interaction is not needed(although this is not shown in the video). You can find further details about this method at <a href="http://tessendorf.org/">http://tessendorf.org/</a> .</p>
<span style="text-align:center; display: block;"><a href="http://therealdblack.wordpress.com/2011/03/06/shallow-water-simulator-opencl-rigid-body-interaction/"><img src="http://img.youtube.com/vi/a6Vw9_sFWd0/2.jpg" alt="" /></a></span>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/126/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/126/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/126/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=126&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2011/03/06/shallow-water-simulator-opencl-rigid-body-interaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
		<item>
		<title>Game Engine Progress</title>
		<link>http://therealdblack.wordpress.com/2011/01/17/game-engine-progress/</link>
		<comments>http://therealdblack.wordpress.com/2011/01/17/game-engine-progress/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 19:35:56 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Hobby Game]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=122</guid>
		<description><![CDATA[Well its been a while since I posted here, apart from Job Hunting I have had time to do a few things on my game engine. Nothing particularly exciting, mostly stabilization, bug fixing and features which are not terribly exciting, but still important. A quick list: Linear space lighting, ie I adjust the gamma of textures [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=122&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well its been a while since I posted here, apart from Job Hunting I have had time to do a few things on my game engine. Nothing particularly exciting, mostly stabilization, bug fixing and features which are not terribly exciting, but still important. A quick list:</p>
<ul>
<li>Linear space lighting, ie I adjust the gamma of textures when reading(in the shader, due to XNA/portability concerns) and convert to 2.2 gamma at the end of tone mapping. While quite a simple change this made a huge difference to the lighting quality.</li>
<li>Colour correction + screen fades etc. A simple change, I added a matrix transform after tone mapping. In addition I added logic nodes to control this.</li>
<li>Limited deferred lighting. The motivation for this was that since I didn&#8217;t want to add GI or lightmapping I needed a way to add many fill/fake GI lights to indoor scenes to give a convincing level of lighting complexity.<br />
I say deferred, but all I do is draw the light volumes to a texture and read the normal/depth map to compute the lighting. I don&#8217;t have any sophisticated attribute buffer/shadow mapping etc, the deferred lighting is controlled with parameters from just the lights. Later this is combined with key lights, textures etc during the forward rendering pass. My deferred lighting texture consists of diffuse + ambient in RGB and a single channel of specular in alpha.</li>
<li>More animation blending nodes, including nodes for inverse kinematics, converting absolute to relative animation(eg converting a climb animation relative to a fixed point to take into account player movement), fading between animations etc. Plus I added lazy animation updates(ie only re-blending animations when something relevant to the nodes changes).</li>
<li>A GUI editor and rendering/interaction system for menus, player HUD etc. This allows plugable GUI controls, each of which can be assigned another plugin node which manages the action of the node. For example loading another GUI page, changing resolution, input bindings etc.</li>
<li>Load/Save support, this just consists of a function to gather marked properties and user-generated save data into a data structure from entities and components. I then use my versioned serializer to write this to a file.</li>
<li>A proper input system which allows arbitrary mapping of keyboard/mouse and game pad input to linear and binary actions. This includes thread communication and UI integration components.</li>
<li>Basic cube map reflectors(ie runtime generated reflection maps). Nice to create mirrored balls, environment maps etc.</li>
<li>Texel snapping and fixed frustras for CSM shadow maps. More or less eliminates the very annoying shadow flickering when moving around.</li>
<li>A particle history node for particle systems, this combined with a couple of other nodes and features allows my particle system to produce beam effects.</li>
<li>Async level loading.</li>
<li>Depth of Field post processing effect.</li>
</ul>
<p>Not sure if I mentioned some of these changes already&#8230; Also hopefully I will find time to add some screenshots of some of these things soon.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=122&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2011/01/17/game-engine-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
		<item>
		<title>Real-Time Simulation of Large Bodies of Water with Small Scale Details</title>
		<link>http://therealdblack.wordpress.com/2010/07/08/real-time-simulation-of-large-bodies-of-water-with-small-scale-details/</link>
		<comments>http://therealdblack.wordpress.com/2010/07/08/real-time-simulation-of-large-bodies-of-water-with-small-scale-details/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 18:22:03 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Heightfield Fluids]]></category>
		<category><![CDATA[Papers]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=111</guid>
		<description><![CDATA[I should highlight this rather useful paper(pdf). It discusses issues faced when building a 2D heightfield fluid simulator (see my former post about the bare bones simulator I added to my engine).  What is so useful is that it provides many references and nuggets of information needed to extend a basic simulator to increase stability and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=111&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I should highlight this rather useful paper(<a href="http://www.matthiasmueller.info/publications/hfFluid.pdf">pdf</a>).</p>
<p>It discusses issues faced when building a 2D heightfield fluid simulator (see my former post about the bare bones simulator I added to my engine).  What is so useful is that it provides many references and nuggets of information needed to extend a basic simulator to increase stability and improve interaction with other systems.</p>
<p>Thankfully it contains only a minimum amount of GPU Compute marketing:-)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/111/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/111/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/111/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=111&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/07/08/real-time-simulation-of-large-bodies-of-water-with-small-scale-details/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
		<item>
		<title>Sweeping a sphere against a sphere</title>
		<link>http://therealdblack.wordpress.com/2010/07/08/sweeping-a-sphere-against-a-sphere/</link>
		<comments>http://therealdblack.wordpress.com/2010/07/08/sweeping-a-sphere-against-a-sphere/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 18:11:30 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Sweep Tests]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=105</guid>
		<description><![CDATA[This is going to be quite a short post, since we did the bulk of the work in the last post, the extension to sphere-sphere is fairly trivial. All that is required is to realize that the time of impact for a sphere swept against a sphere is the same as the time of impact [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=105&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is going to be quite a short post, since we did the bulk of the work in the last post, the extension to sphere-sphere is fairly trivial.</p>
<p>All that is required is to realize that the time of impact for a sphere swept against a sphere is the same as the time of impact for a sphere which is the sum of the radii swept against a point. The contact point is simply the point along the normal at the perimeter of the sphere we swept against.</p>
<p><pre class="brush: csharp;">
        public static bool Sweep(BoundingSphere sweepSphere, BoundingSphere otherSphere, Vector3 direction, out SweepResult sweepResult)
        {
            //like a sphere-point sweep with a sphere the size of the sum of the radii

            sweepResult = new SweepResult(null);

            BoundingSphere infSphere = new BoundingSphere(sweepSphere.Center, sweepSphere.Radius + otherSphere.Radius);

            SweepResult infSweepResult; //Inflated sphere result

            bool infResult = SweepSpherePoint(infSphere, otherSphere.Center, direction, out infSweepResult);

            sweepResult.T = infSweepResult.T;
            if (infSweepResult.T != null)
            {
                sweepResult.Point = infSweepResult.Point + infSweepResult.Normal * otherSphere.Radius;
                sweepResult.Normal = infSweepResult.Normal;
            }

            return sweepResult.Intersection = infResult;
        }
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=105&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/07/08/sweeping-a-sphere-against-a-sphere/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
		<item>
		<title>Sweeping a sphere against a point</title>
		<link>http://therealdblack.wordpress.com/2010/07/03/sweeping-a-sphere-against-a-point/</link>
		<comments>http://therealdblack.wordpress.com/2010/07/03/sweeping-a-sphere-against-a-point/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 16:26:03 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Sweep Tests]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=94</guid>
		<description><![CDATA[Before beginning it is a good idea to grab a computer algebra package, since there is often a bunch of tedious algebraic manipulation involved in writing a sweep test (more so for later tests). A good choice is Maxima, which is free and fairly effective, although it does require a bunch of messing around to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=94&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Before beginning it is a good idea to grab a computer algebra package, since there is often a bunch of tedious algebraic manipulation involved in writing a sweep test (more so for later tests). A good choice is <a href="http://wxmaxima.sourceforge.net/">Maxima</a>, which is free and fairly effective, although it does require a bunch of messing around to get it to do what you want with vectors.</p>
<p>First lets define the prototype for the function we want:</p>
<p><pre class="brush: csharp;">
public static bool SweepSpherePoint(BoundingSphere sweepSphere, Vector3 pt, Vector3 direction, out SweepResult sweepResult)
</pre></p>
<p>I am using C# for the example code and relying on the XNA math types. The function returns true if there is an intersection along direction as t (the time of impact) ranges from 0 to 1, including an initial intersection at t equals zero. sweepSphere is the sphere we will be sweeping and pt is the point we are sweeping against. direction is the vector we will be sweeping along and sweepResult is information about the intersection, if it occurs.</p>
<p><pre class="brush: csharp;">
       public struct SweepResult
       {
              public bool Intersection; // true if there is some intersection(including an initial intersection)
              public float? T;
              public int? FaceIndex;
              public Vector3? Point;
              public Vector3? Normal;
              public float? PenetrationDepth;
       }
</pre></p>
<p>SweepResult contains a bunch of information, a lot of it optional, which is only set when relevant to the situation.</p>
<p>Since many sweeps turn into solving a quadratic equation we will be making use of a function to solve quadratics:</p>
<p><pre class="brush: csharp;">
public static bool SolveQuadratic(float a, float b, float c, out float t0, out float t1)
</pre></p>
<p>This function returns true when there are one or more solutions to the equation <img class="alignnone size-full wp-image-95" style="border:0;" title="spherepoint_html_24248773" src="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_24248773.gif?w=102&#038;h=21" alt="" width="102" height="21" />. The solutions are returned in t0 and t1, with t0 equal to t1 if there is only one solution. The function correctly handles zero coefficients (e.g. linear or constant equations).</p>
<p>Before we begin with the math for this, there are a number of strategies we can use to simplify the problem at hand and other similar problems:</p>
<ul>
<li>Change the subject of the sweep test, for instance sweeping a point against a sphere(a raycast) is the same as sweeping a sphere against the point. This works because we are just changing the frame of reference, only the objects we are considering matter so which one is moving is just a matter of perspective.</li>
<li>Reduce the dimension of the problem by deflating one object and inflating the other. For example the time of impact between spheres of radius R1 and R2 is the same as the time of impact between a sphere of radius R1+R2 and a point located at the centre of the second sphere.</li>
<li>Split the test based on the features of the objects. For example when sweeping against a polyhedron we can decompose this into a number of polygons, which in turn can be decomposed into a number of planes, edges and points.</li>
</ul>
<p>It should be noted that decomposing shapes and deflating/inflating shapes has the added advantage of improved modularity. So we can write a test for a sphere against a point, check that it works as expected, then reuse this test in another situation. For example sphere-point can be used to check the end spheres of a capsule against the points at the end of an edge.</p>
<p>Lets begin, first we have the equation of a line. A point swept along the reverse of our direction, however we ignore the fact that the direction is reversed until we write the code:</p>
<p style="text-align:center;"><img class="size-full wp-image-97 aligncenter" style="border:0;" title="spherepoint_html_m16f33d1b" src="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m16f33d1b.gif?w=69&#038;h=19" alt="" width="69" height="19" /></p>
<p>Where:</p>
<p style="padding-left:30px;">q is the point of interest<br />
p is the origin of the line<br />
V is the direction of the line<br />
t is the time</p>
<p>Then we have the equation of a sphere:</p>
<p style="text-align:center;"><img class="size-full wp-image-96 aligncenter" style="border:0;" title="spherepoint_html_m3fa2f154" src="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m3fa2f154.gif?w=130&#038;h=21" alt="" width="130" height="21" /></p>
<p>Where:</p>
<p style="padding-left:30px;">S is the centre of the sphere<br />
R is the radius of the sphere</p>
<p>If we substitute the equation of the line into the equation for the sphere we can solve for the time of impact:</p>
<p style="text-align:center;"><img class="size-medium wp-image-98 aligncenter" style="border:0;" title="spherepoint_html_m26c72bcd" src="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m26c72bcd.gif?w=300&#038;h=207" alt="" width="300" height="207" /></p>
<p>Something we should note is that when the quadratic is solved we can end up with a number of result:</p>
<ul>
<li>Two results, each result represents a time when the line passes through the shell of the sphere. Or alternatively a time at which the shell of the sphere is swept into the point. We just need to sort the results to obtain the time of impact.</li>
<li>One result represents a grazing impact with the sphere.</li>
<li>No results represents the cases where the sphere misses the point completely.</li>
</ul>
<p>If any of the impact times are negative or greater than one(since by convention we only consider impacts confined to the movement along direction), then we throw away that result since it is outside the range for the sweep. If we throw away both results then there is no impact.</p>
<p>Obtaining the point of impact is as simple as plugging the value of t into the line equation. The normal (on the sphere) is just a case of subtracting the contact point from the sphere centre and normalizing. We reverse the normal in this test, because by convention we return a normal pointing away from the second object in the test. Obviously we couldn&#8217;t compute a true normal for a point.</p>
<p>If we look at the above formulae, we notice that we can simplify things a bit further and improve performance. We subtract the centre of the sphere from the origin of the ray. This makes S zero and eliminates a few multiplies and dot products.</p>
<p style="text-align:center;"><img class="size-full wp-image-99 aligncenter" style="border:0;" title="spherepoint_html_m762efd97" src="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m762efd97.gif?w=98&#038;h=116" alt="" width="98" height="116" /></p>
<p>Finally we should consider a few edge cases, if the direction is zero length, then our sweep test degenerates into a simple point-sphere intersection test. The case where the point and sphere initially intersect is handled by checking if 0 is contained in the range t0 to t1 and returning an appropriate value.</p>
<p><pre class="brush: csharp;">
        public static bool SweepSpherePoint2(BoundingSphere sweepSphere, Vector3 pt, Vector3 direction, out SweepResult sweepResult)
        {
            //sweep point against sphere along -direction

            sweepResult = new SweepResult(null);

            if (direction.Length() &lt; DirectionEpsilon)
            {
                //zero direction, is the point initially touching the sphere?
                return sweepResult.Intersection = Intersects(sweepSphere, pt);
            }

            Vector3 P = pt - sweepSphere.Center;

            float PdotV = Vector3.Dot(P, -direction);
            float PdotP = Vector3.Dot(pt, pt);

            float a = Vector3.Dot(direction, direction);
            float b = 2.0f * PdotV;
            float c = PdotP - sweepSphere.Radius * sweepSphere.Radius;

            float t0, t1;

            if (!FloatHelper.SolveQuadratic(a, b, c, out t0, out t1))
            {
                return sweepResult.Intersection = false;
            }

            FloatHelper.Sort(ref t0, ref t1);

            if ((t1 &lt; 0.0f) || (t0 &gt; 1.0f))
            {
                return sweepResult.Intersection = false;
            }

            if (t0 &lt; 0.0f)
            {
                return sweepResult.Intersection = true;
            }

            Vector3 sphereHitCen0 = sweepSphere.Center + direction * t0;

            sweepResult.T = t0;
            sweepResult.Point = pt;
            sweepResult.Normal = Vector3.Normalize(sphereHitCen0 - pt);

            return sweepResult.Intersection = true;
        }
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=94&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/07/03/sweeping-a-sphere-against-a-point/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_24248773.gif" medium="image">
			<media:title type="html">spherepoint_html_24248773</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m16f33d1b.gif" medium="image">
			<media:title type="html">spherepoint_html_m16f33d1b</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m3fa2f154.gif" medium="image">
			<media:title type="html">spherepoint_html_m3fa2f154</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m26c72bcd.gif?w=300" medium="image">
			<media:title type="html">spherepoint_html_m26c72bcd</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/07/spherepoint_html_m762efd97.gif" medium="image">
			<media:title type="html">spherepoint_html_m762efd97</media:title>
		</media:content>
	</item>
		<item>
		<title>Sweep Tests</title>
		<link>http://therealdblack.wordpress.com/2010/06/26/sweep-tests/</link>
		<comments>http://therealdblack.wordpress.com/2010/06/26/sweep-tests/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 12:20:08 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Sweep Tests]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=86</guid>
		<description><![CDATA[Sweep tests are an essential part of any programmers tool box if they are interested in writing a 3D application. Sadly the amount of information about them is somewhat limited and often inaccessible, at least for the more sophisticated tests. So I plan on writing a number of blog posts describing the approach I have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=86&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sweep tests are an essential part of any programmers tool box if they are interested in writing a 3D application. Sadly the amount of information about them is somewhat limited and often inaccessible, at least for the more sophisticated tests. So I plan on writing a number of blog posts describing the approach I have taken writing my library of sweep tests. These posts will work from basic principles, developing the more sophisticated tests based on simpler tests.</p>
<p>To start with I should probably define what a sweep test is: given a geometric shape and its position in space, check which shapes it intersects when it is swept along a path, returning the first shape that it intersects, the &#8220;time of impact&#8221;, the intersection point and the intersection normal. In these posts I will restrict my discussion to linear sweeps along a single line. In general sweep tests can also be formulated for rotational paths as well, but I will not cover these. In addition I will only cover &#8220;discrete&#8221; sweep tests, ie I will formulate each test individually rather than using a general method such as an adapted GJK approach.</p>
<p>There is a bunch of information available online(and in paper form) concerning intersection testing and some concerning sweep tests, below I will list a few useful resources:</p>
<ul>
<li><a href="http://www.realtimerendering.com/intersections.html">The Real Time Rendering Intersection Tests Page</a> (Website + Book)</li>
<li><a href="http://www.geometrictools.com/">Geometric Tools</a> (Books + Website)</li>
<li><a href="http://realtimecollisiondetection.net/">Real Time Collision Detection</a> (Book)</li>
<li><a href="http://solid.sourceforge.net/">Solid / Collision Detection in Interactive 3D Environments</a>(Book + Website + Collision Library)</li>
</ul>
<p>The rough plan for posts I will make(very much subject to change):</p>
<ol>
<li>Sweeping a sphere against a point and another sphere</li>
<li>Sweeping a sphere against a line/edge</li>
<li>Sweeping a sphere against a plane</li>
<li>Sweeping a sphere against a polygon</li>
<li>Capsules and sweeping them against a sphere</li>
<li>Sweeping a capsule against a point</li>
<li>Sweeping a capsule against a line</li>
<li>Sweeping a capsule against a polygon</li>
<li>Sweeping a capsule against another capsule</li>
<li>Sweeping a polyhedron against points, faces and edges</li>
<li>Sweeping a polyhedron against another polyhedron</li>
<li>&#8230;</li>
</ol>
<p>I should note that I derived the tests I use from first principles and then debugged/optimized them so that they were suitable for my needs. I do not make any assertions about their robustness or performance except that I have been using them for a while to handle player control and moving platforms etc in my hobby game.</p>
<p>An important point to mention is that a lot of the difficulty in writing sweep tests is related to establishing a framework to ensure they are easy to debug and robust. The approach I took was to add a command to my level editor which allowed me to experiment with the sweep tests with a visualization of important information. Being able to do this interactively is essential as most problems are related to long thin objects, objects of different scales, grazing contacts etc. In addition I created a number of unit tests to tackle regressions(however testing all permutations this way is prohibitively expensive).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=86&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/06/26/sweep-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
		<item>
		<title>Texture Tools and Normal Maps</title>
		<link>http://therealdblack.wordpress.com/2010/06/26/texture-tools-and-normal-maps/</link>
		<comments>http://therealdblack.wordpress.com/2010/06/26/texture-tools-and-normal-maps/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 11:13:23 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Hobby Game]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://therealdblack.wordpress.com/?p=76</guid>
		<description><![CDATA[A while ago I noticed that the memory consumption for my hobby game was getting out of hand. So I did some profiling using the CLR Profiler and PIX to find out where all the memory was going. Unsurprising the biggest memory hog was the unmanaged memory for texture maps, especially because I mostly use 2048&#215;2048 colour [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=76&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A while ago I noticed that the memory consumption for my hobby game was getting out of hand. So I did some profiling using the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=a362781c-3870-43be-8926-862b40aa0cd0&amp;DisplayLang=en">CLR Profiler</a> and PIX to find out where all the memory was going. Unsurprising the biggest memory hog was the unmanaged memory for texture maps, especially because I mostly use 2048&#215;2048 colour and normal maps for models.</p>
<p>Anyway, I started by enabling texture compression for the colour maps by enabling texture compression in the XNA texture processor. This helped, but it left a couple of problems, the normals maps were not compressed and the quality wasnt as good as it could be.</p>
<p>First to solve the normal map issue I did a little investigating and found that DXT5 with a little cleverness could be used(note: xna is D3D9 so I couldn&#8217;t use the nice new normal map formats in D3D10+). Since we only require 2 components to reconstruct a normal, we want to store one of the components in the alpha channel and the other in the green channel to maximize the use of the available precision. This format is sometimes called DXT5n(m). Storing the normal in the colour channels doesn&#8217;t produce very good results, (<a href="http://developer.nvidia.com/object/real-time-normal-map-dxt-compression.html">see Real-Time Normal Map DXT Compression</a>).</p>
<p>There is a nice trick for doing the decompression that allows the same code to handle DXT1 compressed normal maps as well(useful when quality is not such a large concern). See <a href="http://realtimecollisiondetection.net/blog/?p=28">Christer Ericsons Blog post</a>.</p>
<p>My normal decompression function:</p>
<p><pre class="brush: csharp;">
float4 UncompressNormals(float4 input)
{
float x = input.r * input.a;
float y = input.g;
float z = sqrt(1.0f - x*x - y*y);

return float4(x, y, z, 1.0f);
}
</pre></p>
<p>With that done, I now faced some quality issues, in particular the normal maps looked very weak when viewed from a distance. This suggests that the mip maps for the normal maps are not being generated correctly, not surprising since the same filtering code is being used for both colour and normal maps. Normal maps should be re-normalized after each level of the mip map is generated and they should also be processed without any gamma correction.</p>
<p>To improve the situation I switched to <a href="http://code.google.com/p/nvidia-texture-tools/">NVidia Texture Tools</a> for the texture processing. This had a number of additional benefits:</p>
<ul>
<li>Explicit Support for DXT5n</li>
<li>More sophisticated controls for gamma, resizing, mip-map generation etc</li>
<li>Support for normal map generation from height maps</li>
<li>support for more sophisticated mip-map filtering</li>
</ul>
<p>However there was no XNA texture processor or functional .NET wrapper, which meant writing one:-) The maintainer of nvidia-texture-tools was nice enough to allow me to commit the changes, so you can grab the processor and .NET wrapper from <a href="http://code.google.com/p/nvidia-texture-tools/source/checkout">http://code.google.com/p/nvidia-texture-tools/source/checkout</a>. (the changes are not included in a release yet).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=76&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/06/26/texture-tools-and-normal-maps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
		<item>
		<title>Light Fade Volumes and Filter Overrides</title>
		<link>http://therealdblack.wordpress.com/2010/05/12/light-fade-volumes-and-filter-overrides/</link>
		<comments>http://therealdblack.wordpress.com/2010/05/12/light-fade-volumes-and-filter-overrides/#comments</comments>
		<pubDate>Wed, 12 May 2010 20:55:22 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Hobby Game]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">https://therealdblack.wordpress.com/2010/05/12/light-fade-volumes-and-filter-overrides/</guid>
		<description><![CDATA[One problem with the system I mentioned in my last post was that the transition from outdoor to indoor lighting was rather harsh. So in order to improve this I added something I call light fade volumes, these are simply trigger volumes which cause the influence of a set of lights identified by a filter [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=73&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One problem with the system I mentioned in my last post was that the transition from outdoor to indoor lighting was rather harsh. So in order to improve this I added something I call light fade volumes, these are simply trigger volumes which cause the influence of a set of lights identified by a filter group to scaled based on the distance of the object through the volume. For example I can place light fade volumes in doorways to gradually reduce the influence of sky lights on the player as they move through the doorway.</p>
<p>In order to support this I needed to add an additional feature to triggers/collision geometry, i.e. a direction for the volume. This direction can be set and displayed in the editor(as shown below). A further motivation for a direction is to support things such as force fields, push volumes, gravity volumes, anisotropic friction etc.</p>
<p>Once I had this working, I noticed that I often wanted a bunch of lights to only affect the static geometry (e.g. steps) but not the dynamic object resting on them (player). To achieve this I added a property set which can be applied to collision geoms which specifies an alternative light filter for objects resting on them.</p>
<p>&#160;</p>
<p><a href="http://therealdblack.files.wordpress.com/2010/05/may12.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="may12" border="0" alt="may12" src="http://therealdblack.files.wordpress.com/2010/05/may12_thumb.png?w=244&#038;h=139" width="244" height="139" /></a> <a href="http://therealdblack.files.wordpress.com/2010/05/may12_2.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="may12_2" border="0" alt="may12_2" src="http://therealdblack.files.wordpress.com/2010/05/may12_2_thumb.png?w=244&#038;h=139" width="244" height="139" /></a> <a href="http://therealdblack.files.wordpress.com/2010/05/may12_3.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="may12_3" border="0" alt="may12_3" src="http://therealdblack.files.wordpress.com/2010/05/may12_3_thumb.png?w=244&#038;h=139" width="244" height="139" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=73&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/05/12/light-fade-volumes-and-filter-overrides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/05/may12_thumb.png" medium="image">
			<media:title type="html">may12</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/05/may12_2_thumb.png" medium="image">
			<media:title type="html">may12_2</media:title>
		</media:content>

		<media:content url="http://therealdblack.files.wordpress.com/2010/05/may12_3_thumb.png" medium="image">
			<media:title type="html">may12_3</media:title>
		</media:content>
	</item>
		<item>
		<title>Occluder Fusion Cells and Light Filtering</title>
		<link>http://therealdblack.wordpress.com/2010/05/02/occluder-fusion-cells-and-light-filtering/</link>
		<comments>http://therealdblack.wordpress.com/2010/05/02/occluder-fusion-cells-and-light-filtering/#comments</comments>
		<pubDate>Sun, 02 May 2010 19:33:21 +0000</pubDate>
		<dc:creator>therealdblack</dc:creator>
				<category><![CDATA[Hobby Game]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">https://therealdblack.wordpress.com/2010/05/02/occluder-fusion-cells-and-light-filtering/</guid>
		<description><![CDATA[Today I added support for optionally setting the occluder fusion cell size for each model. I should probably explain what the occluder fusion cell size is: When rendering multiple instances of an object, for example patches of grass, objects are grouped/fused into chunks. This allows everything in a fusion group to be drawn in a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=65&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I added support for optionally setting the occluder fusion cell size for each model. </p>
<p>I should probably explain what the occluder fusion cell size is: When rendering multiple instances of an object, for example patches of grass, objects are grouped/fused into chunks. This allows everything in a fusion group to be drawn in a single draw call. In addition to reducing the number of draw calls this reduces the amount of overhead for lighting, material setup, occlusion culling etc. </p>
<p>Hence it becomes trivial to support large numbers of identical objects without the need for special case code. Which in turn simplifies other features such as editing, object painting, decals and particle mesh emitters(TODO).</p>
<p>Anyways, the reason I needed to set the cell size was that for most objects a default size suffices, but for distant/background objects, like buildings in the distance the cell size should be much larger. The cell size can also be tweaked to allow more detailed lighting, since light bindings are shared between all objects within a fused group.</p>
<p>&#160;</p>
<p>Next I added a component which sets a models light filter group based on the object which it is standing on. The reason for this is that objects like the player move from outside to inside. When inside, the player should not have lights such as the directional light simulating diffuse light from the sky affecting them. </p>
<p>One pleasing thing about this feature was that it is a good example of the power of my component based architecture. The entire implementation is about 130 lines, with the ability to apply this component to any model and full editor configuration support:-)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/therealdblack.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/therealdblack.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/therealdblack.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/therealdblack.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/therealdblack.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/therealdblack.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/therealdblack.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/therealdblack.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=therealdblack.wordpress.com&amp;blog=13067711&amp;post=65&amp;subd=therealdblack&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://therealdblack.wordpress.com/2010/05/02/occluder-fusion-cells-and-light-filtering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/06802c0d7a8daa9e63224f910ea07025?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">therealdblack</media:title>
		</media:content>
	</item>
	</channel>
</rss>
