Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"07-26-11 - Pixel int-to-float options"

2 Comments -

1 – 2 of 2
Blogger ryg said...

FWIW, D3D10+ graphics HW uses

int-to-float: f = i / 255.0f;
float-to-int: i = round(f * 255.0f + 0.5f);

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.

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.

July 26, 2011 at 11:57 AM

Blogger cbloom said...

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).

But yeah for games you're probably right.

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).

July 27, 2011 at 4:01 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.