# Packing Values

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, each of the four values that I have are actually color values. The colors have been split (8 bits per color, RGBA). So my precision is x/255. My dilema lies in keeping precision, or at the least, creating a unique representation in the range of [0..1).

##### Share on other sites
Quote:
 Original post by DaishiOk, each of the four values that I have are actually color values. The colors have been split (8 bits per color, RGBA). So my precision is x/255. My dilema lies in keeping precision, or at the least, creating a unique representation in the range of [0..1).

1) Your range is [0,1], not [0,1) - or don't you have pure red, blue, green or white [smile]
2) You will loose precision, no matter what since IEEE floats are not evenly distributed and therefore not all numbers can be represented.

Why do you want to map the four values into a single float? Anyway, if you don't plan on remapping the float back to RGBA, you can use a simple conversion to a gray value. Otherwise r/255^1 + g/255^2 + b/255^3 + a/255^4 would be the most simple soution even though you would lose much precision on the way...

Good luck,
Pat

##### Share on other sites
Quote:
Original post by darookie
Quote:
 Original post by DaishiOk, each of the four values that I have are actually color values. The colors have been split (8 bits per color, RGBA). So my precision is x/255. My dilema lies in keeping precision, or at the least, creating a unique representation in the range of [0..1).

1) Your range is [0,1], not [0,1) - or don't you have pure red, blue, green or white [smile]
2) You will loose precision, no matter what since IEEE floats are not evenly distributed and therefore not all numbers can be represented.

Why do you want to map the four values into a single float? Anyway, if you don't plan on remapping the float back to RGBA, you can use a simple conversion to a gray value. Otherwise r/255^1 + g/255^2 + b/255^3 + a/255^4 would be the most simple soution even though you would lose much precision on the way...

Good luck,
Pat

You're right, my range of my four values is actually [0..1], I wasn't paying close enough attention.

I don't need to convert back at all. It's a one way process. I am storing values into a texture and then trying to store the pixel data as a depth value, and then rendering a quad into the depth buffer with GL_EQUAL to detect collisions/matches. Not exactly the intention of a graphics processor. So as long as I can get a unique value, precision won't really matter anymore.

[Edited by - Daishi on December 1, 2005 11:10:21 AM]

• 10
• 34
• 29
• 9
• 15