<?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; OpenGL</title>
	<atom:link href="https://www.numb3r23.net/category/opengl/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>Modified lambert in webgl</title>
		<link>https://www.numb3r23.net/2015/08/04/modified-lambert-in-webgl/</link>
		<comments>https://www.numb3r23.net/2015/08/04/modified-lambert-in-webgl/#comments</comments>
		<pubDate>Tue, 04 Aug 2015 18:13:58 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Github]]></category>
		<category><![CDATA[NPR]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=316</guid>
		<description><![CDATA[i wrote a little demo with a modified lambert function in webgl: You can clamp the illumination into the &#8220;brighter&#8221; colors that is expanded into the (usually unlit) back areas and thus allows you lit the whole object. The light can be toggled between a (fixed) lightsource and the camera-position. This is usefull if you (cheaply) don&#8217;t want to [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>i wrote a little demo with a modified lambert function in webgl:</p>
<div id="attachment_318" style="width: 938px" class="wp-caption alignnone"><a href="http://numb3r23.github.io/GLSLShaderLib/examples/webgl/ModifiedLambert.html"><img class="wp-image-318 size-full" src="http://www.numb3r23.net/wp-content/uploads/2015/08/Screenshot-2015-08-05-00.55.35.png" alt="Screenshot 2015-08-05 00.55.35" width="928" height="511" /></a><p class="wp-caption-text"><a href="http://numb3r23.github.io/GLSLShaderLib/examples/webgl/ModifiedLambert.html" target="_blank">http://numb3r23.github.io/GLSLShaderLib/examples/webgl/ModifiedLambert.html</a></p></div>
<p>You can clamp the illumination into the &#8220;brighter&#8221; colors that is expanded into the (usually unlit) back areas and thus allows you lit the whole object. The light can be toggled between a (fixed) lightsource and the camera-position. This is usefull if you (cheaply) don&#8217;t want to show &#8220;dark parts&#8221; of 3d-models while still showing the structure. It can be further tweaked (not implemented yet!) by adding gamma or a two-tone mapping.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2015/08/04/modified-lambert-in-webgl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebGL-Paccer (more three.js)</title>
		<link>https://www.numb3r23.net/2013/05/21/webgl-paccer-more-three-js/</link>
		<comments>https://www.numb3r23.net/2013/05/21/webgl-paccer-more-three-js/#comments</comments>
		<pubDate>Tue, 21 May 2013 00:52:26 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=287</guid>
		<description><![CDATA[Here&#8217;s a little simplified version of a rather known game I&#8217;d like to call &#8220;WebGL-Paccer&#8221;. You play as a yellow ball, trying to eat all the dots before the enemy gets you. Yeah, that one. http://www.numb3r23.net/webGLex/paccer Even though it has a distinct &#8220;retro&#8221; look, I added an FXAA-aliasing and a bloom-filter to it. I tried [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a little simplified version of a rather known game I&#8217;d like to call &#8220;WebGL-Paccer&#8221;. You play as a yellow ball, trying to eat all the dots before the enemy gets you. Yeah, that one.</p>
<p><a href="http://www.numb3r23.net/webGLex/paccer" target="_blank"><img class="alignnone  wp-image-275" alt="WebGL-Paccer" src="http://www.numb3r23.net/wp-content/uploads/2013/05/Screen-Shot-2013-05-21-at-2.25.07-AM-1024x617.png" width="625" height="376" /></a></p>
<p><a href="http://www.numb3r23.net/webGLex/paccer" target="_blank">http://www.numb3r23.net/webGLex/paccer</a></p>
<p>Even though it has a distinct &#8220;retro&#8221; look, I added an FXAA-aliasing and a bloom-filter to it. I tried doing some dynamic cube-map for floor-reflections, but it didn&#8217;t fit the theme.</p>
<p>Maybe in an extended version could not only add more enemies (Blinky, Inky, Pinky, Clyde) but also some more fx. I loved Geometry wars, maybe some effects from them could fit in here&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2013/05/21/webgl-paccer-more-three-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebGL: three.js &amp; dat.gui.js</title>
		<link>https://www.numb3r23.net/2013/05/17/webgl-three-js-dat-gui-js/</link>
		<comments>https://www.numb3r23.net/2013/05/17/webgl-three-js-dat-gui-js/#comments</comments>
		<pubDate>Fri, 17 May 2013 17:38:57 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[WebGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=261</guid>
		<description><![CDATA[I&#8217;ve uploaded an updated WebGL demo I wrote some time ago. It shows a vertex displacement shader on simple models and applies some screen-space image filter (=fragment shaders) to it: http://numb3r23.net/webgl/vertexAndImages Here are selected screenshots: The effects implemented are: Vertex shader displacement TwoTone shading CEL-Shading Gaussian Blur Image Enhancement by unsharp masking the depthbuffer Gamma/Contrast/Brightness [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve uploaded an updated WebGL demo I wrote some time ago. It shows a vertex displacement shader on simple models and applies some screen-space image filter (=fragment shaders) to it:</p>
<p><a href="http://www.numb3r23.net/webGLex/vertexAndImages" target="_blank">http://numb3r23.net/webgl/vertexAndImages</a></p>
<p>Here are selected screenshots:</p>
<p><img class="alignnone size-medium wp-image-265" alt="Screen Shot 2013-05-17 at 7.03" src="http://www.numb3r23.net/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-7.03-300x184.png" width="300" height="184" /><img class="alignnone size-medium wp-image-262" alt="Screen Shot 2013-05-17 at 7.07" src="http://www.numb3r23.net/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-7.07-300x184.png" width="300" height="184" /></p>
<p><img class="alignnone size-medium wp-image-263" alt="Screen Shot 2013-05-17 at 7.04" src="http://www.numb3r23.net/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-7.04-300x184.png" width="300" height="184" /><img class="alignnone size-medium wp-image-264" alt="Screen Shot 2013-05-17 at 7.06" src="http://www.numb3r23.net/wp-content/uploads/2013/05/Screen-Shot-2013-05-17-at-7.06-300x184.png" width="300" height="184" /></p>
<p>The effects implemented are:</p>
<ul>
<li>Vertex shader displacement</li>
<li><span style="line-height: 14px;">TwoTone shading</span></li>
<li>CEL-Shading</li>
<li>Gaussian Blur</li>
<li>Image Enhancement by unsharp masking the depthbuffer</li>
<li>Gamma/Contrast/Brightness adjustment</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2013/05/17/webgl-three-js-dat-gui-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Github: GLSL shader library</title>
		<link>https://www.numb3r23.net/2013/05/17/github-glsl-shader-library/</link>
		<comments>https://www.numb3r23.net/2013/05/17/github-glsl-shader-library/#comments</comments>
		<pubDate>Fri, 17 May 2013 13:48:43 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Github]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=256</guid>
		<description><![CDATA[Modern OpenGL relies heavily on GLSL shaders. They are needed for pretty much everything you draw. To ease the handling of shaders I&#8217;ve decided publish my shader-collection (well, part of it, for now) on github. The shaders are sorted by GLSL version (currently: version 1.5, webgl 1.0) and &#8220;purpose&#8221;. Their implementation is focused on readability, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Modern OpenGL relies heavily on GLSL shaders. They are needed for pretty much everything you draw. To ease the handling of shaders I&#8217;ve decided publish my shader-collection (well, part of it, for now) on github. The shaders are sorted by GLSL version (currently: version 1.5, webgl 1.0) and &#8220;purpose&#8221;. Their implementation is focused on readability, not speed. Hence, they can be optimized quite heavily and be combined as well. Anyway, here&#8217;s the link:</p>
<p><a title="GLSL Shader Lib" href="https://github.com/numb3r23/GLSLShaderLib">https://github.com/numb3r23/GLSLShaderLib</a></p>
<p>I&#8217;m planning on continuously adding shaders.</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2013/05/17/github-glsl-shader-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Github: OpenGL 3.2 core Render-library [cpp]</title>
		<link>https://www.numb3r23.net/2013/05/17/github-opengl-3-2-core-render-library-cpp/</link>
		<comments>https://www.numb3r23.net/2013/05/17/github-opengl-3-2-core-render-library-cpp/#comments</comments>
		<pubDate>Fri, 17 May 2013 13:30:18 +0000</pubDate>
		<dc:creator><![CDATA[numb3r23]]></dc:creator>
				<category><![CDATA[Github]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.numb3r23.net/?p=253</guid>
		<description><![CDATA[I&#8217;ve shared parts of my rendering library on github: https://github.com/numb3r23/ScIll-library here&#8217;s a feature list: OpenGL 3.2 core profile rendering cpp, compiles with gcc &#38; VS 2010 cmake project-file focus on Imagefilters via GLSL fragment-shader Here&#8217;s a little code example on the usage: Of course it can do much more &#8211; load textures, load models, &#8230;]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve shared parts of my rendering library on github:</p>
<p><a title="SciIllLib" href="https://github.com/numb3r23/ScIll-library">https://github.com/numb3r23/ScIll-library</a></p>
<p>here&#8217;s a feature list:</p>
<ul>
<li><span style="line-height: 14px;">OpenGL 3.2 core profile rendering</span></li>
<li>cpp, compiles with gcc &amp; VS 2010</li>
<li>cmake project-file</li>
<li>focus on Imagefilters via GLSL fragment-shader</li>
</ul>
<p>Here&#8217;s a little code example on the usage:</p>
<pre class="brush: cpp; title: ; notranslate">
using namespace SciIllLib;

CFilter fltFXAA = new CFilter();
fltFXAA-&gt;LoadFragmentShader(&quot;res/glsl/filter/FXAA.frag&quot;);

SFilterEngine::ReGenerateTexture(&amp;m_rtScene, GL_FLOAT); SFilterEngine::ReGenerateTexture(&amp;m_rtFinal, GL_FLOAT);

SFilterEngine::PreRender(m_rtScene);
... render as usual ...
SFilterEngine::PostRender();

SFilterEngine::Apply(fltFXAA, m_rtScene, m_rtFinal);
SFilterEngine::ToScreen(fltDisplay, m_rtFinal);
</pre>
<p>Of course it can do much more &#8211; load textures, load models, &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.numb3r23.net/2013/05/17/github-opengl-3-2-core-render-library-cpp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
