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

<channel>
	<title>Catalin&#039;s XNA Blog &#187; HLSL</title>
	<atom:link href="http://www.catalinzima.com/category/hlsl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.catalinzima.com</link>
	<description>XNA Tutorials, Samples and Thoughts</description>
	<lastBuildDate>Tue, 20 Sep 2011 19:51:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>New tutorial: Crash Course in HLSL</title>
		<link>http://www.catalinzima.com/2009/11/new-tutorial-crash-course-in-hlsl/</link>
		<comments>http://www.catalinzima.com/2009/11/new-tutorial-crash-course-in-hlsl/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 22:00:14 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=583</guid>
		<description><![CDATA[I&#8217;m happy to announce a new tutorial, which happened by chance I accidentally stumbled upon some old drafts of mine for a project that never saw the light of day, and I decided to post one of those drafts online. It talks about the High Level Shading Language, some of its history, syntax and structure.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to announce a new tutorial, which happened by chance <img src='http://www.catalinzima.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I accidentally stumbled upon some old drafts of mine for a project that never saw the light of day, and I decided to post one of those drafts online.</p>
<p>It talks about the High Level Shading Language, some of its history, syntax and structure. The whole tutorial can be found either<a href="http://www.catalinzima.com/?page_id=575"> here on this site</a>; or on <a href="http://www.sgtconker.com/2009/11/crash-course-in-hlsl/">sgtconker.com</a>. I hope you enjoy it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2009/11/new-tutorial-crash-course-in-hlsl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working on shadows&#8230;</title>
		<link>http://www.catalinzima.com/2009/09/working-on-shadows/</link>
		<comments>http://www.catalinzima.com/2009/09/working-on-shadows/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 06:40:33 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[2D]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=554</guid>
		<description><![CDATA[Those that follow my twitter account have seen this already, but I wanted to let everyone know I&#8217;m working on a system for 2D dynamic shadows, again. However, this one is very different from the last sample I made on the subject. In that one, you had to define the geometry of the shadow casters,]]></description>
			<content:encoded><![CDATA[<p>Those that follow my twitter account have seen this already, but I wanted to let everyone know I&#8217;m working on a system for 2D dynamic shadows, again.</p>
<p>However, this one is very different from the<a href="http://www.catalinzima.com/?page_id=313"> last sample</a> I made on the subject. In that one, you had to define the geometry of the shadow casters, and build the shadows based on that. This process also implied lots of computations done each frame on the CPU, which yielded in low peformance. So all in all, even though it looked great, I was never really satisfied with tat technique for shadows.</p>
<p>I spent a lot of time thinking of an alternative way to do dynamic 2D shadows, while not using the CPU too much, and having unlimited complexity for the shadow casters. And two weeks ago, the idea hit me. I&#8217;m not going to go into technical details just yet, since I plan to make a nice tutorial about this, but I can say that my idea was based on taking the concept of shadow maps from 3D and somehow use it in 2D.</p>
<p>Here&#8217;s two pictures of how it looks so far:</p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2009/09/30766017.png" title="30766017.png"><img src="http://www.catalinzima.com/wp-content/uploads/2009/09/30766017.thumbnail.png" alt="first version" /></a></p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2009/09/30977885.png" title="30977885.png"><img src="http://www.catalinzima.com/wp-content/uploads/2009/09/30977885.thumbnail.png" alt="second version" /></a></p>
<p>As you can see, the casters can have any shape and complexity, and furthermore, the complexity of the shadow casters has no effect on the framerate.</p>
<p>I&#8217;m still working on this, but you&#8217;ll know as soon as it&#8217;s done.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2009/09/working-on-shadows/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>FX Composer rocks!</title>
		<link>http://www.catalinzima.com/2008/11/fx-composer-rocks/</link>
		<comments>http://www.catalinzima.com/2008/11/fx-composer-rocks/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 09:33:40 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[HLSL]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=428</guid>
		<description><![CDATA[I had NVIDIA&#8217;s FX Composer installed on my PC for a long time now, as part of my development tools, but rarely used it after installing it. Usually, when I want to experiment with a new shader, I boot up XNA GS, add a random model to the scene, add a new Effect file, apply]]></description>
			<content:encoded><![CDATA[<p>I had <a href="http://developer.nvidia.com/object/FX_Composer_Home.html">NVIDIA&#8217;s FX Composer</a> installed on my PC for a long time now, as part of my development tools, but rarely used it after installing it. </p>
<p>Usually, when I want to experiment with a new shader, I boot up XNA GS, add a random model to the scene, add a new Effect file, apply the Effect on the model, and then start experimenting with the shader code.</p>
<p>Today, I decided to implement a idea I had for next month&#8217;s sample, but instead of going my usual route, I decided to click the FX Composer icon. After about 5 minutes of figuring out the menus and various operations you can do, I was in shader-prototyping heaven. </p>
<p>For a simple comparison: you probably know how when writing native DirectX/OpenGL applications, you have to write some window management code and game loop code before you can get to writing your game, while XNA GS simply lets you write the game. This is exactly what FX Composer does for me.</p>
<p>You can go directly to writing your shader, without bothering with scene management and objects. The changes you make to the shaders are reflected in the rendering window with a single click, and it even provides toolbar buttons to add some basic models in the scene and test your shaders on them. (and that&#8217;s a giant understatement of the features available in FX Composer)</p>
<p>The only thing I would like improved at this moment is some IntelliSense-like features beyond simple syntax highlighting. But given the fact that even in Visual Studio you have notepad-like features for shaders (unless you use <a href="http://intelishade.net/">InteliShade</a>), I&#8217;ll take what is given to me.</p>
<p>So I wholeheartedly recommend FX Composer to anyone interested in shader prototyping/development. It&#8217;s a great tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/11/fx-composer-rocks/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>July Sample: Rim Lighting</title>
		<link>http://www.catalinzima.com/2008/07/july-sample-rim-lighting/</link>
		<comments>http://www.catalinzima.com/2008/07/july-sample-rim-lighting/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 21:08:05 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Dino]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=399</guid>
		<description><![CDATA[I&#8217;m going to go on vacation soon, so I&#8217;m putting the July sample online. It&#8217;s not much, since I&#8217;ve been busy writing the Fur Rendering Tutorial, but I think it&#8217;s a nice effect. The sample is dedicated to Rim Lighting, an effect seen in some &#34;cute&#34; games. Read more about it and get the source]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to go on <a href="http://wikimapia.org/#lat=35.8916359&amp;lon=10.5979496&amp;z=18&amp;l=0&amp;m=a&amp;v=2">vacation</a> soon, so I&#8217;m putting the <a href="http://www.catalinzima.com/?page_id=396">July sample</a> online. It&#8217;s not much, since I&#8217;ve been busy writing the Fur Rendering Tutorial, but I think it&#8217;s a nice effect.</p>
<p>The sample is dedicated to Rim Lighting, an effect seen in some &quot;cute&quot; games. Read more about it and get the source code <a href="http://www.catalinzima.com/?page_id=396">here</a>.</p>
<p><a href="http://www.catalinzima.com/?page_id=396"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="434" alt="RimLightTest 2008-07-18 23-20-23-84" src="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-18-23-20-23-84.jpg" width="560" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/07/july-sample-rim-lighting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fur Rendering in XNA</title>
		<link>http://www.catalinzima.com/2008/07/fur-rendering-in-xna/</link>
		<comments>http://www.catalinzima.com/2008/07/fur-rendering-in-xna/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 19:49:57 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[Dino]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=385</guid>
		<description><![CDATA[My fur rendering article just went online on Ziggyware. It is an entry for the Summer Ziggyware XNA Article Contest, so if you like it, vote for it when voting begins, in a few days. The article explains how to draw fur, animate it, and apply it on models. You can read it here.]]></description>
			<content:encoded><![CDATA[<p>My fur rendering article just went online on <a href="http://www.ziggyware.com/readarticle.php?article_id=194">Ziggyware</a>. It is an entry for the <a href="http://www.ziggyware.com/news.php?readmore=746">Summer Ziggyware XNA Article Contest</a>, so if you like it, vote for it when voting begins, in a few days.</p>
<p>The article explains how to draw fur, animate it, and apply it on models.</p>
<p>You can read it <a href="http://www.ziggyware.com/readarticle.php?article_id=194">here</a>.</p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-09-01-26-51-97.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="180" alt="FurRender 2008-07-09 01-26-51-97" src="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-09-01-26-51-97-thumb.jpg" width="240" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/07/fur-rendering-in-xna/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Coming Soon&#8230;</title>
		<link>http://www.catalinzima.com/2008/07/coming-soon/</link>
		<comments>http://www.catalinzima.com/2008/07/coming-soon/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 11:39:44 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[Tease]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=375</guid>
		<description><![CDATA[Fake Rim Lighting, for use in cute games (inspired by Super Mario Galaxy screenshots) Fur]]></description>
			<content:encoded><![CDATA[<p>Fake Rim Lighting, for use in cute games (inspired by Super Mario Galaxy screenshots)</p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-02-11-42-59-12.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="RimLightTest 2008-07-02 11-42-59-12" src="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-02-11-42-59-12-thumb.jpg" width="240" height="180" /></a> <a href="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-02-11-42-26-62.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="RimLightTest 2008-07-02 11-42-26-62" src="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-02-11-42-26-62-thumb.jpg" width="240" height="180" /></a> </p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-02-11-42-41-85.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="RimLightTest 2008-07-02 11-42-41-85" src="http://www.catalinzima.com/wp-content/uploads/2008/07/rimlighttest-2008-07-02-11-42-41-85-thumb.jpg" width="240" height="180" /></a> </p>
<p>Fur</p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-13-32-03-11.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="FurRender 2008-07-02 13-32-03-11" src="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-13-32-03-11-thumb.jpg" width="240" height="180" /></a> <a href="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-13-31-16-24.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="FurRender 2008-07-02 13-31-16-24" src="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-13-31-16-24-thumb.jpg" width="240" height="180" /></a> </p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-14-29-47-10.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="FurRender 2008-07-02 14-29-47-10" src="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-14-29-47-10-thumb.jpg" width="240" height="180" /></a> <a href="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-14-30-14-23.jpg"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" border="0" alt="FurRender 2008-07-02 14-30-14-23" src="http://www.catalinzima.com/wp-content/uploads/2008/07/furrender-2008-07-02-14-30-14-23-thumb.jpg" width="240" height="180" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/07/coming-soon/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Small pre-pre-beta shadow mapping lirary</title>
		<link>http://www.catalinzima.com/2008/05/small-pre-pre-beta-shadow-mapping-lirary/</link>
		<comments>http://www.catalinzima.com/2008/05/small-pre-pre-beta-shadow-mapping-lirary/#comments</comments>
		<pubDate>Tue, 27 May 2008 23:03:27 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=336</guid>
		<description><![CDATA[I&#8217;m releasing a small library for shadow mapping in XNA. This is the beginning of a library that will allow using shadow maps in XNA without writing a new shader, or setting up your models. Just using some calls to a library class. I also included a small example of using the library with 1]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m releasing a small library for shadow mapping in XNA. This is the beginning of a library that will allow using shadow maps in XNA without writing a new shader, or setting up your models. Just using some calls to a library class.</p>
<p>I also included a small example of using the library with 1 object. The main class of the library is ShadowMapRenderer, and it implements PCF shadow mapping, with screen-space bluring.</p>
<p>Remember, this is a very early version, I will probably change the API very much until a real beta version. I just thought I&#8217;d put it out to help people who want to have quick shadows in their 3D games.</p>
<p>You can download it here: <a href="http://www.catalinzima.com/wp-content/uploads/2008/05/shadowmaptest.zip" title="ShadowMapRenderer">ShadowMapRenderer</a></p>
<p>Have Fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/05/small-pre-pre-beta-shadow-mapping-lirary/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Can a 2D image intersect a 3D model?</title>
		<link>http://www.catalinzima.com/2008/05/can-a-2d-image-intersect-a-3d-model/</link>
		<comments>http://www.catalinzima.com/2008/05/can-a-2d-image-intersect-a-3d-model/#comments</comments>
		<pubDate>Mon, 19 May 2008 00:01:05 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[2D]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=335</guid>
		<description><![CDATA[Yes it can My may sample is also my first public sample written in XNA Game Studio 3.0 CTP, and it shows how to restore the depth buffer from a depth texture. This way, models drawn to a render target, with post processing applied to them can intersect and obscure normal models, drawn after all]]></description>
			<content:encoded><![CDATA[<p>Yes it can <img src='http://www.catalinzima.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>My may sample is also my first public sample written in XNA Game Studio 3.0 CTP, and it shows how to restore the depth buffer from a depth texture.</p>
<p>This way, models drawn to a render target, with post processing applied to them can intersect and obscure normal models, drawn after all the post processing is done.</p>
<p>For more details, jump to the sample&#8217;s page: <a href="http://www.catalinzima.com/?page_id=330">Restoring the Depth Buffer</a>, where you can find a short explanation on how the sample works.</p>
<p>To dive right into the code, download it <a href="http://www.catalinzima.com/wp-content/uploads/2008/05/depthrecovery.zip">here</a>. Please note that the sample is written in XNA Game Studio 3.0 CTP, but the technique also works just fine in 2.0.</p>
<p><a href="http://www.catalinzima.com/wp-content/uploads/2008/05/depthrecovery-2008-05-19-02-30-51-86.jpg"><img src="http://www.catalinzima.com/wp-content/uploads/2008/05/depthrecovery-2008-05-19-02-30-51-86-thumb.jpg" style="border: 0px none " alt="DepthRecovery 2008-05-19 02-30-51-86" width="240" border="0" height="180" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/05/can-a-2d-image-intersect-a-3d-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting Displacement Maps into Normal maps</title>
		<link>http://www.catalinzima.com/2008/01/converting-displacement-maps-into-normal-maps/</link>
		<comments>http://www.catalinzima.com/2008/01/converting-displacement-maps-into-normal-maps/#comments</comments>
		<pubDate>Tue, 29 Jan 2008 01:44:59 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[HLSL]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=106</guid>
		<description><![CDATA[This is a repost from the old blog, since this is one of those interesting stuff, which weren&#8217;t big enough to warrant a sample. Working on my VTF tutorial, I came across the need to apply lighting to a terrain. For lighting, we need normals, of course, but I only had heightmaps available. When the]]></description>
			<content:encoded><![CDATA[<p>This is a repost from the old blog, since this is one of those interesting stuff, which weren&#8217;t big enough to warrant a sample. </p>
<p>Working on my <a href="http://www.catalinzima.com/?page_id=13">VTF tutorial</a>, I came across the need to apply lighting to a terrain. For lighting, we need normals, of course, but I only had heightmaps available. When the terrain is static, this poses no problems at all. All we have to de is generate a normal map from the heightmaps with whatever tools we want. For example, NVIDIA has a Photoshop plugin for this <a href="http://developer.nvidia.com/object/photoshop_dds_plugins.html">here</a>.</p>
<p>However, when we have dynamic terrain, with real time deformation, this is no longer an option. This is especially the case when we make the deformations on the displacement map. After lots of reading and searching, I&#8217;ve come across the <a href="http://en.wikipedia.org/wiki/Sobel">Sobel Filter</a>, which can be used to compute normal maps.</p>
<p>As a result, I made a pixel shader that takes as input the displacement map and outputs the normal map. At runtime, after modifying the displacement map, I apply this shader and put the result into a render target. This result is then used when drawing the terrain, when computing lighting in the pixel shader.</p>
<p>So here&#8217;s the HLSL code:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">float</span> textureSize = 256.0f;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">float</span> texelSize =  1.0f / textureSize ; <span style="color: #008000">//size of one texel;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">float</span> normalStrength = 8;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&#160;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">float4 ComputeNormalsPS(<span style="color: #0000ff">in</span> float2 uv:TEXCOORD0) : COLOR</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">float</span> tl = abs(tex2D (displacementSampler, uv + texelSize * float2(-1, -1)).x);   <span style="color: #008000">// top left</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">float</span>  l = abs(tex2D (displacementSampler, uv + texelSize * float2(-1,  0)).x);   <span style="color: #008000">// left</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">float</span> bl = abs(tex2D (displacementSampler, uv + texelSize * float2(-1,  1)).x);   <span style="color: #008000">// bottom left</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">float</span>  t = abs(tex2D (displacementSampler, uv + texelSize * float2( 0, -1)).x);   <span style="color: #008000">// top</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">float</span>  b = abs(tex2D (displacementSampler, uv + texelSize * float2( 0,  1)).x);   <span style="color: #008000">// bottom</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">float</span> tr = abs(tex2D (displacementSampler, uv + texelSize * float2( 1, -1)).x);   <span style="color: #008000">// top right</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">float</span>  r = abs(tex2D (displacementSampler, uv + texelSize * float2( 1,  0)).x);   <span style="color: #008000">// right</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">float</span> br = abs(tex2D (displacementSampler, uv + texelSize * float2( 1,  1)).x);   <span style="color: #008000">// bottom right</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&#160;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000">// Compute dx using Sobel:</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//           -1 0 1 </span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000">//           -2 0 2</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//           -1 0 1</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">float</span> dX = tr + 2*r + br -tl - 2*l - bl;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&#160;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000">// Compute dy using Sobel:</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//           -1 -2 -1 </span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000">//            0  0  0</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//            1  2  1</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">float</span> dY = bl + 2*b + br -tl - 2*t - tr;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&#160;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #008000">// Build the normalized normal</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    float4 N = float4(normalize(float3(dX, 1.0f / normalStrength, dY)), 1.0f);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&#160;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #008000">//convert (-1.0 , 1.0) to (0.0 , 1.0), if needed</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">return</span> N * 0.5f + 0.5f;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre>
</p></div>
</div>
<p>You should tweak normalStrength until the result you get is satisfactory.</p>
<p>And here is the result of applying that code to two heightmaps, and some terrain lit using a normal map generated by this shader.</p>
<p>&#160;</p>
<p><a href="http://by1.storage.msn.com/y1pt6-V36MAGBpUaSRi9ISM6bBr7_hWfpuLk0_im_oSwFhYmRF55QVlGL0mwHOQGB5RCfd3-FwHIQaSRqcBSLlJPPDfA37FPhCO"><img height="240" alt="displacement" src="http://by1.storage.msn.com/y1pt6-V36MAGBrPB-rmx2GNzW8_gyG9XvyVmutLD6epj4OWqV9w5GMcoldPp0VFNVLFXdvb5c3bTLmAQBFCzct69pmPqwCJ37xT" width="240" /></a> <a href="http://by1.storage.msn.com/y1pt6-V36MAGBpinAwm-t-Kx1Ji60z2C2QxVUNKliIgYMUXdDGMKD-1sdEb7GzdENt7lk22U9trTybNmLop94cKFfFW45Mo-S11"><img height="180" alt="normals" src="http://by1.storage.msn.com/y1pt6-V36MAGBqyD8iai_2JskvPpsI5y1ZWe8jX71y-7iWyPtUdL0X9RigZsVOcchnBJaO8ZPq1sLyju9kTtJFRFfVrjvKoxx0L" width="240" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/01/converting-displacement-maps-into-normal-maps/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>HLSL Learning Resources</title>
		<link>http://www.catalinzima.com/2008/01/hlsl-learning-resources/</link>
		<comments>http://www.catalinzima.com/2008/01/hlsl-learning-resources/#comments</comments>
		<pubDate>Fri, 25 Jan 2008 21:12:07 +0000</pubDate>
		<dc:creator>Catalin Zima</dc:creator>
				<category><![CDATA[HLSL]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://www.catalinzima.com/?p=9</guid>
		<description><![CDATA[In response to some people asking me how to start learning shader programming, I made a list of some resources that could prove helpful when learning HLSL: The Shader Series, found on creators.xna.com are a very good set of articles and samples, that explain the basic knowledge needed to understand and write shaders in HLSL.]]></description>
			<content:encoded><![CDATA[<p>In response to some people asking me how to start learning shader programming, I made a list of some resources that could prove helpful when learning HLSL:</p>
<p>The Shader Series, found on <a href="http://creators.xna.com/">creators.xna.com</a> are a <u>very good</u> set of articles and samples, that explain the basic knowledge needed to understand and write shaders in HLSL.</p>
<ul>
<li><a href="http://creators.xna.com/Headlines/whitepapers/archive/2007/04/26/Shader-Series-Introduction-article.aspx"><strong>Shader Series &#8211; Introduction</strong></a></li>
<li><a href="http://creators.xna.com/Headlines/whitepapers/archive/2007/04/26/Shader-Series-supplemental-article-_1320_-FFP-to-programmable.aspx"><strong>Shader Series &#8211; Fixed Function to Programmable Pipeline</strong></a></li>
<li><a href="http://creators.xna.com/Headlines/whitepapers/archive/2007/04/26/Shader-Series-supplemental-article-_1320_-Coordinate-systems.aspx"><strong>Shader Series &#8211; Coordinate Systems</strong></a><strong> </strong></li>
<li><a href="http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Shader-Series-1_3A00_-Vertex-Lighting-Sample.aspx"><strong>Shader Series 1 &#8211; Vertex Lighting</strong></a></li>
<li><a href="http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Shader-Series-2_3A00_-Textures-and-Colors-Sample.aspx"><strong>Shader Series 2 &#8211; Textures and Colors</strong></a></li>
<li><a href="http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Shader-Series-3_3A00_--Per_2D00_Pixel-Lighting.aspx"><strong>Shader Series 3 &#8211; Per-Pixel Lighting Sample</strong></a></li>
<li><a href="http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Shader-Series-4_3A00_-Materials-and-Multiple-Light-Sources.aspx"><strong>Shader Series 4 &#8211; Materials and Multiple Light Sources</strong></a></li>
</ul>
<p><strong>Riemer Grootjans</strong> also has a series of tutorials on HLSL, which can be found on <a href="http://www.riemers.net/eng/Tutorials/XNA/Csharp/series3.php"><strong>his site</strong></a>.</p>
<p>A good book on shaders is <a href="http://www.amazon.com/Microsoft-DirectX-Programmable-Graphics-Pipeline/dp/0735616531/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1200952318&amp;sr=8-1"><strong>The Microsoft DirectX 9 Programmable Graphics Pipeline by Kris Gray</strong></a>. I found this book extremely useful, with very good explanations, and nicely structured. The code samples, however, are in C/C++, but for most people that shouldn&#8217;t be a problem.</p>
<p>After mastering the basics, you can explore other samples and articles, which can be found on <a href="http://www.ziggyware.com">www.ziggyware.com</a> and <a href="http://creators.xna.com/Education/Samples.aspx">creators.xna.com</a>.</p>
<p>Another good place to find information on shaders are the web pages of the two big GPU manufacturers, <a href="http://developer.nvidia.com/page/home.html"><strong>NVIDIA</strong></a> and <a href="http://ati.amd.com/developer/"><strong>ATI</strong></a>. Each site has a section devoted to developers, which are great places for everyone, beginners are advanced users alike. Both sites provide code samples, documentation, tools and SDK&#8217;s. Out of these, my favorites are <a href="http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html">NVIDIA Shader Library</a>, <a href="http://developer.nvidia.com/object/sdk-9.html">NVIDIA SDK</a> and <a href="http://ati.amd.com/developer/radeonSDK.html">ATI SDK</a>. Most important, these site contains lots of articles and presentations from various conferences, which explain a wide range of effects and techniques, and how they are achieved on the GPU. Admittedly, most of them do not provide HLSL code, but the idea and algorithm is almost always more important than the code itself.</p>
<p>For advanced effects and usages of the GPU, I recommend the <a href="http://developer.nvidia.com/object/gpu-gems-3.html"><strong>GPU Gems</strong></a> series and the <a href="http://www.shaderx5.com/"><strong>ShaderX</strong></a> series.</p>
<p>Finally, as a recommendations for those who want to learn HLSL, try to examine as many samples as possible, and play with the HLSL code to see what happens when changing values, until you understand why things happen the way they do. Don&#8217;t start by doing HDR Lighting, or Relief Mapping. Start with the small tutorials, and understand what happens and why before going on to the more spectacular samples. Last, but not least, don&#8217;t be afraid to look at C/C++ samples. The <a href="http://msdn2.microsoft.com/en-us/directx/aa937788.aspx">DirectX SDK</a> contains some very good samples of HLSL. I know, they&#8217;re written in C/C++, but the shader code stays the same when going from C++ to XNA.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.catalinzima.com/2008/01/hlsl-learning-resources/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

