<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>XNAInfo site updates</title><link>http://www.xnainfo.com</link><description>New and updated tutorials, samples and articles on XNAInfo</description><language>en-us</language><copyright>Copyright 2008 by the XNAInfo authors</copyright><managingEditor>feedback@mdxinfo.com (XNAInfo authors)</managingEditor><webMaster>feedback@mdxinfo.com (XNAInfo authors)</webMaster><lastBuildDate>Sun, 23 Nov 2008 11:01:34 +0000</lastBuildDate><generator>Shabby mdxinfo PHP script</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><ttl>360</ttl><image><url>http://www.xnainfo.com/resources.xnainfo/images/feed-image.png</url><title>XNAInfo site updates</title><link>http://www.xnainfo.com</link><height>43</height><width>144</width><description>New and updated tutorials, samples and articles on XNAInfo</description></image>
<item><title>Slowly getting there</title><link>http://www.xnainfo.com/tutorials.php</link><description><![CDATA[Woo, finally we've got some progress to report over here. We're slowly porting over the tutorials and samples from <a href="http://mdxinfo.com" target="_blank">MDXInfo</a> and are working to get the site into some semblance of order.]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/tutorials.php</guid><pubDate>Tue, 17 Jun 2008 14:28:42 +0100</pubDate></item>
<item><title>An update! Integrating your XNA engine with XSI ModTool</title><link>http://www.xnainfo.com/file.php?file=68</link><description><![CDATA[Incredibly, we're slowly making progress. We've got a few nice new samples in the works and got a most excellent contribution from <a href="http://www.gamedev.net/profile/profile.asp?mode=view&id=118414">MJP</a> to walk you through an implementation of a 3D content authoring system, which can allow you to seamlessly integrate XSI ModTool with your gaming engine.
<br><br>
You can find this guide in our articles section under Game Programming, or download it directly through this posts permalink. Enjoy!]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/file.php?file=68</guid><pubDate>Thu, 03 Jul 2008 08:06:53 +0100</pubDate></item>
<item><title>Snippet time - LogLuv and quaternions</title><link>http://www.xnainfo.com/resources.php</link><description><![CDATA[Here are a few snippets that might prove useful. We've got a nice <a href="http://www.xnainfo.com/content.php?content=17">HLSL LogLuv implementation</a> for storing floating point values in a 32 bpp format and a basic sample showing how to use <a href="http://www.xnainfo.com/content.php?content=18">quaternions for rotation</a>.]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/resources.php</guid><pubDate>Wed, 09 Jul 2008 20:39:56 +0100</pubDate></item>
<item><title>Game of Life on the GPU</title><link>http://www.xnainfo.com/content.php?content=21</link><description><![CDATA[This sample demonstrates how Conway's Game of Life can be implemented on the GPU. It also comes with a couple of custom rules to solve mazes <a href="http://realtimecollisiondetection.net/blog/?p=57" target="_blank">as demonstrated here</a>. <b>Update:</b> the fat maze solver has been fixed, so that works out nicely now too.]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/content.php?content=21</guid><pubDate>Tue, 29 Jul 2008 20:38:00 +0100</pubDate></item>
<item><title>Realtime fur and a request</title><link>http://www.xnainfo.com/content.php?content=23</link><description><![CDATA[Here's a little tutorial I've been wanting to do for ages, showing how to render some simple fur on arbitrary meshes (looks like I've been pretty much upstaged by <a href="http://www.ziggyware.com/readarticle.php?article_id=194" target="_blank">Catalin</a> though). As for my request, I'd be much oblidged if anyone could take a shot at the bug in the <a href="http://blogs.xnainfo.com/post/WebBrowser-control-on-XNA-texture.aspx">webbrowser on an XNA texture project</a>. I've tinkered on it to no end, but I just can't seem to get that bug fixed.]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/content.php?content=23</guid><pubDate>Fri, 01 Aug 2008 08:48:35 +0100</pubDate></item>
<item><title>Drawing a 2D circle</title><link>http://www.xnainfo.com/file.php?file=96</link><description><![CDATA[I finally managed to wrap up a little sample showing how to draw circles/ellipses in a pixel shader using the good old implicit formula for a unit circle. For all its simplicity, I found it's actually a practical way to draw a nice smooth circle. You can find it <a href="http://www.xnainfo.com/resources.php?view=Code%20snippets">over here</a> or download it directly from the link below.]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/file.php?file=96</guid><pubDate>Wed, 10 Sep 2008 09:34:50 +0100</pubDate></item>
<item><title>New sample: HDR Rendering</title><link>http://www.xnainfo.com/content.php?content=28</link><description><![CDATA[Matt (MJP) came up with another great sample which shows how to go about rendering HDR imagery on both Windows and the 360. Following <a href="http://blogs.xnainfo.com/post/XNA-On-The-3602c-Part-2-HDR.aspx">Matt's research</a>, it's also a nice showcase of using LogLuv for storing the HDR information.]]></description><author>feedback@mdxinfo.com (Rim van Wersch)</author><guid isPermaLink="true">http://www.xnainfo.com/content.php?content=28</guid><pubDate>Mon, 29 Sep 2008 14:39:53 +0100</pubDate></item>
</channel><channel><title>XNAInfo blog entries</title><link>http://blogs.xnainfo.com</link><description>General ramblings on XNA, games and stuff</description><language>en-us</language><copyright>Copyright 2008 by the XNAInfo authors</copyright><managingEditor>feedback@mdxinfo.com (XNAInfo authors)</managingEditor><webMaster>feedback@mdxinfo.com (XNAInfo authors)</webMaster><lastBuildDate>Sun, 23 Nov 2008 11:01:34 +0000</lastBuildDate><generator>Shabby mdxinfo PHP script</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><ttl>360</ttl><image><url>http://www.xnainfo.com/resources.xnainfo/images/feed-image.png</url><title>XNAInfo blog entries</title><link>http://blogs.xnainfo.com</link><height>43</height><width>144</width><description>General ramblings on XNA, .NET and stuff</description></image>
<item><title>How I Saved 3ms By Unrolling A Loop</title><link>http://blogs.xnainfo.com/post/How-I-Saved-3ms-By-Unrolling-A-Loop.aspx</link><description><![CDATA[Last night I decided to sit down and do some nitty gritty optimization on the 60 version of my game.  The PC version has been running great even when I crank up every setting I have (although that might have something to do with the 4870 I just bought), but as well all know by now things are never so easy on the Xbox.  For the past few weeks I&#39;d been struggling to keep the framerate above 60Hz, with it slipping down to 55Hz during complex scenes.  Now 55fps wouldn&#39;t be so much of a problem if I weren&#39;t the kinda guy who hates screen tearing, but it just so happens I am.  Which means I want VSYNC to be enabled, which means the game drops to 30fps whenever it&#39;s below 60.  Definitely unacceptable.  For a while I avoided the problem by doing the unthinkable...I dropped the resolution from 1280 x 720 to 1024 x 600.  I even considered leaving it this way for the final release...I mean if Halo 3 and Metal Gear Solid 4 can do it, why can&#39;t I?  <br />
<br />
But no, I&#39;m too finicky to settle with the lowered resolution.  It just looks so much better in 720p!  So I cranked the res back up, and decided to see where I could squeeze out some extra performance.  Naturally, the first place I went to was my show mapping shader.  I already knew this particular shader was giving me trouble, since I&#39;d discovered that decreasing the size of the buffer that I render the shadow occlusion to (since I do a deferred shadowing pass) resulted in significant performance gains.  I&#39;d already reduced thigns to 4 PCF samples on the 360 (did I mention I ditched VSM for the 360?  Performance and precision ended up being so awful it wasn&#39;t worth it) so I couldn&#39;t squeeze that down anymore.  At this point my eyes drifted down to little loop I had for determining which split of shadow map cascade to use, when I remembered an <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=74DB343E-E8FF-44E9-A43E-6F1615D9FCE0">excellent presentation on shader performance</a> that I&#39;d read a long time ago.   One of the things mentioned in there was that unrolling loops can have a significant impact on general purpose register usage, ALU usage, and shader compiler optimization.  So I thought, &quot;hey, let&#39;s try unrolling this loop and flattening this branch&quot;.  I then changed my code from this:<br />
<br />
for (int i = 1; i &lt; NUM_SPLITS; i++)<br />
{<br />
    if (vPositionVS.z &lt;= g_vClipPlanes[i].x &amp;&amp; vPositionVS.z &gt; g_vClipPlanes[i].y)<br />
    {<br />
        matLightViewProj = g_matLightViewProj[i];<br />
        fOffset = i / (float)NUM_SPLITS;            <br />
    }<br />
}   <br />
<br />
to this:<br />
<br />
[unroll(NUM_SPLITS)]<br />
for (int i = 1; i &lt; NUM_SPLITS; i++)<br />
{<br />
    [flatten]<br />
    if (vPositionVS.z &lt;= g_vClipPlanes[i].x &amp;&amp; vPositionVS.z &gt; g_vClipPlanes[i].y)<br />
    {<br />
        matLightViewProj = g_matLightViewProj[i];<br />
        fOffset = i / (float)NUM_SPLITS;            <br />
    }<br />
}          <br />
<br />
I ran the game again, and BAM:  I shot up from 55fps to 65fps!  Huge difference!  I was very impressed with myself.  Moral of the story:  experiement with stuff, and make sure you profile it!<br />
<br />
Today I decided to read through some other presentations to see what other useful bits I could find. <a href="http://download.microsoft.com/download/f/a/a/faa7208f-1c18-48da-9b5c-c1d324bad9b1/Xbox%20360%20GPU%20Performance%20Update.zip">This one</a> from Gamefest 2007 pointed out that vfetch&#39;s should be aligned to 32-bytes on the 360.  I did the math on the vertex declaration used for most of my models, and found out it&#39;s 48 bytes.  Later tonight I&#39;ll have to see if I can squeeze it down to 32, and see if it makes performance any better.  <br />
<br />
I also came across <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=37F8B74D-F170-4B93-9122-0BFC581F9E99&amp;displaylang=en">this one</a> from Gamefest 2008, which is all about how texture and surface formats are handled on the 360.  This gave me some insight into some problems I&#39;d come across already.  For example, R32G32F (Vector2) isn&#39;t actually a format the GPU can render to!  Apparently it renders to R16G16F, and then just expands it upon resolve from eDRAM.  This explained why my VSM&#39;s with exponential warp were have such precision problems.  Another thing pointed out in there is that the 360&#39;s texture units filter fp16 at 1/4 the rate of INT8!  This would help explain why my VSM performance was so poor.  Definitely good things to keep in mind.<br />
<br />
-MJP]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/How-I-Saved-3ms-By-Unrolling-A-Loop.aspx</guid><pubDate>Thu, 25 Sep 2008 11:05:00 +0100</pubDate></item>
<item><title>Dutch .NET Magazine</title><link>http://blogs.xnainfo.com/post/Dutch-NET-Magazine.aspx</link><description><![CDATA[<p>
 
</p>
<p>
A bit of an off-topic post for any Dutch readers that may come across our little blog. MS decided to revamp their Dutch .NET Magazine and change the subscription to Opt-In, meaning you&#39;ll explicitly need to tell them you want to keep receiving the magazine after the next issue of September 22nd. You can find more details and re-subscribe over at this page:
</p>
<p>
<a href="http://www.microsoft.nl/netjesgeregeld">http://www.microsoft.nl/netjesgeregeld</a>
</p>
<p>
It&#39;s quite a risky step for them to take, but they want to make sure they&#39;re reaching their reader base and get a clearer picture of the interests of their readers. The magazine remains free and they&#39;ve drummed up a full-blown redactional team for the revamp, so if you&#39;ve enjoyed the magazine so far make sure you re-subscribe!
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/Dutch-NET-Magazine.aspx</guid><pubDate>Mon, 15 Sep 2008 07:09:00 +0100</pubDate></item>
<item><title>XNA on the Xbox 360, Part 3: General Practices</title><link>http://blogs.xnainfo.com/post/XNA-on-the-Xbox-3602c-Part-3-General-Practices.aspx</link><description><![CDATA[<p>
Over at <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=506393">gamedev.net</a> someone had asked for some general performance pointers regarding using XNA on the 360.  After giving a bullet-point list of what I thought were the important issues I thought to myself &quot;Hey, that was pretty good.  Let&#39;s milk it for all it&#39;s worth!&quot;  And therefore I&#39;ve copied and pasted them all here in glorious display of laziness.  <img src="http://blogs.xnainfo.com/admin/tiny_mce/plugins/emotions/images/smiley-laughing.gif" border="0" alt="Laughing" title="Laughing" />
</p>
<p>
 
</p>
<p>
-The 360 has 512MB of unified memory, which means it&#39;s shared by both the CPU and the GPU. You don&#39;t have all of that available to you, since some of it is taken up by the console&#39;s &quot;OS&quot; and some will also be taken up by the .NET Compact Framework.  You&#39;ll also be working from the managed heap, rather than directly working with native memory.<br />
<br />
-You can only execute pure managed code on the 360.  You can&#39;t, for example, P/Invoke into a non-managed DLL.  <br />
<br />
-As far as GPU shaders go, you&#39;re pretty unrestricted.  You can use SM3.0 HLSL, or you can also write portions of your shaders in the GPU&#39;s native microcode.  This is really very nice...it lets you do things like un-normalized texture addressing, full texturing capabilities in the vertex shader, or directly fetching an element from a vertex stream.  The microcode set is referred to as xvs_3_0 and xps_3_0.  <br />
<br />
-The 360&#39;s GPU is different from your average PC GPU in that it has an eDRAM framebuffer.  The eDRAM is 10MB in size, and has tremendous bandwidth (256GB/s).  What this means is that writing out to the framebuffer or reading it back for blending is very very quick.  Multi-sampling is also very quick, since again you don&#39;t have the bandwidth problem.  In fact MSAA would be &quot;free&quot; if it weren&#39;t for tiled rendering...you see the downside of eDRAM is that if your render-target + z-buffer is too big to fit in eDRAM, you have to render to it in tiles.  This means you render one portion of the target, then another.  This isn&#39;t so bad, except for the fact that any geometry that&#39;s on the edges of 2 tiles has to be drawn twice.  If you&#39;re not doing scenes with hugely complex geometry you probably won&#39;t even notice tiling (it happens automatically).  To figure out whether you&#39;re going to tile you need to count the amount of bytes per pixel and then multiply by resolution.  So for example if you&#39;re rendering to the Color format which is 4 bytes per pixel and you&#39;re using Depth24Stencil8 which is also 4 bytes per pixel, you have 8 bytes per pixel total.  When multi-sampling, you multiply this amount by the number of samples (so 4xMSAA would by 32 bytes per pixel).  1280 x 720 with 4xMSAA would be ~28MB, so you&#39;d need 3 tiles.<br />
<br />
-Be prepared to get CPU-bound really quick if you&#39;re doing anything non-trivial.  DrawPrimitive calls are <em>extremely</em> expensive on the 360...I&#39;ve seen my framerate go from about 70 to 30 just from going from 24 DP calls to 34.  Instancing is a must if you need to draw a lot of meshes...there&#39;s a <a href="http://creators.xna.com/en-us/sample/meshinstancing">good sample</a> on the CC website.  By the same token if you&#39;re doing any really fancy logic on the CPU that&#39;s not graphics-related, you&#39;ll probably need to run it on another thread on a different core since your main thread can get bogged down pretty quick.<br />
<br />
-Watch out for performance pitfalls with the .NET Compact Framework.  Things like Garbage Collection compaction and virtual function calls are much more expensive than they are on the PC.  I suggest reading <a href="http://blogs.msdn.com/netcfteam/archive/2006/12/22/managed-code-performance-on-xbox-360-for-the-xna-framework-1-0.aspx">this blog</a> for tips.  Just remember to keep your live object count as low as possible, and you should be okay.<br />
<br />
-Floating-point performance is not so great on the 360 CPU.  Most of the fp power is in the vector units, but you have no access to those through XNA.  <br />
<br />
-Avoid the surface formats that are larger than 32bpp.  Mainly HalfVector4 and Vector2.  Their performance is generally pretty terrible, and I&#39;ve run into all kinds of driver bugs with them.  This means you can&#39;t do HDR in straightforward way, but there are other options.  There&#39;s an <a href="http://blogs.xnainfo.com/post/XNA-On-The-3602c-Part-2-HDR.aspx">entry on my XNA blog</a> where I talk about how I got around it.<br />
<br />
-Watch your texture sampling bandwidth.  Framebuffer access may be quick, but reads from textures are limited by the 22.1GB/s read bandwidth.  This may be quite a bit less than what you&#39;re used to, if you&#39;re prototyping on a higher-end card like an 8800.  This can be especially painful in scenarios where you want to take multiple samples per pixel, like PCF for shadow maps or SSAO.  <br />
<br />
-Prototyping and developing on the PC is a good idea since you have access to PIX, but make sure you test pretty often on the 360.   You may need to optimize for quite few scenarios if you need to keep the framerate up.   
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/XNA-on-the-Xbox-3602c-Part-3-General-Practices.aspx</guid><pubDate>Thu, 28 Aug 2008 09:55:00 +0100</pubDate></item>
<item><title>XNA On The 360, Part 2: HDR</title><link>http://blogs.xnainfo.com/post/XNA-On-The-3602c-Part-2-HDR.aspx</link><description><![CDATA[<p>
Designing an effective and performant HDR implementation for my game&#39;s engine was another step that was complicated by the Xbox 360.  As a quick refresher for those who aren&#39;t experts on the subject, HDR is most commonly implemented by rendering the scene to a floating-point buffer and then performing a tone-mapping pass to bring the colors back into he visible range.  Floating-point formats (like A16B16G16R16F, AKA HalfVector4) are used because their added precision and floating-point nature allows them to comfortbly store linear RGB values in ranges beyond the [0,1] typically used for shader output to the backbuffer, which is crucial as HDR requires having data with a wide dynamic range.  They&#39;re also convenient, as this it allows values to be stored in the same format they&#39;re manipulated in the shaders.  Newer GPU&#39;s also support full texture filtering and alpha-blending with fp surfaces, which prevents the need for special-case handling of things like non-opaque geometry.  However as with most things, what&#39;s convient is not always the best option.  As with my shadows, I once again came up with a list of possible techniques and enumerated their pros and cons:<br />
<br />
</p>
<ul>
	<li>Standard HDR, fp16 buffer<br />
	+Very easy to integrate (no special work needed for the shaders)<br />
	+Good precision<br />
	+Support for blending on SM3.0+ PC GPU&#39;s<br />
	+Allows for HDR bloom effects<br />
	-Double the bandwidth and storage requirements of R8G8B8A8   <br />
	-Weak support for multi-sampling on SM3.0 GPU&#39;s (Nvidia NV40 and G70/G71 can&#39;t do it)<br />
	-Hardware filtering not available on ATI SM2.0 and SM3.0 GPU&#39;s<br />
	-No blending on the Xbox 360<br />
	-Requires double space in framebuffer on the 360, which increases the number of tiles needed</li>
	<li>HDR with tone-mapping applied directly in the pixel shader (Valve-style)<br />
	+Doesn&#39;t require output to an HDR format, no floating-point or encoding required<br />
	+Multi-sampling and blending is supported, even on old hardware<br />
	-Can&#39;t do HDR bloom, since only an LDR image is availble for post-processing<br />
	-Luminance can&#39;t be calculated directly, need to use fancy techniques to estimate it<br />
	-Increases shader complexity and combinations</li>
	<li>HDR using an encoded format<br />
	+Allows for a standard tone-mapping chain<br />
	+Allows for HDR bloom effects<br />
	+Most formats offer a very wide dynamic range<br />
	+Same bandwidth and storage as LDR rendering<br />
	+Certain formats allow for multi-sampling and/or linear filtering with reasonable quality<br />
	-Alpha-blending usually isn&#39;t an option, since the alpha-channel is used by most formats<br />
	-Linear filtering and multisampling usually isn&#39;t mathmatically correct, although often the results are &quot;good enough&quot;<br />
	-Additional shader math needed for format conversions<br />
	-Adds complexity to shaders</li>
</ul>
<p>
 
</p>
<p>
My early prototyping used a standard tone-mapping chain and I didn&#39;t want to ditch that, nor did I want to move away from what I was comfortable with.  This pretty much eliminated the second option for me off the bat...although I was unlikely to choose it anyway due its other drawbacks (having nice HDR bloom was something I felt was an important part of the look I wanted for my game, and in my opinion Valve&#39;s method doesn&#39;t do a great job of determining average luminance).  When I tried out the first method I found that it worked as well as it always did on the PC (I&#39;ve used it before), but on the 360 it was another story.  I&#39;m not sure why exactly, but for some reason it simply does not like the HalfVector4 format.  Performance was terrible, I couldn&#39;t blend, I got all kinds of strange rendering artifacts (entire lines of pixels missing), and I&#39;d get bizarre exceptions if I enabled multi-sampling. Loads of fun, let me tell you.<br />
<br />
This left me with option #3.  I wasn&#39;t a fan of this approach initially, as my original design plan called for things to be simple and straightforward whenever possible.  I didn&#39;t really want to have two versions of my material shaders to support encoding, nor did I want to integrate decoding into the other parts of the pipeline that needed.  But unfortunately, I wasn&#39;t really left with any other options after I found there were <a href="https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=343887&amp;SiteID=226">no plans to bring the support for the 360&#39;s special fp10 backbuffer format to XNA</a> (which would have conveniently solved my problems on the 360).  So, I started doing my research.  Naturally the first place I looked was to actual released commercial game.  Why?  Because usually when a technique is used in a shipped game, it means it&#39;s gone trhough the paces and has been determined to actually be feasible and practical in game environment.  Which of course naturally led me to consider NAO32.<br />
<br />
NAO32 is a format that gained some fame in the dev community when ex-Ninja Theory programmer Marco Salvi shared some details on the technique over on the beyond3D forums.  Used in the game Heavenly Sword, it allowed for multi-sampling to be used in conjuction with HDR on a platform (PS3) whose GPU didn&#39;t support multi-sampling of floating-point surfaces (The RSX is heavily based on Nvidia G70).  In this technique, color is stored in the <a href="http://www.anyhere.com/gward/papers/jgtpap1.pdf">LogLuv format</a> usinga standard R8G8B8A8 surface.  Two components are used to store X and Y at 8-bit precision, and the other two are used to store the log of luminance at 16-bit precision.  Having 16 bits for luminance allows for a wide dynamic range to be stored in this format, and storing the log of the luminance allows for linear filtering in multi-sampling or texture sampling.  Since he first explained it other games have also used it, such as Naughty Dog&#39;s Uncharted.  It&#39;s likely that it&#39;s been used in many other PS3 games, as well.<br />
<br />
My actual shader implementation was helped along quite a bit by <a href="http://realtimecollisiondetection.net/blog/?p=15">Christer Ericson&#39;s blog post</a>, which described how to derive optimized shader code for encoding RGB into the LogLuv format.  Using his code as a starting point, I came up with the following HLSL code for encoding and decoding:
</p>
<p>
 // M matrix, for encoding<br />
const static float3x3 M = float3x3(<br />
    0.2209, 0.3390, 0.4184,<br />
    0.1138, 0.6780, 0.7319,<br />
    0.0102, 0.1130, 0.2969);<br />
<br />
// Inverse M matrix, for decoding<br />
const static float3x3 InverseM = float3x3(<br />
    6.0013,    -2.700,    -1.7995,<br />
    -1.332,    3.1029,    -5.7720,<br />
    .3007,    -1.088,    5.6268);    <br />
<br />
float4 LogLuvEncode(in float3 vRGB) <br />
{         <br />
    float4 vResult; <br />
    float3 Xp_Y_XYZp = mul(vRGB, M);<br />
    Xp_Y_XYZp = max(Xp_Y_XYZp, float3(1e-6, 1e-6, 1e-6));<br />
    vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;<br />
    float Le = 2 * log2(Xp_Y_XYZp.y) + 127;<br />
    vResult.w = frac(Le);<br />
    vResult.z = (Le - (floor(vResult.w*255.0f))/255.0f)/255.0f;<br />
    return vResult;<br />
}<br />
<br />
float3 LogLuvDecode(in float4 vLogLuv)<br />
{    <br />
    float Le = vLogLuv.z * 255 + vLogLuv.w;<br />
    float3 Xp_Y_XYZp;<br />
    Xp_Y_XYZp.y = exp2((Le - 127) / 2);<br />
    Xp_Y_XYZp.z = Xp_Y_XYZp.y / vLogLuv.y;<br />
    Xp_Y_XYZp.x = vLogLuv.x * Xp_Y_XYZp.z;<br />
    float3 vRGB = mul(Xp_Y_XYZp, InverseM);<br />
    return max(vRGB, 0);<br />
}
</p>
<p>
 <br />
Once I had this implemented and worked through <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=500219">a few small glitches</a>, results were much improved in the 360 version.   Performance was much much better, I could multi-sample again, and the results looked great.  So once again things didn&#39;t exactly work out in an ideal way, but I&#39;m pleased with the results. 
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/XNA-On-The-3602c-Part-2-HDR.aspx</guid><pubDate>Thu, 14 Aug 2008 15:02:00 +0100</pubDate></item>
<item><title>XNA On The 360, Part 1: Shadows</title><link>http://blogs.xnainfo.com/post/XNA-On-The-3602c-Part-1.aspx</link><description><![CDATA[<p>
As get deeper into my current project, which happens to be 3D vehicle-based platformer/racer loosely based on the old DOS game <a href="http://www.bluemoon.ee/history/skyroads">Skyroads</a>, I find myself spending more and more time grappling with various headaches that come up on the 360 version.  So I&#39;ve decided I&#39;m going to share some of trials and tribulations, so that maybe some people learn from them (and also so I can just plain vent about them!).  <br />
<br />
One of the early goals I set for myself when starting the project was that I wanted to make some use of modern graphics techniques, and really try to squeeze some performance out of both the 360 and PC GPU&#39;s.  This meant some decent shaders, HDR, 4xMSAA 1280 x 720 @ 60fps, and of a good shadowing implementation.  Shadows are a topic that I keep near and dear to my heart, so I&#39;m going to talk about them in my first entry. <br />
<br />
When first planning out my renderer, I came up with the following choices for my shadow implementation:
</p>
<ul>
	<li>Stencil shadows<br />
	+Pixel-perfect shadows, no resolution issues<br />
	-Requires multi-pass for any lights needing shadows<br />
	-Hard edges are ugly!<br />
	-Softening is <em>very</em> expensive<br />
	-Tied to geometric complexity<br />
	-Not really any active research on the subject...even Carmack ditched them</li>
	<li>Shadow maps, with standard PCF<br />
	+Very commonly used, lot&#39;s of known optimizations<br />
	+Can soften edges and give good filtering when enough samples are used<br />
	+Can be used with an R32F texture, which gives good precision<br />
	-No hardware filtering<br />
	-PCF samples are incredibly expensive on the 360, which has very limited bandwidth<br />
	-Biasing artifacts are very common</li>
	<li>Variance Shadow Maps<br />
	+Can use hardware filtering<br />
	+Can be used with multi-sampling, which is &quot;free&quot; on the 360<br />
	+Can be pre-filtered, for example with seperable gaussian blur<br />
	-Very precision-hungry, in most cases R32G32F is needed (which doubles bandwidth per read)<br />
	-Light bleeding</li>
</ul>
Ultimately I decide to go with VSM&#39;s first, and then try other approaches later.  VSM is capable of producing some tremendously good-looking shadows thanks when anisotropic filtering and a gaussian blur are used.  Plus being able to enable MSAA very cheaply on the 360 made it seem like a very good fit for the hardware, especially considering how expensive PCF can be.  I remember seeing Wolf mention that he was limited to 6 or so PCF taps on the consoles...IMO that&#39;s not enough to produce high-quality shadows in many situations.  Later on I confirmed this:  using higher numbers of samples (16, 25) was enough to bring my framerate crashing down on the 360.  VSM has not been without it&#39;s headaches though...the anti-aliasing may be cheap but the blurring sure isn&#39;t.  Even using a blur with just 9 taps is enough to cause quite a noticable framerate drop, which unfortunate considering the improvement in quality it brings.  <br />
<br />
One trick I&#39;ve found to be quite effective on the 360 is deferred shadow maps.  The technique is one I first saw mentioned by nAo over on the beyond3d forums, and it involves rendering the results of a shadow-map comparison to a texture in a seperate pass before doing the full lighting pass.  It basically works like this:<br />
<br />
-Have all geometry render linear depth to a screen-sized texture<br />
-Render the shadow-map<br />
-In a full-screen pass: sample depth from the depth texture, reconstruct view space, convert to light-space, and compare depth with the shadow-map<br />
-Use the shadow occlusion texture to attenuate lighting in the actual main pass<br />
<br />
The reason it&#39;s a win performance-wise, is because when you perform a full-screen pass you ensure that every quad of pixels is fully utilized.  This isn&#39;t the case when you&#39;re rendering a bunch of 3D geometry, since the triangles often won&#39;t overlap all 4 pixels of a quad.  It&#39;s all very nice from a pure design standpoint:  your shadowing is completely decoupled from your lighting.  Your fancy normal-mapping or sub-surface scattering don&#39;t need to be aware at all of what shadowing method you&#39;re using, it just needs to sample the final attenuation value from a texture.  Plus you don&#39;t need to have two versions of those shaders:  if shadows are disabled, you can just feed the lighting shaders a 1x1 white texture.  Having a depth texture available also usually isn&#39;t a big deal, since pretty much every modern engine needs depth for just about every friggin&#39; effect.  <br />
<br />
As of now with this shadowing system in place, I have everything running at a little over 60 fps with a 1024 x 1024 shadow map being rendering with 4xMSAA.  In order to keep my framerate high enough to remain at a steady 60fps with vsync, I&#39;m defintely going to need to find some more optimizations and the shadowing system is certainly somewhere I&#39;m going to come back to.  However at the moment, I&#39;m quite satisfied with the results.  <img src="http://blogs.xnainfo.com/admin/tiny_mce/plugins/emotions/images/smiley-laughing.gif" border="0" alt="Laughing" title="Laughing" /><br />
<br />
<br />
<br />
<img src="http://i200.photobucket.com/albums/aa39/archiebot/js_03-1.png" alt="" />]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/XNA-On-The-3602c-Part-1.aspx</guid><pubDate>Fri, 08 Aug 2008 15:57:00 +0100</pubDate></item>
<item><title>DirectX FAQ</title><link>http://blogs.xnainfo.com/post/DirectX-FAQ.aspx</link><description><![CDATA[<p>
 
</p>
<p>
Since the stuff I&#39;m working on for XNAInfo is taking forever to finish, I thought I&#39;d post a link to this little gem here in the meantime. On my forum rounds I find myself linking to <a href="http://tomsdxfaq.blogspot.com/" target="_blank" title="Click here to go there">Tom&#39;s Excellent DirectX Faq</a> at least once a week. Obviously it&#39;s DirectX specific, but that easily translates to tons of useful information on XNA development on Windows. It&#39;s a great resource that should prove useful for just about anyone.
</p>
<p>
 
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/DirectX-FAQ.aspx</guid><pubDate>Wed, 06 Aug 2008 04:23:00 +0100</pubDate></item>
<item><title>WebBrowser control on XNA texture</title><link>http://blogs.xnainfo.com/post/WebBrowser-control-on-XNA-texture.aspx</link><description><![CDATA[<p>
(Sorry if this pops up twice in your RSS reader, something was off with the publishing)  
</p>
<p>
Some time ago <a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=495203" title="View original topic">a topic</a> popped up on GameDev on how to stick a WebBrowser control on a D3D surface, or rather an XNA texture level. After some tinkering we got it to work (obviously Windows only), so it can be used to render <em>any</em> webpage to an XNA texture. The next step was to try and make it interactive, paving the way for HTML and Flash based GUIs. Unfortunately we ran into a strange bug here, which I haven&#39;t been able to solve. So I figured I&#39;d post this out here, hoping anyone comes across this who can help out. 
</p>
<p>
Here are the (messy) demo projects: 
</p>
<ul>
	<li>
	<div>
	<a href="http://xnainfo.com/temp/ControlTexture.zip" title="Download this">Original browser-to-texture code</a> (useful if you&#39;re just looking to draw HTML in XNA)<br />
	  
	</div>
	</li>
	<li>
	<div>
	<a href="http://www.xnainfo.com/temp/ControlTextureThreaded.zip" title="Download this">Threaded interactive browser on texture</a> <br />
	</div>
	</li>
</ul>
<p>
The bug surfaces in the 2nd project. Basically it works fine until the user left-clicks anywhere on the control (doesn&#39;t have to be a link), after which WebBrowser.DrawToBitmap fails silently and only an empty white bitmap gets rendered. The strange thing is that the WebBrowser control does load the new webpage. By uncommenting line 241, mouse moves are posted to the control and the window title will show the HREF of links on the (loaded but invisible) page as you hover over them. 
</p>
<p>
Anyway, perhaps someone better versed in window messages can check this out, see if the code for posting mouse presses/releases is correct. While researching this problem, I also came across <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowserbase.drawtobitmap.aspx" title="Click here to go there">this MSDN page</a> which states DrawToBitmap isn&#39;t supported for the WebBrowser control anyway, so it seems a miracle it works in the first place. If anyone cares to comment on that, please let&#39;s hear it.
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/WebBrowser-control-on-XNA-texture.aspx</guid><pubDate>Mon, 28 Jul 2008 23:19:00 +0100</pubDate></item>
<item><title>The Art of War</title><link>http://blogs.xnainfo.com/post/The-Art-of-War.aspx</link><description><![CDATA[<p>
Having just been badly upstaged by <a href="http://blogs.xnainfo.com/post/A-peek-at-whats-to-come.aspx">MJP&#39;s post</a>, I reckon this might not be too interesting except for a few RTS/AI enthusiasts. Anyway... 
</p>
<p>
In a <a href="http://www.gamedev.net/community/forums/viewreply.asp?ID=3265214" target="_blank" title="Genrally interesting thread with AI ideas">recent discussion</a> on RTS AI, Matias Goldberg pointed out the quite ancient text The Art of War by Sun Tzu. Since I&#39;ve been fostering an RTS pet project for years now, I decided to get a copy and it turned out the best $4.95 I probably ever spent (ISBN10 0-486-42557-6). 
</p>
<p>
Obviously it&#39;s not a cookbook for writing RTS strategies, but after a first read I can definitely see how various stratagems and axioms could be used to construct a clever AI. In fact, I&#39;m amazed how many clear cut rules of thumb Sun Tzu puts forward that could be readily applied. These however may only serve to highlight the limited scale on which popular RTS games play out. 
</p>
<p>
Food for thought at any rate. 
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/The-Art-of-War.aspx</guid><pubDate>Mon, 14 Jul 2008 16:00:00 +0100</pubDate></item>
<item><title>A peek at what's to come</title><link>http://blogs.xnainfo.com/post/A-peek-at-whats-to-come.aspx</link><description><![CDATA[<p>
After completing my first <a href="http://www.xnainfo.com/articles.php?view=Game%20programming">game programming tutorial</a> for <a href="http://www.xnainfo.com/"></a>XNAinfo.com, I&#39;ve realized something:  I like writing these things!  So I&#39;ve been spending some idle time musing about future subjects for which a new article or tutorial would be of use to the XNA community.  Here&#39;s a few possibilities I&#39;ve come up with so far: 
</p>
<ul>
	<li>Debugging shaders and profiling with PIX.  I can&#39;t tell you how many times I&#39;ve replied to a thread in the <a href="http://www.gamedev.net/community/forums"></a>gamedev.net forums by saying &quot;just step through your shader in PIX!&quot;.  PIX is undoubtedly a huguely useful tool (even when it&#39;s occasionally crashing), and I think it&#39;s important that beginners get comfortable with it early on.  There&#39;s documentation in the SDK, but I think a lot of beginner XNA programmers don&#39;t think to look through there and therefore don&#39;t understand how powerful PIX can be.  <br />
	<br />
	</li>
	<li>HDR and tonemapping.  It&#39;s probably pretty advanced for your average XNA project, but thesedays everybody wants to know how to do it.  There&#39;s some great samples in the SDK but once again I&#39;m not sure all XNA programmers want to go poking around in there, especially if they don&#39;t know C++.  Plus there&#39;s always cool things I could throw in, like the <a href="http://www.xnainfo.com/resources.php">LogLuv encoding scheme</a> Rim and I worked out.<br />
	<br />
	</li>
	<li>Skyboxes.  Another topic I see brought up all the time on the gamedev forums.  It&#39;s a very very simple technique once you understand how it works, but unfortunately I don&#39;t know of any tutorials devoted to that topic.  Plus there&#39;s always a few advanced things I could throw in there...like RGBE (or LogLuv) encoding for HDR, or comparing DXT compression vs. uncompressed.<br />
	<br />
	</li>
	<li>An article or maybe even a series about map editors.  I&#39;ve been working on a map editor for my own project, and I&#39;m constantly amazed at all the cool stuff you can do with .NET when your engine is made with managed code. <br />
	<br />
	</li>
	<li>A follow-up article for my ModTool tutorial that discusses instancing.  There&#39;s an excellent Instancing sample on the creator&#39;s club website, however integregating the the technique with the content authoring system I described can be tricky (it requires modifying the shaders quite a bit, and also requires making some changes to the content processor).  <br />
	</li>
</ul>
Well I guess that&#39;s all I have for now.  I&#39;m not sure which I&#39;ll start with...maybe the skybox one because it&#39;s easy.  <img src="http://blogs.xnainfo.com/admin/tiny_mce/plugins/emotions/images/smiley-cool.gif" border="0" alt="Cool" title="Cool" />]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/A-peek-at-whats-to-come.aspx</guid><pubDate>Mon, 14 Jul 2008 12:14:00 +0100</pubDate></item>
<item><title>Beginning is hard for beginners?</title><link>http://blogs.xnainfo.com/post/Beginning-is-hard-for-beginners.aspx</link><description><![CDATA[<p>
On my <a href="http://www.gamedev.net/community/forums/" target="_blank" title="Click here to go there, obviously">favorite GameDev forum</a> a lot of threads seem to be popping up from beginners worrying that getting started in game development, even as a hobby, is Hard. Lacking anything really useful to talk about at the moment, I thought I&#39;d write up some points about this. 
</p>
<!--pagebreak-->
<p>
<strong>Get your feet wet</strong> 
</p>
<p>
When you&#39;re just starting out everything <em>seems</em> hard and no amount of reading is going to do you much good until you sit down and <em>just take a shot at it</em>. Don&#39;t worry if you don&#39;t create an AAA game on your first try or even when you hit a wall and don&#39;t know how to continue (I&#39;ll get back on that). The key is, you&#39;ve at the very least got some basics down and tried out various things that did or did not work. Congratulations, you&#39;ve now learned something and are no longer a n00b.<br />
  
</p>
<p>
<strong>The best language</strong>    
</p>
<p>
Please stop worrying about what would be the best programming language, please! If you even vaguely know how to code in some language, just stick with that unless you feel you absolutely need to move to another language since it offers something you really can&#39;t live without. Programming languages may all have their pros and cons (in no small part due to the libraries they&#39;ll allow you to use), but getting bogged down learning hard language X isn&#39;t going to help you create your game. Most coding skills you aquire carry over pretty well and should make it a lot easier to learn other languages anyway. And though it may be a fact that language X is the current industry standard,  should you really care about that now? <br />
  
</p>
<p>
<strong>Getting into the industry</strong> 
</p>
<p>
Or rather, do you really want to be in the industry right now or in the near future? It&#39;s a nice dream to create games for a living and certainly worth hanging on to, but when you&#39;re just getting started you really shouldn&#39;t be worrying about <em>the industry</em> too much. Just have a go at creating some games or at least coding some fancy things to get a feel for it. Then if coding games really turns out to be the carreer what you want, you will still have plenty of time to brush up on industry standards and how to actually get in there. In the meantime, you&#39;ll have a bit of a portfolio layed down which just might show off your experience and passion better than stating you know language X. Here&#39;s a little <a href="http://blogs.msdn.com/shawnhar/archive/2007/04/04/a-calculator-called-eric.aspx" target="_blank" title="A calculator called Eric">anecdote</a>. 
</p>
<p>
<strong>Getting stuck</strong> 
</p>
<p>
So you went and started coding your game, but you&#39;ve hit a wall. That&#39;s ok, it means you have something new to learn. <a href="http://www.google.com" target="_blank" title="Google is your friend">Research</a> the problem, ask around on <a href="http://www.gamedev.net/community/forums/" target="_blank" title="Another GameDev plug">forums</a> and try to get it working. Even if it turns out you&#39;ve created a monolithic unwieldly behemoth of a program or that something&#39;s deeply flawed in your approach, you&#39;ll at least know to avoid it in the future and you can start fresh with your newly gained knowledge. But chances are things aren&#39;t this bad and you&#39;ll have learned how to solve the (perhaps common) issue.<br />
  
</p>
<p>
Well, that about covers it for now. I&#39;m sure more ramblings will be forthcoming <img src="http://blogs.xnainfo.com/admin/tiny_mce/plugins/emotions/images/smiley-smile.gif" border="0" alt="Smile" title="Smile" width="18" height="18" /> 
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/Beginning-is-hard-for-beginners.aspx</guid><pubDate>Wed, 09 Jul 2008 09:22:00 +0100</pubDate></item>
<item><title>Possibly the best development diary ever</title><link>http://blogs.xnainfo.com/post/Possibly-the-best-development-diary-ever.aspx</link><description><![CDATA[<p>
I stumbled upon Tim Schafers <a href="http://www.gamespot.com/features/fandango_dd/013098/index.html" target="_blank" title="Grim Fandango Development Diary">development diary for Grim Fandango</a> today on GameSpot. Obviously it&#39;s quite dated, but it&#39;s both interesting and fun to read that there are just some things that never seem to change. 
</p>]]></description><author>feedback@mdxinfo.com (XNAInfo bloggers)</author><guid isPermaLink="true">http://blogs.xnainfo.com/post/Possibly-the-best-development-diary-ever.aspx</guid><pubDate>Tue, 17 Jun 2008 10:15:00 +0100</pubDate></item>
</channel></rss>