<?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>numb3r23 &#187; Tutorial</title>
	<atom:link href="https://www.numb3r23.net/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.numb3r23.net</link>
	<description>&#039;bout coding grafx &#38; more</description>
	<lastBuildDate>Tue, 27 Oct 2015 00:22:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.38</generator>
	<item>
		<title>Presentation: Distance fields</title>
		<link>https://www.numb3r23.net/2015/10/27/presentation-distance-fields/</link>
		<comments>https://www.numb3r23.net/2015/10/27/presentation-distance-fields/#comments</comments>
		<pubDate>Tue, 27 Oct 2015 00:22:25 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=339</guid>
		<description><![CDATA[I prepared some slides on a presentation on distance fields and what you can do with them: numb3r23.github.io/cgTalk/04_distancefields.html A note on the navigation: space for the next slide backspace for the previous slide left/right to jump to the next chapter up/down to navigate in current chapter Enjoy!]]></description>
				<content:encoded><![CDATA[<p>I prepared some slides on a presentation on <strong>distance fields</strong> and what you can do with them:</p>
<p><center><br />
<strong><a title="http://numb3r23.github.io/cgTalk/04_distancefields.html" href="http://numb3r23.github.io/cgTalk/04_distancefields.html" target="_blank">numb3r23.github.io/cgTalk/04_distancefields.html</a><br />
</strong></center></p>
<p><object data="http://numb3r23.github.io/cgTalk/04_distancefields.html" width="600px" height="400px"><embed src="http://numb3r23.github.io/cgTalk/04_distancefields.html" width="0" height="0" /></object><br />
A note on the navigation:</p>
<ul>
<li><code>space</code> for the next slide</li>
<li><code>backspace</code> for the previous slide</li>
<li><code>left/right</code> to jump to the next chapter</li>
<li><code>up/down</code> to navigate in current chapter</li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2015/10/27/presentation-distance-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using fwidth for distance based anti-aliasing</title>
		<link>https://www.numb3r23.net/2015/08/17/using-fwidth-for-distance-based-anti-aliasing/</link>
		<comments>https://www.numb3r23.net/2015/08/17/using-fwidth-for-distance-based-anti-aliasing/#comments</comments>
		<pubDate>Mon, 17 Aug 2015 23:20:51 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=322</guid>
		<description><![CDATA[Analytic, function-based distance fields are great for drawing things procedurally in the shader. As long as you can combine a few function and model the distance right you can simply create sharp-looking geometrical objects &#8211; even complex combinations are possible. The following is also true for texture-based distance fields (sdf fonts), but I&#8217;ve decided to [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Analytic, function-based distance fields are great for drawing things procedurally in the shader. As long as you can combine a few function and model the distance right you can simply create sharp-looking geometrical objects &#8211; even complex combinations are possible. The following is also true for texture-based distance fields (sdf fonts), but I&#8217;ve decided to give distance functions the space they deserve.</p>
<div id="attachment_328" style="width: 610px" class="wp-caption alignnone"><a href="http://www.numb3r23.net/wp-content/uploads/2015/08/portalSDF.png"><img class="wp-image-328 size-full" src="http://www.numb3r23.net/wp-content/uploads/2015/08/portalSDF.png" alt="2D portal, composed of 2D distance field functions" width="600" height="399" /></a><p class="wp-caption-text">2D portal, composed of 2D distance field functions</p></div>
<p>One of the great aspects of these functions is that they can be evaluated for every pixel independent of a target resolution and can thus be used to create a proper, anti-aliased images. If you set it up right.</p>
<p>Instead of the usual circle example where the distance is simple the <code>distance(coordinate, center)</code> and create a diamond pattern:</p>
<div id="attachment_330" style="width: 310px" class="wp-caption alignnone"><a href="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.07.25.png"><img class="wp-image-330 size-medium" src="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.07.25-e1439853219485-300x297.png" alt="Distance Field Diamond" width="300" height="297" /></a><p class="wp-caption-text">Distance Field Diamond</p></div>
<pre class="brush: cpp; title: ; notranslate">
float dst = dot(abs(coord-center), vec2(1.0));
</pre>
<p>Using a radius as a step/threshold we can very easily create &#8220;diamonds&#8221; in the size we like:</p>
<div id="attachment_331" style="width: 518px" class="wp-caption alignnone"><a href="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.07.54.png"><img class="size-full wp-image-331" src="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.07.54.png" alt="Diamond Step Function" width="508" height="506" /></a><p class="wp-caption-text">Diamond Step Function</p></div>
<pre class="brush: cpp; title: ; notranslate">
vec3 color = vec3(1.0 - step(radius, dst));
</pre>
<p>So far so good. what&#8217;s missing is now the antialiasing part of it all &#8211; the step function creates a hard edge. Enter <code>smoothstep</code>, a function that performs a hermite interpolation between two values:</p>
<div id="attachment_333" style="width: 521px" class="wp-caption alignnone"><a href="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.10.43.png"><img class="size-full wp-image-333" src="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.10.43.png" alt="y = smoothstep(0.3, 0.7, x)" width="511" height="481" /></a><p class="wp-caption-text">y = smoothstep(0.3, 0.7, x)</p></div>
<p>If both values are the same, it boils down to a step. What we now want is to &#8220;blend&#8221; the diamond into the background, ideally on the border pixels (and therefor not wider than 1 pixel). If we had such a value, let&#8217;s call it &#8220;<code>aaf</code>&#8221; (= anti-aliasing-factor), we could smoothly fade-out the diamond into the background:</p>
<div id="attachment_332" style="width: 509px" class="wp-caption alignnone"><a href="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.08.26.png"><img class="size-full wp-image-332" src="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-18-00.08.26.png" alt="Diamond Smoothstep" width="499" height="489" /></a><p class="wp-caption-text">Diamond Smoothstep</p></div>
<pre class="brush: cpp; title: ; notranslate">
vec3 color = vec3(1.0 - smoothstep(radius - aaf, radius, dst));
</pre>
<p>Luckily most OpenGL implementations have the three functions <code>dFdx</code>, <code>dFdy</code> and <code>fwidth</code>:</p>
<ul>
<li><code>dFdx</code> calculates the change of the parameter along the viewport&#8217;s x-axis</li>
<li><code>dFdy</code> calculates the change of the parameter along the viewport&#8217;s y-axis</li>
<li><code>fwidth</code> is effectively <code>abs(dFdx) + abs(dFdy)</code> and gives you the positive change in both directions</li>
</ul>
<p>The functions are present in &gt;= GLSL 110 on desktop or &gt;= GLSL ES 3.0. For es pre-GLSL 3.0 there&#8217;s an extension <code>GL_OES_standard_derivatives</code> that allows to enable the usage:</p>
<pre class="brush: cpp; title: ; notranslate">
#extension GL_OES_standard_derivatives : enable
</pre>
<p>But how does it connect together? What we need is the effective change of the distance field per pixel so we can identify a single pixel for the distance field. Since we need this for both axis we can do this:</p>
<pre class="brush: cpp; title: ; notranslate">
float aaf = fwidth(dst);
</pre>
<p><code>fwidth</code> evaluates the change of the distance field, the value stored in the variable dst, for the current pixel &#8211; relative to it&#8217;s screen tile. The size of that change determines how wide our smoothstep interpolation needs to be set up in order to fade out the pattern on a per pixel level. The antialiasing fade can be used in numerous ways:</p>
<ul>
<li>store it in the alpha-channel and do regular alpha-blending</li>
<li>use it to blend between two colors with a <code>mix</code></li>
<li>use it to blend in a single pattern element</li>
</ul>
<p>The whole shader boils down to this:</p>
<pre class="brush: cpp; title: ; notranslate">
float dst = dot(abs(coord-center), vec2(1.0));
float aaf = fwidth(dst);
float alpha = smoothstep(radius - aaf, radius, dst);
vec4 color = vec4(colDiamond, alpha);
</pre>
<p>Selected remarks:</p>
<ul>
<li><code>fwidth</code> is not free. in fact, it&#8217;s rather expensive. Try not to call it too much!</li>
<li>it&#8217;s great if you can sum up all distances so that you can arrive at a single dst-value so you only call <code>fwidth</code> once.</li>
<li>give <code>fwidth</code> the variable you want to <code>smoothstep</code>. Not the underlying coordinate &#8211; that&#8217;s a completely different change and would lead to a wrong-sized filter</li>
<li><code>length(fwidth(coord))</code> is &#8220;ok&#8221;, but not great if you look closely. Depending e.g. on the distortion/transformation applied to the coordinates to derive the distance value it might look very odd.</li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2015/08/17/using-fwidth-for-distance-based-anti-aliasing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>libSOIL</title>
		<link>https://www.numb3r23.net/2012/12/22/libsoil/</link>
		<comments>https://www.numb3r23.net/2012/12/22/libsoil/#comments</comments>
		<pubDate>Sat, 22 Dec 2012 19:44:51 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=142</guid>
		<description><![CDATA[As I was working with libSOIL (https://github.com/smibarber/libSOIL for a mac makefile) an exception occured and I couldn&#8217;t load anything. Turns out, libSOIL is not OpenGL 3.2 core compatible. Main reason for this is the beautiful safety-net which I encountered in the function This mechanism can be found elsewhere too. As this specific feature is definitely [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>As I was working with libSOIL (https://github.com/smibarber/libSOIL for a mac makefile) an exception occured and I couldn&#8217;t load anything. Turns out, libSOIL is not <strong>OpenGL 3.2 core</strong> compatible. Main reason for this is the beautiful safety-net which I encountered in the function</p>
<pre class="brush: cpp; title: ; notranslate">
int query_NPOT_capability( void ){
  ...
  if((NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ), 
      &quot;GL_ARB_texture_non_power_of_two&quot;)){
  ...
</pre>
<p>This mechanism can be found elsewhere too. As this specific feature is definitely part of <strong>OpenGL 3.2 core</strong> the problem was easy to resolve (remove the check) and it works now as expected. Yay!</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2012/12/22/libsoil/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Doxygen and GLSL shader</title>
		<link>https://www.numb3r23.net/2012/02/15/doxygen-and-glsl-shader/</link>
		<comments>https://www.numb3r23.net/2012/02/15/doxygen-and-glsl-shader/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 19:01:26 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Doxygen]]></category>
		<category><![CDATA[GLSL]]></category>

		<guid isPermaLink="false">http://www.grasmo.de/?p=46</guid>
		<description><![CDATA[As I&#8217;ve finished the documentation-madness I stumbled over my GLSL shader. Doxygen, _the_ documentation tool of choice, reads them (as they are very c-like) but dumps them rather unfancy. Doxygen is not only very flexible &#8211; it is also extensible with filters to process other languages. Idea Write a small filter, that pads every shader [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>As I&#8217;ve finished the documentation-madness I stumbled over my GLSL shader. <a title="Doxygen" href="http://www.doxygen.org/" target="_blank">Doxygen</a>, _the_ documentation tool of choice, reads them (as they are very c-like) but dumps them rather unfancy. Doxygen is not only very flexible &#8211; it is also extensible with <a title="Filters for Doxygen" href="http://www.stack.nl/~dimitri/doxygen/helpers.html" target="_blank">filters</a> to process other languages.</p>
<h5>Idea</h5>
<p>Write a small filter, that pads every shader into a class and set a namespace that acts kinda like a category (e.g. class <code>Gauss</code> in namespace <code>GLSL::FILTER::BLUR</code>). The result is my glslfilter.py python-script.</p>
<h5>Usage</h5>
<ol>
<li>Make Doxygen aware of the filter and the newly supported file extensions. To do this, edit your Doxyfile:
<ul>
<li>Add <code>FILE_PATTERNS: *.frag, *.vert</code></li>
<li>Add <code>FILTER_PATTERNS: "*.frag=./glslfilter.py", "*.vert=./glslfilter.py"</code></li>
<li>Add <code>EXTENSION_MAPPING=.frag=C++, .vert=C++</code> (thanks the_summer)</li>
</ul>
</li>
<li>If you want, add annotations to your shader:
<ul>
<li>Use <code>@class</code> to set the class name</li>
<li>Use <code>@namespace</code> to set the namespace &#8211; a category</li>
</ul>
<p>If you set no name, the script will use the bare filename and the default namespace is &#8220;GLSL&#8221;.</p>
<p>Of course you can further document your shader with doxytags &#8211; they are fully processed by Doxygen. The only limitation here (blame my lazyness or my thought it just wasn&#8217;t worth it) is that you have to put the &#8220;<em>class</em>&#8221; comment (= the shader information) at the very beginning in one big blockcomment starting with <code>/*</code> or <code>/**</code>. But seriously &#8211; why would you comment it in any other way? <img src="https://www.numb3r23.net/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley" /></li>
</ol>
<p>To better illustrate the procedure here&#8217;s a little GLSL fragment shader:</p>
<h5>Example</h5>
<pre class="brush: cpp; title: ; notranslate">
/**
 * A simple 3x3 gaussian convolution filter, non-separated version
 * @author Sebastian Schaefer
 * @date 2012
 * @namespace GLSL::FILTER::BLUR
 * @class Gauss3x3
 */
#version 150 core

uniform sampler2D image; ///&lt; the input image

in vec2 tex;	///&lt; texture coordinated
out vec4 color; ///&lt; the color output

/**
 * The main routine: read the 3x3 neighbours and multiply with kernel
 */
void main()
{
    ...
}
</pre>
<p>Click <a title="glslfilter example" href="http://www.grasmo.de/download/glslfilter/glslfilter_example.html" target="_blank">here</a> to see how the above example can look like.</p>
<h5>Download</h5>
<p>Grab the filter at my github-repository <a href="https://github.com/numb3r23/glslAdditions" target="_new">github.com/numb3r23/glslAdditions</a><br />
<em>This page might get updated so please link to this page only, not the direct download. thank you!</em></p>
<p>&#8212;<br />
edit: moved source to github</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2012/02/15/doxygen-and-glsl-shader/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mac: Automator Service for a Google popup</title>
		<link>https://www.numb3r23.net/2012/02/10/automator-services/</link>
		<comments>https://www.numb3r23.net/2012/02/10/automator-services/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 15:08:48 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Automator]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Service]]></category>

		<guid isPermaLink="false">http://www.grasmo.de/?p=40</guid>
		<description><![CDATA[As I was documenting a big amount of source-code today, I ran into the problem of looking up some stuff in the web (OpenGL-SDK docs to be specific) while inside XCode. There may be better ways to do this, but I ended up seeing that service entry in the context-menu and thought &#8211; hey, why [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>As I was documenting a big amount of source-code today, I ran into the problem of looking up some stuff in the web (OpenGL-SDK docs to be specific) while inside XCode. There may be better ways to do this, but I ended up seeing that service entry in the context-menu and thought &#8211; hey, why not make a service to look up that stuff?</p>
<p>Here&#8217;s what I found out:</p>
<ol>
<li>Create a new Automator Service</li>
<li>On the top right, set &#8220;<strong>Service recieves selected text</strong>&#8221; in &#8220;<strong>any application</strong>&#8220;</li>
<li>Drop a &#8220;<strong>Run AppleScript</strong>&#8221; from the Actions Library</li>
<li>Add the following text:
<pre class="brush: applescript; title: ; notranslate">
	on run {input, parameters}
		set theURL to (&quot;http://www.google.com/search?btnI=I%27m+Feeling+Lucky&amp;q=&quot; &amp; input &amp; &quot;&amp;go=Go&quot;)
		return theURL
	end run
	</pre>
</li>
<li>Drop a &#8220;<strong>Website Popup</strong>&#8221; from the Actions Library and configure it as desired <br/><br />
	I choose size &amp; agent &#8220;<strong>iPhone</strong>&#8221; so it&#8217;s not too big but readable.</li>
</ol>
<p>The selected text is searched by google and the first hit is opened (a.k.a. I&#8217;m feeling lucky). Good enough for my documentation problems as the service can be mapped to a global shortcut.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2012/02/10/automator-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating FXAA</title>
		<link>https://www.numb3r23.net/2012/02/07/integrating-fxaa/</link>
		<comments>https://www.numb3r23.net/2012/02/07/integrating-fxaa/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 09:39:25 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Anti-Aliasing]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.grasmo.de/?p=37</guid>
		<description><![CDATA[Revently I&#8217;ve integrated Timothy Lottes extreme powerful Anti-Alising filter Fast Approximate Anti-Aliasing into my ph.d.-project (might be introduced later on&#8230;).  It didn&#8217;t really take a long time as the filter source is documented quite well. As I already have a class CPostProcessor that takes a base image and filters it using a generic vertex- and [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Revently I&#8217;ve integrated <a title="Timothy Lottes" href="http://timothylottes.blogspot.com" target="_blank">Timothy Lottes</a> extreme powerful Anti-Alising filter <a title="Fast Approxiamte Anti-Aliasing" href="http://timothylottes.blogspot.com/2011/03/nvidia-fxaa.html" target="_blank">Fast Approximate Anti-Aliasing</a> into my ph.d.-project (might be introduced later on&#8230;).  It didn&#8217;t really take a long time as the filter source is documented quite well.</p>
<p>As I already have a class CPostProcessor that takes a base image and filters it using a generic vertex- and a custom fragment-shader I&#8217;ve created a class CPPFXAA that applies the FXAA filter.</p>
<p><strong>1. Setup</strong></p>
<p>Before integrating the FXAA shader you have to set it up, meaning going through the first part of the downloadable header-file and choose the defines to what you need/want.</p>
<p><strong>2. Texture to RGBL</strong></p>
<p>This step is not really necessary, but I somehow ended up integrating it anyway. Instead of an alpha value the alpha channel stores the luminace: (for me: color.a = dot(color.rgb, vec3(0.299, 0.587, 0.114));).</p>
<p><strong>3. FXAA filter</strong></p>
<p>Disable blending (if it was enabled) and apply the filter: render a screen-aligned quad with a fxaa as a fragment-shader. Set the input image as your &#8220;BaseImage&#8221; and set the correct viewport dimensions (&#8220;screenwidth&#8221; and &#8220;screenheight&#8221;).</p>
<p><strong>4. done.</strong></p>
<p>That&#8217;s it.</p>
<p>&nbsp;</p>
<p>I hope it works as good for you as it does for me:)</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2012/02/07/integrating-fxaa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
