<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>digitalerr0r</title>
	<atom:link href="http://digitalerr0r.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://digitalerr0r.wordpress.com</link>
	<description>Modern art using the GPU</description>
	<lastBuildDate>Wed, 15 Feb 2012 21:37:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='digitalerr0r.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>digitalerr0r</title>
		<link>http://digitalerr0r.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://digitalerr0r.wordpress.com/osd.xml" title="digitalerr0r" />
	<atom:link rel='hub' href='http://digitalerr0r.wordpress.com/?pushpress=hub'/>
		<item>
		<title>New game: Project Binary Man</title>
		<link>http://digitalerr0r.wordpress.com/2012/01/29/new-game-project-binary-man/</link>
		<comments>http://digitalerr0r.wordpress.com/2012/01/29/new-game-project-binary-man/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 20:48:17 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Binary Man]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1083</guid>
		<description><![CDATA[Project Binary Man is a 2D-sidescrolling game for Windows Phone. You are a digital-superhero controlled by a scientist who must be able to recover LarsOtek’s new mainframe system. The game is actually a combination of an action-shooter game and a &#8230; <a href="http://digitalerr0r.wordpress.com/2012/01/29/new-game-project-binary-man/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1083&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2012/01/introcomic.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;float:left;padding-top:0;border-width:0;margin:0 10px 0 0;" title="Introcomic" border="0" alt="Introcomic" align="left" src="http://digitalerr0r.files.wordpress.com/2012/01/introcomic_thumb.png?w=293&#038;h=177" width="293" height="177"></a>Project Binary Man is a 2D-sidescrolling game for Windows Phone. You are a digital-superhero controlled by a scientist who must be able to recover LarsOtek’s new mainframe system.</p>
<p>The game is actually a combination of an action-shooter game and a puzzle game, where each enemy is a puzzle itself. The more effective you can kill an enemy, the more points you will get.</p>
<p>Each level is rated with five stars, where a one star is bad, and five stars is perfect.</p>
<p>As the game is based on a superhero, I decided to make the intro with a comic-style to it.</p>
<span style="text-align:center; display: block;"><a href="http://digitalerr0r.wordpress.com/2012/01/29/new-game-project-binary-man/"><img src="http://img.youtube.com/vi/1-z76gfq_RA/2.jpg" alt="" /></a></span>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1083/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1083/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1083/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1083/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1083/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1083/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1083/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1083/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1083&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2012/01/29/new-game-project-binary-man/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2012/01/introcomic_thumb.png" medium="image">
			<media:title type="html">Introcomic</media:title>
		</media:content>
	</item>
		<item>
		<title>Modern Art Using The GPU article</title>
		<link>http://digitalerr0r.wordpress.com/2011/12/20/modern-art-using-the-gpu-article/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/12/20/modern-art-using-the-gpu-article/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 15:37:54 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1079</guid>
		<description><![CDATA[Just wanted to quickly mention that my article “Modern art using the GPU” article for SDJ was published earlier this year. The article is based on my previous tutorials for XNA 3.1. As the article is based on XNA 3.1, &#8230; <a href="http://digitalerr0r.wordpress.com/2011/12/20/modern-art-using-the-gpu-article/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1079&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img style="display:inline;float:left;margin:0 10px 0 0;" align="left" src="http://en.sdjournal.org/wp-content/uploads/2011/07/Modern-art-using-the-GPU-.jpg" width="173" height="250"></p>
<p>Just wanted to quickly mention that my article “Modern art using the GPU” article for SDJ was published earlier this year. The article is based on my previous tutorials for XNA 3.1.</p>
<p>As the article is based on XNA 3.1, it’s a bit out of date. My current tutorial series covering Shader programming for XNA 4.0 will cover most of the differences, but all examples, code, shaders and text is rewritten for the new version.</p>
<p>If you are interested to read this it’s available on <a title="http://en.sdjournal.org/modern-art-using-the-gpu-learn-about-xna-sdj-extra-022011/" href="http://en.sdjournal.org/modern-art-using-the-gpu-learn-about-xna-sdj-extra-022011/">http://en.sdjournal.org/modern-art-using-the-gpu-learn-about-xna-sdj-extra-022011/</a>, but I think you need to be a registered member.</p>
<p>Still, nice to see, and I like the cover <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile3.png?w=640"></p>
<p>Looking forward to work more with my new series. You can find the first three parts in the tutorial section.</p>
<p>&nbsp;</p>
<p>Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1079/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1079/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1079/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1079/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1079/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1079/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1079/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1079/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1079&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/12/20/modern-art-using-the-gpu-article/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://en.sdjournal.org/wp-content/uploads/2011/07/Modern-art-using-the-GPU-.jpg" medium="image" />

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile3.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA 4.0 Shader Programming #3&#8211;Specular light</title>
		<link>http://digitalerr0r.wordpress.com/2011/12/20/xna-4-0-shader-programming-3specular-light/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/12/20/xna-4-0-shader-programming-3specular-light/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 11:46:55 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XNA Shader Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1071</guid>
		<description><![CDATA[Hi, and welcome to Tutorial 3 of my XNA 4.0 Shader Programming tutorial. Today we are going to implement an other lighting algorithm called Specular Lighting. This algorithm builds on my Ambient and Diffuse lighting tutorials, so if you haven’t &#8230; <a href="http://digitalerr0r.wordpress.com/2011/12/20/xna-4-0-shader-programming-3specular-light/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1071&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image4.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb4.png?w=400&#038;h=300" width="400" height="300"></a></p>
<p>Hi, and welcome to Tutorial 3 of my XNA 4.0 Shader Programming tutorial. Today we are going to implement an other lighting algorithm called Specular Lighting. This algorithm builds on my Ambient and Diffuse lighting tutorials, so if you haven’t been trough them, now is the time. <img alt=":)" src="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1308978452g"></p>
<p><b>Technique: Specular light</b></p>
<p>So far, we got a nice lighting model for making a good looking lighting on objects. But, what if we got a blank, polished or shiny object we want to render? Say a metal surface, plastic, glass, bottle and so on? Diffuse light does not include any of the tiny reflections that make a smooth surface shine. </p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image5.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb5.png?w=562&#038;h=263" width="562" height="263"></a></p>
<p>fig 3.1 – specular light in EVE Online (GREAT game btw.)</p>
<p>To simulate this shininess, we can use a lighting model named Specular highlights.<br />Specular highlights calculate another vector that simulates a reflection of a light source, which hits the camera, or “the eye”.
<p>What’s &#8220;the eye&#8221; vector, you might think? Well, it&#8217;s a pretty easy answer to this. It&#8217;s the vector that points from our camera position to the camera target.
<p>We already got this vector in our application code: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:adfa27ae-482e-4f10-b952-846c11ef3900" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp; pad-line-numbers: true;">
viewMatrix   = Matrix.CreateLookAt( new Vector3(x, y, z), Vector3.Zero, Vector3.Up );
</pre>
</pre>
</div>
<p>The position of &#8220;The eye&#8221; is the first parameter in CreateLookAt: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:7c77370d-6bd7-471f-9a3e-8c0426aa6791" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
new Vector3(x, y, z)
</pre>
</pre>
</div>
<p>So let&#8217;s take this vector, and store it in a variable: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:38eb0ba7-8c8d-4fa0-a661-84d5752cc344" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
Vector4 vecEye = new Vector4(x, y, z,0);
</pre>
</pre>
</div>
<p><i>Note: x,y,z represents a point in 3d space.</i> </p>
<p>Let&#8217;s look more closely about how to use the shader after we have created it. </p>
<p>The formula for Specular light is </p>
<p><i><font size="6">I=Ai*Ac+Di*Dc*N.L+Si*Sc*(R.V)<sup>n</sup> (3.1)<br /></font></i></p>
<p>Where </p>
<p><i><font size="6">R=2*(N.L)*N-L</font></i> </p>
<p><em><font size="6"></font></em>&nbsp;
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb6.png?w=577&#038;h=366" width="577" height="366"></a> </p>
<p><em>fig 3.2 – Vector diagram for specular light</em> </p>
<p>As we can see, we got the new Eye vector V, and also we got a reflection vector R. </p>
<p>To compute the specular light, we need to take the dot product of R and V and use this in the power of n, where n is controlling how &#8220;shiny&#8221; the object is. </p>
<p>Implementing the shader</p>
<p>We start with the VertexShader. There is only one modification, and that is to add a View vector to the VertexShaderOutput structure, so we will need to calculate this in the VertexShaderFunction.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:3fb15270-0673-42d5-b1a9-384a0195682f" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
	float3 View : TEXCOORD1;
};
</pre>
</pre>
</div>
<p>To calculate the View vector V (check figure 3.2), we need the position of the “eye”, in other words – the position of the camera, we will need to add a new global variable to the shader.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:ba0f187d-82aa-4a3b-be48-834f43cbe650" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float3 EyePosition;
</pre>
</pre>
</div>
<p>Now, in the vertex shader, we need to set the View-vector in the output structure:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:7bd1fd96-1b66-45c8-9a00-43e6a13adafe" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
output.View = normalize(float4(EyePosition,1.0) - worldPosition);
</pre>
</pre>
</div>
<p>The whole VertexShaderFunction can be seen below:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:a25d7153-52df-4363-81e2-d2f8e42ceadc" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
// The output from the vertex shader, used for later processing
struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
	float3 View : TEXCOORD1;
};

// The VertexShader.
VertexShaderOutput VertexShaderFunction(VertexShaderInput input,float3 Normal : NORMAL)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	float3 normal = normalize(mul(Normal, World));
	output.Normal = normal;
	output.View = normalize(float4(EyePosition,1.0) - worldPosition);

    return output;
}
</pre>
</pre>
</div>
<p>Now we got what we need to calculate the specular light in the pixel shader! <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile2.png?w=640"></p>
<p>The pixel shader will return a float4, which represents the finished color, I, of the current pixel, based on the formula for specular lighting described earlier. </p>
<p>The new thing in the Pixel Shader for Specular Lighting is to calculate and use a reflection vector for L by N, and using this vector to compute the specular light. </p>
<p>So, we start with computing the reflection vector of L by N: <br />R = 2 * (N.L) * N – L </p>
<p>As we can see, we have already computed the Dot product N.L when computing the diffuse light.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:33362351-4b18-4ae1-93ec-a83c2798f50d" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4 diffuse = saturate(dot(-LightDirection,normal));
</pre>
</pre>
</div>
<p>Let’s use this and write the following code: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:dc5e40e4-0900-4410-888d-db67f0d8dd6f" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4 reflect = normalize(2*diffuse*normal-float4(LightDirection,1.0));
</pre>
</pre>
</div>
<p><i>Note: We could also use the reflect function that is built in to HLSL instead, taking an incident vector and a normal vector as parameters, returning a reflection vector:<br />float3 ref =&nbsp; reflect( L, N );</i> </p>
<p>Now, all there is left is to compute the specular light. We know that this is computed by taking the power of the dot product of the reflection vector and the view vector, by n: (R.V)^n <br />You can think of n as a factor for how shiny the object will be. The more n is, the less shiny it is, so play with n to get the result you like. </p>
<p>As you might have noticed, we are using a new HLSL function pow(a,b). What this does is quite simple, it returns a<sup>b</sup>.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:3edd8021-32c5-41a3-8df8-36908ac8db03" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4 specular = pow(saturate(dot(reflect,input.View)),15);
</pre>
</pre>
</div>
<p>Now we are finally ready to put all this together and compute the final pixel color: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:db5502e1-7622-4e9c-b42d-8bd2393b8ea4" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
return AmbientColor*AmbientIntensity+DiffuseIntensity*DiffuseColor*diffuse+SpecularColor*specular;
</pre>
</pre>
</div>
<p>This formula should no longer be a surprise for anyone, right? </p>
<p>We start by calculating the Ambient and Diffuse light, and add these together. Then we take the specular light color and multiply it with the specular component we just calculated, and add it with the Ambient and Diffuse color we created in the previous techniques. </p>
<p>The whole PixelShaderFunction code can be seen below.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:2daf57ba-4ba5-4b1f-9b2b-cd89d59aa60f" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
// The Pixel Shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float4 normal = float4(input.Normal, 1.0);
	float4 diffuse = saturate(dot(-LightDirection,normal));
	float4 reflect = normalize(2*diffuse*normal-float4(LightDirection,1.0));
	float4 specular = pow(saturate(dot(reflect,input.View)),15);

    return AmbientColor*AmbientIntensity+DiffuseIntensity*DiffuseColor*diffuse+SpecularColor*specular;
}
</pre>
</pre>
</div>
<p>And the whole shader effect code:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:99961d29-08ae-491c-83ab-d675bc434ade" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
// XNA 4.0 Shader Programming #2 - Diffuse light

// Matrix
float4x4 World;
float4x4 View;
float4x4 Projection;

// Light related
float4 AmbientColor;
float AmbientIntensity;

float3 LightDirection;
float4 DiffuseColor;
float DiffuseIntensity;

float4 SpecularColor;
float3 EyePosition;


// The input for the VertexShader
struct VertexShaderInput
{
    float4 Position : POSITION0;
};

// The output from the vertex shader, used for later processing
struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
	float3 View : TEXCOORD1;
};

// The VertexShader.
VertexShaderOutput VertexShaderFunction(VertexShaderInput input,float3 Normal : NORMAL)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	float3 normal = normalize(mul(Normal, World));
	output.Normal = normal;
	output.View = normalize(float4(EyePosition,1.0) - worldPosition);

    return output;
}

// The Pixel Shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float4 normal = float4(input.Normal, 1.0);
	float4 diffuse = saturate(dot(-LightDirection,normal));
	float4 reflect = normalize(2*diffuse*normal-float4(LightDirection,1.0));
	float4 specular = pow(saturate(dot(reflect,input.View)),15);

    return AmbientColor*AmbientIntensity+DiffuseIntensity*DiffuseColor*diffuse+SpecularColor*specular;
}

// Our Techinique
technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
</pre>
</pre>
</div>
<p>&nbsp;</p>
<p>In the example, I made the zombie spin instead of the camera so you can see how the specular light is working.</p>
<p>To implement the shader, all we need to do is to add the two new parameters and set them, check the shader source to see how it all fit together <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile2.png?w=640"></p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/download.png"><img title="download" border="0" alt="download" align="left" src="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#038;h=31&#038;h=31" width="31" height="31"></a><a href="https://skydrive.live.com/redir.aspx?cid=2b7007e9ec2ae37b&amp;resid=2B7007E9EC2AE37B!2228&amp;parid=2B7007E9EC2AE37B!2227"><font size="6" face="Segoe WP">Download Source (XNA 4.0)</font></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1071/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1071/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1071/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1071&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/12/20/xna-4-0-shader-programming-3specular-light/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1308978452g" medium="image">
			<media:title type="html">:)</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile2.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile2.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#38;h=31&#38;h=31" medium="image">
			<media:title type="html">download</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA 4.0 Shader Programming #2&#8211;Diffuse light</title>
		<link>http://digitalerr0r.wordpress.com/2011/12/13/xna-4-0-shader-programming-2diffuse-light/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/12/13/xna-4-0-shader-programming-2diffuse-light/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 17:55:59 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XNA Shader Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1056</guid>
		<description><![CDATA[Hi, and welcome to Tutorial 2 of my XNA 4.0 Shader Programming tutorial. Today we are going to work on Tutorial 1 in order to make the lighting equation a bit more interesting, by implementing Diffuse lighting. Diffuse light isn’t &#8230; <a href="http://digitalerr0r.wordpress.com/2011/12/13/xna-4-0-shader-programming-2diffuse-light/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1056&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/t2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="t2" border="0" alt="t2" src="http://digitalerr0r.files.wordpress.com/2011/12/t2_thumb.png?w=400&#038;h=300" width="400" height="300"></a></p>
<p>Hi, and welcome to Tutorial 2 of my XNA 4.0 Shader Programming tutorial. Today we are going to work on Tutorial 1 in order to make the lighting equation a bit more interesting, by implementing Diffuse lighting.</p>
<p>Diffuse light isn’t very different from ambient light implementation wise, but it got one very important property, a direction to the light. As we saw, using only ambient light can make a 3D scene look 2D, but adding a diffuse will increase the realism of the scene and add a nice 3D look to it. Figure 1 shows the same zombie we rendered in the first example, but with diffuse white light, and a dark gray ambient light<br /><a href="http://digitalerr0r.files.wordpress.com/2011/12/clip_image002.gif"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:0;" title="clip_image002" border="0" alt="clip_image002" src="http://digitalerr0r.files.wordpress.com/2011/12/clip_image002_thumb.gif?w=240&#038;h=240" width="240" height="240"></a><br /><em>Figure 1 – Diffuse light</em></p>
<p>As mentioned above, the ambient light got the following equation:
<p><i>I = Aintensity * Acolor (1.1)</i>
<p>Diffuse light builds on this equation, adding a directional light to the equation:
<p><i>I = Aintensity x Acolor + Dintensity x Dcolor x N.L (1.2)</i>
<p>From this equation, you can see that we still use the Ambient light, with an addition of two more variables for describing the color and intensity of the Diffuse light, and two vectors N and L for describing the light direction L and the surface normal N.
<p>We can think of diffuse lighting as a value that indicates how much a surface reflects light. The light that is reflected will be stronger and more visible when the angle between the Normal N and the light direction L gets smaller.
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image7.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb7.png?w=489&#038;h=308" width="489" height="308"></a>
<p>If L is parallel with N, the light will be most reflected, and if L is parallel with the surface, the light will be reflected with the minimal amount.
<p>To compute the angle between L and N, we can use the Dot-product, or the scalar product. This rule is used to find the angle between two given vectors and can be defined as the following:<br />N.L = |N| x |L| x cos(a)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<p>where <b>|N|</b> is the length of vector <b>N</b>, <b>|L|</b> is the length of vector <b>L</b> and <b>cos(a)</b> is the angle between the two vectors.
<p>Let’s try to convert this in to HSLS! In order to do this, we start by defining three new global variables:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:5c6bda81-475c-4d4a-8270-79f2091730f6" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp; pad-line-numbers: true;">
float3 DiffuseDirection;
float4 DiffuseColor;
float DiffuseIntensity;
</pre>
</pre>
</div>
<p>These will contain the direction of the light&nbsp; ( L ), the color of the diffuse light and the intensity of the light.</p>
<p>The Vertex Shader input is the same as before, containing only the position.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:578ee2a2-0708-4713-9797-a83bc9594af6" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
struct VertexShaderInput
{
    float4 Position : POSITION0;
};
</pre>
</pre>
</div>
<p>The VertexShaderOutput will contain one additional member, the Normal. The normal will be calculated in the Vertex Shader function, based on the objects Normal at the given vertex.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:b244fa3b-a6f9-489e-a96c-9b460a57e22a" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
};
</pre>
</pre>
</div>
<p>But where do we get this Normal from? We need to pass in the Normal as input to the Vertex Shader! So.. Why didn’t we add it to the VertexShaderInput structure? Because the NORMAL semantic isn’t supported when defining structures in XNA. So how do we get the normals? We pass in the Normal as a parameter to the VertexShaderFunction in addition to the VertexShaderInput parameter. Sounds complicated? Some code might clear it up for you <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png?w=640"></p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:2b52e216-13b7-45c8-baad-239f1446124b" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
VertexShaderOutput VertexShaderFunction(VertexShaderInput input,float3 Normal : NORMAL)
</pre>
</pre>
</div>
<p>Here you can see that we pass in the VertexShaderInput structure, as well as the Normal. When passing in the parameter directly, the NORMAL semantic will work <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png?w=640"> </p>
<p>The Vertex Shader function is very similar to the one in the ambient light tutorial, but we also transform the Normal into worldspace, as this is the space we would like to calculate the normal in, just like the position:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:0b4bd0de-8c9e-4d1f-8bbc-fedd1f5bc78d" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
VertexShaderOutput VertexShaderFunction(VertexShaderInput input,float3 Normal : NORMAL)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	float3 normal = normalize(mul(Normal, World));
	output.Normal = normal;

    return output;
}
</pre>
</pre>
</div>
<p>So what&#8217;s really happening here? We take the input Normal and multiply it with the World matrix, and then we normalize it and store it in a variable normal. Next, we must remember to set the Normal variable in output, to make sure it’s passed to the Pixel Shader by setting output.Normal = normal.</p>
<p>And that’s really it for the Vertex Shader. But it’s still in the Pixel Shader most of the “magic” happens. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png?w=640"></p>
<p>In order to pass the Normal to the pixel shader, we added a float3 Normal : TEXCOORD0 variable to the VertexShaderOutput structure. We needed to store the Normal in a register on the GPU, but since NORMAL doesn’t exist, we just used another one that is not in use yet; the TEXCOORD0. In other words, TEXCOORDn (n = any number up to the supported amount of registers on your GPU, anything between 0 and 7 is usually safe to use) can be used for any values, and as we don&#8217;t yet use any texture coordinates, we can easily just use these registers as a storage for our Normal-vector.</p>
<p>Moving on. The pixel shaders job is to calculate the final light equation. It will need to implement 1.2:</p>
<p><i>I = Aintensity x Acolor + Dintensity x Dcolor x N.L</i></p>
<p>We already got Aintensity and Acolor. Also, the Dintensity and Dcolor are just variables passed in to the shader, just as the ambient light.</p>
<p>But what about the last part? N.L? This means that we take the dot-product between N and L (remember, the angel of the incoming light, “compared” with the Normal).</p>
<p>Let’s try! First, we store our Normal vector, and convert it to a float4, as this is the variable-type we use in the other calculations. When we use the build in HLSL function dot(x,y) to calculate the dot-product between L and N. Also, we negate L as the value L is containing the direction the light comes FROM, and not where the light points TO.</p>
<p>Now, all that is left is to put this into eq. 1.2 like the code shows below:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:1cf7f3d2-a646-4c11-98ee-847cf01b8456" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float4 norm = float4(input.Normal, 1.0);
	float4 diffuse = saturate(dot(-DiffuseDirection,norm));

    return AmbientColor*AmbientIntensity+DiffuseIntensity*DiffuseColor*diffuse;
}
</pre>
</pre>
</div>
<p>Not very hard right? <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png?w=640"> </p>
<p>Now if you apply this shader to a scene, the output will be something like this:</p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb3.png?w=224&#038;h=427" width="224" height="427"></a></p>
<p>There is nothing new when it comes to how this shader is used in XNA. Take a look at the source so see how it all fits together and play with the values.</p>
<p>The complete shader listing can be seen below:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:41950c37-5c6b-4127-ad9e-2b839016fef4" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
// XNA 4.0 Shader Programming #2 - Diffuse light

// Matrix
float4x4 World;
float4x4 View;
float4x4 Projection;

// Light related
float4 AmbientColor;
float AmbientIntensity;

float3 DiffuseDirection;
float4 DiffuseColor;
float DiffuseIntensity;


// The input for the VertexShader
struct VertexShaderInput
{
    float4 Position : POSITION0;
};

// The output from the vertex shader, used for later processing
struct VertexShaderOutput
{
    float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
};

// The VertexShader.
VertexShaderOutput VertexShaderFunction(VertexShaderInput input,float3 Normal : NORMAL)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);
	float3 normal = normalize(mul(Normal, World));
	output.Normal = normal;

    return output;
}

// The Pixel Shader
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
	float4 norm = float4(input.Normal, 1.0);
	float4 diffuse = saturate(dot(-DiffuseDirection,norm));

    return AmbientColor*AmbientIntensity+DiffuseIntensity*DiffuseColor*diffuse;
}

// Our Techinique
technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
</pre>
</pre>
</div>
<span style="text-align:center; display: block;"><a href="http://digitalerr0r.wordpress.com/2011/12/13/xna-4-0-shader-programming-2diffuse-light/"><img src="http://img.youtube.com/vi/mtMyqffe8y4/2.jpg" alt="" /></a></span>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/download.png"><font size="6" face="Segoe WP"><img title="download" border="0" alt="download" align="left" src="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#038;h=31&#038;h=31" width="31" height="31"></font></a><font size="6" face="Segoe WP"> </font><a href="http://digitalerr0r.darkcodex.net/Tutorials/xnasp2dl.zip"><font size="6" face="Segoe WP">Download Source (XNA 4.0)</font></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1056/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1056/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1056/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1056&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/12/13/xna-4-0-shader-programming-2diffuse-light/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/t2_thumb.png" medium="image">
			<media:title type="html">t2</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/clip_image002_thumb.gif" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#38;h=31" medium="image">
			<media:title type="html">download</media:title>
		</media:content>
	</item>
		<item>
		<title>Kinect Fundamentals #4: Implementing Skeletal Tracking</title>
		<link>http://digitalerr0r.wordpress.com/2011/12/13/kinect-fundamentals-4-implementing-skeletal-tracking/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/12/13/kinect-fundamentals-4-implementing-skeletal-tracking/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 14:50:37 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Kinect]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1045</guid>
		<description><![CDATA[Hi and welcome to tutorial #4 in my Kinect Fundamentals tutorial. In this tutorial, I will show you how you can implement Skeletal Tracking using the Kinect SDK for Windows API, and how you can move a cursor by using &#8230; <a href="http://digitalerr0r.wordpress.com/2011/12/13/kinect-fundamentals-4-implementing-skeletal-tracking/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1045&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb1.png?w=400&#038;h=300" width="400" height="300"></a></p>
<p>Hi and welcome to tutorial #4 in my Kinect Fundamentals tutorial. In this tutorial, I will show you how you can implement Skeletal Tracking using the Kinect SDK for Windows API, and how you can move a cursor by using your hand.</p>
<p>It’s very simple, and it is quite similar to the approaches we have used in the previous tutorials.</p>
<p><strong>Let’s get started!</strong></p>
<p>First of all, you must initialize your NUI Runtime instance using the RuntimeOptions.UseSkeletalTracking parameter, like this:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:52ad95ae-6dae-4857-b9e0-58227b66b85c" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp; pad-line-numbers: true;">
kinectSensor.Initialize(RuntimeOptions.UseSkeletalTracking);
</pre>
</pre>
</div>
<p>Remember, if you want to initialize using more RuntimeOptions you can &amp; them together:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:f45f3fe9-58e8-43a3-a7cb-ebae0f3cd8e3" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
kinectSensor.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking);
</pre>
</pre>
</div>
<p></p>
<p>After the kinect knows that is should start tracking the skeleton, you must tell it how it should be done. You got a lot of different parameters to do this, and the key is to play around with these until you are satisfied.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:ed37d5db-171f-4b3c-8d9d-4026d57a1472" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
kinectSensor.SkeletonEngine.TransformSmooth = true;
TransformSmoothParameters p = new TransformSmoothParameters
{
    Smoothing = 0.75f,
    Correction = 0.0f,
    Prediction = 0.0f,
    JitterRadius = 0.05f,
    MaxDeviationRadius = 0.04f
};


kinectSensor.SkeletonEngine.SmoothParameters = p;
</pre>
</pre>
</div>
<p>Play around with the parameters to see what they do. Basically, it’s all about if you want smooth transforming or not, and how the kinect should anticipate your movement and handle it.</p>
<p>Then you will need to add a new event to your Kinect NUI Runtime object. It’s the same as before but this time you will be using the SkeletonFrameReady event:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:dc9bf200-629e-494e-b7b5-d643930d2471" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
kinectSensor.SkeletonFrameReady += new EventHandler&lt;SkeletonFrameReadyEventArgs&gt;(kinectSensor_SkeletonFrameReady);
</pre>
</pre>
</div>
<p>Only one more thing left, and that is the implementation of the event itself. Let me show you the code first as it’s pretty much self explaining:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:c22b8583-ff60-4faf-a94a-8c22f506d494" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
    SkeletonFrame allSkeletons = e.SkeletonFrame;
    SkeletonData playerSkeleton = (from s in allSkeletons.Skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
    Joint rightHandJoint = playerSkeleton.Joints[JointID.HandRight];

    try
    {
        position = new Vector2((((0.5f * rightHandJoint.Position.X) + 0.5f) * (resolution.X)), (((-0.5f * rightHandJoint.Position.Y) + 0.5f) * (resolution.Y)));
    }
    catch
    {
        // handle error
    }

}
</pre>
</pre>
</div>
<p>First you get all the skeletons in the returned collection. Then we find all the skeletons that belong to the player currently being tracked (this is automatic), and find the joint of the Right Hand. This joint includes a position that you simply can use to render your object at.</p>
<p>All that is left is to render a sprit or 3d model at the returned position.</p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb2.png?w=333&#038;h=283" width="333" height="283"></a></p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/download.png"><font face="Segoe WP"><img title="download" border="0" alt="download" align="left" src="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#038;h=31&#038;h=31" width="31" height="31"></font></a><font face="Segoe WP"><font size="6"> </font><a href="http://digitalerr0r.darkcodex.net/Tutorials/kinect4tutorial.zip"><font size="6">Download Source (XNA 4.0)</font></a></font><font face="Segoe WP"></font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1045/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1045/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1045/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1045/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1045/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1045/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1045/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1045/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1045&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/12/13/kinect-fundamentals-4-implementing-skeletal-tracking/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#38;h=31" medium="image">
			<media:title type="html">download</media:title>
		</media:content>
	</item>
		<item>
		<title>XNA 4.0 Shader Programming #1&#8211;Intro to HLSL, Ambient light</title>
		<link>http://digitalerr0r.wordpress.com/2011/12/12/xna-4-0-shader-programming-1intro-to-hlsl-ambient-light/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/12/12/xna-4-0-shader-programming-1intro-to-hlsl-ambient-light/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 18:36:17 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[XNA Shader Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1036</guid>
		<description><![CDATA[So, you want to learn the magic that puts the gold into modern games? Note: This series is an update to the previous XNA Shader Programming series I have written for XNA 3.0. If you know both XNA 3.0 and &#8230; <a href="http://digitalerr0r.wordpress.com/2011/12/12/xna-4-0-shader-programming-1intro-to-hlsl-ambient-light/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1036&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/tutoriallogo_template.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="tutoriallogo_template" border="0" alt="tutoriallogo_template" src="http://digitalerr0r.files.wordpress.com/2011/12/tutoriallogo_template_thumb.png?w=400&#038;h=300" width="400" height="300"></a>
<p>So, you want to learn the magic that puts the gold into modern games?
<p><em>Note: This series is an update to the previous XNA Shader Programming series I have written for XNA 3.0. If you know both XNA 3.0 and XNA 4.0, it should be no problem for you to understand the shaders from the other series if you want to move on faster than I can update the old ones.</em>
<p>My name is Petri Wilhelmsen and is a member of Dark Codex Studios. We usually participate in various competitions regarding graphics/game development, at The Gathering, Assembly, Solskogen, Dream-Build-Play, NGA and so on.
<p>The XNA Shader Programming series will cover many different aspects of XNA, and how to write HLSL shaders using XNA and your GPU. I will start with some basic theory, and then move over to a more practical approach to shader programming.
<p>The theory part will not be very detailed, but should be enough for you to get started with Shaders and be able to experiment for yourself. It will cover the basics around HLSL, how the HLSL language works and some keywords that is worth knowing about.
<p>Today I will cover XNA and HLSL, as well as a simple ambient lighting algorithm.
<p><strong>Prerequisites<br /></strong>Some programming in XNA (this tutorial is about shader programming and not XNA in it self), as I wont go much into details about loading textures, 3d models, matrices and some math.
<p><b>2001: A shader odyssey – A brief history of shaders</b><br />Before DirectX8, GPU&#8217;s had a fixed way to transform pixels and vertices, called &#8220;The fixed pipeline&#8221;. This made it impossible to developers to change how pixels and vertices was transformed and processed after passing them to the GPU, and made games looked quite similar graphics wise.
<p>In 2001, DirectX8 introduced the vertex and pixel shaders, as a utility that developers could use to decide how the vertices and pixels should be processed when going through the pipeline, giving them a lot of flexibility.<br />An assembly language was used to program the shaders, something that made it pretty hard to be a shader developers, and shader model 1.0 was the only supported version. But this changed once DirectX9 was released, giving developers the opportunity to develop shaders in a high level language, called High Level Shading Language( HLSL ), replacing the assembly shading language with something that looked more like the C-language. This made shaders much easier to write, read and understand.
<p>DirectX10.0 introduced a new shader, the Geometry Shader, and was a part of Shader Model 4.0. But this required a new state-of-the-art graphics card, and Windows Vista.
<p>The latest addition to the DirectX series is the DirectX 11 including a tesselator, DirectCompute for paralell programming and much more.
<p>XNA supports Shader Model 1.0 to 3.0, but works on XP, Vista and XBox360!
<p><b>Taking the red pill</b><br />So, the question is.. What is a shader? Well, a shader is simply a set of instructions that will be run on you graphics processing unit (GPU), performing specific tasks of you need. This makes it possible to developer small/tiny applications that make you in control of three stages in the graphics pipeline: The vertex shader stage, the geometry shader stage, and the pixel shader stage.
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/shaderstages.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="shaderstages" border="0" alt="shaderstages" src="http://digitalerr0r.files.wordpress.com/2011/12/shaderstages_thumb.jpg?w=294&#038;h=616" width="294" height="616"></a>
<p><i>Fig 1 –High level Programmable pipeline</i>
<p>As you can see in fig 1, you are able to program all the green squares, and the rest is fixed, meaning that you cannot control them. The geometry shader is not supported by Xbox360 and XNA, so it will not be covered in this article. Rather, let’s take a quick tour through the vertex and pixel shaders (don’t get frustrated if you don’t understand the code yet, it will be covered in a later section).
<p><b>Vertex shader</b><br />Vertex shaders are used to manipulate vertex-data, per vertex. This can for example be a shader that makes a model “fatter” during rendering by moving vertexes along their normals to a new position for every vertex in the model (deform shaders).<br />Vertex shaders get input from a vertex structure defined in the application code, and load this from the vertex buffer, passed into the shader. This describes what properties each vertex will have during shading: Position, Color, Normal, Tangent and so on.
<p>The vertex shader sends its output for later use to the pixel shader. To define what data the vertex shader will pass to the next stage can be done by defining a structure in the shader, containing the data you want to store, and make the vertex shader return this instance, or by defining parameters in the shader, using the out keyword. Output can be Position, Fog, Color, Texture coordinates, Tangets, Light position and so on.
<p>An example of a simple Vertex Shader that transforms an object to a position on the screen can be seen below.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:09ba6aaa-00a6-4cbf-b2e1-bcd0c37f8b30" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp; pad-line-numbers: true;">
struct VertexShaderInput
{
    float4 Position : POSITION0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    return output;
}
</pre>
</pre>
</div>
<p><b>Pixel shader</b><br />The Pixel shader manipulates all pixels (per pixel) on a given model/object/collection of vertices. This can be a metal box, where we want to customize the lighting algorithm on, colors and so on. The pixel shader gets data from the vertex shader’s output values, like position, normals and texture coordinates, and interpolates these values to the different pixels. A very simple and small pixel shader can look like the snippet below.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:537589b0-a7c5-4b98-b97a-688670c395e5" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    return float4(1,0,0,1);
}
</pre>
</pre>
</div>
<p>The code colors everything that flows through the shader RED.</p>
<p>The pixel shader can have two output values, Color and Depth. </p>
<p>All of the stages displayed in Fig 1 are working together in order to synthesize images and display them on the monitor. </p>
<p>So, are you ready to take control of the GPU using shaders? In that case, sit back, you are about to join a long ride and be reborn in the world of shaders. </p>
<p><b>HLSL<br /></b>High Level Shading Language(HLSL) is used to develop shaders using a language similar to C. Just as in C, HLSL gives you tools like declaring variables, functions, data types, testing( if/else/for/do/while and so on) and much more, in order to create a logic for processing vertices and pixels. Below is a table of some keywords that exists in HLSL. This is not all of them, but some of the most important ones. </p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="234">
<p><b>Examples of datatypes in HSLS</b></p>
</td>
</tr>
<tr>
<td valign="top" width="64">
<p>bool</p>
</td>
<td valign="top" width="170">
<p>true or false</p>
</td>
</tr>
<tr>
<td valign="top" width="64">
<p>int</p>
</td>
<td valign="top" width="170">
<p>32-bit integer</p>
</td>
</tr>
<tr>
<td valign="top" width="64">
<p>half</p>
</td>
<td valign="top" width="170">
<p>16bit integer</p>
</td>
</tr>
<tr>
<td valign="top" width="64">
<p>float</p>
</td>
<td valign="top" width="170">
<p>32bit float</p>
</td>
</tr>
<tr>
<td valign="top" width="64">
<p>double</p>
</td>
<td valign="top" width="170">
<p>64bit double</p>
</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="271">
<p><b>Examples of vectors in HSLS</b></p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>float3 vectorTest</p>
</td>
<td valign="top" width="131">
<p>float x 3</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>float vectorTest[3]</p>
</td>
<td valign="top" width="131">
<p>float x 3</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>vector vectorTest</p>
</td>
<td valign="top" width="131">
<p>float x 3</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>float2 vectorTest</p>
</td>
<td valign="top" width="131">
<p>float x 2</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>bool3 vectorTest</p>
</td>
<td valign="top" width="131">
<p>bool x 3</p>
</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="271">
<p><b>Matrices in HSLS</b></p>
</td>
</tr>
<tr>
<td valign="top" width="83">
<p>float3x3</p>
</td>
<td valign="top" width="188">
<p>a 3&#215;3 matrix, type float</p>
</td>
</tr>
<tr>
<td valign="top" width="83">
<p>float2x2</p>
</td>
<td valign="top" width="188">
<p>a 2&#215;2 matrix, type float</p>
</td>
</tr>
</tbody>
</table>
<p>HSLS offers a huge set of functions that can be used to solve complex equations. As we go through this article, we will cover many, but for now, here is a list with just a handful of them. It’s important to learn all of them in order to create high-performance shaders without re-implementing the wheel. </p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="271">
<p><b>Some functions in HLSL</b></p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>cos( x )</p>
</td>
<td valign="top" width="131">
<p>Returns cosine of x</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>sin( x)</p>
</td>
<td valign="top" width="131">
<p>Returns sinus of x</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>cross( a, b )</p>
</td>
<td valign="top" width="131">
<p>Returns the cross product of two vectors a and b</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>dot( a,b )</p>
</td>
<td valign="top" width="131">
<p>Returns the dot product of two vectors a and b</p>
</td>
</tr>
<tr>
<td valign="top" width="140">
<p>normalize( v )</p>
</td>
<td valign="top" width="131">
<p>Returns a normalized vector v ( v / |v| )</p>
</td>
</tr>
</tbody>
</table>
<p>For a complete list: <a href="http://msdn2.microsoft.com/en-us/library/bb509611.aspx">http://msdn2.microsoft.com/en-us/library/bb509611.aspx</a> </p>
<p><b>Effect files</b><br />Effect files (.fx) makes shader developing in HSLS easier. You can think of them as containers where you can store shader functionality, including vertex-, geometry- and pixel shaders. This includes global variables, functions, structures, vertex shader functions, pixel shader functions, different techniques/passes, textures and so on. </p>
<p>We have already seen how to declare variables and structures in a shader, but what is this technique/passes thing?&nbsp; It’s pretty simple. One Shader can have one or more techniques. One Technique is a piece of functionality that represents one functionality of a given .fx file. Each technique can have a unique name, and from the game/application, we can select what technique in the shader we want to used when rendering a given geometry, by setting the CurrentTechnique property of the Effect class like this: </p>
<p>effect.CurrentTechnique = effect.Techniques["AmbientLight"]; </p>
<p>One .fx file represents one effect. On the line above, we tell the effect to use the technique “AmbientLight”. One technique can have one or more passes, and we must remember to process all passes in order to archive the result we want. </p>
<p>This is an example of a shader containing one technique named “AmbientLight” and one pass named “P0”: </p>
<p>technique AmbientLight<br />{<br />&nbsp;&nbsp;&nbsp; pass P0<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VertexShader = compile vs_1_1 VS();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelShader = compile ps_1_1 PS();<br />&nbsp;&nbsp;&nbsp; }<br />}</p>
<p>This is an example of a shader containing one technique and two passes:<br />technique Shader<br />{<br />pass P0<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VertexShader = compile vs_1_1 VS();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelShader = compile ps_1_1 PS();<br />&nbsp;&nbsp;&nbsp; }<br />pass P1<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VertexShader = compile vs_1_1 VS_Other();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelShader = compile ps_1_1 PS_Other();<br />&nbsp;&nbsp;&nbsp; }<br />}</p>
<p>This is an example of a shader containing two techniques and one pass:<br />technique Shader_11<br />{<br />&nbsp;&nbsp;&nbsp; pass P0<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VertexShader = compile vs_1_1 VS();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelShader = compile ps_1_1 PS();<br />&nbsp;&nbsp;&nbsp; }<br />} </p>
<p>technique Shader_2a<br />{<br />&nbsp;&nbsp;&nbsp; pass P0<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VertexShader = compile vs_1_1 VS2();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelShader = compile ps_2_a PS2();<br />&nbsp;&nbsp;&nbsp; }<br />} </p>
<p>We can see that a technique got two functions, one for the pixel shader and one for the vertex shader: <br />VertexShader = compile vs_1_1 VS2();<br />PixelShader = compile ps_1_1 PS2(); </p>
<p>This tells us that the technique will use VS2() function as the vertex shader, PS2() function as the pixel shader, and the shader requires shader model 1.1 or higher. This makes it possible to have a different and more complex shader for GPUs supporting higher shader model versions, and simpler shaders for older hardware that only support the earlier shader models. </p>
<p><b>XNA and shaders<br /></b>It’s really easy to implement shaders in XNA. In fact, only a few lines of code are needed to load and use a shader. Here is a list of steps that can be followed when making a shader, each of them covered in detail below:<br />1. Make the shader<br />2. Put the shade file (.fx) in “Contents”<br />3. Make an instance of the Effect class<br />4. Initiate the instance of the Effect class.<br />5. Select what technique you want to use<br />6. Pass different parameters to the shader<br />7. Draw the scene/object</p>
<p><b>The steps in a bit more detail:</b> </p>
<p>1.When making a shader, several programs like notepad, the visual studio editor and so on can be used. There are also some shader IDEs available, and personally I like to use nVidias FX Composer: <a href="http://developer.nvidia.com/object/fx_composer_home.html">http://developer.nvidia.com/object/fx_composer_home.html</a> </p>
<p>2. When the shader is created, drag it into the ”Content” folder, so it gets an asset name. The asset name will be the same as the filename of the fx file, but you can edit this asset name so it better suits your needs. </p>
<p>3. XNA Framework includes an Effect class that is used to load and compile the shaders. To make an instance of this class, write the following line of code: </p>
<p>Effect effect;<br />Effect is a part of the “Microsoft.Xna.Framework.Graphics” library, so remember to add this line of code to the using statement block:<br />using Microsoft.Xna.Framework.Graphics; </p>
<p>4. To initiate the shader, we can use the Content property to either load if from the project or from a file: </p>
<p><a href="https://cdmmng.bay.livefilestore.com/y1mUOCkvb3Yv_DVEXdM-Ccv50VJUNhhp4uqO57fpJGTDIzEj3Iwv7ojucSopn8LFG-F7oxFI-tiSucCTOBxd0LgkGBT2AM7BJmJPPVNovs04DRqOSbubr9lKcc6XXV2tLELP-FgRmiksMY/5.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="clip_image001" border="0" alt="clip_image001" src="http://digitalerr0r.files.wordpress.com/2011/12/clip_image001.jpg?w=275&#038;h=124" width="275" height="124"></a><br />effect = Content.Load&lt;Effect&gt;(&#8220;Shader&#8221;);<br />In the line above, “Shader” is the asset name of the shader you added to the Contents folder. </p>
<p>5. Select what technique you want to use: <br />effect.CurrentTechnique = effect.Techniques["AmbientLight"]; </p>
<p>6. Pass the parameters you want to set in the shader. </p>
<p>First you need to create a EffectParamter object:<br />EffectParameter projectionParameter; </p>
<p>Then in the LoadContent() function you bind the parameter object with a variable in the shader:<br />projectionParameter = effect.Parameters["Projection"]; </p>
<p>Now, you can set the parameter by using the SetValue function like this:<br />projectionParameter.SetValue(projection); </p>
<p>where projection is a matrix (here: representing the projection matrix). </p>
<p>7. All that is left is to go through all the different passes in the shader and render your object. This is done by using a loop: </p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:5c5930a6-efc3-4f5b-9342-f70ec05bf8d4" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
for (int i = 0; i &lt; effect.CurrentTechnique.Passes.Count; i++)
{
    //EffectPass.Apply will update the device to
    //begin using the state information defined in the current pass
    effect.CurrentTechnique.Passes[i].Apply();

    //sampleMesh contains all of the information required to draw
    //the current mesh
    graphics.GraphicsDevice.DrawIndexedPrimitives(
        PrimitiveType.TriangleList, 0, 0,
        meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount);
}
</pre>
</pre>
</div>
<p><b>Technique: Ambient light</b><br />So, you now got the answer to what a shader is! Let’s take that in to use and create your first real shader! The first shader you will write is a really simple one that just transforms the vertexes and calculates the ambient light on the model.<br />But wait&#8230; What is the &#8220;Ambient light&#8221; thing we are talking about? </p>
<p>Well, ambient light is the basic light in a scene that&#8217;s “just there”. If you go into a complete dark room, the ambient light is typically zero, but when walking outside there is almost always some light that makes it possible to see. This light got no direction and is there to make sure objects that are facing a light source, will have a basic color. </p>
<p>A scene with only a yellow ambient light can be seen in figure 2. The scene consists of a black background color and an un-textured zombie model. We will make this zombie scene look a lot better as we are going through this series. </p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb.png?w=213&#038;h=320" width="213" height="320"></a> </p>
<p><em>Fig 2. Scene lit with ambient light.</em> </p>
<p>Before we can implement the ambient light technique, we need to understand it. The formula for Ambient light can be seen in 1.1 below.<br /><i>I = Aintensity x Acolor ( 1.1)</i> </p>
<p><b>I</b> is the final light color on a given pixel, <b>Aintensity</b> is the intensity of the light (usually between 0.0 (0%) and 1.0 (100%)), and <b>Acolor</b> is the color of the ambient light. This color can be a hardcoded value, a parameter or a texture. </p>
<p>Ok, let’s start implementing the shader. First of all, we need a matrix that represents the world matrix, the view matrix and the projection matrix:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:55bb85df-cc6e-4b09-af0e-e44fa5837ca8" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4x4 World;
float4x4 View;
float4x4 Projection;

float4 AmbientColor;
float AmbientIntensity;
</pre>
</pre>
</div>
<p></p>
<p>You might also notice that we added two variables in the end, the AmbientColor and AmbientIntensity. I don’t think I need to explain those now? <img style="border-style:none;" class="wlEmoticon wlEmoticon-winkingsmile" alt="Winking smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-winkingsmile.png?w=640"> </p>
<p>Next, we create a structure that will contain the shader inputs, and outputs.<br />These are used in the Vertex Shader itself. </p>
<p>The structures contains a variable of the type float4 with the name Position. The : POSITION in the end tells the GPU what register to put this value in. So, what is a register? Well, a register is simply just a container in the GPU that contains data. The GPU got different registers to put position data, normal, texture coordinates and so on, and when defining a variable that the shader will pass to the pixel shader, we must also decide where in the GPU this value is stored. </p>
<p>When declaring the Vertex Shader function “VertexShaderFunction” (works like the main() function for Vertex Shaders), we specify that the function should return a VertexShaderOutput object (you can name the structure yourself, it could be VSOut and so on), and it takes in the VertexShaderInput structure. All that the shader needs to to is to create an instance of the VertexShaderOutput structure, set its members and return it.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:20bc03a9-c2ce-459b-ab7f-5a2d3bcbebf6" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
struct VertexShaderInput
{
    float4 Position : POSITION0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    return output;
}
</pre>
</pre>
</div>
<p>This is a basic “pass-through” shader. It will take the position of the vertex in the model and transform it to the correct space.</p>
<p>&nbsp;</p>
<p>Next we create the Pixel Shader function, where we will compute the Ambient Light. This takes the output from the Vertex Shader as input. It’s a simple function that takes the pixel it is working on, and color it to the AmbientColor*AmbientIntensity. Simply: A color, the color of the given pixel. Remember, pixel shaders works with one and one pixel at a time.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:80b5edbe-9cda-429f-9044-fe0219f6ae20" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    return AmbientColor*AmbientIntensity;
}
</pre>
</pre>
</div>
<p>&nbsp;</p>
<p>The last thing we need to do is to create the Technique and the passes. This shader will contain one Technique with one pass.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:a477de62-d21d-4f43-aed2-1360638dd15f" class="wlWriterEditableSmartContent">
<pre style="white-space:normal;">
<pre class="brush: csharp;">
technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_2_0 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
</pre>
</pre>
</div>
<p>Ok, thats it! </p>
<p>Now, i recommend you to look at the source code and play around with the values in order to understand how to setup and implement a shader using XNA. Especially, take a look at how the shader is loaded and what parts is needed. I have tried to minimize everything so the code mostly only consists of Shader related code. The camera spins around the model by using a Cos/Sin function on the view matrix. <span style="text-align:center; display: block;"><a href="http://digitalerr0r.wordpress.com/2011/12/12/xna-4-0-shader-programming-1intro-to-hlsl-ambient-light/"><img src="http://img.youtube.com/vi/vn6K5mY_B_w/2.jpg" alt="" /></a></span></p>
<p>&nbsp;
<p><a href="http://digitalerr0r.files.wordpress.com/2011/12/download.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;float:left;padding-top:0;border-width:0;" title="download" border="0" alt="download" align="left" src="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png?w=31&#038;h=31" width="31" height="31"></a>&nbsp;<font size="6" face="Segoe UI"><a href="http://digitalerr0r.darkcodex.net/Tutorials/xnasp1al.zip" target="_blank">Download Source (XNA 4.0)</a></font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1036/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1036/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1036/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1036/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1036/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1036/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1036/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1036/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1036&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/12/12/xna-4-0-shader-programming-1intro-to-hlsl-ambient-light/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/tutoriallogo_template_thumb.png" medium="image">
			<media:title type="html">tutoriallogo_template</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/shaderstages_thumb.jpg" medium="image">
			<media:title type="html">shaderstages</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/clip_image001.jpg" medium="image">
			<media:title type="html">clip_image001</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-winkingsmile.png" medium="image">
			<media:title type="html">Winking smile</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/download_thumb.png" medium="image">
			<media:title type="html">download</media:title>
		</media:content>
	</item>
		<item>
		<title>Updating my Shader Tutorials to XNA 4.0</title>
		<link>http://digitalerr0r.wordpress.com/2011/12/12/updating-my-shader-tutorials-to-xna-4-0/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/12/12/updating-my-shader-tutorials-to-xna-4-0/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 14:25:36 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HLSL]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/?p=1023</guid>
		<description><![CDATA[Just wanted to quickly notify you that I’m in the process of updating all the shader tutorials to XNA 4.0. A lot of people have asked me about it so I decided to do the job. I’ll keep you posted &#8230; <a href="http://digitalerr0r.wordpress.com/2011/12/12/updating-my-shader-tutorials-to-xna-4-0/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1023&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just wanted to quickly notify you that I’m in the process of updating all the shader tutorials to XNA 4.0. A lot of people have asked me about it so I decided to do the job. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile.png?w=640"></p>
<p>I’ll keep you posted once the updates are done!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1023/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1023/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1023/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1023&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/12/12/updating-my-shader-tutorials-to-xna-4-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/12/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Kinect Fundamentals #3: Getting distance-data from the Depth Sensor</title>
		<link>http://digitalerr0r.wordpress.com/2011/06/21/kinect-fundamentals-3-getting-data-from-the-depth-sensor/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/06/21/kinect-fundamentals-3-getting-data-from-the-depth-sensor/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 18:04:28 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Kinect]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/2011/06/21/kinect-fundamentals-3-getting-data-from-the-depth-sensor/</guid>
		<description><![CDATA[Now that you know how to use the RGB Camera data, it’s time to take a look at how you can use the depth data from the Kinect sensor. It’s quite similar to getting data from the RGB image, but &#8230; <a href="http://digitalerr0r.wordpress.com/2011/06/21/kinect-fundamentals-3-getting-data-from-the-depth-sensor/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1010&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image11.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb11.png?w=400&#038;h=300" alt="image" width="400" height="300" border="0" /></a><br />
Now that you know how to use the RGB Camera data, it’s time to take a look at how you can use the depth data from the Kinect sensor.</p>
<p>It’s quite similar to getting data from the RGB image, but instead of RGB values, you have distance data. We will convert the distance into a black and white image representing the depth map. Remember, there are two sensors that contains distance data, so this need to be handled.</p>
<p><strong><span style="color:#9b00d3;">Initializing the Kinect Sensor</span></strong></p>
<p>Not much new here from the other tutorial, with an exception of some parameters. First, we need to create an instance of the Runtime object, and the Texture2D object that will contain the depth data.</p>
<p><span style="color:#9b00d3;font-size:x-small;">Runtime kinectSensor;</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">Texture2D kinectDepthVideo;</span></p>
<p>Next, in the Initialize(..) function, we initialize the Runtime instance to return DepthData using RuntimeOptions.UseDepth as the parameter to the Initialize function.</p>
<p><span style="color:#9b00d3;font-size:x-small;">protected override void Initialize()<br />
{<br />
// TODO: Add your initialization logic here<br />
kinectSensor = new Runtime();<br />
kinectSensor.Initialize(RuntimeOptions.UseDepth);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    base.Initialize();<br />
}</span></p>
<p>We also have to create the event that will handle the data received from the Kinect sensor:</p>
<p><span style="font-size:x-small;">kinectSensor.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth);<br />
kinectSensor.DepthFrameReady += new EventHandler&lt;ImageFrameReadyEventArgs&gt;(kinectSensor_DepthFrameReady);</span></p>
<p>Here, we open the DepthStream and tell the sensor that we want to have depth data with the resolution of 320&#215;240. We also create an event handler that kicks in everytime the kinect got some data ready for us.</p>
<p><strong><span style="color:#9b00d3;">Converting the depth data</span></strong></p>
<p>Now is the time for the meat of this tutorial. Here we get the depth data from the device in millimeter, and convert it into a distance we can use for displaying a black and white map of the depth. The Kinect device got a range from 0.85m to 4m. We can use this knowledge to create a black and white image where each pixel is the distance from the camera. White pixels are close, while black are far. We might also get some unknown depth pixels if the rays are hitting a window, shadow, mirror and so on (these will have the distance of 0).</p>
<p>Because we are using a Depth Image, there are two bytes per pixel that represents the distance (one from each depth sensor). To get the distance at a given pixel, you will need to bitshift the second byte left by 8.</p>
<p>Let’s take a look at the code.</p>
<p><span style="color:#9b00d3;font-size:x-small;">void kinectSensor_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)<br />
{<br />
PlanarImage p = e.ImageFrame.Image;</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    Color[] DepthColor = new Color[p.Height * p.Width];</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    float maxDist = 4000;<br />
float minDist = 850;<br />
float distOffset = maxDist &#8211; minDist;</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    kinectDepthVideo = new Texture2D(GraphicsDevice, p.Width, p.Height);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    int index = 0;<br />
for (int y = 0; y &lt; p.Height; y++)<br />
{<br />
for (int x = 0; x &lt; p.Width; x++, index += 2)<br />
{<br />
int n = (y * p.Width + x) * 2;<br />
int distance = (p.Bits[n + 0]  |  p.Bits[n + 1] &lt;&lt; 8);<br />
byte intensity = (byte)(255 &#8211; (255 * Math.Max(distance &#8211; minDist, 0) / (distOffset)));<br />
DepthColor[y * p.Width + x] = new Color(intensity, intensity, intensity);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">        }<br />
}</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    kinectDepthVideo.SetData(DepthColor);<br />
}</span></p>
<p>First, we get the raw image as a PlanarImage. Next, we create a Color array (as in the previous tutorial) that will contain the pixeldata.</p>
<p>Then we create three variables, the minimum distance from the Kinect sensor, the maximum distance, and the offset between these.</p>
<p>Now, for every pixel x,y in the data, we calculate the distance. This is done by first finding the index of the pixel and byte we are getting the distance from. Then we bitshift this left by 8 to get the correct distance.</p>
<p>Now that we have the distance, we convert it to a value between 0 and 255, based on the distance, and store this to create a black and white texture.</p>
<p><strong><span style="color:#9b00d3;">Rendering</span></strong></p>
<p>Last we render the texture using a sprite batch.</p>
<p><span style="color:#9b00d3;font-size:x-small;">protected override void Draw(GameTime gameTime)<br />
{<br />
GraphicsDevice.Clear(Color.CornflowerBlue);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    // TODO: Add your drawing code her</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    spriteBatch.Begin();<br />
spriteBatch.Draw(kinectDepthVideo, new Rectangle(0, 0, 640, 480), Color.White);<br />
spriteBatch.Draw(overlay, new Rectangle(0, 0, 640, 480), Color.White);<br />
spriteBatch.End();</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    base.Draw(gameTime);<br />
}</span></p>
<p>And that&#8217;s it for getting the depth data. <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://digitalerr0r.files.wordpress.com/2011/06/wlemoticon-smile2.png?w=640" alt="Smilefjes" /> The result should be something similar to below:</p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image12.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb12.png?w=294&#038;h=220" alt="image" width="294" height="220" border="0" /></a></p>
<p>Download: <a href="http://digitalerr0r.darkcodex.net/Tutorials/KinectFundamentals_tutorial3.rar" target="_blank">Source (XNA 4.0 + Kinect for Windows SDK beta)</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1010/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1010/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1010/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1010/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1010/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1010/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1010/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1010/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1010&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/06/21/kinect-fundamentals-3-getting-data-from-the-depth-sensor/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb11.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/wlemoticon-smile2.png" medium="image">
			<media:title type="html">Smilefjes</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb12.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Kinect Fundamentals #2: Basic programming</title>
		<link>http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-2-basic-programming/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-2-basic-programming/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 23:39:49 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Kinect]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-2-basic-programming/</guid>
		<description><![CDATA[Our first Kinect program will be using XNA 4.0 to create a texture that is updated with a new image from the Kinect Sensor every time a new image is created, thus displaying a video. Setting up the project Create &#8230; <a href="http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-2-basic-programming/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1001&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb7.png?w=400&#038;h=300" alt="image" width="400" height="300" border="0" /></a></p>
<p>Our first Kinect program will be using XNA 4.0 to create a texture that is updated with a new image from the Kinect Sensor every time a new image is created, thus displaying a video.</p>
<p><strong><span style="color:#9b00d3;">Setting up the project<br />
</span></strong>Create a new XNA Windows game and give it a name. To use the Kinect SDK, you will need to add a reference to it. This can be done by right clicking on the References folder, click Add Reference.. and in the .NET tab find Microsoft.Research.Kinect.<br />
<a href="http://digitalerr0r.files.wordpress.com/2011/06/image8.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb8.png?w=459&#038;h=198" alt="image" width="459" height="198" border="0" /></a></p>
<p>Click OK to add it, and you will see it in the projects references.<br />
<a href="http://digitalerr0r.files.wordpress.com/2011/06/image9.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb9.png?w=220&#038;h=35" alt="image" width="220" height="35" border="0" /></a></p>
<p>Next, you will need to add a using statement to it, by adding this line below the rest of the using statements:<br />
using Microsoft.Research.Kinect.Nui;</p>
<p><span style="color:#9b00d3;"><strong>Creating the NUI object<br />
</strong></span>Now we are ready to create the object that will “hold” the Kinect Sensor. The Kinect SDK have a class named Runtime that contains the NUI library. To get what you need our from the Kinect Sensor, instantiate an object from this class:<br />
Runtime kinectSensor;</p>
<p>We also create a Texture2D object that will contain our images:<br />
<span style="color:#9b00d3;font-size:x-small;">Texture2D kinectRGBVideo;</span></p>
<p>Now we need to initialize the object to get the streams we want. We want out application to simply render what the Kinect can see (images from the RGB Camera). To do this, we initialize the Runtime object to have RuntimeOptions.UseColor.</p>
<p><span style="color:#9b00d3;font-size:x-small;">protected override void Initialize()<br />
{<br />
// TODO: Add your initialization logic here<br />
kinectSensor = new Runtime();<br />
kinectSensor.Initialize(RuntimeOptions.UseColor);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">            base.Initialize();<br />
}</span></p>
<p>This makes the RGB Camera in the Kinect Sensor ready for use.</p>
<p>Getting images from the Kinect RGB camera<br />
Now that the camera is ready, we will need to specify what the camera should return (resolution). We want the 640&#215;480 resolution:</p>
<p><span style="color:#9b00d3;font-size:x-small;">protected override void LoadContent()<br />
{<br />
// Create a new SpriteBatch, which can be used to draw textures.<br />
spriteBatch = new SpriteBatch(GraphicsDevice);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    kinectRGBVideo = new Texture2D(GraphicsDevice, 1337, 1337);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    kinectSensor.VideoStream.Open(ImageStreamType.Video,<br />
2,  ImageResolution.Resolution640x480,<br />
ImageType.Color);<br />
kinectSensor.VideoFrameReady += new EventHandler&lt;ImageFrameReadyEventArgs&gt;<br />
(kinectSensor_VideoFrameReady);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    // TODO: use this.Content to load your game content here<br />
}</span></p>
<p>First we open the video stream and tell it to capture images of 640&#215;480. Then we create an eventhandler VideoFrameReady that is running every time the device captures and image. Now, all that is left is to convert this raw-image data to a Texture object, and render it. Also, we create a new instance of a blank 2D texture.</p>
<p><strong><span style="color:#9b00d3;">Creating our Texture2D object</span></strong><br />
This function is very simple. It captures the image from the Kinect sensor, creates a Color array, fills it with the data from the captures image for each pixel, and then finally stores it in a Texture2d object. Let’s take a look at the EventHandler:</p>
<p><span style="color:#9b00d3;font-size:x-small;">void kinectSensor_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)<br />
{<br />
PlanarImage p = e.ImageFrame.Image;</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    Color[] color = new Color[p.Height * p.Width];<br />
kinectRGBVideo = new Texture2D(graphics.GraphicsDevice, p.Width, p.Height);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    int index = 0;<br />
for (int y = 0; y &lt; p.Height; y++)<br />
{<br />
for (int x = 0; x &lt; p.Width; x++, index += 4)<br />
{<br />
color[y * p.Width + x] =<br />
new Color(p.Bits[index + 2], p.Bits[index + 1], p.Bits[index + 0]);<br />
}<br />
}</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    kinectRGBVideo.SetData(color);<br />
}</span></p>
<p>Alos, in the UnloadContent (or Dispose), add the following line:</p>
<p><span style="color:#9b00d3;font-size:x-small;">protected override void UnloadContent()<br />
{<br />
// TODO: Unload any non ContentManager content here<br />
kinectSensor.Uninitialize();<br />
}</span></p>
<p><strong><span style="color:#9b00d3;">Rendering</span></strong></p>
<p>We only need to render the Texture2D image as a normal texture:</p>
<p><span style="color:#9b00d3;font-size:x-small;">protected override void Draw(GameTime gameTime)<br />
{<br />
GraphicsDevice.Clear(Color.CornflowerBlue);</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    // TODO: Add your drawing code her</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    spriteBatch.Begin();<br />
spriteBatch.Draw(kinectRGBVideo, new Rectangle(0, 0, 640, 480), Color.White);<br />
spriteBatch.Draw(overlay, new Rectangle(0, 0, 640, 480), Color.White);<br />
spriteBatch.End();</span></p>
<p><span style="color:#9b00d3;font-size:x-small;">    base.Draw(gameTime);<br />
}</span></p>
<p>This should render the image that the Kinect Sensor is taking, 30 images pr. second. Below is a screenshot from our application.</p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image10.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb10.png?w=263&#038;h=198" alt="image" width="263" height="198" border="0" /></a></p>
<p>Download: <a href="http://digitalerr0r.darkcodex.net/Tutorials/KinectFundamentals_Tutorial1.rar" target="_blank">Source (XNA 4.0, Kinect for Windows SDK beta)</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/1001/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/1001/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/1001/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=1001&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-2-basic-programming/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Kinect Fundamentals #1: Installation &amp; Setup</title>
		<link>http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-1-installation-setup/</link>
		<comments>http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-1-installation-setup/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 22:19:17 +0000</pubDate>
		<dc:creator>digitalerr0r</dc:creator>
				<category><![CDATA[Kinect]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">https://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-1-installation-setup/</guid>
		<description><![CDATA[What is the Kinect? The Kinect is a motion sensing device for XBOX 360, and now also for Windows. It is a natural user interface for interacting with the XBOX 360 and Windows PC by using gestures and body movement, &#8230; <a href="http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-1-installation-setup/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=990&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb.png?w=400&#038;h=300" width="400" height="300"></a></p>
<p><strong><font color="#9b00d3">What is the Kinect?</font></strong><br /><img src="http://crenk.com/wp-content/uploads/2010/07/kinect.jpg" width="359" height="224"></p>
<p>The Kinect is a motion sensing device for XBOX 360, and now also for Windows. It is a natural user interface for interacting with the XBOX 360 and Windows PC by using gestures and body movement, instead of a controller.</p>
<p><strong><font color="#9b00d3">The Kinect Sensor</font></strong><br />The Kinect Sensor device consists of an RGB camera taking 30 images pr. second (not a video stream) @ <strong>640&#215;480</strong>, and 15 images pr. second @ <strong>1280&#215;1024</strong>, depth cameras (infrared) and a multi-array mic.</p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb1.png?w=484&#038;h=231" width="484" height="231"></a></p>
<p><strong><font color="#9b00d3">Connecting the Kinect</font></strong></p>
<p>Step 0:<br />If you don’t have a Kinect Sensor, you can (probably) find it at your nearest electronics dealer.</p>
<p>Step 1: <br />Download and install the Kinect SDK:<br /><a title="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/" href="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/">http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/</a></p>
<p>Step 2:<br />Connect the Kinect device using the adapter for USB (if the plug is orange, don’t plug it, you will need the adapter) and Automatic Update will install the drivers.<br /><a href="http://digitalerr0r.files.wordpress.com/2011/06/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb2.png?w=513&#038;h=217" width="513" height="217"></a><br />If correctly installed, you can see the device in Device Manager (Control panel-&gt;System). <br /><a href="http://digitalerr0r.files.wordpress.com/2011/06/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb3.png?w=261&#038;h=74" width="261" height="74"></a></p>
<p>Once the Kinect is connected, you can find the microphone as any other microphone connected to your PC.</p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image4.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb4.png?w=334&#038;h=50" width="334" height="50"></a></p>
<p><strong><font color="#9b00d3">Testing the Kinect<br /></font></strong>There should be an application that you can use to view the skeletal. The application was installed with the Kinect SDK.<br /><a href="http://digitalerr0r.files.wordpress.com/2011/06/image5.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb5.png?w=234&#038;h=111" width="234" height="111"></a></p>
<p>Now start the Sample Skeletal Viewer and see how it reacts to your sensor. <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smilefjes" src="http://digitalerr0r.files.wordpress.com/2011/06/wlemoticon-smile1.png?w=640"></p>
<p><a href="http://digitalerr0r.files.wordpress.com/2011/06/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="image" border="0" alt="image" src="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb6.png?w=479&#038;h=172" width="479" height="172"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/digitalerr0r.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/digitalerr0r.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/digitalerr0r.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/digitalerr0r.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/digitalerr0r.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/digitalerr0r.wordpress.com/990/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/digitalerr0r.wordpress.com/990/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/digitalerr0r.wordpress.com/990/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=digitalerr0r.wordpress.com&amp;blog=17968461&amp;post=990&amp;subd=digitalerr0r&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://digitalerr0r.wordpress.com/2011/06/20/kinect-fundamentals-1-installation-setup/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ae142c9015a7dd01506596b91003322c?s=96&#38;d=retro&#38;r=G" medium="image">
			<media:title type="html">digitalerr0r</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://crenk.com/wp-content/uploads/2010/07/kinect.jpg" medium="image" />

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smilefjes</media:title>
		</media:content>

		<media:content url="http://digitalerr0r.files.wordpress.com/2011/06/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>
