<?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; Palette-Remapping</title>
	<atom:link href="http://blog.glowinteractive.com/index.php/tag/palette-remapping/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>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>
	</channel>
</rss>
