<?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: A day well spent (encoding floats to RGBA)</title>
	<atom:link href="http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/feed/" rel="self" type="application/rss+xml" />
	<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/</link>
	<description>Random thoughts of a triangle pusher</description>
	<lastBuildDate>Sat, 17 Jul 2010 12:39:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Lost in the Triangles &#187; Blog Archive &#187; Encoding floats to RGBA, again</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-12199</link>
		<dc:creator>Lost in the Triangles &#187; Blog Archive &#187; Encoding floats to RGBA, again</dc:creator>
		<pubDate>Fri, 20 Jun 2008 15:56:03 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-12199</guid>
		<description>[...] it looks like the quest for encoding floats to RGBA textures (part 1, part 2) did not end [...]</description>
		<content:encoded><![CDATA[<p>[...] it looks like the quest for encoding floats to RGBA textures (part 1, part 2) did not end [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lost in the Triangles &#187; Blog Archive &#187; Encoding floats to RGBA, redux</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-717</link>
		<dc:creator>Lost in the Triangles &#187; Blog Archive &#187; Encoding floats to RGBA, redux</dc:creator>
		<pubDate>Fri, 29 Jun 2007 07:58:36 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-717</guid>
		<description>[...] has interesting comments in my earlier post. So I thought I&#8217;d share what I am using right now, and try to throw some more complexities in [...]</description>
		<content:encoded><![CDATA[<p>[...] has interesting comments in my earlier post. So I thought I&#8217;d share what I am using right now, and try to throw some more complexities in [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gleserg</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-716</link>
		<dc:creator>gleserg</dc:creator>
		<pubDate>Fri, 29 Jun 2007 07:15:31 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-716</guid>
		<description>Oops, forgot about HTML.

After some thinking with Rej and Kravchenko, the final idea looks like:

Just before truncating to a screen buffer byte value 0..255, our number looks like 

0.1234 5678 9ABC DEFG HIJK LMN // 23 bit mantissa, with exponent=0, numbers represent binary digits

frac(0.123456789ABCDEFGHIJKLMN) = 0.123456789ABCDEFGHIJKLMN
framebuffer will receive 12345678 + ((bit9&gt;0)?1:0); // rounded

frac(0.123456789ABCDEFGHIJKLMN * 256) = frac(0.123456789ABCDEFGHIJKLMN &lt;&lt; 8) = frac(12345678.9ABCDEFGHIJKLMN) = 0.9ABCDEFGHIJKLMN
framebuffer will receive 9ABCDEFG + ((bitH&gt;0)?1:0); // rounded

frac(0.123456789ABCDEFGHIJKLMN * 65536) = frac(0.123456789ABCDEFGHIJKLMN &lt;&lt; 16) = frac(123456789ABCDEFG.HIJKLMN) = 0.HIJKLMN0
framebuffer will receive HIJKLMN0

further multiplication with 16777216.0 is useless since IEEE mantissa has not enough precision.

bit 9 affects both first byte and second which is bad and causes error you mentioned. The same goes for bit H which affects 2nd and 3rd bytes.</description>
		<content:encoded><![CDATA[<p>Oops, forgot about HTML.</p>
<p>After some thinking with Rej and Kravchenko, the final idea looks like:</p>
<p>Just before truncating to a screen buffer byte value 0..255, our number looks like </p>
<p>0.1234 5678 9ABC DEFG HIJK LMN // 23 bit mantissa, with exponent=0, numbers represent binary digits</p>
<p>frac(0.123456789ABCDEFGHIJKLMN) = 0.123456789ABCDEFGHIJKLMN<br />
framebuffer will receive 12345678 + ((bit9&gt;0)?1:0); // rounded</p>
<p>frac(0.123456789ABCDEFGHIJKLMN * 256) = frac(0.123456789ABCDEFGHIJKLMN &lt;&lt; 8) = frac(12345678.9ABCDEFGHIJKLMN) = 0.9ABCDEFGHIJKLMN<br />
framebuffer will receive 9ABCDEFG + ((bitH&gt;0)?1:0); // rounded</p>
<p>frac(0.123456789ABCDEFGHIJKLMN * 65536) = frac(0.123456789ABCDEFGHIJKLMN &lt;&lt; 16) = frac(123456789ABCDEFG.HIJKLMN) = 0.HIJKLMN0<br />
framebuffer will receive HIJKLMN0</p>
<p>further multiplication with 16777216.0 is useless since IEEE mantissa has not enough precision.</p>
<p>bit 9 affects both first byte and second which is bad and causes error you mentioned. The same goes for bit H which affects 2nd and 3rd bytes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gleserg</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-705</link>
		<dc:creator>gleserg</dc:creator>
		<pubDate>Tue, 26 Jun 2007 07:43:51 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-705</guid>
		<description>oops, html ate my comment :)
out.rgba = (RGBADecode(RGBAEncode(z)) &lt; z);
out.rgba = (RGBADecode(RGBAEncode(z)) &gt; z);
both render black.
(1,2,4) were simply a mathematical replacement, maybe a bad one</description>
		<content:encoded><![CDATA[<p>oops, html ate my comment :)<br />
out.rgba = (RGBADecode(RGBAEncode(z)) &lt; z);<br />
out.rgba = (RGBADecode(RGBAEncode(z)) &gt; z);<br />
both render black.<br />
(1,2,4) were simply a mathematical replacement, maybe a bad one</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gleserg</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-704</link>
		<dc:creator>gleserg</dc:creator>
		<pubDate>Tue, 26 Jun 2007 07:34:59 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-704</guid>
		<description>I meant RGBADecode(RGBAEncode(z))!=z, component fraction values seem to overlap. Shouldn&#039;t RGBAEncode contain something like:

out.w = frac(16777216.0*v);
v-=out.w/16777216.0;
out.z = frac(65536.0*v);
v-=out.z/65536.0;
out.y = frac(256.0*v);
v-=out.y/256.0;
out.x = v;

Of course it&#039;s way slower than vectorized frac, but in this case 
out.rgba = (RGBADecode(RGBAEncode(z))==z)
renders totally white and both of
out.rgba = (RGBADecode(RGBAEncode(z))z);
render totally black picture.

The only thing I didn&#039;t check yet is how value rounding during texture read/writes will affect precision.</description>
		<content:encoded><![CDATA[<p>I meant RGBADecode(RGBAEncode(z))!=z, component fraction values seem to overlap. Shouldn&#8217;t RGBAEncode contain something like:</p>
<p>out.w = frac(16777216.0*v);<br />
v-=out.w/16777216.0;<br />
out.z = frac(65536.0*v);<br />
v-=out.z/65536.0;<br />
out.y = frac(256.0*v);<br />
v-=out.y/256.0;<br />
out.x = v;</p>
<p>Of course it&#8217;s way slower than vectorized frac, but in this case<br />
out.rgba = (RGBADecode(RGBAEncode(z))==z)<br />
renders totally white and both of<br />
out.rgba = (RGBADecode(RGBAEncode(z))z);<br />
render totally black picture.</p>
<p>The only thing I didn&#8217;t check yet is how value rounding during texture read/writes will affect precision.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nearaz</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-697</link>
		<dc:creator>nearaz</dc:creator>
		<pubDate>Mon, 25 Jun 2007 21:01:24 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-697</guid>
		<description>The thing is that first component encodes the value. Second encodes the fraction of the value that got rounded off (because of limited precision of the first component). And so on.

If you&#039;re using 1,2,4 for encoding; that would mean it encodes for a 1-bit texture or something like that.</description>
		<content:encoded><![CDATA[<p>The thing is that first component encodes the value. Second encodes the fraction of the value that got rounded off (because of limited precision of the first component). And so on.</p>
<p>If you&#8217;re using 1,2,4 for encoding; that would mean it encodes for a 1-bit texture or something like that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gleserg</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-696</link>
		<dc:creator>gleserg</dc:creator>
		<pubDate>Mon, 25 Jun 2007 17:08:38 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-696</guid>
		<description>Quick check. 
Didn&#039;t test it in life, but mathematics seem to be incorrect.

Let&#039;s test it with value 1/3 = 0.33333333333...

frac( (1/3)*float3(1,2,4) ) = float3(1/3,2/3,1/3)

but

dot( float3(1/3,2/3,1/3), float3(1,1/2,1/4) ) = 1/3 + 1/3 + 1/12  is far from original 1/3

I might misunderstood the idea though</description>
		<content:encoded><![CDATA[<p>Quick check.<br />
Didn&#8217;t test it in life, but mathematics seem to be incorrect.</p>
<p>Let&#8217;s test it with value 1/3 = 0.33333333333&#8230;</p>
<p>frac( (1/3)*float3(1,2,4) ) = float3(1/3,2/3,1/3)</p>
<p>but</p>
<p>dot( float3(1/3,2/3,1/3), float3(1,1/2,1/4) ) = 1/3 + 1/3 + 1/12  is far from original 1/3</p>
<p>I might misunderstood the idea though</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ReJ</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-170</link>
		<dc:creator>ReJ</dc:creator>
		<pubDate>Wed, 07 Mar 2007 22:19:00 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-170</guid>
		<description>Hmmm... I wonder if you would get the same quantinization by doing &#039;dummy&#039; texture reads from the 256x256 texture filled with f(u,v,0,1)... but even if that would work, it&#039;s of course 2 additional texture reads per pixel, which is basically a crap :(</description>
		<content:encoded><![CDATA[<p>Hmmm&#8230; I wonder if you would get the same quantinization by doing &#8216;dummy&#8217; texture reads from the 256&#215;256 texture filled with f(u,v,0,1)&#8230; but even if that would work, it&#8217;s of course 2 additional texture reads per pixel, which is basically a crap :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NeARAZ</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-171</link>
		<dc:creator>NeARAZ</dc:creator>
		<pubDate>Wed, 07 Mar 2007 20:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-171</guid>
		<description>...but it still won&#039;t be &lt;I&gt;exactly&lt;/I&gt; like the quantized version. For example, it looks like Radeon X1600 quantizes like this: x*255.0-0.55781; the last number is approximate. No idea why it&#039;s a minus, because I would think it should be a plus, but experiments tell otherwise.&lt;BR/&gt;&lt;BR/&gt;So my thinking is that the chances of getting quantized-float-myself and float-coming-from-8bit-texture equal are pretty slim.</description>
		<content:encoded><![CDATA[<p>&#8230;but it still won&#8217;t be <i>exactly</i> like the quantized version. For example, it looks like Radeon X1600 quantizes like this: x*255.0-0.55781; the last number is approximate. No idea why it&#8217;s a minus, because I would think it should be a plus, but experiments tell otherwise.</p>
<p>So my thinking is that the chances of getting quantized-float-myself and float-coming-from-8bit-texture equal are pretty slim.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ReJ</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-172</link>
		<dc:creator>ReJ</dc:creator>
		<pubDate>Wed, 07 Mar 2007 14:36:00 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-172</guid>
		<description>I suppose you can simulate quantinization by scaling and clamping. For example something along the lines:&lt;BR/&gt;&lt;BR/&gt;// t = sign(EncodeFloatRGBA(a)-rgba_encoded_b);&lt;BR/&gt;&lt;BR/&gt;float INV_EPSILON = 127;// or 255?&lt;BR/&gt;d = EncodeFloatRGBA(a)-rgba_encoded_b;&lt;BR/&gt;t = (clamp(d*INV_EPSILON+0.5)-0.5)*2;</description>
		<content:encoded><![CDATA[<p>I suppose you can simulate quantinization by scaling and clamping. For example something along the lines:</p>
<p>// t = sign(EncodeFloatRGBA(a)-rgba_encoded_b);</p>
<p>float INV_EPSILON = 127;// or 255?<br />d = EncodeFloatRGBA(a)-rgba_encoded_b;<br />t = (clamp(d*INV_EPSILON+0.5)-0.5)*2;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NeARAZ</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-173</link>
		<dc:creator>NeARAZ</dc:creator>
		<pubDate>Wed, 07 Mar 2007 10:17:00 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-173</guid>
		<description>Does not quite work. I think this code depends on sign() returning zero in case arguments are equal; otherwise only the first component (dotted with 8) affects the result.&lt;BR/&gt;&lt;BR/&gt;Now, one argument comes from a 8-bit texture, while the other is encoded on the fly. So basically they are never equal (at least I couldn&#039;t make them equal). What would be needed here is some sort of QuantizeFloatAsYouWouldDoWhenWritingIntoATexture() function :)</description>
		<content:encoded><![CDATA[<p>Does not quite work. I think this code depends on sign() returning zero in case arguments are equal; otherwise only the first component (dotted with 8) affects the result.</p>
<p>Now, one argument comes from a 8-bit texture, while the other is encoded on the fly. So basically they are never equal (at least I couldn&#8217;t make them equal). What would be needed here is some sort of QuantizeFloatAsYouWouldDoWhenWritingIntoATexture() function :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ReJ</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-174</link>
		<dc:creator>ReJ</dc:creator>
		<pubDate>Sun, 04 Mar 2007 20:40:00 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-174</guid>
		<description>... give a bit of a thought for a previous (offline) discussion. Corrected code:&lt;BR/&gt;&lt;BR/&gt;// rgba_encoded_b = tex2d(s)&lt;BR/&gt;// x = (a &gt;= rgba_encoded_b)&lt;BR/&gt;&lt;BR/&gt;float4 t = &lt;B&gt;sign&lt;/B&gt;(EncodeFloatRGBA(a) - rgba_encoded_b);&lt;BR/&gt;x = (dot(float4(8,4,2,1), t) &gt;= 0);</description>
		<content:encoded><![CDATA[<p>&#8230; give a bit of a thought for a previous (offline) discussion. Corrected code:</p>
<p>// rgba_encoded_b = tex2d(s)<br />// x = (a >= rgba_encoded_b)</p>
<p>float4 t = <b>sign</b>(EncodeFloatRGBA(a) &#8211; rgba_encoded_b);<br />x = (dot(float4(8,4,2,1), t) >= 0);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ReJ</title>
		<link>http://aras-p.info/blog/2007/03/03/a-day-well-spent-encoding-floats-to-rgba/comment-page-1/#comment-175</link>
		<dc:creator>ReJ</dc:creator>
		<pubDate>Sun, 04 Mar 2007 08:52:00 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=103#comment-175</guid>
		<description>Have you tried exactly the same code on CPU? My pure non-educated guess would be that such operations screw up precision anyhow...</description>
		<content:encoded><![CDATA[<p>Have you tried exactly the same code on CPU? My pure non-educated guess would be that such operations screw up precision anyhow&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
