<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Shawn Hargreaves Blog</title><link>http://blogs.msdn.com/b/shawnhar/</link><description /><dc:language>en</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>SimpleMath is now part of the DirectX ToolKit</title><link>http://blogs.msdn.com/b/shawnhar/archive/2013/02/22/simplemath-is-now-part-of-the-directx-toolkit.aspx</link><pubDate>Fri, 22 Feb 2013 22:16:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10396331</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10396331</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2013/02/22/simplemath-is-now-part-of-the-directx-toolkit.aspx#comments</comments><description>&lt;p&gt;Just a quick note to let y'all know that the &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2013/01/08/simplemath-a-simplified-wrapper-for-directxmath.aspx" target="_blank"&gt;SimpleMath&lt;/a&gt; header has been merged into the &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectX Tool Kit&lt;/a&gt; on CodePlex.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10396331" width="1" height="1"&gt;</description></item><item><title>DirectXTK now supports loading and drawing 3D models</title><link>http://blogs.msdn.com/b/shawnhar/archive/2013/01/25/directxtk-now-supports-loading-and-drawing-3d-models.aspx</link><pubDate>Sat, 26 Jan 2013 04:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10388491</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10388491</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2013/01/25/directxtk-now-supports-loading-and-drawing-3d-models.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/" target="_blank"&gt;Chuck&lt;/a&gt;, awesome fellow that he is, has been slaving away on a 3D model loading solution for the &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectX Tool Kit&lt;/a&gt;.&amp;nbsp; Documentation &lt;a href="http://directxtk.codeplex.com/wikipage?title=Model" target="_blank"&gt;here&lt;/a&gt;.&amp;nbsp; I won't bother to repeat all the details in this post, but as a quick summary:&lt;/p&gt;
&lt;p&gt;This is an implementation of a mesh renderer similar to the XNA Game Studio Model, ModelMesh, ModelMeshPart design.&amp;nbsp; It can load data from two different model formats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The .cmo format used by the &lt;a href="http://code.msdn.microsoft.com/windowsapps/Visual-Studio-3D-Starter-455a15f1" target="_blank"&gt;Visual Studio 3D Starter Kit&lt;/a&gt;.&amp;nbsp; This is a basic format with an extremely simplistic material system, but can be handy because the ability to convert from .fbx to .cmo is built into Visual Studio 2012.&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;The .sdkmesh format used by the legacy DirectX SDK.&amp;nbsp; This is a more advanced format than .cmo, with a richer feature set.&amp;nbsp; You can get a .fbx to .sdkmesh converter &lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/04/25/samples-content-exporter-update.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Note: Model currently only supports rigid models. Support for animation, skinning, and frame hierarchy is on our radar for the future, but not yet implemented.&lt;/p&gt;
&lt;p&gt;Check it out, let us know what you think, and a big thank you to Chuck for filling what until today was the biggest hole in our little toolkit!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10388491" width="1" height="1"&gt;</description></item><item><title>Where should SimpleMath live?</title><link>http://blogs.msdn.com/b/shawnhar/archive/2013/01/15/where-should-simplemath-live.aspx</link><pubDate>Tue, 15 Jan 2013 20:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10385243</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>24</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10385243</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2013/01/15/where-should-simplemath-live.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Feb 2013 update: in response to overwhelming popular opinion, SimpleMath has now been merged into the &lt;a href="http://directxtk.codeplex.com/"&gt;DirectX Tool Kit &lt;/a&gt;on Codeplex.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;I am curious what folks think is the right long term home for the &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2013/01/08/simplemath-a-simplified-wrapper-for-directxmath.aspx" target="_blank"&gt;SimpleMath&lt;/a&gt; helper code?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2013/01/08/simplemath-a-simplified-wrapper-for-directxmath.aspx" target="_blank"&gt;post on my blog&lt;/a&gt; is fine&lt;/li&gt;
&lt;li&gt;The &lt;a href="http://code.msdn.microsoft.com/" target="_blank"&gt;MSDN code gallery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Merge it into &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt;&amp;nbsp; &lt;em&gt;(seems kinda weird to me, as SimpleMath isn't really a DirectX graphics helper like the other code in there)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;A standalone CodePlex project&amp;nbsp; &lt;em&gt;(also seems kinda weird, as SimpleMath is so small)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Other?&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10385243" width="1" height="1"&gt;</description></item><item><title>SimpleMath - a simplified wrapper for DirectXMath</title><link>http://blogs.msdn.com/b/shawnhar/archive/2013/01/08/simplemath-a-simplified-wrapper-for-directxmath.aspx</link><pubDate>Tue, 08 Jan 2013 22:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10383307</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10383307</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2013/01/08/simplemath-a-simplified-wrapper-for-directxmath.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Feb 2013 update: SimpleMath has now been merged into the &lt;a href="http://directxtk.codeplex.com/"&gt;DirectX Tool Kit &lt;/a&gt;on Codeplex.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;SimpleMath, created by my colleague &lt;a href="http://blogs.msdn.com/b/chuckw/" target="_blank"&gt;Chuck Walbourn&lt;/a&gt;, is a header file that wraps the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh437833%28v=vs.85%29.aspx" target="_blank"&gt;DirectXMath&lt;/a&gt; SIMD vector/matrix math API with an easier to use C++ interface.&amp;nbsp; It provides the following types, with similar names, methods, and operator overloads to the XNA Game Studio math API:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vector2&lt;/li&gt;
&lt;li&gt;Vector3&lt;/li&gt;
&lt;li&gt;Vector4&lt;/li&gt;
&lt;li&gt;Matrix&lt;/li&gt;
&lt;li&gt;Color&lt;/li&gt;
&lt;li&gt;Plane&lt;/li&gt;
&lt;li&gt;Quaternion&lt;/li&gt;
&lt;li&gt;Ray&lt;/li&gt;
&lt;li&gt;BoundingSphere&lt;/li&gt;
&lt;li&gt;BoundingBox&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="http://directxtk.codeplex.com/"&gt;&lt;strong&gt;Download SimpleMath here&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Why wrap DirectXMath?&lt;/h4&gt;
&lt;p&gt;DirectXMath provides highly optimized vector and matrix math functions, which take advantage of SSE SIMD intrinsics when compiled for x86/x64, or the ARM NEON instruction set when compiled for an ARM platform such as Windows RT or Windows Phone.&amp;nbsp; The downside of being designed for efficient SIMD usage is that DirectXMath can be somewhat complicated to work with.&amp;nbsp; Developers must be aware of &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee418725%28v=vs.85%29.aspx#type_usage_guidelines_" target="_blank"&gt;correct type usage&lt;/a&gt; (understanding the difference between SIMD register types such as XMVECTOR vs. memory storage types such as XMFLOAT4), must take care to maintain correct alignment for SIMD heap allocations, and must carefully structure their code to &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee418732%28v=vs.85%29.aspx#use_accessors_sparingly" target="_blank"&gt;avoid accessing individual components&lt;/a&gt; from a SIMD register.&amp;nbsp; This complexity is necessary for optimal SIMD performance, but sometimes you just want to get stuff working without so much hassle!&lt;/p&gt;
&lt;p&gt;Enter SimpleMath...&lt;/p&gt;
&lt;p&gt;These types derive from the equivalent DirectXMath memory storage types (for instance Vector3 is derived from XMFLOAT3), so they can be stored in arbitrary locations without worrying about SIMD alignment, and individual components can be accessed without bothering to call SIMD accessor functions. But unlike XMFLOAT3, the Vector3 type defines a rich set of methods and overloaded operators, so it can be directly manipulated without having to first load its value into an XMVECTOR.&amp;nbsp; Vector3 also defines an operator for automatic conversion to XMVECTOR, so it can be passed directly to methods that were written to use the lower level DirectXMath types.&lt;/p&gt;
&lt;p&gt;If that sounds horribly confusing, the short version is that the SimpleMath types pretty much Just Work&amp;trade; the way you would expect them to.&lt;/p&gt;
&lt;p&gt;By now you must be wondering, where is the catch?&amp;nbsp; And of course there is one.&amp;nbsp; SimpleMath hides the complexities of SIMD programming by automatically converting back and forth between memory and SIMD register types, which tends to generate additional load and store instructions.&amp;nbsp; This can add significant overhead compared to the lower level DirectXMath approach, where SIMD loads and stores are under explicit control of the programmer.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Who is SimpleMath for?&lt;/h4&gt;
&lt;p&gt;You should use SimpleMath if you are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Looking for a C++ math library with similar API to the C# Microsoft.Xna.Framework types&lt;/li&gt;
&lt;li&gt;Porting existing XNA code from C# to C++&lt;/li&gt;
&lt;li&gt;Wanting to optimize for programmer efficiency (simplicity, readability, development speed) at the expense of runtime efficiency&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You should go straight to the underlying DirectXMath API if you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Want to create the fastest possible code&lt;/li&gt;
&lt;li&gt;Enjoy the lateral thinking sometimes needed to express an algorithm in terms of SIMD operations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This need not be a global either/or decision.&amp;nbsp; The SimpleMath types know how to convert themselves to and from the corresponding DirectXMath types, so it is easy to mix and match.&amp;nbsp; You can use SimpleMath for the parts of your program where readability and development time matter most, then drop down to DirectXMath for performance hotspots where runtime efficiency is more important.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Example&lt;/h4&gt;
&lt;p&gt;Here is a simple object movement calculation, implemented using DirectXMath.&amp;nbsp; Note the skullduggery to make sure the PlayerCat instance will always be 16 byte aligned (and I didn't even include the implementation of the AlignedNew helper here!)&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    #include &amp;lt;DirectXMath.h&amp;gt;

    &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; DirectX;


    __declspec(align(16)) &lt;span class="kwrd"&gt;class&lt;/span&gt; PlayerCat : &lt;span class="kwrd"&gt;public&lt;/span&gt; AlignedNew&amp;lt;PlayerCat&amp;gt;
    {
    &lt;span class="kwrd"&gt;public&lt;/span&gt;:
        &lt;span class="kwrd"&gt;void&lt;/span&gt; Update()
        {
            &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;float&lt;/span&gt; cFriction = 0.99f;

            XMVECTOR pos = XMLoadFloat3A(&amp;amp;mPosition);
            XMVECTOR vel = XMLoadFloat3A(&amp;amp;mVelocity);

            XMStoreFloat3A(&amp;amp;mPosition, pos + vel);
            XMStoreFloat3A(&amp;amp;mVelocity, vel * cFriction);
        }

    &lt;span class="kwrd"&gt;private&lt;/span&gt;:
        XMFLOAT3A mPosition;
        XMFLOAT3A mVelocity;
    };&lt;/pre&gt;
&lt;p&gt;Using SimpleMath, the same math is, well, a little more simple :-)&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    #include &lt;span class="str"&gt;"SimpleMath.h"&lt;/span&gt;

    &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; DirectX::SimpleMath;


    &lt;span class="kwrd"&gt;class&lt;/span&gt; PlayerCat
    {
    &lt;span class="kwrd"&gt;public&lt;/span&gt;:
        &lt;span class="kwrd"&gt;void&lt;/span&gt; Update()
        {
            &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;float&lt;/span&gt; cFriction = 0.99f;

            mPosition += mVelocity;
            mVelocity *= cFriction;
        }

    &lt;span class="kwrd"&gt;private&lt;/span&gt;:
        Vector3 mPosition;
        Vector3 mVelocity;
    };&lt;/pre&gt;
&lt;p&gt;Here is the x86 SSE code generated for the DirectXMath version of the Update method:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;     movaps      xmm2,xmmword ptr [ecx+10h]
     movaps      xmm1,xmmword ptr [ecx]
     andps       xmm2,xmmword ptr [?g_XMMask3@DirectX@@3UXMVECTORI32@1@B]
     andps       xmm1,xmmword ptr [?g_XMMask3@DirectX@@3UXMVECTORI32@1@B]
     movaps      xmm0,xmmword ptr [__xmm@3f7d70a43f7d70a43f7d70a43f7d70a4]
     addps       xmm1,xmm2
     mulps       xmm0,xmm2
     movq        mmword ptr [ecx],xmm1
     shufps      xmm1,xmm1,0AAh
     movss       dword ptr [ecx+8],xmm1
     movq        mmword ptr [ecx+10h],xmm0
     shufps      xmm0,xmm0,0AAh
     movss       dword ptr [ecx+18h],xmm0
     ret&lt;/pre&gt;
&lt;p&gt;The SimpleMath version generates slightly more than twice as many machine instructions:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;     movss       xmm2,dword ptr [ecx]
     movss       xmm0,dword ptr [ecx+4]
     movss       xmm1,dword ptr [ecx+0Ch]
     unpcklps    xmm2,xmm0
     movss       xmm0,dword ptr [ecx+8]
     movlhps     xmm2,xmm0
     movss       xmm0,dword ptr [ecx+10h]
     unpcklps    xmm1,xmm0
     movss       xmm0,dword ptr [ecx+14h]
     movlhps     xmm1,xmm0
     addps       xmm2,xmm1
     movss       dword ptr [ecx],xmm2
     movaps      xmm0,xmm2
     shufps      xmm0,xmm2,55h
     movss       dword ptr [ecx+4],xmm0
     shufps      xmm2,xmm2,0AAh
     movss       dword ptr [ecx+8],xmm2
     movss       xmm1,dword ptr [ecx+0Ch]
     movss       xmm0,dword ptr [ecx+10h]
     unpcklps    xmm1,xmm0
     movss       xmm0,dword ptr [ecx+14h]
     movlhps     xmm1,xmm0
     mulps       xmm1,xmmword ptr [__xmm@3f7d70a43f7d70a43f7d70a43f7d70a4]
     movaps      xmm0,xmm1
     movss       dword ptr [ecx+0Ch],xmm1
     shufps      xmm0,xmm1,55h
     shufps      xmm1,xmm1,0AAh
     movss       dword ptr [ecx+10h],xmm0
     movss       dword ptr [ecx+14h],xmm1
     ret&lt;/pre&gt;
&lt;p&gt;Most of this difference is because I was able to used aligned loads and stores in the DirectXMath version, while the SimpleMath code must do extra work to handle memory locations that might not be properly aligned.&amp;nbsp; Also note how the SimpleMath version loads the mVelocity value from memory into SIMD registers twice, while the extra control offered by DirectXMath allowed me to do this just once.&lt;/p&gt;
&lt;p&gt;But hey, sometimes performance isn't the most important goal.&amp;nbsp; If you care more about optimizing for developer efficiency, SimpleMath could be for you.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Resources&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/03/27/introducing-directxmath.aspx"&gt;http://blogs.msdn.com/b/chuckw/archive/2012/03/27/introducing-directxmath.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-sse-sse2-and-arm-neon.aspx"&gt;http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-sse-sse2-and-arm-neon.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-sse3-and-ssse3.aspx"&gt;http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-sse3-and-ssse3.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-sse4-1-and-sse-4-2.aspx"&gt;http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-sse4-1-and-sse-4-2.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-avx.aspx"&gt;http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-avx.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-f16c-and-fma.aspx"&gt;http://blogs.msdn.com/b/chuckw/archive/2012/09/11/directxmath-f16c-and-fma.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10383307" width="1" height="1"&gt;</description></item><item><title>A brewing puzzle: solution</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/12/04/a-brewing-puzzle-solution.aspx</link><pubDate>Tue, 04 Dec 2012 17:52:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10374543</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10374543</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/12/04/a-brewing-puzzle-solution.aspx#comments</comments><description>&lt;p&gt;Kudos to Clayton, mantis, and MannekinPis, who were on the right track about &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2012/12/03/a-brewing-puzzle.aspx" target="_blank"&gt;how to make beer in 17th century Germany&lt;/a&gt;.&amp;#160; The trick to exactly hitting arbitrary temperatures without a thermometer lies in the fact that boiling water is always 212 °F.&lt;/p&gt;  &lt;p&gt;Ice is not relevant here, though.&amp;#160; For one thing, ice does not have a single fixed temperature, and can be much colder than freezing point.&amp;#160; For another, Hans does not have a freezer, electricity, or any other way to make ice!&lt;/p&gt;  &lt;p&gt;A traditional brewing technique is:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Take 10 gallons of water from the well. Underground temperatures are extremely steady throughout the year, so this will not vary by more than a degree or two. Hans must learn by trial and error what temperature his particular well happens to produce. Let’s say this is 50 °F.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Measure out 6.3 gallons, and bring it to a boil.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Mix everything back together. 3.7 gallons at 50 °F plus 6.3 gallons at 212 °F = the desired 152 °F.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There is no need to worry about heat loss once the mash is at the desired temperature. Five or ten gallons of hot liquid has a lot of thermal inertia, and can sit long enough for the enzymes to do their work without cooling too much.&lt;/p&gt;  &lt;p&gt;More complex mashes (used to make various kinds of beer) require a series of different temperatures, which can be achieved by repeatedly boiling the appropriate portion of the liquid and then mixing back together.&amp;#160; The measurement could be done by weight, but volume was more often used. It’s trivial to do this by ratio (“&lt;i&gt;1 scoop into the small kettle, 2 into the big… 1 in the small, 2 in the big…&lt;/i&gt;”) without needing any dedicated measuring equipment at all. And having counted out the scoops once, future batches can hit the exact same temperatures just by remembering how close to the top each kettle was filled.&lt;/p&gt;  &lt;p&gt;I think it’s pretty amazing that, armed with nothing more than two kettles, a ladle, and a fire, uneducated farmers were able to follow complex mashing schedules such as:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;20 minutes at 109 °F&amp;#160; &lt;em&gt;(acid rest: phytase enzymes alter pH while beta-glucanase breaks down gums)&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;20 minutes at 122 °F&amp;#160; &lt;em&gt;(protein rest: proteolytic enzymes split up the longer protein chains)&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;30 minutes at 149 °F&amp;#160; &lt;em&gt;(saccharification rest: beta-amylase enzymes convert starch to sugar)&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;30 minutes at 158 °F&amp;#160; &lt;em&gt;(saccharification rest: alpha-amylase enzymes convert starch to sugar)&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;10 minutes at 168 °F&amp;#160; &lt;em&gt;(mash out: denatures all enzymes, freezing the mash chemistry in its current form)&lt;/em&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;and consistently get within a few degrees of each target temperature.&lt;/p&gt;  &lt;p&gt;But what really blows my mind is how anyone managed to figure out the right temperatures to make great beer, long before we understood enzymes or starch molecules!&amp;#160; Those medieval monks must have had a LOT of spare time to experiment :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10374543" width="1" height="1"&gt;</description></item><item><title>A brewing puzzle</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/12/03/a-brewing-puzzle.aspx</link><pubDate>Tue, 04 Dec 2012 00:43:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10374266</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10374266</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/12/03/a-brewing-puzzle.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Warning: this post is not about programming.&amp;#160; Andy suggested I should sneak some homebrewing material onto my blog, and I thought hmm, why not?&amp;#160; If you violently object, let me know in the comments and I won't do it again :-)&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Yesterday I brewed a traditional German hefeweizen, which was the first time I tried a &lt;a href="http://www.brewery.org/brewery/library/DecoctFAQ.html" target="_blank"&gt;decoction mash&lt;/a&gt;.&amp;#160; This got me thinking about how incredibly accurate traditional brewers managed to be, long before the arrival of chemistry, biology, or scientific measuring tools.&amp;#160; This particular trick might be obvious to people with a stronger background in physics, but I thought it was pretty amazing.&amp;#160; So, a puzzle...&lt;/p&gt;  &lt;p&gt;Hans is a 17th century German brewer.&amp;#160; He wants to attract a loyal customer base who will seek out his beer in preference to that of competitors.&amp;#160; To achieve this, he must:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Make beer that people like to drink&lt;/li&gt;    &lt;li&gt;Make it the same way every time, so customers come to trust the quality of his product&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;One of the key steps in brewing is heating a mix of water and crushed malted barley (called the &amp;quot;mash&amp;quot;) to 152 °F, where amylase enzymes will convert starch molecules into sugars that yeast can later ferment into alcohol.&amp;#160; But Hans does not have access to a thermometer, so he has no way to accurately hit the right temperature.&amp;#160; He can estimate by sticking his finger in the mash, but even with lots of practice this is horribly inaccurate.&amp;#160; Sometimes he ends up at 148 °F, which produces a dry, thin beer.&amp;#160; Other days he ends up at 158 °F, which gives a thick, syrupy end result.&amp;#160; One time he overshot all the way to 170 °F, which accidentally denatured the enzymes, leaving him with a couple of tons of watery grain that could no longer be used to make beer at all!&lt;/p&gt;  &lt;p&gt;Is it possible to do better?&amp;#160; How can Hans heat his mash to exactly 152 °F without the use of a thermometer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10374266" width="1" height="1"&gt;</description></item><item><title>Debugging Direct3D programs: a taxonomy of error conditions</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/11/27/debugging-direct3d-programs-a-taxonomy-of-error-conditions.aspx</link><pubDate>Tue, 27 Nov 2012 23:01:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10372419</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10372419</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/11/27/debugging-direct3d-programs-a-taxonomy-of-error-conditions.aspx#comments</comments><description>&lt;p&gt;Eric Lippert wrote a &lt;a href="http://blogs.msdn.com/b/ericlippert/archive/2008/09/10/vexing-exceptions.aspx" target="_blank"&gt;fantastic article&lt;/a&gt; that categorizes C# exceptions into four categories:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;&lt;strong&gt;Exogenous &lt;/strong&gt;exceptions occur due to the messy nature of reality.&amp;#160; Filesystems can run out of space.&amp;#160; Network connections can drop.&amp;#160; These things are rare, but they do happen and robust code needs to be ready to deal with them. &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;strong&gt;Boneheaded &lt;/strong&gt;exceptions, as Eric puts it, &amp;quot;&lt;em&gt;are your own darn fault, you could have prevented them and therefore they are bugs in your code. You should not catch them; doing so is hiding a bug in your code. Rather, you should write your code so that the exception cannot possibly happen in the first place&lt;/em&gt;&amp;quot;. &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;strong&gt;Fatal &lt;/strong&gt;exceptions occur when something truly unexpected went wrong (memory corruption, thread abort, etc.).&amp;#160; Again in Eric's words, &amp;quot;&lt;em&gt;not your fault, you cannot prevent them, and you cannot sensibly clean up from them. They almost always happen because the process is deeply diseased and is about to be put out of its misery&lt;/em&gt;&amp;quot;. &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Finally, &lt;strong&gt;Vexing &lt;/strong&gt;exceptions are caused by design flaws where someone foolishly decided to throw an exception in response to a situation that was not truly exceptional.&amp;#160; Sometimes you are forced to catch these in order to use the offending API, but ideally that API should be changed to report non-exceptional results in some other way (e.g. as return values). &lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;At this point the attentive reader may be wondering, what on earth does C# exception handling have to do with D3D?&amp;#160; In a COM based C++ API such as D3D, errors are reported via HRESULT return values, not exceptions, right?&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Not so fast...&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;D3D actually has three different mechanisms for reporting errors, which exactly correlate to the first three of Eric's exception categories.&amp;#160; There is no equivalent of vexing exceptions, because the D3D API does not use exceptions.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Exogenous errors In D3D&lt;/h4&gt;  &lt;p&gt;D3D reports exogenous errors by returning failure HRESULT codes.&amp;#160; You should always check these return values and handle any failures.&lt;/p&gt;  &lt;p&gt;Note that some D3D methods have a return type of void instead of HRESULT.&amp;#160; This is because not all methods have any exogenous failure paths.&amp;#160; For instance the ID3D11Device::CreateBlendState method returns an HRESULT (which you should check and handle) but ID3D11DeviceContext::OMSetBlendState returns void.&amp;#160; This does not mean it is impossible for OMSetBlendState to fail, but that there is no point checking a return value because all the possible OMSetBlendState failures are boneheaded or fatal.&amp;#160; You could pass a null pointer or try to set a state object that had previously been released, but as long as you specify valid parameters OMSetBlendState will always succeed.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Boneheaded errors in D3D&lt;/h4&gt;  &lt;p&gt;By default, D3D does not bother to check for boneheaded errors at all.&amp;#160; This is because it takes some time to validate everything, and hey, this should be unnecessary as long as you don't have any bugs in your program, right? :-)&lt;/p&gt;  &lt;p&gt;If you do make a boneheaded error calling into D3D, the result is undefined behavior.&amp;#160; You might get lucky and the call happens to work like you expect in spite of the mistake, or it might work on one computer but not on others, or it might crash, or it might mess things up so some other call crashes later on, or you might just get weird rendering results.&amp;#160; This is not good.&lt;/p&gt;  &lt;p&gt;D3D provides an optional &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/jj200584(v=vs.85).aspx" target="_blank"&gt;debug layer&lt;/a&gt; to help you find and fix such problems. This is enabled if you pass the D3D11_CREATE_DEVICE_DEBUG flag when creating your D3D device.&amp;#160; It adds detailed parameter and state validation, which slows things down but will print nice messages back to the debugger output pane if it finds any boneheaded errors.&lt;/p&gt;  &lt;p&gt;If you used the Windows 8 or Windows Phone 8 project templates as a starting point for your D3D app, the debug layer will be turned on by default in debug builds.&amp;#160; The Direct3DBase::CreateDeviceResources method does this like so:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;      UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

&lt;span class="preproc"&gt;  #if&lt;/span&gt; defined(_DEBUG)
      &lt;span class="rem"&gt;// If the project is in a debug build, enable debugging via SDK Layers with this flag.&lt;/span&gt;
      creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
&lt;span class="preproc"&gt;  #endif&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;It's always a good idea to test with the debug layer turned on, keep an eye on the output pane in Visual Studio, and fix any issues it complains about.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h4&gt;Fatal errors in D3D&lt;/h4&gt;

&lt;p&gt;Unexpected, non-recoverable D3D errors can (rarely) occur for several reasons:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The GPU hardware could hang due to a driver bug, hardware fault, overheating, etc.&amp;#160; It must then be reset (basically rebooting the GPU) before rendering can continue. This is referred to as a &lt;a href="http://msdn.microsoft.com/en-us/library/windows/hardware/ff570087%28v=vs.85%29.aspx" target="_blank"&gt;TDR&lt;/a&gt;, which stands for Timeout Detection and Recovery.&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;The GPU could have been physically removed from the computer (which happens when undocking certain laptop models) or its driver could have been updated on the fly.&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;The driver could have a bug that got it into a messed up state.&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;The driver or D3D runtime could run out of memory in a place that isn't recoverable.&amp;#160; Some allocation failures (for instance not having enough room to create a new texture) are easy to report back to the caller, but others (for instance failing to allocate an internal renamed resource while flushing a command buffer) could leave things in an ambiguous partial state where some amount of rendering might already have taken place yet other work cannot be completed.&amp;#160; There is no good way to describe such a situation to the caller, and not really anything they could do to continue past the problem.&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;A boneheaded error could have gone unnoticed (especially if the debug D3D layer was not in use) so the D3D runtime passed invalid parameters through to the driver.&amp;#160; What happens next is entirely up to the driver (this is undefined behavior!) but one likely outcome is for the driver to become horribly confused, fling its hands in the air, and shout &lt;em&gt;huh? you want me to do whaaaat???&lt;/em&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In all these cases things have gone badly wrong, and not in a clean way where D3D could report back that any single method call was rejected.&amp;#160; We know the D3D device has ended up in a different state to what the program intended, but cannot describe exactly how things are different or what needs to happen to get everything back in sync. At this point D3D switches into a special &amp;quot;device removed&amp;quot; state.&amp;#160; You can still call D3D methods, but they will be ignored and nothing will actually be rendered.&amp;#160; When you eventually come to call Present, it will return one of the error codes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DXGI_ERROR_DEVICE_REMOVED &lt;/li&gt;

  &lt;li&gt;DXGI_ERROR_DEVICE_RESET &lt;/li&gt;

  &lt;li&gt;DXGI_ERROR_DEVICE_HUNG &lt;/li&gt;

  &lt;li&gt;DXGI_ERROR_DRIVER_INTERNAL_ERROR &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only way to recover from device removed state is to destroy the broken D3D device, destroy all its associated resources, create a new device, and reload a whole new set of fresh resources.&amp;#160; Some apps go to great pains to robustly handle this situation, but many (most?) games don't bother, and will just crash in response, or stop rendering and need to be killed by the user.&lt;/p&gt;

&lt;p&gt;Note that D3D11 device removed state is different from the old D3D9 device lost behavior, which occurred any time the monitor switched between windowed and fullscreen mode (e.g. when pressing alt+tab).&amp;#160; This was a common occurrence, so all D3D9 apps had to handle device lost.&amp;#160; In D3D11, display mode switches are handled by the runtime without any special effort from the app.&amp;#160; Device removed is reserved for situations where the state of the device is not well defined and thus no automatic recovery is possible, which is much rarer.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;/em&gt;If you frequently run into device removed errors, the first step is to check the debug D3D layer to make sure these are not just knock-on consequences of an earlier boneheaded error.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10372419" width="1" height="1"&gt;</description></item><item><title>Catalin Zima on converting textures to .dds</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/11/15/catalin-zima-on-converting-textures-to-dds.aspx</link><pubDate>Thu, 15 Nov 2012 18:30:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10368978</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10368978</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/11/15/catalin-zima-on-converting-textures-to-dds.aspx#comments</comments><description>&lt;p&gt;Catalin has a &lt;a href="http://www.catalinzima.com/2012/11/converting-textures-to-dds/" target="_blank"&gt;great article on how to convert textures to .dds format&lt;/a&gt;, which is the most efficient way to load images for use with Direct3D.&amp;#160; He describes how to integrate the texconv tool (from &lt;a href="http://directxtex.codeplex.com/" target="_blank"&gt;DirectXTex&lt;/a&gt;) into Visual Studio using MSBuild, so textures can be automatically converted every time you build your project.&lt;/p&gt;  &lt;p&gt;There's lots of other great stuff on his blog, too.&amp;#160; You should subscribe, if you haven't already :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10368978" width="1" height="1"&gt;</description></item><item><title>Beware of D3D feature level 11 in the Windows Phone emulator</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/11/06/beware-of-d3d-feature-level-11-in-the-windows-phone-emulator.aspx</link><pubDate>Tue, 06 Nov 2012 16:58:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10366223</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10366223</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/11/06/beware-of-d3d-feature-level-11-in-the-windows-phone-emulator.aspx#comments</comments><description>&lt;p&gt;Windows Phone 8 devices support Direct3D 11.1 feature level 9.3, but our emulator uses the WARP rasterizer, which can handle all the way up to feature level 11.&amp;#160; This means that, if you aren't careful, it is possible to accidentally use more advanced D3D features while developing in the emulator, only to get an unpleasant surprise when these things don't work on an actual device.&lt;/p&gt;  &lt;p&gt;Q:&amp;#160; how to avoid unpleasant surprises?&lt;/p&gt;  &lt;p&gt;A:&amp;#160; make sure you explicitly select feature level 9.3, even when running in the emulator.&lt;/p&gt;  &lt;p&gt;Starting with the &lt;em&gt;Windows Phone Direct3D App&lt;/em&gt; project template, open up Direct3DBase.cpp, find this code in the CreateDeviceResources method:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
        D3D_FEATURE_LEVEL_9_3
    };&lt;/pre&gt;

&lt;p&gt;and change it to:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_9_3
    };&lt;/pre&gt;

&lt;p&gt;Tada!&amp;#160; Now you will be using 9.3 in the emulator, the same as on actual device hardware.&lt;/p&gt;

&lt;p&gt;Right above this code, notice how the template turns on D3D11_CREATE_DEVICE_DEBUG only if the _DEBUG define is set?&amp;#160; This enables extra validation to give more useful error messages if you make a mistake in your D3D API usage.&amp;#160; But that validation is not free, so we only enable it in debug builds.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10366223" width="1" height="1"&gt;</description></item><item><title>Speed: in which MSDOS meets Windows Phone 8</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/11/01/speed-in-which-msdos-meets-windows-phone-8.aspx</link><pubDate>Thu, 01 Nov 2012 18:46:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10364972</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10364972</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/11/01/speed-in-which-msdos-meets-windows-phone-8.aspx#comments</comments><description>&lt;p&gt;Inspired by &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2009/06/12/appweek.aspx" target="_blank"&gt;long standing&lt;/a&gt; XNA team &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2010/09/28/appweek-2010.aspx" target="_blank"&gt;tradition&lt;/a&gt;, the Windows Phone graphics team recently spent some time using our product and trying to build some apps.&amp;#160; One of our goals in supporting native C++ was to make it easier to port existing software and frameworks to the platform, so I thought, what is the most legacy thing I could possibly try to port?&amp;#160; For App Week I took a &lt;a href="http://www.shawnhargreaves.com/speed/" target="_blank"&gt;game called Speed&lt;/a&gt;, which I wrote 13 years ago (last century!) in C (yep, that's C, not C++) using an MSDOS library called &lt;a href="http://alleg.sourceforge.net/" target="_blank"&gt;Allegro&lt;/a&gt;, and ported it to Windows Phone 8.&lt;/p&gt;  &lt;p&gt;Check it out:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="display: inline" title="t" alt="t" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/5460.t_5F00_11E2BD3A.png" width="480" height="288" /&gt;&lt;/p&gt;    &lt;p&gt;     &lt;br /&gt;&lt;img style="display: inline" title="ety" alt="ety" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/4087.ety_5F00_6AA87404.png" width="480" height="288" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;     &lt;br /&gt;&lt;img style="display: inline" title="5u" alt="5u" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/6138.5u_5F00_2A725A8A.png" width="480" height="288" /&gt;&lt;/p&gt;    &lt;p&gt;     &lt;br /&gt;&lt;img style="display: inline" title="rwr" alt="rwr" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/6622.rwr_5F00_03381155.png" width="480" height="288" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;   &lt;br /&gt;If you want to play this yourself, or look at the code, you can download it here:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/1220.Speed.zip" target="_blank"&gt;&lt;strong&gt;Speed.zip&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You'll need a copy of &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt; to build it (unzip into a folder named DirectXTK in the same location as the Speed.sln file).&amp;#160; Although it runs ok in the Windows Phone emulator, you really need an actual device to play this properly.&amp;#160; Touch input using left, right and center of the screen, not to mention tilt sensor input, doesn't work so well via a mouse!&lt;/p&gt;  &lt;p&gt;Porting this turned out to be pleasingly straightforward.&amp;#160; The OriginalGame folder contains, can you guess? Yup, that's the original C code, almost entirely unchanged since 1999.&amp;#160; Meanwhile, allegro.h and allegro.cpp (in the PhonePort folder) provide an emulation layer which translates the necessary subset of the old Allegro API into D3D11, XAudio2 and WinRT calls.&amp;#160; It uses DirectXTK &lt;a href="http://directxtk.codeplex.com/wikipage?title=SpriteFont" target="_blank"&gt;SpriteFont&lt;/a&gt; for the text rendering, &lt;a href="http://directxtk.codeplex.com/wikipage?title=PrimitiveBatch" target="_blank"&gt;PrimitiveBatch&lt;/a&gt; and &lt;a href="http://directxtk.codeplex.com/wikipage?title=Effects" target="_blank"&gt;BasicEffect&lt;/a&gt; for all other graphics, &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee415737%28v=vs.85%29.aspx" target="_blank"&gt;XAudio2&lt;/a&gt; for the music and sound effects, and WinRT &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool.runasync" target="_blank"&gt;ThreadPool::RunAsync&lt;/a&gt; to emulate Allegro timer interrupts.&lt;/p&gt;  &lt;p&gt;A silly-but-I-think-kinda-neat thing about this game is that the music is entirely procedural.&amp;#160; The &lt;em&gt;init_music()&lt;/em&gt; function (in OriginalGame\sound.c) generates a set of single cycle waveform samples using sine, square, and sawtooth waves.&amp;#160; Then the &lt;em&gt;music_player()&lt;/em&gt; function is installed as a custom timer interrupt handler.&amp;#160; This walks through a set of tables describing the pitch and duration of each note, and calls the Allegro voice functions to trigger or stop playback as appropriate.&amp;#160; I didn't change this code at all, yet my emulation layer is good enough to play the music exactly as it sounded in the original.&lt;/p&gt;  &lt;p&gt;For bonus points I added a bloom postprocess (implemented in PhonePort\Game.cpp) because, hey, this is 2012 after all :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10364972" width="1" height="1"&gt;</description></item><item><title>DirectX Tool Kit now supports Windows Phone 8</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/10/30/directx-tool-kit-now-supports-windows-phone-8.aspx</link><pubDate>Tue, 30 Oct 2012 23:42:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10364283</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10364283</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/10/30/directx-tool-kit-now-supports-windows-phone-8.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;I suspect this will come as no surprise to anyone who's been paying attention to what I've been working on recently...&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The latest version of &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt; adds support for Windows Phone 8.&amp;#160; In fact, DirectXTK pretty much already worked on WP8, which uses the same D3D11 API as Windows 8.&amp;#160; The only changes in this release are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Added project and solution files for use with the newly released &lt;a href="http://go.microsoft.com/fwlink/?LinkID=261873" target="_blank"&gt;Windows Phone SDK&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Updated WICTextureLoader and SaveWICTextureToFile to indicate that these are not available on Windows Phone (which does not support WIC) &lt;/li&gt;    &lt;li&gt;Updated the readme to match &lt;/li&gt; &lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10364283" width="1" height="1"&gt;</description></item><item><title>Apollo has landed</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/10/30/apollo-has-landed.aspx</link><pubDate>Tue, 30 Oct 2012 23:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10364282</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10364282</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/10/30/apollo-has-landed.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/10/30/announcing-the-new-windows-phone-8-developer-platform.aspx" target="_blank"&gt;developer SDK for Windows Phone 8&lt;/a&gt; (codename Apollo) is &lt;a href="http://go.microsoft.com/fwlink/?LinkID=261873" target="_blank"&gt;now available for download&lt;/a&gt; from an internet near you.&amp;nbsp; Which means I can finally talk about what I&amp;rsquo;ve been working on this past year!&amp;nbsp; I am dev lead for graphics, so I&amp;rsquo;ll probably have most to say about that area, but knowing me I&amp;rsquo;m sure I&amp;rsquo;ll find other topics to write about too.&lt;/p&gt;
&lt;p&gt;This first post is basically just a bullet list summarizing the graphics capabilities of the platform:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Write games in high performance &lt;strong&gt;native C++ &lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Or you can interop between XAML and C++/D3D, similar to the Silverlight/XNA interop feature in Mango&lt;/li&gt;
&lt;li&gt;Graphics APIs are a subset of Windows 8, so it&amp;rsquo;s easy to move code back and forth between phones, tablets, and desktop PCs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Direct3D 11.1 &lt;/strong&gt;API, targeting &lt;strong&gt;feature level 9.3 &lt;/strong&gt;hardware capabilities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DirectXMath &lt;/strong&gt;provides high performance SIMD vector math, optimized for SSE and NEON &lt;!--EndFragment--&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;XAudio2 &lt;/strong&gt;provides game focused audio playback, mixing, and effects &lt;em&gt;(ok, you got me, this one isn't graphics)&lt;/em&gt;&lt;!--EndFragment--&gt;&lt;/li&gt;
&lt;li&gt;Not all Windows graphics components are supported on phone
&lt;ul&gt;
&lt;li&gt;No WIC - &lt;i&gt;use &lt;a href="http://directxtex.codeplex.com/" target="_blank"&gt;DirectXTex&lt;/a&gt; to preconvert textures to .dds format, then &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt; to load them&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;No Direct2D or DirectWrite - &lt;i&gt;use &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt; instead&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;No legacy features such as GDI, D3DX, or fixed function - &lt;i&gt;parts of these can be replaced with &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt;&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;What does D3D11 feature level 9.3 give you?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Shader model &lt;strong&gt;4_0_level_9_3 &lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Max texture size 4096&lt;/li&gt;
&lt;li&gt;BC1-BC3 texture compression&lt;/li&gt;
&lt;li&gt;Floating point texture formats&lt;/li&gt;
&lt;li&gt;Conditional non-power-of-2 textures&amp;nbsp; (can&amp;rsquo;t use wrap addressing or have mipmaps)&lt;/li&gt;
&lt;li&gt;Multiple rendertargets&lt;/li&gt;
&lt;li&gt;Hardware instancing&lt;/li&gt;
&lt;li&gt;Occlusion queries&lt;/li&gt;
&lt;li&gt;Separate alpha blend&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, you read that right.&amp;nbsp; Shader model 4_0_level_9_3 means that programmable shaders are now fully supported on Windows Phone.&amp;nbsp; But what is this 4_0_level_9_3 thing, you may well ask?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Not quite the same as D3D9 shader model 2.0&lt;/li&gt;
&lt;li&gt;Uses HLSL 4.0 syntax&lt;/li&gt;
&lt;li&gt;Similar features to vs_2_a and ps_2_b&amp;nbsp; (think of it as 2.0 turned up to 11 :-)&lt;/li&gt;
&lt;li&gt;Long pixel shaders (512 instructions)&lt;/li&gt;
&lt;li&gt;Dynamic flow control&lt;/li&gt;
&lt;li&gt;Gradient instructions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So what notable D3D11 features are NOT included in feature level 9.3?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No geometry shaders&lt;/li&gt;
&lt;li&gt;No hull/domain shaders&lt;/li&gt;
&lt;li&gt;No DirectCompute&lt;/li&gt;
&lt;li&gt;No resource arrays&lt;/li&gt;
&lt;li&gt;No BC4&amp;ndash;BC7 compression&lt;/li&gt;
&lt;li&gt;No vertex texture fetch&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Another way to think of this: feature level 9.3 is basically the same as the &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2010/03/12/reach-vs-hidef.aspx" target="_blank"&gt;XNA HiDef profile&lt;/a&gt;, except without vertex texture fetch.&lt;/p&gt;
&lt;p&gt;Anything else important you should know?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Windows Phone 8 uses a tiled GPU architecture, so for best performance you'll need to understand how to use the D3D11_MAP_WRITE and D3D11_COPY flags to specify DISCARD and NOOVERWRITE behaviors, and when to call ID3D11DeviceContext1::DiscardView&amp;nbsp; &lt;i&gt;(ooh, good topic for future articles)&lt;/i&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Native D3D apps handle their own rotation: this isn&amp;rsquo;t &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2010/07/12/orientation-and-rotation-on-windows-phone.aspx" target="_blank"&gt;automatic like in XNA&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Windows Phone 8 device manufacturers can choose one of three screen resolutions:
&lt;ul&gt;
&lt;li&gt;480x800&lt;/li&gt;
&lt;li&gt;720x1280&lt;/li&gt;
&lt;li&gt;768x1280&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Windows Phone 8 includes the same &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2010/07/12/resolution-and-scaling-on-windows-phone.aspx" target="_blank"&gt;hardware scaler &lt;/a&gt;feature as WP7.&amp;nbsp; Use this to draw at the same resolution on all devices (simplifying development) or to draw fewer pixels for better performance.&amp;nbsp; Use the new DXGI_SCALING_ASPECT_RATIO_STRETCHED mode.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I think this is a pretty exciting set of capabilities, and am looking forward to seeing what y&amp;rsquo;all will be able to do with it.&amp;nbsp; To whet your appetite, check out these screenshots from an HDR rendering demo created by my colleague Adrian.&amp;nbsp; It's crazy that this does on a phone what would have been impossible on a &lt;a href="http://en.wikipedia.org/wiki/Xbox" target="_blank"&gt;high end gaming console&lt;/a&gt; of just 10 years ago, and at a higher resolution to boot!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;blockquote&gt;
&lt;table style="width: 1019px; height: 503px;" border="0" cellpadding="2" cellspacing="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="133"&gt;
&lt;p&gt;&lt;img style="display: inline;" title="ss2" alt="ss2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/0160.ss2_5F00_2F8DE39F.jpg" height="480" width="300" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="133"&gt;
&lt;p style="margin-right: 0px;" dir="ltr"&gt;&lt;img style="display: inline;" title="ss1" alt="ss1" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/3716.ss1_5F00_08539A6A.jpg" height="480" width="300" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="133"&gt;
&lt;p style="margin-right: 0px;" dir="ltr"&gt;&lt;img style="display: inline;" title="ss4" alt="ss4" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/1663.ss4_5F00_1625E065.jpg" height="480" width="300" /&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10364282" width="1" height="1"&gt;</description></item><item><title>DirectXTK PrimitiveBatch helper makes it easy to draw user primitives with D3D11</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/10/12/directxtk-primitivebatch-helper-makes-it-easy-to-draw-user-primitives-with-d3d11.aspx</link><pubDate>Sat, 13 Oct 2012 00:45:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10359296</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10359296</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/10/12/directxtk-primitivebatch-helper-makes-it-easy-to-draw-user-primitives-with-d3d11.aspx#comments</comments><description>&lt;p&gt;The latest version of &lt;a target="_blank" href="http://directxtk.codeplex.com/"&gt;DirectXTK&lt;/a&gt; adds a PrimitiveBatch helper, for easily and efficiently drawing dynamically generated geometry such as lines or triangles.&amp;nbsp; This fills the same role as the legacy D3D9 APIs DrawPrimitiveUP and DrawIndexedPrimitiveUP.&amp;nbsp; PrimitiveBatch manages the vertex and index buffers for you, using DISCARD and NO_OVERWRITE hints to avoid stalling the GPU pipeline.&amp;nbsp; It automatically merges adjacent draw requests, so if you call DrawLine 100 times in a row, only a single GPU draw call will be generated.&lt;br /&gt;&lt;br /&gt;PrimitiveBatch is responsible for setting the vertex buffer, index buffer, and primitive topology, then issuing the final draw call. Unlike the higher level SpriteBatch helper, it does not provide shaders, set the input layout, or set any state objects. PrimitiveBatch is often used in conjunction with BasicEffect and the structures from VertexTypes.h, but it can work with any other shader or vertex formats of your own.&lt;br /&gt;&lt;br /&gt;To initialize a PrimitiveBatch for drawing VertexPositionColor data:&lt;/p&gt;
&lt;pre&gt;    std::unique_ptr&amp;lt;PrimitiveBatch&amp;lt;VertexPositionColor&amp;gt;&amp;gt; primitiveBatch(new PrimitiveBatch&amp;lt;VertexPositionColor&amp;gt;(deviceContext));&lt;/pre&gt;
&lt;p&gt;To draw a line:&lt;/p&gt;
&lt;pre&gt;    basicEffect-&amp;gt;Apply(deviceContext);

    deviceContext-&amp;gt;IASetInputLayout(inputLayout);

    primitiveBatch-&amp;gt;Begin();
    primitiveBatch-&amp;gt;DrawLine(VertexPositionColor(...), VertexPositionColor(...));
    primitiveBatch-&amp;gt;End();&lt;/pre&gt;
&lt;p&gt;PrimitiveBatch provides five drawing methods:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DrawLine(v1, v2)&lt;/li&gt;
&lt;li&gt;DrawTriangle(v1, v2, v3)&lt;/li&gt;
&lt;li&gt;DrawQuad(v1, v2, v3, v4)&lt;/li&gt;
&lt;li&gt;Draw(topology, vertices, vertexCount)&lt;/li&gt;
&lt;li&gt;DrawIndexed(topology, indices, indexCount, vertices, vertexCount)&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10359296" width="1" height="1"&gt;</description></item><item><title>DirectXTK October 2012 release</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/10/02/directxtk-october-2012-release.aspx</link><pubDate>Tue, 02 Oct 2012 23:58:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10355323</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10355323</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/10/02/directxtk-october-2012-release.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectX Tool Kit&lt;/a&gt; has been updated with two new features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Added a ScreenGrab module for easily saving rendertarget contents into .dds or other image formats&lt;/li&gt;    &lt;li&gt;Extended GeometricPrimitive.h with a new CreateGeoSphere method&amp;#160; &lt;em&gt;(thanks to my colleague Adrian Tsai for contributing this code!)&lt;/em&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There are also some minor tweaks and bugfixes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Moved DDSTextureLoader and WICTextureLoader into the DirectX C++ namespace&lt;/li&gt;    &lt;li&gt;Renamed project files for better consistency&lt;/li&gt;    &lt;li&gt;Extended WICTextureLoader to support Windows 8 96bpp floating point formats&lt;/li&gt;    &lt;li&gt;Updated Win32 desktop projects to use Windows Vista (0x0600) rather than Windows 7 (0x0601) APIs&lt;/li&gt;    &lt;li&gt;Tweaked SpriteBatch.cpp to workaround an ARM NEON compiler codegen bug&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So what is this GeoSphere thingie, you may well ask, and why might it be better than a plain old fashioned UV sphere primitive?&amp;#160; Shamelessly plagiarizing an explanation from Adrian:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Generally speaking, geospheres are more efficient than non-geodesic spheres (which are typically generated by using rings of vertices along the latitudes/longitudes of the sphere). In an ideal geosphere each triangle has the same area, which means an even distribution of vertices around the sphere. This means geospheres can give better visual quality at the same vertex count.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;My implementation approximates an ideal geosphere by recursively subdividing a starting shape – in this case an octahedron. Almost any regular polyhedron can be used, but octahedrons or icosahedrons typically give best results. Starting with an icosahedron would give slightly more accurate results (i.e. it would produce an output closer to an ideal geosphere) but would make the implementation more complex.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Each successive subdivision increases the number of vertices by a factor of four. Hence the total number of vertices is approximately 4^(N+1), where N is the number of tessellations specified in CreateGeoSphere. A value of 3 or 4 is usually enough to give good results.     &lt;br /&gt;&lt;/em&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;table border="0" cellspacing="0" cellpadding="2" width="500"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="246"&gt;           &lt;p align="center"&gt;&lt;em&gt;CreateSphere                &lt;br /&gt;Tessellation = 11                 &lt;br /&gt;276 vertices&lt;/em&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top" width="6"&gt;&lt;em&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/em&gt;&lt;/td&gt;          &lt;td valign="top" width="246"&gt;           &lt;p align="center"&gt;&lt;em&gt;CreateGeoSphere                &lt;br /&gt;Tessellation = 3                 &lt;br /&gt;277 vertices&lt;/em&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="246"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/7215.image_5F00_5BA2D21B.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/8875.image_5F00_thumb_5F00_067B362E.png" width="240" height="239" /&gt;&lt;/a&gt;&lt;/td&gt;          &lt;td valign="top" width="6"&gt;&amp;nbsp;&lt;/td&gt;          &lt;td valign="top" width="246"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/8666.image_5F00_144D7C29.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/6523.image_5F00_thumb_5F00_0D2E3FB1.png" width="240" height="239" /&gt;&lt;/a&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt;&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10355323" width="1" height="1"&gt;</description></item><item><title>DirectXTK samples?</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/07/07/directxtk-samples.aspx</link><pubDate>Sat, 07 Jul 2012 17:31:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10327728</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10327728</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/07/07/directxtk-samples.aspx#comments</comments><description>&lt;p&gt;Lots of people asking for samples for the DirectX Tool Kit - sorry I haven't had a chance to work on such a thing yet&amp;#160; (I'm kinda busy right now getting &lt;a href="http://channel9.msdn.com/Events/Windows-Phone/Summit" target="_blank"&gt;Windows Phone 8&lt;/a&gt; finished :-)&lt;/p&gt;  &lt;p&gt;Would appreciate feedback on what platform you most want to see samples for (Win8 Metro? Classic Desktop?) and which areas of DirectXTK to prioritize (SpriteBatch? BasicEffect? DDS loading? other?)&lt;/p&gt;  &lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10327728" width="1" height="1"&gt;</description></item><item><title>DirectX Tool Kit is now on CodePlex</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/06/18/directx-tool-kit-is-now-on-codeplex.aspx</link><pubDate>Mon, 18 Jun 2012 21:57:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10321512</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>17</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10321512</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/06/18/directx-tool-kit-is-now-on-codeplex.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;DirectX Tool Kit&lt;/strong&gt; (aka &lt;strong&gt;DirectXTK&lt;/strong&gt;) is a collection of helper classes for writing Direct3D 11 code for Metro style apps, Windows 8 Desktop, and Windows 7 'classic' applications in C++.&lt;/p&gt;  &lt;p&gt;Features:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SpriteBatch - simple &amp;amp; efficient 2D sprite rendering &lt;/li&gt;    &lt;li&gt;SpriteFont - bitmap based text rendering &lt;/li&gt;    &lt;li&gt;Effects - set of built-in shaders for common rendering tasks &lt;/li&gt;    &lt;li&gt;GeometricPrimitive - draws basic shapes such as cubes and spheres &lt;/li&gt;    &lt;li&gt;CommonStates - factory providing commonly used D3D state objects &lt;/li&gt;    &lt;li&gt;VertexTypes - structures for commonly used vertex data formats &lt;/li&gt;    &lt;li&gt;DDSTextureLoader - light-weight DDS file texture loader &lt;/li&gt;    &lt;li&gt;WICTextureLoader - WIC-based image file texture loader &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://directxtk.codeplex.com/"&gt;http://directxtk.codeplex.com/&lt;/a&gt;&lt;/p&gt;    &lt;hr /&gt;    &lt;p&gt;&lt;strong&gt;DirectXTex&lt;/strong&gt; is a shared source library for reading and writing DDS files, and performing various texture content processing operations including resizing, format conversion, mip-map generation, block compression for Direct3D runtime texture resources, and height-map to normal-map conversion. This library makes use of the Windows Image Component (WIC) APIs. It also includes a simple .TGA reader and writer since this image file format is commonly used for texture content processing pipelines, but is not currently supported by a built-in WIC codec.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://directxtex.codeplex.com/"&gt;http://directxtex.codeplex.com/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10321512" width="1" height="1"&gt;</description></item><item><title>DirectXTK now includes SpriteFont</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/05/02/directxtk-now-includes-spritefont.aspx</link><pubDate>Thu, 03 May 2012 00:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10300207</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10300207</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/05/02/directxtk-now-includes-spritefont.aspx#comments</comments><description>&lt;p&gt;The &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2012/03/02/spritebatch-and-basiceffect-for-c-direct3d-11.aspx" target="_blank"&gt;DirectX Tool Kit&lt;/a&gt; (&lt;em&gt;DirectXTK&lt;/em&gt;) has been updated with the addition of a SpriteFont implementation, similar to the one in XNA.&lt;/p&gt;
&lt;p&gt;Get it here: &lt;a href="http://directxtk.codeplex.com/"&gt;DirectXTK&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Shamelessly plagiarizing the readme file&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;This is a native D3D11 implementation of a bitmap font renderer, similar to the SpriteFont type from XNA Game Studio, plus a command line tool (MakeSpriteFont) for building fonts into bitmap format. It is less fully featured than Direct2D and DirectWrite, but may be useful for those who want something simpler and lighter weight.&lt;/p&gt;
&lt;p&gt;At build time:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    MakeSpriteFont.exe &lt;span class="str"&gt;"Comic Sans"&lt;/span&gt; myfile.spritefont /FontSize:16&lt;/pre&gt;
&lt;p&gt;During initialization:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    std::unique_ptr&amp;lt;SpriteBatch&amp;gt; spriteBatch(&lt;span class="kwrd"&gt;new&lt;/span&gt; SpriteBatch(deviceContext));&lt;br /&gt;
    std::unique_ptr&amp;lt;SpriteFont&amp;gt; spriteFont(&lt;span class="kwrd"&gt;new&lt;/span&gt; SpriteFont(device, L&lt;span class="str"&gt;"myfile.spritefont"&lt;/span&gt;));&lt;/pre&gt;
&lt;p&gt;Simple drawing:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;    spriteBatch-&amp;gt;Begin();&lt;br /&gt;
    spriteFont-&amp;gt;DrawString(spriteBatch.get(), L&lt;span class="str"&gt;"Hello, world!"&lt;/span&gt;, XMFLOAT2(x, y));&lt;br /&gt;
    spriteBatch-&amp;gt;End();&lt;/pre&gt;
&lt;p&gt;The Draw method has several overloads with parameters controlling color, rotation, origin point, scaling, horizontal or vertical mirroring, and layer depth. These work the same way as the equivalent SpriteBatch::Draw parameters.&lt;/p&gt;
&lt;p&gt;SpriteFont has three constructors:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pass a filename string to read a binary file created by MakeSpriteFont&lt;/li&gt;
&lt;li&gt;Pass a buffer containing a MakeSpriteFont binary that was already loaded some other way&lt;/li&gt;
&lt;li&gt;Pass an array of Glyph structs if you prefer to entirely bypass MakeSpriteFont&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you try to draw or call MeasureString with a character that is not included in the font, by default you will get an exception. Use SetDefaultCharacter to specify some other character that will be automatically substituted in place of any that are missing.&lt;/p&gt;
&lt;p&gt;This implementation supports sparse fonts, so if you are localizing into languages such as Chinese, Japanese, or Korean, you can build a spritefont including only the specific characters needed by your program. This is usually a good idea for CJK languages, as a complete CJK character set is too large to fit in a Direct3D texture! (if you need full CJK support, Direct2D or DirectWrite would be a better choice). SpriteFont does not support combining characters or right-to-left (RTL) layout, so it will not work for languages with complex layout requirements such as Arabic or Thai.&lt;/p&gt;
&lt;p&gt;The MakeSpriteFont tool can process any TrueType font that is installed on your system (using GDI+ to rasterize them into a bitmap) or it can import character glyphs from a specially formatted bitmap file. This latter option allows you to create multicolored fonts, drawing special effects such as gradients or drop shadows directly into your glyph textures. Characters should be arranged in a grid ordered from top left to bottom right. Monochrome fonts should use white for solid areas and black for transparent areas. To include multicolored characters, add an alpha channel to the bitmap and use that to control which parts of each character are solid. The spaces between characters and around the edges of the grid should be filled with bright pink (red=255, green=0, blue=255). It doesn't matter if your grid includes lots of wasted space, because the converter will rearrange characters, packing everything as tightly as possible.&lt;/p&gt;
&lt;p&gt;See readme.txt for a list of MakeSpriteFont command line options.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10300207" width="1" height="1"&gt;</description></item><item><title>A reusable, reflection based command-line parser</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/04/20/a-reusable-reflection-based-command-line-parser.aspx</link><pubDate>Fri, 20 Apr 2012 23:55:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10296014</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10296014</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/04/20/a-reusable-reflection-based-command-line-parser.aspx#comments</comments><description>&lt;p&gt;I often find myself writing little throwaway utilities to help with other tasks, and many of these utilities need to parse command lines.&amp;#160; There are myriad ways to do this in C#, ranging from the quick and dirty to the infinitely flexible and confusing.&amp;#160; The middle ground approach shown here is not especially unique, but I have found it useful over the years, and thought I would post it here in case you do too.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/7028.CommandLineParser.zip" target="_blank"&gt;&lt;strong&gt;Get it here&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Use it like so:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; CatSpecies
    {
        Tabby,
        Siamese,
        Alley,
    }


    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Options
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; NumberOfCats = 23;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; CatSpecies Species = CatSpecies.Siamese;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ChaseTheCats;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; PostToYouTube;
    }


    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program
    {
        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
        {
            var options = &lt;span class="kwrd"&gt;new&lt;/span&gt; Options();
            var parser = &lt;span class="kwrd"&gt;new&lt;/span&gt; CommandLineParser(options);

            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!parser.ParseCommandLine(args))
                &lt;span class="kwrd"&gt;return&lt;/span&gt; 1;

            DoStuff(options);

            &lt;span class="kwrd"&gt;return&lt;/span&gt; 0;
        }
    }&lt;/pre&gt;

&lt;p&gt;You can run this program like so:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    MyProgram /NumberOfCats:10 /species:alley /posttoyoutube&lt;/pre&gt;

&lt;p&gt;It automatically generates usage help if you pass invalid values:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font color="#008000"&gt;    &amp;gt; MyProgram /foo&lt;/font&gt;
&lt;font color="#000000"&gt;    Unknown option &lt;span class="str"&gt;'foo'&lt;/span&gt;

    Usage: MyProgram

    Options:
        /NumberOfCats:&lt;span class="kwrd"&gt;value&lt;/span&gt;
        /Species:&lt;span class="kwrd"&gt;value&lt;/span&gt;
        /ChaseTheCats
        /PostToYouTube&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;You can mark some options as required:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Options
    {
        [CommandLineParser.Required]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; NumberOfCats;

        [CommandLineParser.Required]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; CatSpecies Species;

        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; ChaseTheCats;
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; PostToYouTube;
    }&lt;/pre&gt;

&lt;p&gt;Required options are specified without the /ParameterName: prefix:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    MyProgram 10 alley /posttoyoutube&lt;/pre&gt;

&lt;p&gt;Of course you will get an error if any required parameters are not specified.&lt;/p&gt;

&lt;p&gt;The parser also supports list types, which allow a single parameter to be specified more than once (each entry will be appended to the list).&amp;#160; For instance:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Options
    {
        [CommandLineParser.Required]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt; Names = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;();

        [CommandLineParser.Name(&lt;span class="str"&gt;&amp;quot;Color&amp;quot;&lt;/span&gt;)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; List&amp;lt;System.Drawing.Color&amp;gt; Colors = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;System.Drawing.Color&amp;gt;();
    }&lt;/pre&gt;

&lt;p&gt;This allows you to call:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    MyProgram shawn tracy rhys boo kess finch /color:red /color:white&lt;/pre&gt;

&lt;p&gt;Note that I was able to specify System.Drawing.Color values by string name (eg. &amp;quot;red&amp;quot;).&amp;#160; This works because the parser uses TypeDescriptor/TypeConverter to convert string arguments into whatever types it finds in the Options object.&amp;#160; If you have custom types, just write a matching TypeConverter and you'll be able to specify them directly as argument values.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10296014" width="1" height="1"&gt;</description></item><item><title>CreateThread for Windows 8 Metro</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx</link><pubDate>Mon, 12 Mar 2012 20:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10281576</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>17</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10281576</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/03/12/createthread-for-windows-8-metro.aspx#comments</comments><description>&lt;p&gt;The WinRT programming environment, which is used to create Metro applications for Windows 8, replaces the old Win32 threading APIs such as &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453%28v=vs.85%29.aspx" target="_blank"&gt;CreateThread&lt;/a&gt; with a new &lt;a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.system.threading.threadpool" target="_blank"&gt;ThreadPool::RunAsync&lt;/a&gt; API.&amp;nbsp; This is generally a good thing (ThreadPool is better than CreateThread for several reasons) but it can be a pain when trying to port existing code that depends on those older APIs.&lt;/p&gt;
&lt;p&gt;Porting shim to the rescue!&amp;nbsp; This code emulates a subset of the Win32 threading APIs as a wrapper on top of WinRT ThreadPool:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;CreateThread&lt;/li&gt;
&lt;li&gt;CREATE_SUSPENDED and ResumeThread&lt;/li&gt;
&lt;li&gt;Partial support for SetThreadPriority&amp;nbsp; (see comments in the header for details)&lt;/li&gt;
&lt;li&gt;Sleep&lt;/li&gt;
&lt;li&gt;Thread local storage&amp;nbsp; (TlsAlloc, TlsFree, TlsGetValue, TlsSetValue, plus see header comments about TlsShutdown)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Get it here:&amp;nbsp; &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20/8741.ThreadEmulation.zip" target="_blank"&gt;ThreadEmulation.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I recommend only using this for porting legacy code.&amp;nbsp; When writing new Metro applications, it is better to directly use WinRT ThreadPool.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10281576" width="1" height="1"&gt;</description></item><item><title>SpriteBatch and BasicEffect for C++ Direct3D 11</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/03/02/spritebatch-and-basiceffect-for-c-direct3d-11.aspx</link><pubDate>Fri, 02 Mar 2012 21:38:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10276733</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>33</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10276733</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/03/02/spritebatch-and-basiceffect-for-c-direct3d-11.aspx#comments</comments><description>&lt;p&gt;Over the Christmas break I spent some time porting the &lt;a href="http://create.msdn.com/en-US/education/catalog/sample/stock_effects" target="_blank"&gt;built-in XNA effects&lt;/a&gt; (BasicEffect, SkinnedEffect, etc.) to native C++ using Direct3D 11.&amp;nbsp; Finding that strangely enjoyable, I went on to make a C++ version of SpriteBatch, and also ported the XNA &lt;a href="http://create.msdn.com/en-US/education/catalog/sample/primitives_3d" target="_blank"&gt;Primitives 3D sample&lt;/a&gt;, built-in state objects, and helper vertex types.&amp;nbsp; And my colleague &lt;a href="http://blogs.msdn.com/b/chuckw/" target="_blank"&gt;Chuck Walbourn&lt;/a&gt; chimed in with some code for easily loading Direct3D 11 textures.&lt;/p&gt;
&lt;div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:c8906790-1d15-46ce-b1ce-14eabba0e102" class="wlWriterEditableSmartContent"&gt;
&lt;p&gt;Get it here: &lt;a href="http://directxtk.codeplex.com/" target="_blank"&gt;DirectXTK&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Changelog:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;3/5 - fixed bug in SpriteBatch with &amp;gt; 2048 sprites in a batch&lt;em&gt;&amp;nbsp; (thanks Pete Lewis!)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;3/8 - added separate project files for Win8 Metro builds&amp;nbsp; &lt;em&gt;(thanks George Clingerman!)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;5/2 - added SpriteFont implementation&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;Supported operating systems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Windows 8 Consumer Preview (both Metro and Desktop)&lt;/li&gt;
&lt;li&gt;Windows 7&lt;/li&gt;
&lt;li&gt;Windows Vista with &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ee416644.aspx" target="_blank"&gt;DirectX 11 update&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Supported compilers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Visual Studio 11 (&lt;a href="http://blogs.msdn.com/b/chuckw/archive/2012/02/29/visual-studio-11-beta.aspx" target="_blank"&gt;currently in beta&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Visual Studio 2010 plus the standalone &lt;a href="http://msdn.microsoft.com/en-us/windows/hardware/hh852363" target="_blank"&gt;Windows 8.0 SDK&lt;/a&gt;&amp;nbsp; (you need the SDK to get the latest version of &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh437833.aspx" target="_blank"&gt;DirectXMath&lt;/a&gt;, which this code depends on)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How to use it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Unzip, load the solution into Visual Studio, and build it&lt;/li&gt;
&lt;li&gt;Link your program with the resulting static lib&lt;/li&gt;
&lt;li&gt;Add the &lt;em&gt;Inc&lt;/em&gt;&amp;nbsp; folder to your include path&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To draw sprites:&lt;/p&gt;
&lt;pre class="str"&gt;    #include &lt;span class="str"&gt;"SpriteBatch.h"&lt;br /&gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; DirectX;

    std::unique_ptr&amp;lt;SpriteBatch&amp;gt; spriteBatch(&lt;span class="kwrd"&gt;new&lt;/span&gt; SpriteBatch(deviceContext));

    spriteBatch-&amp;gt;Begin();
    spriteBatch-&amp;gt;Draw(texture, XMFLOAT2(x, y));
    spriteBatch-&amp;gt;End();&lt;/pre&gt;
&lt;p&gt;To draw geometry using BasicEffect:&lt;/p&gt;
&lt;pre class="str"&gt;    #include &lt;span class="str"&gt;"BasicEffect.h"&lt;br /&gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; DirectX;

    std::unique_ptr&amp;lt;BasicEffect&amp;gt; effect(&lt;span class="kwrd"&gt;new&lt;/span&gt; BasicEffect(device));

    effect-&amp;gt;SetWorld(world);
    effect-&amp;gt;SetView(view);
    effect-&amp;gt;SetProjection(projection);

    effect-&amp;gt;SetTexture(cat);
    effect-&amp;gt;SetTextureEnabled(&lt;span class="kwrd"&gt;true&lt;/span&gt;);

    effect-&amp;gt;EnableDefaultLighting();

    effect-&amp;gt;Apply(deviceContext);

    deviceContext-&amp;gt;IASetInputLayout(...);
    deviceContext-&amp;gt;IASetVertexBuffers(...);
    deviceContext-&amp;gt;IASetIndexBuffer(...);
    deviceContext-&amp;gt;IASetPrimitiveTopology(...);

    deviceContext-&amp;gt;DrawIndexed(...);&lt;/pre&gt;
&lt;p&gt;To draw geometric primitives:&lt;/p&gt;
&lt;pre class="str"&gt;    #include &lt;span class="str"&gt;"GeometricPrimitive.h"&lt;br /&gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;namespace&lt;/span&gt; DirectX;

    std::unique_ptr&amp;lt;GeometricPrimitive&amp;gt; teapot(GeometricPrimitive::CreateTeapot(deviceContext));

    teapot-&amp;gt;Draw(world, view, projection, Colors::CornflowerBlue);&lt;/pre&gt;
&lt;p&gt;See the readme inside the zip for more info.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10276733" width="1" height="1"&gt;</description></item><item><title>Bloom on Windows Phone</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/01/19/bloom-on-windows-phone.aspx</link><pubDate>Fri, 20 Jan 2012 01:04:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10258697</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10258697</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/01/19/bloom-on-windows-phone.aspx#comments</comments><description>&lt;p&gt;Ok, &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2011/12/29/is-spritebatch-turing-complete.aspx" target="_blank"&gt;silliness aside&lt;/a&gt;, is it possible to implement an efficient bloom effect on Windows Phone without custom shaders?&lt;/p&gt;  &lt;p&gt;Bloom consists of three operations:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Identify which parts of the image should be bloomed &lt;/li&gt;    &lt;li&gt;Blur those parts &lt;/li&gt;    &lt;li&gt;Combine blurred bloomy bits with the original image &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;There are many choices for how each operation should be implemented, the combination of which determines the visual result.&amp;#160; In the &lt;a href="http://create.msdn.com/en-US/education/catalog/sample/bloom" target="_blank"&gt;XNA bloom sample&lt;/a&gt;:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Bright areas are identified by subtracting a threshold value, then scaling back up to preserve full color range: (value - threshold) / (1 - threshold) &lt;/li&gt;    &lt;li&gt;Blur is applied using a two pass separable Gaussian filter &lt;/li&gt;    &lt;li&gt;To avoid excessively bright areas, the final combine operation is: (base * (1 – bloom)) + bloom&amp;#160; (done in a pixel shader that also provides brightness and saturation adjustment for both images) &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;There is no good way to adjust saturation without shaders, but everything else in this design can be done with simple alpha blending operations:&lt;/p&gt;  &lt;pre class="_shawn_csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.Xna.Framework;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Microsoft.Xna.Framework.Graphics;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; BloomPostprocess
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; BloomComponent : DrawableGameComponent
    {
        &lt;span class="rem"&gt;// Adjust these values to change visual appearance.&lt;/span&gt;
        &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;float&lt;/span&gt; BloomThreshold = 0.25f;
        &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;float&lt;/span&gt; BloomIntensity = 1.5f;
        &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; BlurPasses = 4;


        &lt;span class="rem"&gt;// result = source - destination&lt;/span&gt;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; BlendState extractBrightColors = &lt;span class="kwrd"&gt;new&lt;/span&gt; BlendState
        {
            ColorSourceBlend = Blend.One,
            AlphaSourceBlend = Blend.One,

            ColorDestinationBlend = Blend.One,
            AlphaDestinationBlend = Blend.One,

            ColorBlendFunction = BlendFunction.Subtract,
            AlphaBlendFunction = BlendFunction.Subtract,
        };


        &lt;span class="rem"&gt;// result = source + destination&lt;/span&gt;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; BlendState additiveBlur = &lt;span class="kwrd"&gt;new&lt;/span&gt; BlendState
        {
            ColorSourceBlend = Blend.One,
            AlphaSourceBlend = Blend.One,

            ColorDestinationBlend = Blend.One,
            AlphaDestinationBlend = Blend.One,
        };


        &lt;span class="rem"&gt;// result = source + (destination * (1 - source))&lt;/span&gt;
        &lt;span class="kwrd"&gt;static&lt;/span&gt; BlendState combineFinalResult = &lt;span class="kwrd"&gt;new&lt;/span&gt; BlendState
        {
            ColorSourceBlend = Blend.One,
            AlphaSourceBlend = Blend.One,

            ColorDestinationBlend = Blend.InverseSourceColor,
            AlphaDestinationBlend = Blend.InverseSourceColor,
        };


        SpriteBatch spriteBatch;

        RenderTarget2D scene;
        RenderTarget2D halfSize;
        RenderTarget2D quarterSize;
        RenderTarget2D quarterSize2;


        &lt;span class="kwrd"&gt;public&lt;/span&gt; BloomComponent(Game game)
            : &lt;span class="kwrd"&gt;base&lt;/span&gt;(game)
        { }


        &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; LoadContent()
        {
            spriteBatch = &lt;span class="kwrd"&gt;new&lt;/span&gt; SpriteBatch(GraphicsDevice);

            PresentationParameters pp = GraphicsDevice.PresentationParameters;

            &lt;span class="kwrd"&gt;int&lt;/span&gt; w = pp.BackBufferWidth;
            &lt;span class="kwrd"&gt;int&lt;/span&gt; h = pp.BackBufferHeight;

            scene = &lt;span class="kwrd"&gt;new&lt;/span&gt; RenderTarget2D(GraphicsDevice, w, h, &lt;span class="kwrd"&gt;false&lt;/span&gt;, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents);
            halfSize = &lt;span class="kwrd"&gt;new&lt;/span&gt; RenderTarget2D(GraphicsDevice, w / 2, h / 2, &lt;span class="kwrd"&gt;false&lt;/span&gt;, pp.BackBufferFormat, DepthFormat.None);
            quarterSize = &lt;span class="kwrd"&gt;new&lt;/span&gt; RenderTarget2D(GraphicsDevice, w / 4, h / 4, &lt;span class="kwrd"&gt;false&lt;/span&gt;, pp.BackBufferFormat, DepthFormat.None);
            quarterSize2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; RenderTarget2D(GraphicsDevice, w / 4, h / 4, &lt;span class="kwrd"&gt;false&lt;/span&gt;, pp.BackBufferFormat, DepthFormat.None);
        }


        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; BeginDraw()
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (Visible)
            {
                GraphicsDevice.SetRenderTarget(scene);
            }
        }


        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Draw(GameTime gameTime)
        {
            &lt;span class="rem"&gt;// Shrink to half size.&lt;/span&gt;
            GraphicsDevice.SetRenderTarget(halfSize);
            DrawSprite(scene, BlendState.Opaque);

            &lt;span class="rem"&gt;// Shrink again to quarter size, at the same time applying the threshold subtraction.&lt;/span&gt;
            GraphicsDevice.SetRenderTarget(quarterSize);
            GraphicsDevice.Clear(&lt;span class="kwrd"&gt;new&lt;/span&gt; Color(BloomThreshold, BloomThreshold, BloomThreshold));
            DrawSprite(halfSize, extractBrightColors);

            &lt;span class="rem"&gt;// Kawase blur filter (see http://developer.amd.com/media/gpu_assets/Oat-ScenePostprocessing.pdf)&lt;/span&gt;
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; BlurPasses; i++)
            {
                GraphicsDevice.SetRenderTarget(quarterSize2);
                GraphicsDevice.Clear(Color.Black);

                &lt;span class="kwrd"&gt;int&lt;/span&gt; w = quarterSize.Width;
                &lt;span class="kwrd"&gt;int&lt;/span&gt; h = quarterSize.Height;

                &lt;span class="kwrd"&gt;float&lt;/span&gt; brightness = 0.25f;

                &lt;span class="rem"&gt;// On the first pass, scale brightness to restore full range after the threshold subtraction.&lt;/span&gt;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (i == 0)
                    brightness /= (1 - BloomThreshold);

                &lt;span class="rem"&gt;// On the final pass, apply tweakable intensity adjustment.&lt;/span&gt;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (i == BlurPasses - 1)
                    brightness *= BloomIntensity;

                Color tint = &lt;span class="kwrd"&gt;new&lt;/span&gt; Color(brightness, brightness, brightness);

                spriteBatch.Begin(0, additiveBlur);

                spriteBatch.Draw(quarterSize, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(0.5f, 0.5f), &lt;span class="kwrd"&gt;new&lt;/span&gt; Rectangle(i + 1, i + 1, w, h), tint);
                spriteBatch.Draw(quarterSize, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(0.5f, 0.5f), &lt;span class="kwrd"&gt;new&lt;/span&gt; Rectangle(-i, i + 1, w, h), tint);
                spriteBatch.Draw(quarterSize, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(0.5f, 0.5f), &lt;span class="kwrd"&gt;new&lt;/span&gt; Rectangle(i + 1, -i, w, h), tint);
                spriteBatch.Draw(quarterSize, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(0.5f, 0.5f), &lt;span class="kwrd"&gt;new&lt;/span&gt; Rectangle(-i, -i, w, h), tint);
                
                spriteBatch.End();

                Swap(&lt;span class="kwrd"&gt;ref&lt;/span&gt; quarterSize, &lt;span class="kwrd"&gt;ref&lt;/span&gt; quarterSize2);
            }

            &lt;span class="rem"&gt;// Combine the original scene and bloom images.&lt;/span&gt;
            GraphicsDevice.SetRenderTarget(&lt;span class="kwrd"&gt;null&lt;/span&gt;);
            DrawSprite(scene, BlendState.Opaque);
            DrawSprite(quarterSize, combineFinalResult);
        }


        &lt;span class="kwrd"&gt;void&lt;/span&gt; DrawSprite(Texture2D source, BlendState blendState)
        {
            spriteBatch.Begin(0, blendState);
            spriteBatch.Draw(source, GraphicsDevice.Viewport.Bounds, Color.White);
            spriteBatch.End();
        }


        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Swap&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;ref&lt;/span&gt; T a, &lt;span class="kwrd"&gt;ref&lt;/span&gt; T b)
        {
            T tmp = a;
            a = b;
            b = tmp;
        }
    }
}&lt;/pre&gt;


&lt;p&gt;Notes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;High quality blur filters can be expensive, so most bloom implementations do a cheap bilinear downsample to lower resolution before the ‘real’ blur.&amp;#160; The original XNA sample operates at half resolution, but in a nod to the limited bandwidth of mobile GPUs, I made this version shrink to quarter size.&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;It is possible to implement Gaussian blur (or indeed any multi-tap filter) as a series of additive and subtractive blends with suitable offsets, but that gets expensive for large filter kernels.&amp;#160; Instead I chose a Kawase blur (originally developed by Masaki Kawase for the Xbox1 game Wreckless), which cunningly exploits GPU bilinear filtering to get a not-quite-as-good-but-still-ok result more cheaply.&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;The threshold subtraction is perhaps the least intuitive operation.&amp;#160; We want (source - threshold), but the alpha blending hardware only gives us (source - destination).&amp;#160; So, we simply clear the destination rendertarget to our desired threshold value before drawing the source image!&lt;/p&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;There are two scaling operations in this bloom design: one to preserve full color range after the threshold subtraction, and a second after the blur to adjust intensity of the bloom.&amp;#160; For efficiency, I apply these adjustments during the first and last blur passes, getting them for free as a side effect of drawing work that was already taking place.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So how does it look?&lt;/p&gt;

&lt;p&gt;With BloomThreshold = 0.25f,&amp;#160; BloomIntensity = 1.5f,&amp;#160; BlurPasses = 4:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/3286.image_5F00_27321E14.png" width="640" height="406" /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With BloomThreshold = 0.5f,&amp;#160; BloomIntensity = 3,&amp;#160; BlurPasses = 6:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/0363.image_5F00_0F4B36EE.png" width="640" height="406" /&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With BloomThreshold = 0,&amp;#160; BloomIntensity = 1.5f,&amp;#160; BlurPasses = 3:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/0363.image_5F00_13750EB3.png" width="640" height="406" /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10258697" width="1" height="1"&gt;</description></item><item><title>Voting results are in!</title><link>http://blogs.msdn.com/b/shawnhar/archive/2012/01/19/voting-results-are-in.aspx</link><pubDate>Thu, 19 Jan 2012 20:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10258609</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10258609</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2012/01/19/voting-results-are-in.aspx#comments</comments><description>&lt;p&gt;Thanks for the comments about &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2011/12/29/what-should-i-write-about-next.aspx" target="_blank"&gt;what I should write about next&lt;/a&gt;.&amp;#160; Hopefully I managed to count these more accurately than the &lt;a href="http://www.guardian.co.uk/world/2012/jan/19/mitt-romney-iowa-win-recount" target="_blank"&gt;Iowa Republican party&lt;/a&gt;&amp;#160; :-)&lt;/p&gt;  &lt;blockquote&gt;   &lt;table border="1" cellspacing="0" cellpadding="2" width="184"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="130"&gt;C++&lt;/td&gt;          &lt;td valign="top" width="52"&gt;16&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="130"&gt;How GPU’s work&lt;/td&gt;          &lt;td valign="top" width="52"&gt;11&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="130"&gt;3D math&lt;/td&gt;          &lt;td valign="top" width="52"&gt;10&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="130"&gt;Game design&lt;/td&gt;          &lt;td valign="top" width="52"&gt;10&lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td valign="top" width="130"&gt;SIMD optimization&lt;/td&gt;          &lt;td valign="top" width="52"&gt;3&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/blockquote&gt;  &lt;p&gt;Of course my blog is not a democracy, so I’m not promising to actually cover these topics in that order!&amp;#160; But it is useful to know that for instance I have more readers interested in C++ than in SIMD optimization.&lt;/p&gt;  &lt;p&gt;There were also several write-in nominations:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Specifics of how XNA is implemented.&amp;#160; &lt;em&gt;It does seem like there should be a couple of interesting articles to be had here. I will have to think about exactly what they might be.&lt;/em&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Managed &amp;lt;-&amp;gt; native interop (esp. WinRT).&amp;#160; &lt;em&gt;Hmm. My immediate reaction is I don’t know enough about this topic, but I will mull it over and see if anything worthwhile comes to mind.&lt;/em&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;A couple of requests to talk about future XNA plans.&amp;#160; &lt;em&gt;Sorry, no can do. Not my team any more!&lt;/em&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Single-vote requests to write about input, component based entities, and XACT garbage.&amp;#160; &lt;em&gt;Unlikely (due to lack of knowledge / opinions / info to share) but I will bear them in mind.&lt;/em&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Thank you all!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10258609" width="1" height="1"&gt;</description></item><item><title>Is SpriteBatch Turing complete?</title><link>http://blogs.msdn.com/b/shawnhar/archive/2011/12/29/is-spritebatch-turing-complete.aspx</link><pubDate>Thu, 29 Dec 2011 22:58:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10251913</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10251913</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2011/12/29/is-spritebatch-turing-complete.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;Time for some end-of-year silliness...&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Inspired by this recent Twitter exchange:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Scionwest - &lt;em&gt;@shawnhargreaves @nickgravelyn How about post processing for WP7? I've seen people do Bloom effects and thought P.P. was not part of WP7?&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;nickgravelyn - &lt;em&gt;@Scionwest Shaders aren't available, but I've seen some clever post-processing done without custom shaders.&amp;#160; You theoretically could do CPU based &amp;quot;shaders&amp;quot;, but you can also use blend states in fun ways to achieve effects&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;(which is actually an interesting topic that I may someday return to)&lt;/p&gt;  &lt;p&gt;I found myself thinking &amp;quot;&lt;em&gt;well, of course you &lt;/em&gt;could &lt;em&gt;implement bloom, because the no-programmable-shaders Reach graphics subset on Windows Phone is &lt;a href="http://en.wikipedia.org/wiki/Turing_completeness" target="_blank"&gt;Turing complete&lt;/a&gt;, so can do anything you can imagine given sufficient ingenuity. It might not be &lt;/em&gt;easy&lt;em&gt;, &lt;/em&gt;efficient&lt;em&gt;, or &lt;/em&gt;sensible&lt;em&gt;, but anything is possible...&lt;/em&gt;&amp;quot;&lt;/p&gt;  &lt;p&gt;And then I found myself thinking, is that really true?&lt;/p&gt;  &lt;p&gt;We can add and subtract via blend states, and perform comparisons with AlphaTestEffect, which seems like it should be enough to enable arbitrary algorithms (at least if we ignore mundane practicalities such as time and space constraints :-)&amp;#160; But can I &lt;em&gt;prove &lt;/em&gt;that XNA on Windows Phone is enough to enable Turing complete GPU computation?&lt;/p&gt;  &lt;p&gt;Conway's &lt;a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" target="_blank"&gt;Game of Life&lt;/a&gt; is already proven to be a form of universal Turing machine, so I set out to see if I could implement that on the GPU without custom shaders.&lt;/p&gt;  &lt;p&gt;Starting with the default Game template, I declared two rendertargets to hold the state of my simulation:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; width = 256;
    &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; height = 128;

    RenderTarget2D currentState;
    RenderTarget2D nextState;&lt;/pre&gt;

&lt;p&gt;Plus two helper objects:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    AlphaTestEffect alphaTestEffect;

    Texture2D singleWhitePixel;&lt;/pre&gt;

&lt;p&gt;These are initialized in LoadContent:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    currentState = &lt;span class="kwrd"&gt;new&lt;/span&gt; RenderTarget2D(GraphicsDevice, width, height, &lt;span class="kwrd"&gt;false&lt;/span&gt;, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
    nextState    = &lt;span class="kwrd"&gt;new&lt;/span&gt; RenderTarget2D(GraphicsDevice, width, height, &lt;span class="kwrd"&gt;false&lt;/span&gt;, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

    alphaTestEffect = &lt;span class="kwrd"&gt;new&lt;/span&gt; AlphaTestEffect(GraphicsDevice);

    singleWhitePixel = &lt;span class="kwrd"&gt;new&lt;/span&gt; Texture2D(GraphicsDevice, 1, 1);&lt;br /&gt;
    singleWhitePixel.SetData(&lt;span class="kwrd"&gt;new&lt;/span&gt; Color[] { Color.White });&lt;/pre&gt;

&lt;p&gt;In order for it to do anything interesting, the Game of Life must be initialized to more than just zeros. This code (at the end of LoadContent) creates a single glider that will move diagonally across the screen:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    Color[] initialData = &lt;span class="kwrd"&gt;new&lt;/span&gt; Color[width * height];

    initialData[3 + 1 * width] = Color.White;
    initialData[3 + 2 * width] = Color.White;
    initialData[3 + 3 * width] = Color.White;
    initialData[2 + 3 * width] = Color.White;
    initialData[1 + 2 * width] = Color.White;

    currentState.SetData(initialData);&lt;/pre&gt;

&lt;p&gt;For a more interesting initial state, add this (before the currentState.SetData call) to randomize the cells:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    Random random = &lt;span class="kwrd"&gt;new&lt;/span&gt; Random();

    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10000; i++)
    {
        initialData[random.Next(width * height)] = Color.White;
    }&lt;/pre&gt;

&lt;p&gt;My Draw code is simple.&amp;#160; It uses SamplerState.PointClamp to scale up the current simulation state to fill the entire screen, without any filtering:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    SimulateLife();

    GraphicsDevice.Clear(Color.CornflowerBlue);

    spriteBatch.Begin(SpriteSortMode.Deferred, &lt;span class="kwrd"&gt;null&lt;/span&gt;, SamplerState.PointClamp, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
    spriteBatch.Draw(currentState, GraphicsDevice.Viewport.Bounds, Color.White);
    spriteBatch.End();&lt;/pre&gt;

&lt;p&gt;Ok, that's the boilerplate taken care of.&amp;#160; How are we actually going to implement this SimulateLife method?&amp;#160; Wikipedia defines the rules as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Any live cell with fewer than two live neighbours dies, as if caused by under-population
      &lt;br /&gt;Any live cell with two or three live neighbours lives on to the next generation

      &lt;br /&gt;Any live cell with more than three live neighbours dies, as if by overcrowding

      &lt;br /&gt;Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But I found it useful to rearrange this to a different (equivalent) form:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Rule 1:&amp;#160; If there are two live neighbours, preserve the current state of the cell
      &lt;br /&gt;Rule 2:&amp;#160; If there are three live neighbours, set the cell to alive

      &lt;br /&gt;Rule 3:&amp;#160; Otherwise set the cell to dead&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ok, let's do it!&amp;#160; SimulateLife starts by drawing onto the nextState rendertarget, and setting up the AlphaTestEffect to only accept pixels with alpha greater than 128, i.e.. cells that are currently alive:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    GraphicsDevice.SetRenderTarget(nextState);

    GraphicsDevice.Clear(Color.Transparent);

    Viewport viewport = GraphicsDevice.Viewport;

    Matrix projection = Matrix.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1);
    Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);

    alphaTestEffect.Projection = halfPixelOffset * projection;

    alphaTestEffect.AlphaFunction = CompareFunction.Greater;
    alphaTestEffect.ReferenceAlpha = 128;&lt;/pre&gt;

&lt;p&gt;We are going to count how many alive neighbours each cell has, accumulating this value in the stencil buffer (which was previously cleared to zero).&amp;#160; We do this by drawing the current simulation state texture 8 times, shifted one pixel to the top left, top, top right, left, etc.&amp;#160; We use a blend state that prevents drawing anything to the color buffer, because we are only interested in generating stencil values.&amp;#160; This code combines AlphaTestEffect (which rejects dead neighbour pixels) and the stencil buffer (which counts how many neighbour pixels pass the alpha test):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    spriteBatch.Begin(SpriteSortMode.Deferred, blendNone, &lt;span class="kwrd"&gt;null&lt;/span&gt;, stencilAdd, &lt;span class="kwrd"&gt;null&lt;/span&gt;, alphaTestEffect);

    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(-1, -1), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2( 0, -1), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2( 1, -1), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(-1,  0), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2( 1,  0), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2(-1,  1), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2( 0,  1), Color.White);
    spriteBatch.Draw(currentState, &lt;span class="kwrd"&gt;new&lt;/span&gt; Vector2( 1,  1), Color.White);

    spriteBatch.End();&lt;/pre&gt;

&lt;p&gt;This uses two custom state objects:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; BlendState blendNone = &lt;span class="kwrd"&gt;new&lt;/span&gt; BlendState
    {
        ColorSourceBlend = Blend.Zero,
        ColorDestinationBlend = Blend.One,

        AlphaSourceBlend = Blend.Zero,
        AlphaDestinationBlend = Blend.One,

        ColorWriteChannels = ColorWriteChannels.None,
    };

    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DepthStencilState stencilAdd = &lt;span class="kwrd"&gt;new&lt;/span&gt; DepthStencilState
    {
        DepthBufferEnable = &lt;span class="kwrd"&gt;false&lt;/span&gt;,
        StencilEnable = &lt;span class="kwrd"&gt;true&lt;/span&gt;,
        StencilFunction = CompareFunction.Always,
        StencilPass = StencilOperation.Increment,
    };&lt;/pre&gt;

&lt;p&gt;We now have our rendertarget cleared to zero (which means all dead, so we have already implemented rule #3),&amp;#160; while stencil contains a count of live neighbour cells.&amp;#160; It is but the work of a moment to draw a copy of the current simulation state, using stencil to only accept cells that have 2 live neighbours, thus implementing rule #1:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, &lt;span class="kwrd"&gt;null&lt;/span&gt;, stencilDrawIf2, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
    spriteBatch.Draw(currentState, Vector2.Zero, Color.White);
    spriteBatch.End();&lt;/pre&gt;

&lt;p&gt;The last draw call implements rule #2 by rendering solid white (which means alive) over only those cells which have 3 live neighbours:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, &lt;span class="kwrd"&gt;null&lt;/span&gt;, stencilDrawIf3, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
    spriteBatch.Draw(singleWhitePixel, viewport.Bounds, Color.White);
    spriteBatch.End();&lt;/pre&gt;

&lt;p&gt;This requires two new state objects:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DepthStencilState stencilDrawIf2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; DepthStencilState
    {
        DepthBufferEnable = &lt;span class="kwrd"&gt;false&lt;/span&gt;,
        StencilEnable = &lt;span class="kwrd"&gt;true&lt;/span&gt;,
        StencilFunction = CompareFunction.Equal,
        ReferenceStencil = 2,
    };

    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; DepthStencilState stencilDrawIf3 = &lt;span class="kwrd"&gt;new&lt;/span&gt; DepthStencilState
    {
        DepthBufferEnable = &lt;span class="kwrd"&gt;false&lt;/span&gt;,
        StencilEnable = &lt;span class="kwrd"&gt;true&lt;/span&gt;,
        StencilFunction = CompareFunction.Equal,
        ReferenceStencil = 3,
    };&lt;/pre&gt;

&lt;p&gt;Finally, the end of SimulateLife unsets our output rendertarget, then swap the two rendertargets, replacing the current state with the new one we just computed:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    GraphicsDevice.SetRenderTarget(&lt;span class="kwrd"&gt;null&lt;/span&gt;);

    Swap(&lt;span class="kwrd"&gt;ref&lt;/span&gt; currentState, &lt;span class="kwrd"&gt;ref&lt;/span&gt; nextState);&lt;/pre&gt;

&lt;p&gt;Swap is a handy little helper, implemented like so:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;    static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Swap&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;ref&lt;/span&gt; T a, &lt;span class="kwrd"&gt;ref&lt;/span&gt; T b)
    {
        T temp = a;
        a = b;
        b = temp;
    }&lt;/pre&gt;

&lt;p&gt;So, does it work?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/3716.image_5F00_1305EC40.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-70-20-metablogapi/2234.image_5F00_thumb_5F00_32B4C608.png" width="640" height="406" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tada!&amp;#160; SpriteBatch is Turing complete :-)&lt;/p&gt;

&lt;p&gt;Exercise for the reader: is it possible to do the same thing &lt;em&gt;without &lt;/em&gt;using stencil?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10251913" width="1" height="1"&gt;</description></item><item><title>What should I write about next?</title><link>http://blogs.msdn.com/b/shawnhar/archive/2011/12/29/what-should-i-write-about-next.aspx</link><pubDate>Thu, 29 Dec 2011 19:34:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10251836</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>59</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10251836</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2011/12/29/what-should-i-write-about-next.aspx#comments</comments><description>&lt;p&gt;I have a couple more articles planned about aliasing and motion blur, but am curious to hear where you would like me to take this blog next.&lt;/p&gt;  &lt;p&gt;Some topics I am considering:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;C++&lt;/strong&gt;.&amp;#160; Dirty secret: although I've mostly blogged about C# programming, much of XNA itself is written in C++, so I've actually been straddling both worlds for years.&amp;#160; And interesting things are happening in C++ land right now, with the arrival of C++11 and maturity of the standard library affecting best practices and recommended style.&amp;#160; But are my readers interested in such things?&amp;#160; You tell me!&lt;/p&gt;  &lt;p&gt;More about &lt;strong&gt;how GPU's work&lt;/strong&gt;.&amp;#160; Tiling, swizzling, caching, parallelism, predication, etc.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3D Math&lt;/strong&gt;.&amp;#160; Vectors, matrices, what really is an orientation, how to think in multiple coordinate spaces, and why rotation angles are Teh Evil.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Game design&lt;/strong&gt;.&amp;#160; What makes it fun?&amp;#160; What makes a good AI?&amp;#160; How does one persuade customers to try/buy your work?&amp;#160; I've been reluctant to cover these topics because it's not really my area of expertise, but I do have some opinions about it so who knows, maybe a few worthwhile articles to be had here.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;SIMD optimization&lt;/strong&gt;, SSE, DirectXMath.&lt;/p&gt;  &lt;p&gt;Other?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10251836" width="1" height="1"&gt;</description></item><item><title>From games to telephones</title><link>http://blogs.msdn.com/b/shawnhar/archive/2011/12/13/from-games-to-telephones.aspx</link><pubDate>Wed, 14 Dec 2011 00:22:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10247403</guid><dc:creator>Shawn Hargreaves - MSFT</dc:creator><slash:comments>44</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/shawnhar/rsscomments.aspx?WeblogPostID=10247403</wfw:commentRss><comments>http://blogs.msdn.com/b/shawnhar/archive/2011/12/13/from-games-to-telephones.aspx#comments</comments><description>&lt;p&gt;After six years working on XNA, I decided it was time to take on a new challenge.&amp;#160; I am moving to the Windows Phone team, where I will be working on things I'm not sure how much I can say about here&amp;#160; (leaking future business plans on MSDN might not be the best way to endear myself to my new boss :-)&lt;/p&gt;  &lt;p&gt;Writing this post is a bittersweet moment for me.&amp;#160; I'm excited by what the future holds for Windows Phone, and looking forward to my chance to be part of that, but also sad to leave a team and product that have given me so much satisfaction.&amp;#160; There'll be no going back once I hit that &lt;em&gt;Publish &lt;/em&gt;button a few minutes from now...&lt;/p&gt;  &lt;p&gt;I feel an urge to wax nostalgic about some of my favorite times with XNA:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Staying up all night to &lt;a href="http://blogs.msdn.com/b/shawnhar/archive/2006/12/11/mysterious-goings-on-in-the-night.aspx" target="_blank"&gt;watch Michael purchase the first ever Creators Club subscription&lt;/a&gt;.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;The first Dream Build Play competition, when we got to see the first actual games made with our technology&amp;#160; (&lt;a href="http://create.msdn.com/en-US/community/spotlight/dishwasher" target="_blank"&gt;Dishwasher FTW&lt;/a&gt;!)&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;On stage with Mitch at Gamefest, where I wrote a network game 'from scratch'&amp;#160; (if you ignore some minor snippet cheating :-)&amp;#160; in less than an hour.&amp;#160; I'm still blown away by the fact that our APIs were simple enough to make this possible.&amp;#160; Also amazed that the demo actually worked, considering what an unstable early build we were using!&amp;#160; Unfortunately there is no video of this, and the &lt;a href="http://download.microsoft.com/download/7/2/a/72afc5a1-17a9-452a-a4cf-b975e8f3225e/Networking%20with%20the%20XNA%20Framework.zip" target="_blank"&gt;slides&lt;/a&gt; don't do it justice since the whole point was the live coding demo.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;On stage once more at MIX, demonstrating &lt;a href="http://channel9.msdn.com/events/MIX/MIX10/CL22" target="_blank"&gt;XNA graphics on the new Windows Phone&lt;/a&gt; with a frighteningly last minute demo cobbled together just a few days earlier using a hot-off-the-presses build of XNA on an even more experimental frankenbuild of the phone OS.&amp;#160; Then rushing back to my hotel room to blog about the new features coming in XNA 4.0&amp;#160; (which, modesty aside, I still think is some of the best design work I have done to date).&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Trying to decide, of all the lines of code I have written in my life, which one has been executed the most times?&amp;#160; I think it must be the default SpriteBatch pixel shader.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Last but not least, spending time with y'all on forums and this blog, where I got to know so many great people and see the amazing things you create.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I'm not yet sure what this means for my blog.&amp;#160; I want to keep writing, but will probably cover more general graphics and game development topics, and will obviously no longer have inside scoop on XNA implementation details.&amp;#160; I'm also not sure how much time I will have for writing, especially in the early months as I settle into the new job, but I will do my best.&lt;/p&gt;  &lt;p&gt;Ok, I'm off now to meet some new people and learn my way around a whole new product.&lt;/p&gt;  &lt;p&gt;&amp;lt;nervously excited&amp;gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10247403" width="1" height="1"&gt;</description></item></channel></rss>