<?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>GLOW interactive™ BLOG &#187; Jan Kalis</title>
	<atom:link href="http://blog.glowinteractive.com/index.php/author/jan/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.glowinteractive.com</link>
	<description>codify, media, gaming, industry ramblings, finance</description>
	<lastBuildDate>Tue, 29 Jun 2010 21:39:42 +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>Z-Buffer Implementation In Flash Alchemy</title>
		<link>http://blog.glowinteractive.com/index.php/2010/04/z-buffer-implementation-in-flash-alchemy/</link>
		<comments>http://blog.glowinteractive.com/index.php/2010/04/z-buffer-implementation-in-flash-alchemy/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 01:41:08 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[alchemy]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[perspectively-correct-texture-mapping]]></category>
		<category><![CDATA[texture-mapping]]></category>
		<category><![CDATA[z-buffer]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=802</guid>
		<description><![CDATA[One way to perform perspectively correct texture mapping is via an actual calculation of the z-value at every pixel of the triangle to be rendered. That made me wonder if someone has implemented a simultaneous texture mapping and z-buffer in Flash using Alchemy.]]></description>
			<content:encoded><![CDATA[<p>One way to perform <a href="http://en.wikipedia.org/wiki/Texture_mapping#Perspective_correctness">perspectively correct texture mapping</a> is via an <a href="http://www.comp.nus.edu.sg/~lowkl/publications/lowk_persp_interp_techrep.pdf">actual calculation of the z-value at every pixel</a> of the triangle to be rendered. That made me wonder if someone has implemented a simultaneous texture mapping and z-buffer in Flash using <a href="http://labs.adobe.com/technologies/alchemy/">Alchemy</a>. It seems that no one has done that yet so I decided to put together a demo (to code it as fast as possible I used <a href="http://www.lysator.liu.se/~mikaelk/doc/perspectivetexture/">PTPOLY1.CPP</a> for the triangle rendering).</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/gigl/gigl001/GiglTest.html"><img class="alignnone size-full wp-image-803" title="codify_post_gigl_001" src="http://blog.glowinteractive.com/wp-content/uploads/2010/04/codify_post_gigl_001.jpg" alt="" width="670" height="320" /></a></p>
<p>The demo shows 100 random (intersecting) triangles textured with a Lena image and is rendering at about 30FPS on my Windows 7/Intel Xeon 5160.</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/gigl/gigl001/gigl.zip">Grab the source code!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2010/04/z-buffer-implementation-in-flash-alchemy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bresenham&#8217;s Line Algorithm in Flash Alchemy</title>
		<link>http://blog.glowinteractive.com/index.php/2010/04/bresenhams-line-algorithm-in-flash-alchemy/</link>
		<comments>http://blog.glowinteractive.com/index.php/2010/04/bresenhams-line-algorithm-in-flash-alchemy/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 03:45:14 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[bresenham-line-algorithm]]></category>
		<category><![CDATA[flash-alchemy]]></category>
		<category><![CDATA[grass-effect]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=782</guid>
		<description><![CDATA[We are currently working on a platform game that will feature an occasional gravity flip. In some levels the effect will be accompanied by flipping the entire screen but in others it may be too distracting. For those levels we have to come up with other ways to convey that the gravity switched direction.]]></description>
			<content:encoded><![CDATA[<p>We are currently working on a platform game that will feature an occasional gravity flip. In some levels the effect will be accompanied by flipping the entire screen but in others it may be too distracting. For those levels we have to come up with other ways to convey that the gravity switched direction. My idea is to have some kind of grass or hair on platforms that will be influenced by the direction of the gravity force.</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/bresenham_alchemy/Bresenham.html"><img class="alignnone size-full wp-image-783" title="codify_post_bresenham_alchemy" src="http://blog.glowinteractive.com/wp-content/uploads/2010/04/codify_post_bresenham_alchemy.jpg" alt="" width="400" height="300" /></a></p>
<p>A  quick demo showed that I would need a lot of line segments. It turned out that <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Graphics.html">Graphics</a>&#8216; moveTo and lineTo is too slow for that amount of lines. So I started looking for an <a href="http://labs.adobe.com/technologies/alchemy/">Alchemy</a> implementation of a line drawing algorithm, specifically <a href="http://en.wikipedia.org/wiki/Bresenham's_line_algorithm">Bresenham&#8217;s line algorithm</a>. The search was not successful so I rolled up my sleeves and started coding it myself &#8211; with help of existing Alchemy demos and a <a href="http://www.cs.unm.edu/~angel/BOOK/INTERACTIVE_COMPUTER_GRAPHICS/FOURTH_EDITION/PROGRAMS/bresenham.c">C implementation of the algorithm</a>. <a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/bresenham_alchemy/Bresenham.html">Here&#8217;s the result.</a> Click it to switch between Alchemy rendering and Graphics rendering.</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/bresenham_alchemy/bresenham.zip">Source code here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2010/04/bresenhams-line-algorithm-in-flash-alchemy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Motion Blur of a Spinning Sphere in iPhone OpenGL ES</title>
		<link>http://blog.glowinteractive.com/index.php/2010/02/motion-blur-of-a-spinning-sphere-in-iphone-opengl-es/</link>
		<comments>http://blog.glowinteractive.com/index.php/2010/02/motion-blur-of-a-spinning-sphere-in-iphone-opengl-es/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 19:15:49 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Motion-Blur]]></category>
		<category><![CDATA[OpenGL-ES]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=655</guid>
		<description><![CDATA[The task is simple: how to go about a motion blur of a fast-spinning OpenGL ES sphere on the iPhone? That is, how to achieve the following effect...]]></description>
			<content:encoded><![CDATA[<p>The task is simple: how to go about a motion blur of a fast-spinning OpenGL ES sphere on the iPhone? That is, how to achieve the following effect.</p>
<p><img class="size-full wp-image-724 alignnone" title="iphone_codify_blur_globe" src="http://blog.glowinteractive.com/wp-content/uploads/2010/02/iphone_codify_blur_globe.jpg" alt="openGL ES Blur" width="670" height="500" /></p>
<p><strong> </strong></p>
<p><strong>Attempt #1 &#8211; drawing on top of previous frames &#8211; rejected</strong></p>
<p>Very simple but occasionally powerful effect of blending with the previous frame (looks like what&#8217;s going on when you get hit in Call of Duty 4). It works for slow motion, but as soon as the globe starts spinning quickly, you can see the individual frames.</p>
<p><strong>Attempt #2 &#8211; accumulation buffer using FBO &#8211;  rejected</strong></p>
<p>Also simple to implement. Basically it&#8217;s simulating the accumulation buffer (which is not available on the iPhone). I wasn&#8217;t able to find a sweet spot between a nice-looking motion blur and maintaining high fps (even if the rendering is performed at a much lower resolution).</p>
<p><strong>Attempt #3 &#8211; screen space blurring &#8211; rejected</strong></p>
<p>Originally sounded like a good idea &#8211; thought no one would be able to tell that it&#8217;s only a 2d blur. Not true. Rejected.</p>
<p><strong>Attempt #4 &#8211; pre-blurred texture maps &#8211; used</strong></p>
<p>Main idea: if the globe is spinning along its &#8220;main&#8221; axis (south pole to north pole), the motion blur can be simulated by just blurring the texture horizontally. How about generating a couple of pre-blurred texture maps corresponding to different rotations axes.</p>
<p><img class="alignnone size-full wp-image-775" title="iphone_codify_blur_globe_2" src="http://blog.glowinteractive.com/wp-content/uploads/2010/02/iphone_codify_blur_globe_2.jpg" alt="Globe Blur" width="670" height="320" /></p>
<p>Before I get into details I must say that it works really well. I only use 32 different versions (making the amount of rotation axes 64) and it&#8217;s really hard to tell that it&#8217;s blurred along an axis that&#8217;s slightly off (in the actual iPhone application that this was developed for I am actually snapping to the correct axis which is impossible to notice).</p>
<p>The next disadvantage is also obvious: I only have a limited amount of blur values. In the application I work around that by accelerating and decelerating rapidly.</p>
<p><em>Step 1</em></p>
<p>How to find the best distribution of 32 points on a sphere (actually 64, but the other 32 are just opposite versions of the first 32)? I wrote a <a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/blurred_globe/points_distribution.swf">Flash application</a> that does it for me. It runs a simulation of the following algorithm. Thirty two points are randomly positioned in space, each has a positive charge and is restricted to the unit sphere. The purpose of the positive charge is that the points are repulsed from each other, eventually ending up in an even distribution.</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/blurred_globe/points_distribution.swf" target="_blank"><img class="alignnone size-full wp-image-776" title="iphone_codify_globe_distributed_points" src="http://blog.glowinteractive.com/wp-content/uploads/2010/02/iphone_codify_globe_distributed_points.jpg" alt="Distributed Points" width="670" height="320" /></a></p>
<p><em>Step 2</em></p>
<p>Blurring the original texture by a general axis is just a matter of writing down a couple of equations and hoping that you haven&#8217;t made a typo.</p>
<p><em>Step 3</em></p>
<p>Using the pre-blurred textures is now a piece of cake. Just find the nearest axis and use the corresponding texture.</p>
<p><strong>Attempt #5 &#8211; am I missing something obvious here?</strong></p>
<p>Let me know if I am.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2010/02/motion-blur-of-a-spinning-sphere-in-iphone-opengl-es/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Teaching Worms to Crawl Using Genetic Algorithms</title>
		<link>http://blog.glowinteractive.com/index.php/2010/02/teaching-worms-to-crawl-using-genetic-algorithms/</link>
		<comments>http://blog.glowinteractive.com/index.php/2010/02/teaching-worms-to-crawl-using-genetic-algorithms/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 13:27:28 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[Crawling-Creatures]]></category>
		<category><![CDATA[Emergent-Behavior]]></category>
		<category><![CDATA[Evolution]]></category>
		<category><![CDATA[Genetic-Algorithms]]></category>
		<category><![CDATA[Neural-Networks]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=688</guid>
		<description><![CDATA[This is a follow-up to the first article about training creatures to walk using neural networks and genetic algorithms. The next creature I decided to train is a worm. Here's the result (generation ~200).]]></description>
			<content:encoded><![CDATA[<p>This is a follow-up to <a href="http://blog.glowinteractive.com/index.php/2010/02/on-using-genetic-algorithm-to-train-neural-network-driven-creatues-to-walk-in-flash/">the first article</a> about training creatures to walk using neural networks and genetic algorithms. The next creature I decided to train is a worm. Here&#8217;s the result (generation ~200).</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/worms.swf" target="_blank"><img class="alignnone size-full wp-image-773" title="codify_genetic_algorithms_worms" src="http://blog.glowinteractive.com/wp-content/uploads/2010/02/codify_genetic_algorithms_worms.jpg" alt="Genetic Algorithms - Worms" width="670" height="320" /></a></p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/creatures.zip">Get the source code</a> (contains the walking creatures, too).</p>
<p>PS: Again, if you happen to evolve an interesting locomotion, send me your code/swf and I&#8217;ll post it here.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2010/02/teaching-worms-to-crawl-using-genetic-algorithms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>On Using Genetic Algorithms to Train Neural Network Driven Creatures to Walk in Flash</title>
		<link>http://blog.glowinteractive.com/index.php/2010/02/on-using-genetic-algorithm-to-train-neural-network-driven-creatues-to-walk-in-flash/</link>
		<comments>http://blog.glowinteractive.com/index.php/2010/02/on-using-genetic-algorithm-to-train-neural-network-driven-creatues-to-walk-in-flash/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 04:32:26 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[Emergent-Behavior]]></category>
		<category><![CDATA[Evolution]]></category>
		<category><![CDATA[Genetic-Algorithms]]></category>
		<category><![CDATA[Neural-Networks]]></category>
		<category><![CDATA[Walking-Creatures]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=595</guid>
		<description><![CDATA[I remember seeing Karl Sims' video Evolved Virtual Creatures a long time ago. I was completely stunned but unfortunately forgot about it for many years. I was reminded of it again last year when reading about training neural networks using genetic algorithms and decided to evolve my own creatures.]]></description>
			<content:encoded><![CDATA[<p>I remember seeing <a href="Evolved Virtual Creatures">Karl Sims&#8217; video Evolved Virtual Creatures</a> a long time ago. I was completely stunned but unfortunately forgot about it for many years. I was reminded of it again last year when reading about training <a href="http://en.wikipedia.org/wiki/Neural_network">neural networks</a> using <a href="http://en.wikipedia.org/wiki/Genetic_algorithm">genetic algorithms</a> (Tom Mitchell&#8217;s <a href="http://www.cs.cmu.edu/~tom/mlbook.html">Machine Learning</a> is highly recommended) and decided to evolve my own creatures.</p>
<p><strong>Preparation</strong></p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/ants.swf">Here is the first demo.</a></p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/ants.swf" target="_blank"><img class="alignnone size-full wp-image-770" title="codify_genetic_algorithms_ants" src="http://blog.glowinteractive.com/wp-content/uploads/2010/02/codify_genetic_algorithms_ants.jpg" alt="Genetic Algorithms - Ants" width="670" height="320" /></a></p>
<p>The task is to teach an ant to get to the end of the L-shaped corridor as fast as possible. All an ant is allowed to do (every frame) is rotate freely and turn on its forward thrust (acceleration). Ant&#8217;s behavior is encoded in its DNA consisting of several genes. Every gene prescribes what an ant does in the frame that corresponds to the index of the gene in the DNA. Specifically, each gene is a 3-bit number encoding the ant&#8217;s possible behavior:</p>
<pre class="brush: as3;">
var gene:int = dna[simulationStep];
var acceleration:Boolean = gene &amp; 1;
var turnPositive:Boolean = gene &amp; 2;
var turnNegative:Boolean = gene &amp; 4;
</pre>
<p>The <a href="http://en.wikipedia.org/wiki/Genetic_operator">genetic operators</a> used are not tuned for this particular application. What you see on the screen is one population of 100 individuals. It takes time but if you let them learn you&#8217;ll see that in the end they achieve the goal in the most optimal way.</p>
<p><strong>Evolution</strong></p>
<p>Encouraged by the result (also, it only took about 2 hours to code) I wanted more. Without further ado I present the <strong><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/walking_gen0300.swf">walking creatures</a><span style="font-weight: normal;"> (after 300 generations)</span></strong>.</p>
<p><a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/walking_gen0300.swf" target="_blank"><img class="alignnone size-full wp-image-771" title="codify_genetic_algorithms_walking" src="http://blog.glowinteractive.com/wp-content/uploads/2010/02/codify_genetic_algorithms_walking.jpg" alt="Genetic Algorithms - Walking" width="670" height="320" /></a></p>
<p>The task here is to give physics-based (thank you, <a href="http://box2dflash.sourceforge.net/">Box2D</a>!) ragdoll figures brains to be able to move a certain distance. Following Ngo and Marks&#8217; paper <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.42.2303">Spacetime Constrains Revisited</a> I set out to make my own creatures in Flash. In short, I am using a genetic algorithm to train a neural network that controls motors in the creature&#8217;s joints. The <a href="http://en.wikipedia.org/wiki/Fitness_function">fitness function</a> is plainly how far a creature can get within a certain amount of time. The neural network used is very simple &#8211; it&#8217;s a single layer <a href="http://en.wikipedia.org/wiki/Feedforward_neural_network">feed-forward</a> neural network with the inputs being the angles at every joint, vertical velocity and horizontal distance traveled and the outputs the speed of the motor and the target angle of every joint.</p>
<p><strong>Results</strong></p>
<p>I was really happy to see results only after about 300 generations (it took a night though): a frog. Excited, I ran it again and again and interestingly, I only got frogs. I tried to change the fitness function a bit so that the creatures that touch the ground are penalized but didn&#8217;t get anything interesting. Also tried to make the torso a bit heavier and an inchworm-like creature evolved. If you like, you can try to evolve your own creatures, <a href="http://blog.glowinteractive.com/wp-content/themes/glow/flash/jan/genetic/walking_gen0000.swf">here&#8217;s the link to first generation</a> (with a little bit of creativistic randomization to start with). At the end of every generation, the best DNA is <a href="http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary808.html">traced </a> so if you happen to get some interesting locomotion, please send it to me and I&#8217;ll post it here. (Source code to follow after a brief clean-up.)</p>
<p><strong><span style="color: #ff0000;">Edit:</span></strong><strong> </strong>Get the source code in the <a href="http://blog.glowinteractive.com/index.php/2010/02/teaching-worms-to-crawl-using-genetic-algorithms/">next GA post</a>.</p>
<p><strong>What&#8217;s Next</strong></p>
<p>My plan is to try what behaviors will emerge with different shapes, physics set up, fitness functions or selection algorithms.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2010/02/on-using-genetic-algorithm-to-train-neural-network-driven-creatues-to-walk-in-flash/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Quake in Flash 9</title>
		<link>http://blog.glowinteractive.com/index.php/2010/01/quake-in-flash-9/</link>
		<comments>http://blog.glowinteractive.com/index.php/2010/01/quake-in-flash-9/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 03:28:32 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Backface-Culling]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Frustum-Clipping]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Texturing]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=266</guid>
		<description><![CDATA[About a year ago, our company decided to come up with a game that would utilize a highly stylized 3D city neighborhood  as the main "menu" for the game. In a nutshell, just a couple of semitransparent 3D boxes. I figured, rather than looking into an existing Flash 3D engine, I can code it myself.]]></description>
			<content:encoded><![CDATA[<p>About a year ago, our company decided to come up with a game that would utilize a highly stylized 3D city neighborhood  as the main &#8220;menu&#8221; for the game. In a nutshell, just a couple of semitransparent 3D boxes. I figured, rather than looking into an existing Flash 3D engine, I can code it myself. There would be no problems with visibility ordering, backface culling, texturing, frustum clipping, etc. It turned out that it really wasn&#8217;t a big deal and in a couple of days I had a very simple and efficient engine running. We didn&#8217;t make the game eventually, but I had a really light-weight base of a 3D engine.</p>
<p>I decided to work on a little bit more, but as it turned out really soon, I needed some open format model files that would serve as demos. As a fan of the original <a href="http://www.idsoftware.com/games/quake/quake/">Quake</a>, and <a href="http://www.bluesnews.com/abrash/">everything</a> <a href="http://www.beyond3d.com/content/articles/8/">around</a> it, and having a feeling that the original levels could run easily on present hardware minus Flash, I started working on a Quake <a href="http://www.gamers.org/dEngine/quake/spec/quake-spec34/qkspec_4.htm">BSP</a> parser. <a href="http://glowinteractive.com/staging/jan/blog/quake/quake.html" target="_blank">See the result for yourself.</a> Use mouse (with left button down) for mouselook, ASDW to move horizontally, RF to move up/down.  (It&#8217;s intentionally running fullscreen, just maximize your window.)</p>
<p><a href="http://glowinteractive.com/staging/jan/blog/quake/quake.html" target="_blank"><img class="alignleft size-full wp-image-462" title="codify_post_quake" src="http://blog.glowinteractive.com/wp-content/uploads/2010/01/codify_post_quake.jpg" alt="Quake in Flash 9" width="670" height="320" /></a></p>
<p>I would like to point out that it is Flash 9, i.e. no Alchemy involved!</p>
<p>Conclusion: the demo is running just fine to create a true 3D environment for a Flash game!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2010/01/quake-in-flash-9/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>True Phong Shading in Flash 9</title>
		<link>http://blog.glowinteractive.com/index.php/2009/11/true-phong-shading-in-flash-9/</link>
		<comments>http://blog.glowinteractive.com/index.php/2009/11/true-phong-shading-in-flash-9/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 22:56:38 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[Light-Bloom]]></category>
		<category><![CDATA[Palette-Remapping]]></category>
		<category><![CDATA[Phong-Shading]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=275</guid>
		<description><![CDATA[Most Flash 3D engines use a clever technique called normal mapping to compensate for the lack of mesh detail. How could a normal map be used for Phong shading? We already have all the normals we need, the only problem left is the shininess exponent, that would have to be computed per pixel. My solution follows.]]></description>
			<content:encoded><![CDATA[<p>Most (Flash) 3D engines use a clever technique called <a href="http://en.wikipedia.org/wiki/Normal_mapping">normal mapping</a> to compensate for the lack of mesh detail. How could a normal map be used for <a href="http://en.wikipedia.org/wiki/Phong_shading">Phong shading</a> (specifically highlights)? The formula for highlights is (L . N) ^ s, where L is the vector towards the light, N is the normal and s is the shininess exponent. We can easily calculate L .N using ColorMatrixFilter. But what do we do about the exponent? My solution follows:</p>
<p>I recently noticed <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#paletteMap%28%29">this little function</a> in the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html">BitmapData </a>class.</p>
<pre class="brush: as3;">
public function paletteMap (sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, redArray:Array = null, greenArray:Array = null, blueArray:Array = null, alphaArray:Array = null):void
</pre>
<div>What if I just remapped a linear gradient to an &#8220;exponential&#8221; gradient and use normal mapping with this new palette? That is:</div>
<pre class="brush: as3;">
var shininess:Number = 50;

for (var j:int = 0; j &lt; 256; j++)
{
	var alpha:Number = j / 255;
	newPalette[j] = Math.floor(Math.pow(alpha, shininess) * 255);
}
</pre>
<div><a href="http://glowinteractive.com/staging/jan/blog/cherry/cherry.html" target="_blank">Here&#8217;s the result</a> (use mouse to rotate the cherry).  It&#8217;s using a combination of <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#threshold%28%29">threshold</a> and <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filters/GlowFilter.html">GlowFilter</a> to simulate <a href="http://en.wikipedia.org/wiki/Bloom_%28shader_effect%29">light bloom</a>.</div>
<div>
<p><a href="http://glowinteractive.com/staging/jan/blog/cherry/cherry.html" target="_blank"><img class="alignleft size-full wp-image-465" title="codify_post_true_phong_shading" src="http://blog.glowinteractive.com/wp-content/uploads/2009/11/codify_post_true_phong_shading.jpg" alt="True Phong Shading in Flash 9" width="670" height="320" /></a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2009/11/true-phong-shading-in-flash-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>#tweetcoding Revisited</title>
		<link>http://blog.glowinteractive.com/index.php/2009/11/tweetcoding-revisited/</link>
		<comments>http://blog.glowinteractive.com/index.php/2009/11/tweetcoding-revisited/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 19:56:41 +0000</pubDate>
		<dc:creator>Jan Kalis</dc:creator>
				<category><![CDATA[Codify]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[TweetCoding]]></category>

		<guid isPermaLink="false">http://blog.glowinteractive.com/?p=200</guid>
		<description><![CDATA[Earlier this year Grant Skinner organized coding competition. The task was particularly simple: to code something cool in ActionScript using at most 140 characters (whence the name, tweetcoding). As everybody else, let me talk about my submissions a little bit, too.]]></description>
			<content:encoded><![CDATA[<p>Earlier this year <a href="http://www.gskinner.com">Grant Skinner</a> organized a coding competition called<a href="http://www.gskinner.com/blog/archives/2009/02/tweetcoding_con.html"> Tweetcoding</a>. The task was particularly simple: to code something cool in ActionScript3 using at most 140 characters (whence the name, tweetcoding). As everyone else writing a blog did, let me repost my submissions, too (another reason is that it seems that the original site with all submissions is down now). There is nothing really to talk about code-wise to dissect &#8211; it&#8217;s so short, just read it and enjoy the &#8220;coolness.&#8221;</p>
<h2><strong>Anemone</strong></h2>
<p>My first entry was called <a title="Tweet Coding - Anemone" href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/anemone.swf" target="_blank">Anemone</a>.</p>
<p>The Code:</p>
<pre class="brush: as3;">if(i++&lt;9)o[i-1]={x:275,y:200,a:l=i,w:30};with(o[i%l]){if(w&gt;5)o[l++]={x:x,y:y,a:a,w:w};ls(w--,i);mt(x,y);lt(x+=9*s(2-a),y+=9*s(a+=r()*.6+6))}</pre>
<p><a href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/anemone.swf" target="_blank"><img class="alignleft size-full wp-image-480" title="codify_post_tweetcoding_anemone" src="http://blog.glowinteractive.com/wp-content/uploads/2009/11/codify_post_tweetcoding_anemone.jpg" alt="Tweet Coding Anemone" width="670" height="320" /></a></p>
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<p style="text-align: center;">
<h2><strong>Wormhole</strong></h2>
<p>I was really happy about <a title="Tweet Coding - Wormhole" href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/wormhole.swf" target="_blank">Wormhole</a>, because it seemed to become an inspiration for <a href="http://pixelero.wordpress.com/" target="_blank">piXelero&#8217;s</a> <a href="http://www.petrileskinen.fi/Actionscript/Tweetcodes/TunnelOfStripes.html" target="_blank">winning entry Tunnel of Stripes</a>.</p>
<p>The Code:</p>
<pre class="brush: as3;">g.clear();for(c=-90;c++;){d=91+(c-i*10)%90;ls(.1*d+9/d,0,1/d);g.drawCircle(275+.3*(s(i)+s(2*i))*(d+99),200+30*s(i),999/d)}i+=.01</pre>
<p><a href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/wormhole.swf" target="_blank"><img title="codify_post_tweetcoding_wormhole" src="http://blog.glowinteractive.com/wp-content/uploads/2009/11/codify_post_tweetcoding_wormhole.jpg" alt="Tweet Coding - Wormhole" width="670" height="320" /></a><strong><strong><strong><strong>Twister</strong></strong></strong></strong></p>
<p>The next submission received a notable mention, <a title="Tweet Coding - Twister" href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/twister.swf" target="_blank">Twister</a>.</p>
<p>The Code:</p>
<pre class="brush: as3;">g.clear();for(c=999;c--;mt(c,k=275))if(!i)o[c]=r();else ls(1,lt(c,k),l=o[c],g.drawCircle(k+l*c*s(i+c)/9+99*s(i*.1)*s(2-2*l),k-l*k,.5));i+=.1</pre>
<p><a href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/twister.swf" target="_blank"><img class="alignleft size-full wp-image-488" title="codify_post_tweetcoding_twister" src="http://blog.glowinteractive.com/wp-content/uploads/2009/11/codify_post_tweetcoding_twister.jpg" alt="Tweet Coding - Twister" width="670" height="320" /></a></p>
<h2><strong><strong>Grass</strong></strong></h2>
<p>Fourth is <a title="Tweet Coding - Grass" href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/grass.swf" target="_blank">Grass</a>.</p>
<p>The Code:</p>
<pre class="brush: as3;">g.clear();for(m=c=275;c--;ls(1,c&lt;&lt;8))for(u=c&amp;4,v=9,mt(p=m+m*s(c*6),q=m+99*s(c*5)),k=.1+s(c+i)/20,d=15;d--;u+=v*k,v-=u*k)lt(p+=u,q-=v);i+=.1</pre>
<p><a href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/grass.swf" target="_blank"><img class="alignleft size-full wp-image-490" title="codify_post_tweetcoding_grass" src="http://blog.glowinteractive.com/wp-content/uploads/2009/11/codify_post_tweetcoding_grass.jpg" alt="Tweet Coding - Grass" width="670" height="320" /></a></p>
<h2><strong>Fur</strong></h2>
<p>Last but not least. At the time of the competition, our whole office became obsessed with the &#8220;fur effect&#8221; that you can see in the blog header. It was a bit challenging to recreate the effect in 140 characters, but it worked out well and I also had a couple of characters left to give the result a form, <a title="Tweet Coding - Fur" href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/femaleform.swf" target="_blank">Female Form</a> (let it run for a while).</p>
<p>The Code:</p>
<pre class="brush: as3;">l=r();o.a=r()*7;mt(o.x=275+l*(r()-.5)*200,o.y=300-l*200);for(c=9;c--;){ls(1,0,c/9);l=r()*9;lt(o.x+=l*s(o.a+=r()-.5),o.y+=l*s(1.6-o.a))}</pre>
<p><a href="http://www.glowinteractive.com/staging/jan/blog/tweetcoding/femaleform.swf" target="_blank"><img class="alignleft size-full wp-image-491" title="codify_post_tweetcoding_fur" src="http://blog.glowinteractive.com/wp-content/uploads/2009/11/codify_post_tweetcoding_fur.jpg" alt="Tweet Coding - Fur" width="670" height="320" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.glowinteractive.com/index.php/2009/11/tweetcoding-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
