<?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/"
	>

<channel>
	<title>Encelo's Blog</title>
	<atom:link href="http://encelo.netsons.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://encelo.netsons.org/blog</link>
	<description>When I grow up I want to be a game developer</description>
	<pubDate>Tue, 06 Jan 2009 04:26:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Composing renders in a strip</title>
		<link>http://encelo.netsons.org/blog/2009/01/06/composing-renders-in-a-strip/</link>
		<comments>http://encelo.netsons.org/blog/2009/01/06/composing-renders-in-a-strip/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 03:58:43 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[3d Graphics]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Blender]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=159</guid>
		<description><![CDATA[First of all happy new year to everyone, then let&#8217;s talk about this post topic&#8230;  
During these days I was relaxing and practicing subdivision modeling, after a long time away from Blender I was back to the dream of creating a convincing human head model, but my programming side win the day. 
While I [...]]]></description>
			<content:encoded><![CDATA[<p>First of all happy new year to everyone, then let&#8217;s talk about this post topic&#8230; <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>During these days I was relaxing and practicing subdivision modeling, after a long time away from Blender I was back to the dream of creating a convincing human head model, but my programming side win the day. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
While I was studying in detail some face key parts topology from <a hrefl="http://www.subdivisionmodeling.com/forums/showthread.php?t=2806">here</a>, I noticed the <a href="http://en.wikipedia.org/wiki/Picture-in-picture">PiP</a>-like composed images attached to the first post&#8230;</p>
<div id="attachment_136" class="wp-caption alignnone" style="width: 310px"><a href="http://encelo.netsons.org/blog/wp-content/uploads/2009/01/strip_3dview.png"><img src="http://encelo.netsons.org/blog/wp-content/uploads/2009/01/strip_3dview-300x235.png" alt="Showing camera keyframes" title="strip_3dview" width="300" height="235" class="size-medium wp-image-136" /></a><p class="wp-caption-text">Showing camera keyframes</p></div>
<p>The previous night I was thinking of a way to automates the process and today it becomes reality in the form of a Blender Python script: it is capable of producing an image which is composed of multiple rendered frames, think of a daily comic strip and you understand the name ;).</p>
<p>The user can select which frames to render specifying a string similar to the following one: &#8220;<em>1-3, 5, 7, 9-11</em>&#8220;.<br />
Moreover it is possible, of course, to choose the size of a single frame and the composed image table dimensions, i.e. how many rows and columns it should have.<br />
Have a look to how well my topology study renders fit the script purpose. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div id="attachment_137" class="wp-caption alignnone" style="width: 310px"><a href="http://encelo.netsons.org/blog/wp-content/uploads/2009/01/strip_imgeditor.png"><img src="http://encelo.netsons.org/blog/wp-content/uploads/2009/01/strip_imgeditor-300x235.png" alt="The resulting composed image" title="strip_imgeditor" width="300" height="235" class="size-medium wp-image-137" /></a><p class="wp-caption-text">The resulting composed image</p></div>
<p>This second script is a bit more complex than <a href="/blog/2008/10/18/automatic-parallax-map-generation-with-blender/">my first one</a>, making use of the <em>Registry</em> module to load and save options and the <em>Draw.PupBlock()</em> method to display a bigger GUI.</p>
<p>Of course it is released under the GNU GPL License and available online, download it from <a href="http://encelo.netsons.org/_download/strip_render.py.gz">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2009/01/06/composing-renders-in-a-strip/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Blurring the parallax</title>
		<link>http://encelo.netsons.org/blog/2008/11/10/blurring-the-parallax/</link>
		<comments>http://encelo.netsons.org/blog/2008/11/10/blurring-the-parallax/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 22:26:14 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Real-time Graphics]]></category>

		<category><![CDATA[C++]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[OpenGL]]></category>

		<category><![CDATA[post-processing]]></category>

		<category><![CDATA[shaders]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=99</guid>
		<description><![CDATA[Today I have published the first demo making use of my new C++ class library, I designed it to be very easily ported to a strict GL3 profile or to ES 2.0.
As a matter of fact, it doesn&#8217;t make use of fixed pipeline or deprecated functions at all:

No immediate mode, only VBOs
No use of OpenGL [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have published the first demo making use of my new C++ class library, I designed it to be very easily ported to a strict GL3 profile or to ES 2.0.</p>
<div id="attachment_101" class="wp-caption alignnone" style="width: 310px"><a href="http://encelo.netsons.org/blog/wp-content/uploads/2008/11/plain_to_dof_strip.jpg"><img src="http://encelo.netsons.org/blog/wp-content/uploads/2008/11/plain_to_dof_strip-300x75.jpg" alt="From plain rendering to depth of field" title="From plain rendering to depth of field" width="300" height="75" class="size-medium wp-image-101" /></a><p class="wp-caption-text">From plain rendering to depth of field</p></div>
<p>As a matter of fact, it doesn&#8217;t make use of fixed pipeline or deprecated functions at all:</p>
<ul>
<li>No immediate mode, only VBOs</li>
<li>No use of OpenGL matrix stacks, I have my classes handling transformations and passing matrices to shaders directly</li>
<li>No OpenGL lighting, only per-fragment one</li>
<li>No quads or polygons, just triangles</li>
</ul>
<div id="attachment_116" class="wp-caption alignnone" style="width: 310px"><a href="http://encelo.netsons.org/blog/wp-content/uploads/2008/11/normal_vs_parallax.jpg"><img src="http://encelo.netsons.org/blog/wp-content/uploads/2008/11/normal_vs_parallax-300x75.jpg" alt="Normal versus parallax mapping" title="Normal vs parallax" width="300" height="75" class="size-medium wp-image-116" /></a><p class="wp-caption-text">Normal versus parallax mapping</p></div>
<p>I couldn&#8217;t release something only to show changes &#8220;under the hood&#8221;, I had to make something cool, so I decided to mix together parallax mapping (that, as you can see in the screenshot, is a lot more pronounced now) and depth of field, with the little addition of Stanford PLY mesh loading. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Mr.Fixit model and maps (the character players protray in <a href="http://www.sauerbraten.org">Sauerbraten</a>) are courtesy of John Siar, thank you John. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>As usual, you can have a look to Vimeo videos (<a href="http://vimeo.com/2208683">640&#215;480</a>, <a href="http://vimeo.com/2208706">1280&#215;720</a>) and download the <a href="/_download/gl3_parallax_dof.tar.gz">sources</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/11/10/blurring-the-parallax/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Automatic parallax map generation with Blender</title>
		<link>http://encelo.netsons.org/blog/2008/10/18/automatic-parallax-map-generation-with-blender/</link>
		<comments>http://encelo.netsons.org/blog/2008/10/18/automatic-parallax-map-generation-with-blender/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 16:24:47 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[3d Graphics]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Blender]]></category>

		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=66</guid>
		<description><![CDATA[It has been a long time since I last wrote something here, during these months two new things happened that are worth to be mentioned: first of all I&#8217;m really close to graduation!
Well, actually I need to pass the last exam and spend a period of at least four months of internship, nothing is sure [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a long time since I last wrote something here, during these months two new things happened that are worth to be mentioned: first of all I&#8217;m really close to graduation!<br />
Well, actually I need to pass the last exam and spend a period of at least four months of internship, nothing is sure now but I&#8217;m in close contact with a game developing company&#8230; <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The second thing is closely related to this post instead, a couple of months ago I began to convert, following M3xican&#8217;s advice, my OpenGL demos to object oriented C++.<br />
What I have now is really not much, nevertheless my class library can load a Stanford PLY model, it is ES 2.0 compliant (this means it will be easily converted to &#8220;Pure&#8221; OpenGL 3.x), and it can already display both parallax mapping and depth of field!</p>
<p>I&#8217;m not going to publish any screenshot by now because I think it&#8217;s not the time yet, what I&#8217;m showing you is a easy script, my first one, which I wrote yesterday night using the Blender Python API.<br />
What it does is really simple yet time-saving, you select a high-poly and a low-poly model, run the script from the Object->Scripts menu and watch Blender baking your normal and height map and then saving them.</p>
<p><a href="/blog/wp-content/uploads/2008/10/parallax_maps.png"><img src="/blog/wp-content/uploads/2008/10/parallax_maps-320x200.png" alt="Blender parallax maps" /></a></p>
<p>I have also set up an easy compositing nodes configuration to mix the two images in a single parallax map with height data encoded in the alpha channel.</p>
<p><a href="/blog/wp-content/uploads/2008/10/parallax_maps_nodes.png"><img src="/blog/wp-content/uploads/2008/10/parallax_maps_nodes-320x200.png" alt="Blender parallax maps nodes" /></a></p>
<p>You can download the script from <a href="/_download/parallax_maps.py.gz">here</a>.<br />
Everything is very simple (and funny!) with the astonishing power of Blender! <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/10/18/automatic-parallax-map-generation-with-blender/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A long presentation&#8230;</title>
		<link>http://encelo.netsons.org/blog/2008/06/10/a-long-presentation/</link>
		<comments>http://encelo.netsons.org/blog/2008/06/10/a-long-presentation/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 13:39:45 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Rants]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[GPU]]></category>

		<category><![CDATA[shaders]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=64</guid>
		<description><![CDATA[The professor of the computer graphics course at my university was continuosly annoyed by my protests and comments during her lectures..

I&#8217;m sorry but I just couldn&#8217;t stand some claims like: &#8220;Phong shading is never used in interactive applications because of it being computationally too heavy&#8221;&#8230; 
Fortunately she gave me the opportunity to give everyone a [...]]]></description>
			<content:encoded><![CDATA[<p>The professor of the computer graphics course at my university was continuosly annoyed by my protests and comments during her lectures..</p>
<p><img src="/blog/wp-content/uploads/2008/07/latex_logo.png" title="LaTeX_logo" width="300" height="129" /></p>
<p>I&#8217;m sorry but I just couldn&#8217;t stand some claims like: &#8220;Phong shading is never used in interactive applications because of it being computationally too heavy&#8221;&#8230; <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Fortunately she gave me the opportunity to give everyone a small technological update. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
After about a month, my presentation was born.<br />
Made entirely with <a href="http://latex-beamer.sourceforge.net/">LaTeX Beamer</a>, <a href="http://www.vim.org/">VIM</a>, <a href="http://www.gnome.org/projects/dia/">Dia</a> and <a href="http://www.gimp.org/">GIMP</a>, it deals about what modern GPU are capable of, showing some GPGPU applications, along with traditional ones (videogames <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ), and some shader examples together with commented code.</p>
<p>I discussed it yesterday in a couple of hours, I was all shook up at first but then I advanced smooth and plain. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
It is in Italian, of course, but I published it anyway: <a href="/_download/le_moderne_gpu.pdf">Le Moderne GPU</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/06/10/a-long-presentation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Let there be light!</title>
		<link>http://encelo.netsons.org/blog/2008/04/28/let-there-be-light/</link>
		<comments>http://encelo.netsons.org/blog/2008/04/28/let-there-be-light/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 20:24:12 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Real-time Graphics]]></category>

		<category><![CDATA[deferred]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[OpenGL]]></category>

		<category><![CDATA[PyOpenGL]]></category>

		<category><![CDATA[shaders]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=62</guid>
		<description><![CDATA[I started exploring deferred shading rendering to display multiple light sources and ended writing a demo featuring eight different lighting techniques and a PyOpenGL class library.  

The whole story is more than a month old, just after releasing the first depth of field demo I began studying deferred shading, but I extended my purpose [...]]]></description>
			<content:encoded><![CDATA[<p>I started exploring deferred shading rendering to display multiple light sources and ended writing a demo featuring eight different lighting techniques and a PyOpenGL class library. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="/blog/wp-content/uploads/2008/04/glsl_multilight.png" alt="glsl_multilight" /></p>
<p>The whole story is more than a month old, just after releasing the first depth of field demo I began studying deferred shading, but I extended my purpose to include other lighting methods, like single and multi-pass fixed-pipeline lighting, per-vertex and per-pixel single and multi-pass shader lighting and, of course, deferred one.</p>
<p>While writing the C code, I thought it was going to be fun to also port it to Python, this way I could have also have a look to the &#8220;new&#8221; (ArchLinux adopted it quite late <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) ctypes PyOpenGL, aka PyOpenGL 3.</p>
<p>Unfortunately, many little but annoying issues delayed me until today:</p>
<ul>
<li>not setting explicitely <tt>glDepthFunc(GL_LEQUAL)</tt> (or, alternatively, not clearing the depth buffer at each pass) for multi-pass scene rendering made every pass to be discarded excepting the first one.</li>
<li>trying to make a buggy Python <tt>glDrawBuffers()</tt> wrapper work.<br />
Actually I had no luck with this and give up on MRTs support in PyOpenGL.</li>
<li>trying to figure out why VBOs didn&#8217;t work on PyOpenGL, I give up on this too. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>using a uniform variable to index the <tt>gl_LightSource</tt> structure array, which prevented the shader from running on Shader Model 3.0 cards</li>
<li>exploring all the possibilities that could ever lead to &#8220;the brick room is very dark in fixed-pipeline mode&#8221; issue, only to discover today that this was a mere scaled normals problem.<br />
It was easily solved enabling <tt>GL_RESCALE_NORMAL</tt></li>
</ul>
<p>At last I made it, I have made a multi light demo that includes deferred lighting (although very rough and not optimized at all) and shows coherent lighting in all rendering modes.<br />
The PyOpenGL class library almost works, no MRTs and VBOs, but it is functional enough to sport a complete DoF2  and multilight (without deferred mode, which relies on MRTs, of course) demo conversions.</p>
<p>It&#8217;s not a news anymore that you can view it in action on my <a href="http://www.youtube.com/encelo">YouTube Channel</a>, or in a high definition <a href="http://www.vimeo.com/952114">720p version</a> hosted on my <a href="http://www.vimeo.com/encelo">Vimeo page</a>.</p>
<p>All&#8217;s well that ends well. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/04/28/let-there-be-light/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Depth of field reloaded</title>
		<link>http://encelo.netsons.org/blog/2008/04/15/depth-of-field-reloaded/</link>
		<comments>http://encelo.netsons.org/blog/2008/04/15/depth-of-field-reloaded/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 16:28:09 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Real-time Graphics]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[OpenGL]]></category>

		<category><![CDATA[post-processing]]></category>

		<category><![CDATA[shaders]]></category>

		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/?p=60</guid>
		<description><![CDATA[Lately I&#8217;ve been really disappointed by the poor performances of my first depth of field implementation, thus I decided to do something about it&#8230;

The most natural step to do was to give a look to the second Direct3D example from the same paper I used for the first one, as I was sure it would [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been really disappointed by the poor performances of my <a href="/blog/2008/03/23/i-love-depth-of-field/">first depth of field implementation</a>, thus I decided to do something about it&#8230;</p>
<p><img src="/blog/wp-content/uploads/2008/04/glsl_dof2.png" alt="glsl_dof2" /></p>
<p>The most natural step to do was to give a look to the second Direct3D example from the <a href="http://ati.amd.com/developer/shaderx/ShaderX2_Real-TimeDepthOfFieldSimulation.pdf">same paper</a> I used for the first one, as I was sure it would have led to more satisfactory results.<br />
I spent the two last nights converting, correcting and fine tuning it, but I was rewarded by the fact that I was right: even if it is a five passes algorithm which is using four different <a href="http://en.wikipedia.org/wiki/Framebuffer_Object">Frame Buffer Objects</a>, it is about 2.5 times faster than my previous implementation!</p>
<p>I think the speed boost depends on the two following:</p>
<ol>
<li>image blurring is achieved by a gaussian filter which is calculated separating the X from the Y axis, it is an approximation of a standard 2D kernel but it also means that the convolution matrix calculation complexity decreases from a quadratic to a linear factor.</li>
<li>this filter operates only on a downsampled (1/4th of the screen resolution actually) FBO</li>
</ol>
<p>Another nice note about this new implementation is that there are only two focal parameters, <em>focus depth</em> and <em>focus range</em>, which really help to setup a correct scene.</p>
<p>Now let&#8217;s review the five passes in detail:</p>
<ol>
<li>Render the scene normally while calculating a blur amount per-vertex, then store the interpolated value per-pixel inside the alpha component of the fragment.<br />
The calculation at the vertex shader is just:</p>
<pre name="code" class="cpp">

Blur = clamp(abs(-PosWV.z - focalDistance) / focalRange, 0.0, 1.0);
</pre>
</li>
<li>Downsample the scene rendered at the previous pass storing it in a smaller FBO</li>
<li>Apply the gaussian filter along the X axis on the downsampled scene and store it in a new FBO</li>
<li>Apply the gaussian filter along the Y axis on the already X blurred scene and store it in a new FBO</li>
<li>Calculate a linear interpolation between the first full resolution FBO and the XY downsampled blurred one<br />
This is performed in the fragment shader as:</p>
<pre name="code" class="cpp">

gl_FragColor = Fullres + Fullres.a * (Blurred - Fullres);
</pre>
</li>
</ol>
<p>Again, you can view it in action on my <a href="http://www.youtube.com/encelo">YouTube Channel</a>, or in a high definition <a href="http://www.vimeo.com/899935">720p version</a> hosted on my <a href="http://www.vimeo.com/encelo">Vimeo page</a>. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/04/15/depth-of-field-reloaded/feed/</wfw:commentRss>
		</item>
		<item>
		<title>I love depth of field</title>
		<link>http://encelo.netsons.org/blog/2008/03/23/i-love-depth-of-field/</link>
		<comments>http://encelo.netsons.org/blog/2008/03/23/i-love-depth-of-field/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 19:33:48 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Real-time Graphics]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[OpenGL]]></category>

		<category><![CDATA[post-processing]]></category>

		<category><![CDATA[shaders]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/2008/03/23/i-love-depth-of-field/</guid>
		<description><![CDATA[I consider depth of field as one of the most beautiful post-processing effects of the &#8220;next-gen&#8221; games.
It was natural for me to choose it as the first shader demo to implement after months of inactivity, as a matter of fact GLSL_impgro was really just a testbed for post-processing basic techniques, like Frame Buffer Objects.

I have [...]]]></description>
			<content:encoded><![CDATA[<p>I consider <a href="http://en.wikipedia.org/wiki/Depth_of_field">depth of field</a> as one of the most beautiful post-processing effects of the &#8220;next-gen&#8221; games.<br />
It was natural for me to choose it as the first shader demo to implement after months of inactivity, as a matter of fact GLSL_impgro was really just a testbed for post-processing basic techniques, like <a href="http://en.wikipedia.org/wiki/Framebuffer_Object">Frame Buffer Objects</a>.</p>
<p><img src='/blog/wp-content/uploads/2008/03/glsl_dof.png' alt='GLSL_DoF' /></p>
<p>I have studied the theory from an ATI paper included in the ShaderX2 book, titled <a href="http://ati.amd.com/developer/shaderx/ShaderX2_Real-TimeDepthOfFieldSimulation.pdf">Real-Time Depth of Field Simulation</a>, I have choosen the first of the two different implementation and converted it from Direct3D and HLSL to OpenGL and GLSL.</p>
<p>Of course, being a post-processing effect, the rendering is actually divided in two pass:</p>
<ol>
<li>Rendering the scene storing the depth of every vertex and calculating the amount of blur per fragment</li>
<li>Applying the blur per fragment based on the value from the previous step</li>
</ol>
<p>The second pass fragment shader, the one which is really applying the blur effect, is slow even on my 8600GT, because it performs several calculations for every one of the twelve fragments that are contributing to the blur of the center one.</p>
<p>Another interesting aspect is that, in order to calculate a correct approximation of the circular blur needed for <a href="http://en.wikipedia.org/wiki/Circle_of_confusion">circles of confusion</a> simulation, these twelve pixel are sampled around the center based on a poissonian disc distribution, thus creating much less artifacts than a small convolution matrix scaled too much in order to sample from far away the center.</p>
<p>Just like the previous demo you can view it in action on my <a href="http://www.youtube.com/encelo">YouTube Channel</a>, but I really suggest you to give a look to the high definition <a href="http://www.vimeo.com/798278">720p version</a> instead, hosted together with the other ones on my <a href="http://www.vimeo.com/encelo">Vimeo page</a>. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/03/23/i-love-depth-of-field/feed/</wfw:commentRss>
		</item>
		<item>
		<title>glUniform1f() is working!</title>
		<link>http://encelo.netsons.org/blog/2008/03/17/gluniform1f-is-working/</link>
		<comments>http://encelo.netsons.org/blog/2008/03/17/gluniform1f-is-working/#comments</comments>
		<pubDate>Mon, 17 Mar 2008 21:02:36 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Rants]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[OpenGL]]></category>

		<category><![CDATA[shaders]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/2008/03/17/gluniform1f-is-working/</guid>
		<description><![CDATA[I faced this problem for the first time a year ago, while working for my parallax mapping demo, and I met it again these days, in which I&#8217;m busy to fine tune my depth of field demo to permit keyboard driven parameters tweaking.

The issue I&#8217;m talking about is quite seriuos, on my machine it is [...]]]></description>
			<content:encoded><![CDATA[<p>I faced this problem for the first time a year ago, while working for my <a href="/blog/2007/05/01/parallax-mapping-for-the-masses/">parallax mapping</a> demo, and I met it again these days, in which I&#8217;m busy to fine tune my <em>depth of field</em> demo to permit keyboard driven parameters tweaking.</p>
<p><img src='http://encelo.netsons.org/blog/wp-content/uploads/2008/03/bug.jpg' alt='Bug' /></p>
<p>The issue I&#8217;m talking about is quite seriuos, on my machine it is impossible to pass a float uniform variable to a shader, and I&#8217;m not the only one reporting it:</p>
<ul>
<li><a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=470542">glUniform*f seems to&#8230; not work.</a></li>
<li><a href="http://www.nvnews.net/vbulletin/showthread.php?t=95980">Problem with glUniform1f in 100.14.11 on 8800GTS</a></li>
<li><a href="http://www.groupsrv.com/computers/about318237.html">GLSL Vertex Sh. uniform aren&#8217;t set (OGL 2.0)</a></li>
</ul>
<p>The first link is a forum thread from GameDev written by a girl whose applications suffer from this annoying issue, he has written a <em>proof of concept</em> which works perfectly on my box, i.e. float uniforms are NOT passed. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
But it has been the third one which made me think about how to fix the problem: it has been reported that, after calling <tt>glewInit()</tt>, <tt>glUniform*f()</tt> functions work again.</p>
<p>The first thing I did, of course, was to download and investigate inside <a href="http://glew.sourceforge.net/">GLEW</a> sources to see what was happening inside that magic function. What it does, actually, is redefining all the GL function pointers calling <tt>glXGetProcAddress()</tt> for everyone of them, I thought it would have been a good thing to try to replicate this behaviour in my programs, and I was right! <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>This is what I added to my sources for the incriminated function to work:</p>
<pre name="code" class="cpp">

PFNGLUNIFORM1FPROC glUniform1f = NULL;
glUniform1f = (PFNGLUNIFORM1FPROC)glXGetProcAddress((const GLubyte*)&quot;glUniform1f&quot;);
</pre>
<p>This also seems to explain why my Python shader demo didn&#8217;t suffer from all of this, I think that PyOpenGL initializes itself retrieving the addresses for all the GL functions it needs.</p>
<p><strong>IMPORTANT UPDATE</strong><br />
<a href="http://www.m3xbox.com">M3xican</a>, the <em>shader master</em> came with THE solution, just add <tt>-DGL_GLEXT_PROTOTYPES</tt> to CFLAGS.<br />
Hail to the master! <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/03/17/gluniform1f-is-working/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Image post-processing with shaders</title>
		<link>http://encelo.netsons.org/blog/2008/03/13/image-post-processing-with-shaders/</link>
		<comments>http://encelo.netsons.org/blog/2008/03/13/image-post-processing-with-shaders/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 01:00:04 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Real-time Graphics]]></category>

		<category><![CDATA[GLSL]]></category>

		<category><![CDATA[OpenGL]]></category>

		<category><![CDATA[post-processing]]></category>

		<category><![CDATA[shaders]]></category>

		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/2008/03/13/image-post-processing-with-shaders/</guid>
		<description><![CDATA[I&#8217;m back to work after many months, university exams take really a lot of time&#8230;
For I am a bit rusty on GLSL programming, but willing to learn new things anyway, I have decided to begin with a simple yet interesting topic, image processing.

The whole thing, actually, needs two rendering passes and relies heavily on Frame [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back to work after many months, university exams take really a lot of time&#8230;<br />
For I am a bit rusty on GLSL programming, but willing to learn new things anyway, I have decided to begin with a simple yet interesting topic, image processing.</p>
<p><img src='/blog/wp-content/uploads/2008/03/glsl_imgpro.png' alt='GLSL_imgpro' /></p>
<p>The whole thing, actually, needs two rendering passes and relies heavily on <a href=""http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt>Frame Buffer Objects</a> because:</p>
<ol>
<li>You render the scene to an off-screen texture.</li>
<li>You render a quad covering the entire screen and binded to the previously written texture.</li>
<li>You make a shader process the fragments resulted from rendering this textured quad, i.e. post-processing the original scene.</li>
</ol>
<p>In this program post-processing is demanded to convolution matrices calculated with these kernels:</p>
<pre name="code" class="cpp">

GLfloat kernels[7][9] = {
    { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, /* Identity */
    { 0.0f,-1.0f, 0.0f,-1.0f, 5.0f,-1.0f, 0.0f,-1.0f, 0.0f}, /* Sharpen */
    { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f}, /* Blur */
    { 1.0f, 2.0f, 1.0f, 2.0f, 4.0f, 2.0f, 1.0f, 2.0f, 1.0f}, /* Gaussian blur */
    { 0.0f, 0.0f, 0.0f,-1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, /* Edge enhance */
    { 1.0f, 1.0f, 1.0f, 1.0f, 8.0f, 1.0f, 1.0f, 1.0f, 1.0f}, /* Edge detect */
    { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,-1.0f}  /* Emboss */
};
</pre>
<p>The final fragment color is calculated by a simple shader which, at the core, just performs the following:</p>
<pre name="code" class="cpp">

for(i = -1; i &lt;= 1; i++)
    for(j = -1; j &lt;= 1; j++) {
        coord = gl_TexCoord[0].st + vec2(float(i) * (1.0/float(Width)) * float(Dist), float(j) * (1.0/float(Height)) * float(Dist));
        sum += Kernel[i+1][j+1] * texture2D(Tex0, coord.xy);
        contrib += Kernel[i+1][j+1];
    }

    gl_FragColor = sum/contrib;
</pre>
<p>When the user chooses a filter, the application updates the kernel currently in use with a call to:</p>
<pre name="code" class="cpp">

loc = glGetUniformLocation(sh.p2, &quot;Dist&quot;);
glUniform1i(loc, dist);
loc = glGetUniformLocation(sh.p2, &quot;Kernel&quot;);
glUniformMatrix3fv(loc, 1, GL_FALSE, &amp;kernels[curker]);
</pre>
<p>Dist is a user defined parameter (you can change it using arrows) that defines the distance in pixels from the center to the contributing sample.</p>
<p>Since a month I have created a <a href="http://www.youtube.com/encelo">YouTube Channel</a>, now you can have an idea of how this demo works without downloading and compiling <a href="/_download/glsl_imgpro.tar.gz">the source code</a>: have a look at <a href="http://www.youtube.com/watch?v=lmTS9qSwCLg">this link</a>! <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2008/03/13/image-post-processing-with-shaders/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GameCon 2007</title>
		<link>http://encelo.netsons.org/blog/2007/12/10/gamecon-2007/</link>
		<comments>http://encelo.netsons.org/blog/2007/12/10/gamecon-2007/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 02:28:38 +0000</pubDate>
		<dc:creator>encelo</dc:creator>
		
		<category><![CDATA[Opinions]]></category>

		<category><![CDATA[Videogames]]></category>

		<category><![CDATA[Game in Italy]]></category>

		<category><![CDATA[GameCon]]></category>

		<guid isPermaLink="false">http://encelo.netsons.org/blog/2007/12/10/gamecon-2007/</guid>
		<description><![CDATA[GameCon is the only game and videogame showroom in Italy, and, fortunately for me, it is held in my city. 
Last year it changed its name from N-joy to the current one and received much more advertising and public visibility, therefore me and M3xican decided to attend it.  

We had the possibility to view, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gamecon.it">GameCon</a> is the only game and videogame showroom in Italy, and, fortunately for me, it is held in my city. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
Last year it changed its name from <a href="http://www.n-joy.it/">N-joy</a> to the current one and received much more advertising and public visibility, therefore me and M3xican decided to attend it. <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img src='http://encelo.netsons.org/blog/wp-content/uploads/2007/12/gamecon.jpg' alt='GameCon Logo' /></p>
<p>We had the possibility to view, and what is more important, to test next-gen consoles the way they deserved, on huge LCDs! <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
There were a lot of <em>XBox 360</em> running the most recent games, like the first UE3 engine powered one, the stunning <em>Gears of War</em>, some <em>Nintendo Wii</em> made their first Italian apparition at the show and, last but not least, I have heard that the last day a <em>Playstation 3</em> was previewed!<br />
You could play with many <em>Nintendo DS</em> and some powerful PCs, subscribe to rewarded tournaments in many games, admire original Benoît Sokal illustrations (which unfortunately couldn&#8217;t be there as scheduled), moreover some space had been dedicated to a lot of different board games and somebody was enjoying <a href="http://en.wikipedia.org/wiki/Cosplay">cosplaying</a>.<br />
However, something more interesting happened some weeks before the event, when I got in touch with its Cultural Director.<br />
Our emails shared the common vision to evolve the current target of attendees to include game developers too, for example organizing interesting conferences and gathering the most influential Italian exponents of the industry.</p>
<p>This was what happened this very year, with the announce of <em>Game in Italy 2007</em>, thus on Saturday me and M3xican went there, loaded with great expectations (like the hope to assist to a little <a href="http://www.gdconf.com/">GDC</a> wannabe <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> )!<br />
Even if a lot of important Italian software houses were invited, even if Rasmus Poulsen (a concept artist working for IO Interactive) was present as a guest star, it has been a disappointment.<br />
The event was too modest to even feature a fair-sized room, it was not only so small that just a dozen guys could sit inside, but so hot (damned lamps!) that you couldn&#8217;t stand at the entrance, ignoring for a while the fact that there was only one speaker and that you could barely hear what it was said by the participants.<br />
It was interesting to notice that outside the room there was a big LCD showing what was happening inside, but we were surprised to discover that nothing was audible, it was mute! <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_eek.gif' alt='8O' class='wp-smiley' /><br />
I only hope they have recorded the speeches&#8230;</p>
<p>To draw a conclusion, it failed to meet our expectations, we couldn&#8217;t attend the conferences while the rest of the show wasn&#8217;t so extraordinary, it has been less interesting than the previous year, maybe because next-generation gaming is now current-generation&#8230; <img src='http://encelo.netsons.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
I only hope that next year <em>Game in Italy</em> gains the space, the attention and the visibility it deserves!</p>
]]></content:encoded>
			<wfw:commentRss>http://encelo.netsons.org/blog/2007/12/10/gamecon-2007/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
