<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Encoding floats to RGBA, again</title>
	<atom:link href="http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/feed/" rel="self" type="application/rss+xml" />
	<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/</link>
	<description>Random thoughts of a triangle pusher</description>
	<lastBuildDate>Thu, 04 Mar 2010 23:01:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Faustyvat</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-25365</link>
		<dc:creator>Faustyvat</dc:creator>
		<pubDate>Mon, 18 Jan 2010 11:29:29 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-25365</guid>
		<description>Rural pharmacy.
Small prices a month.&lt;a href=&quot;http://stolyr.co.cc/sitemap.html&quot; rel=&quot;nofollow&quot;&gt;Buy Viagra $0.87&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Rural pharmacy.<br />
Small prices a month.<a href="http://stolyr.co.cc/sitemap.html" rel="nofollow">Buy Viagra $0.87</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lost in the Triangles &#187; Blog Archive &#187; Encoding floats to RGBA &#8211; the final?</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-20146</link>
		<dc:creator>Lost in the Triangles &#187; Blog Archive &#187; Encoding floats to RGBA &#8211; the final?</dc:creator>
		<pubDate>Thu, 30 Jul 2009 12:58:20 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-20146</guid>
		<description>[...] right there on my previous blog post [...]</description>
		<content:encoded><![CDATA[<p>[...] right there on my previous blog post [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Salvatore Previti</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-16380</link>
		<dc:creator>Salvatore Previti</dc:creator>
		<pubDate>Tue, 03 Feb 2009 07:17:13 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-16380</guid>
		<description>Use these two :)

inline float4 FloatToRGBA(float value)
{
	float4 packedValue = frac(value * float4(16777216, 65536, 256, 1));
	return packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256);
}

inline float RGBAToFloat(float4 packedValue)
{
	return dot(packedValue, float4( 1.0 / 16777216, 1.0 / 65536, 1.0 / 256, 1.0));
}

This works quite well for all values from 0.0 (included) to 1.0 (excluded).
If you need to store value 1.0 too, you can simply divide the input of FloatToRGBA and  multiply the output of RGBAToFloat by 0.9999991 loosing only a small amount of precision.
It seems to work quite well also with bilinear interpolation of textures.</description>
		<content:encoded><![CDATA[<p>Use these two :)</p>
<p>inline float4 FloatToRGBA(float value)<br />
{<br />
	float4 packedValue = frac(value * float4(16777216, 65536, 256, 1));<br />
	return packedValue &#8211; packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256);<br />
}</p>
<p>inline float RGBAToFloat(float4 packedValue)<br />
{<br />
	return dot(packedValue, float4( 1.0 / 16777216, 1.0 / 65536, 1.0 / 256, 1.0));<br />
}</p>
<p>This works quite well for all values from 0.0 (included) to 1.0 (excluded).<br />
If you need to store value 1.0 too, you can simply divide the input of FloatToRGBA and  multiply the output of RGBAToFloat by 0.9999991 loosing only a small amount of precision.<br />
It seems to work quite well also with bilinear interpolation of textures.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aras Pranckevičius</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-12339</link>
		<dc:creator>Aras Pranckevičius</dc:creator>
		<pubDate>Tue, 01 Jul 2008 10:50:49 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-12339</guid>
		<description>@Pat: I think the difference is caused by the texture sampler differences. Even if GPUs do have floating point precision internally, regular 8 bit/channel textures are still sampled (and filtered!) at 8 bit precision, I guess for backwards compatibility reasons. Now, if there&#039;s a very slight change in how the sampling and filtering works, then differences like we have here might surface. That&#039;s my theory at least :)

@Alex: not sure, I haven&#039;t actually tried that approach.</description>
		<content:encoded><![CDATA[<p>@Pat: I think the difference is caused by the texture sampler differences. Even if GPUs do have floating point precision internally, regular 8 bit/channel textures are still sampled (and filtered!) at 8 bit precision, I guess for backwards compatibility reasons. Now, if there&#8217;s a very slight change in how the sampling and filtering works, then differences like we have here might surface. That&#8217;s my theory at least :)</p>
<p>@Alex: not sure, I haven&#8217;t actually tried that approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Lindsay</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-12338</link>
		<dc:creator>Alex Lindsay</dc:creator>
		<pubDate>Tue, 01 Jul 2008 10:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-12338</guid>
		<description>Hi, I had a go at this problem in my own special way. I&#039;d be very interested in your opinions and results with the following (my post):
http://www.gamedev.net/community/forums/topic.asp?topic_id=485186
It&#039;s certainly less elegant than the frac encode!</description>
		<content:encoded><![CDATA[<p>Hi, I had a go at this problem in my own special way. I&#8217;d be very interested in your opinions and results with the following (my post):<br />
<a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=485186" rel="nofollow">http://www.gamedev.net/community/forums/topic.asp?topic_id=485186</a><br />
It&#8217;s certainly less elegant than the frac encode!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat Wilson</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-12252</link>
		<dc:creator>Pat Wilson</dc:creator>
		<pubDate>Tue, 24 Jun 2008 16:49:52 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-12252</guid>
		<description>Hmm, come to think of it, I don&#039;t think you could get enough texture addressing with FP16, so scratch that theory.</description>
		<content:encoded><![CDATA[<p>Hmm, come to think of it, I don&#8217;t think you could get enough texture addressing with FP16, so scratch that theory.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat Wilson</title>
		<link>http://aras-p.info/blog/2008/06/20/encoding-floats-to-rgba-again/comment-page-1/#comment-12251</link>
		<dc:creator>Pat Wilson</dc:creator>
		<pubDate>Tue, 24 Jun 2008 16:49:05 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=181#comment-12251</guid>
		<description>This looks like it&#039;s related to the internal float representation of the card. I&#039;m pulling numbers out of air, but I would guess that the early Radeons used FP16, x13-x19 used FP24, and HD series finally went to FP32. That would explain the large discrepancies between the early Radeons and the HD/GeForce/Intel cards.</description>
		<content:encoded><![CDATA[<p>This looks like it&#8217;s related to the internal float representation of the card. I&#8217;m pulling numbers out of air, but I would guess that the early Radeons used FP16, x13-x19 used FP24, and HD series finally went to FP32. That would explain the large discrepancies between the early Radeons and the HD/GeForce/Intel cards.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
