tag:blogger.com,1999:blog-5246987755651065286.post4985948503791560042..comments2024-02-22T16:15:42.388-08:00Comments on cbloom rants: 07-26-11 - Pixel int-to-float optionscbloomhttp://www.blogger.com/profile/10714564834899413045noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5246987755651065286.post-51764252839304419462011-07-27T16:01:02.272-07:002011-07-27T16:01:02.272-07:00I'm still a little torn about whether 1.f is n...I'm still a little torn about whether 1.f is nice for white or not (it's sort of cool to be able to write code where "255" means the same thing whether you are on int pixels or float pixels).<br /><br />But yeah for games you're probably right.<br /><br />When you're writing image code though (such as compressors) you can get a benefit from using one or the other of these, largely depending on what the rest of your pipeline does. (in particular your quantizer).cbloomhttps://www.blogger.com/profile/10714564834899413045noreply@blogger.comtag:blogger.com,1999:blog-5246987755651065286.post-71991645578604602672011-07-26T11:57:54.921-07:002011-07-26T11:57:54.921-07:00FWIW, D3D10+ graphics HW uses
int-to-float: f = i...FWIW, D3D10+ graphics HW uses<br /><br />int-to-float: f = i / 255.0f;<br />float-to-int: i = round(f * 255.0f + 0.5f);<br /><br />It's usually not computed correctly to 0.5 ULP, but it's close, and required to be exact at the end points, and implementations are also required to guarantee that ftoi(itof(x)) == x for obvious reasons. This is really just an exponent-shifted version of your option 3.<br /><br />In large(-ish) code bases it's best to pick one convention and stick with it, even if it may not be optimal for everything, just to avoid confusion (and the friction that arises from it). If the data ends up in textures, that's how the GPU will unpack it; might as well use this convention on the SW side. Has the added advantage that you can then freely move computations (or even share code) between shaders and C++ code.ryghttps://www.blogger.com/profile/03031635656201499907noreply@blogger.com