<?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>webr3.org &#187; Perlin Noise</title>
	<atom:link href="http://webr3.org/blog/tag/perlin-noise/feed/" rel="self" type="application/rss+xml" />
	<link>http://webr3.org/blog</link>
	<description>brain&#039;s on fire!</description>
	<lastBuildDate>Tue, 19 Jul 2011 15:38:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PixelBender is more useful than I assumed!</title>
		<link>http://webr3.org/blog/general/pixelbender-is-more-useful-than-i-assumed/</link>
		<comments>http://webr3.org/blog/general/pixelbender-is-more-useful-than-i-assumed/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 11:18:25 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[PixelBender]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[Abstract algebra]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Computer graphics]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[image processing algorithms]]></category>
		<category><![CDATA[Linear algebra]]></category>
		<category><![CDATA[Perlin Noise]]></category>
		<category><![CDATA[Pixel Bender]]></category>
		<category><![CDATA[Shader]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=94</guid>
		<description><![CDATA[All too often it's too easy to overlook a technology, or indeed its uses, by mentaly boxing it in to the role it's advertised to fill.
PixelBender is one of these technologies, as advertised "You can use the Pixel Bender kernel language to implement image processing algorithms (filters or effects) in a hardware-independent manner"; however this [...]]]></description>
			<content:encoded><![CDATA[<p>All too often it's too easy to overlook a technology, or indeed its uses, by mentaly boxing it in to the role it's advertised to fill.</p>
<p>PixelBender is one of these technologies, as advertised "You can use the Pixel Bender kernel language to implement image processing algorithms (filters or effects) in a hardware-independent manner"; however this isn't the whole truth of the matter.</p>
<p>PixelBender is a highly under-rated and under-used technology imho. Simply put PixelBender is actually a very fast way of converting or manipulating large sets of numerical data, whether it's image based or not. In this post I'm only going to skim the surface and give some pointers.</p>
<p>The standard input types cover Vector, ByteArray and BitmapData, likewise with output data, additionally many types are supported for parameters, everything from ints up to 4x4 Matrix' of floats.</p>
<p>Some obvious and simple uses include:</p>
<ul>
<li>3D Data Manipulation (Float3 input and output - rgb or xyz)</li>
<li>Raw Sound Data Manipulation (from Sound.extract, you could even build an FFT implementation in PixelBender)</li>
<li>Visual Effects Calculations</li>
<li>Batch Processing and Data Transformation.</li>
</ul>
<p>Starting with Batch Processing and Data Transformation, here is the simplest PixelBender usage and example you could ever get.</p>
<h3>Problem</h3>
<p>Turn a BitmapData in to a Vector of RGB float values where each value is float &lt; 1 and each set of 3 values comprises a pixel.</p>
<p>Doing this with pure AS3 or haXe or anything else is quite intensive, then you add PixelBender in to the equation</p>
<p><strong>Solution</strong><br />
PixelBender Code:</p>
<pre>&lt;languageVersion : 1.0;&gt;
kernel Identity
&lt;   namespace : "org.webr3.pb";
 vendor : "WebR3";
 version : 1;
 description : "Converts BitmapData to Vector Number (rgb)";
&gt;
{
 input image3 src;
 output pixel3 dst;

 void evaluatePixel()
 {
 dst = sampleNearest( src, outCoord() );
 }
}</pre>
<p>And to use this we can create a simple wrapper class in AS3:</p>
<pre>package test
{
 import __AS3__.vec.Vector;

 import flash.display.BitmapData;
 import flash.display.Shader;
 import flash.display.ShaderJob;
 import flash.utils.ByteArray;

 public class ShaderVector
 {
 [Embed("/rgb.pbj", mimeType="application/octet-stream")]
 private var shaderClass : Class;

 private var shader : Shader;

 public function ShaderVector()
 {        
 shader = new Shader(new shaderClass() as ByteArray);
 }

 public function convert( img : BitmapData ) : Vector.&lt;Number&gt;
 {
 var output : Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;( (img.width*img.height) * 3 , false );
 shader.data.src.input = img;
 var job : ShaderJob = new ShaderJob( shader , output , img.width , img.height );
 job.start( true );
 output.fixed = true;
 return output;
 }

 }
}</pre>
<p>Now we've got a kind of worker / utility class which we can farm all the hard work on to; usage is simple:</p>
<pre>var worker : ShaderVector = new ShaderVector();
var rgb : Vector.&lt;Number&gt; = worker.convert( someBitmapData );</pre>
<p>that's it, in one line we've solved the problem.</p>
<p>PixelBender is a lot easier than you may think, the above code is a small model you can easily manipulate just embed different pixel bender files.</p>
<p>Here's another simple kernel file; this one will take a BitmapData of perlin noise and convert it in to Vector of 3D positions for us to use.</p>
<p>It takes the bitmap data, converts every pixels r,g,b values in to float -0.5 to +0.5 values, then scales them up and finally returns back a vector of what are essentially 3D Perlin Noise Particles (like the ones in my <a href="http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/">earlier experiments</a>)</p>
<pre>&lt;languageVersion : 1.0;&gt;
kernel Scaler
&lt;   namespace : "org.webr3.pb";
 vendor : "WebR3";
 version : 1;
 description : "For Perlin Noise, Converts BitmapData to 3D x,y,z positions";
&gt;
{
 input image3 src;
 output pixel3 dst;

 parameter float scaleX
 &lt;
 defaultValue : float(1.0);
 minValue     : float(0.1);
 maxValue     : float(100000.0);
 &gt;;

 parameter float scaleY
 &lt;
 defaultValue : float(1.0);
 minValue     : float(0.1);
 maxValue     : float(100000.0);
 &gt;;

 parameter float scaleZ
 &lt;
 defaultValue : float(1.0);
 minValue     : float(0.000001);
 maxValue     : float(100000.0);
 &gt;;

 void evaluatePixel()
 {
 dst = sampleNearest( src, outCoord() );
 dst -= 0.5;
 dst.r *= scaleX;
 dst.g *= scaleY;
 dst.b *= scaleZ;
 }
}</pre>
<p>and the modified shader vector, only 3 new lines to set up the scale values:</p>
<pre>package test
{
 import __AS3__.vec.Vector;

 import flash.display.BitmapData;
 import flash.display.Shader;
 import flash.display.ShaderJob;
 import flash.utils.ByteArray;

 public class ShaderVector
 {
 [Embed("/rgb.pbj", mimeType="application/octet-stream")]
 private var shaderClass : Class;

 private var shader : Shader;

 public function ShaderVector()
 {        
 shader = new Shader(new shaderClass() as ByteArray);
 shader.data.scaleX.value = [200];
 shader.data.scaleY.value = [200];
 shader.data.scaleZ.value = [200];
 }

 public function convert( img : BitmapData ) : Vector.&lt;Number&gt;
 {
 var output : Vector.&lt;Number&gt; = new Vector.&lt;Number&gt;( (img.width*img.height) * 3 , false );
 shader.data.src.input = img;
 var job : ShaderJob = new ShaderJob( shader , output , img.width , img.height );
 job.start( true );
 output.fixed = true;
 return output;
 }

 }
}</pre>
<p>If you're thinking this is complex, it's honestly not - try coding this in pure AS3 and it'll be a lot of complex slow lines, been there and done that!</p>
<p>I'm going to leave the examples there for now, if your looking for a 3D example then <a href="http://bit.ly/JnQzA" target="_blank">check the PixelBender files in Ralphs 3D Particle example</a>.</p>
<h3>Conclusion.</h3>
<p>AS3 together with PixelBender, haXe and Alchemy is fast becoming an immense tech for us developers, have a play around you may be suprised by the results you can achieve by utilizing these techs.</p>
<p>Coming very soon I'll be posting some examples which show what can be done when you use PixelBender, Fast Memory, Vectors and haXe / AS3 together, but in unconventional ways. Until then I hope this is enough to get some more dev's playing with PixelBender.</p>
<p>peace ::</p>
<p><img class="alignnone size-full wp-image-96" title="pb" src="http://webr3.org/blog/wp-content/uploads/2009/07/pb.jpg" alt="pb" width="600" height="250" /></p>
<p>image is a still from <a href="http://www.apple.com/trailers/wb/iamlegendawakening/" target="_self">I am Legend : Awakening</a> a very well made 5 minute short animation.</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/general/pixelbender-is-more-useful-than-i-assumed/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>3D Perlin Particle Light Cloud (and source) - haXe / Flash 10</title>
		<link>http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/</link>
		<comments>http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 17:19:47 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Perlin Noise]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[3D computer graphics]]></category>
		<category><![CDATA[Environment]]></category>
		<category><![CDATA[Fractals]]></category>
		<category><![CDATA[Noise]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=47</guid>
		<description><![CDATA[
Been doing some more playing with Perlin Particles, this time going for more natural, and indeed more useful!
Full source and comments included with this one: 3D Perlin Particle Light Cloud
]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-51" title="perlincloud" src="http://webr3.org/blog/wp-content/uploads/2009/06/perlincloud1.jpg" alt="perlincloud" width="600" height="250" /></p>
<p>Been doing some more playing with Perlin Particles, this time going for more natural, and indeed more useful!</p>
<p>Full source and comments included with this one: <a href="http://webr3.org/experiments/perlin-particles/light-cloud/">3D Perlin Particle Light Cloud</a></p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/3d-perlin-particle-light-cloud-and-source-haxe-flash-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>3D Perlin Noise Particles in Realtime</title>
		<link>http://webr3.org/blog/haxe/3d-perlin-noise-particles-in-realtime/</link>
		<comments>http://webr3.org/blog/haxe/3d-perlin-noise-particles-in-realtime/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 15:55:06 +0000</pubDate>
		<dc:creator>nathan</dc:creator>
				<category><![CDATA[Flash 10]]></category>
		<category><![CDATA[Perlin Noise]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[haXe]]></category>
		<category><![CDATA[Computer graphics]]></category>
		<category><![CDATA[Fractals]]></category>
		<category><![CDATA[Joa Ebert]]></category>
		<category><![CDATA[Noise]]></category>
		<category><![CDATA[Perlin]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">http://webr3.org/blog/?p=42</guid>
		<description><![CDATA[
I was flicking through Joa Eberts site the other day and came across a post he did, speed coding 2; the product of which was a load of 2D perlin noise particles that looked.. well great! Kindly Joa gave me permission to dissect, modify and port it to haxe. Ultimately though I ended up recoding [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-43" title="perlincube" src="http://webr3.org/blog/wp-content/uploads/2009/06/perlincube.jpg" alt="perlincube" width="600" height="250" /></p>
<p>I was flicking through Joa Eberts site the other day and came across a post he did, <a href="http://blog.joa-ebert.com/2008/01/20/speedcoding-2/">speed coding 2</a>; the product of which was a load of 2D perlin noise particles that looked.. well great! Kindly Joa gave me permission to dissect, modify and port it to haxe. Ultimately though I ended up recoding it all from scratch, I did however borrow the nice color transform code from the original though, they're damn nice.</p>
<p>Typically you'd call BitmapData.perlinNoise() to generate a 2 color, 2 octave fractal perlin noise image - you then take the 0-255 color values for both of the channels, scale them and use them as your x &amp; y coordinates.</p>
<p>I decided to twist it a bit and try 3D, so in the experiments I'm generating a 3 color, 4 octave fractal perlin noise image then using the   scaling the values to provide x,y,z coordinates. Then mapping each particle into a 3d space, calculating it's color by merging values of particles which land on the same display pixel together.</p>
<p>Enough of the going on anyways, I'll post the full code for the examples once I've cleaned and commented it - all done in haXe of course.</p>
<p>First off, we have a 3D version of <a href="http://blog.joa-ebert.com/2008/01/20/speedcoding-2/">Joa's original</a>; in this one the particles are all mapped into an imaginary cube and some nice effects added : <a href="http://webr3.org/experiments/perlin-particles/cube-tracing-light-particles/">3D perlin noise particles tracing a cube.</a></p>
<p>Next up I thought I'd try some variations:</p>
<ul>
<li><a href="http://webr3.org/experiments/perlin-particles/lazer-tracing-cube/">Lazer tracing a cube</a> (runs v fast)</li>
<li><a href="http://webr3.org/experiments/perlin-particles/noise-in-a-box/">Perlin Noise, In a Box!</a></li>
</ul>
<p>Quite impressed with the base performance here from haxe, I get 100fps on the lazer tracing example, and circa 45-50 fps on the versions with effects or more complex algo's.</p>
<p>liking perlin noise (and haXe).</p>
]]></content:encoded>
			<wfw:commentRss>http://webr3.org/blog/haxe/3d-perlin-noise-particles-in-realtime/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

