# 32 bit - 4*8 bit

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

## Recommended Posts

I need to pass a 32 bit float from a vertex shader and encode it into a A8R8G8B8 texture. So I need to seperate the number into four 8 bit sections. Any ideas on how I can do this? Something like..... Num = 32 bit value between 0 and 1 A = Num B = Num / 4 C = Num / 8 D = Num / 16 My math skills leave a lot to be desired. :P

##### Share on other sites
If I understand your question correctly, I think what you need to do is use bitmasking.
Something like, A = (Num & 0xff000000) >> 24;
B = (Num & 0x00ff0000) >> 16;
etc.

##### Share on other sites
Mask out the unwanted bits then shift the wanted ones into the 8 most significant? Thats exactly what I want to do, but I can't use bit shifting or & in the vertex shader, so I need some formula that would simulate it.

##### Share on other sites
Quote:
 Original post by OsulatorMask out the unwanted bits then shift the wanted ones into the 8 most significant? Thats exactly what I want to do, but I can't use bit shifting or & in the vertex shader, so I need some formula that would simulate it.

If it's a vertex shader, then normally you're working with a 4 element float, rather than a single float...

But if you want to change a single float into 4 color channels in a vertex shader, you're probably sunk. Actually, come to think of it...normally this is something you do with a 32 bit int, not a float. What are you doing?

##### Share on other sites
the_phantom posted some code here.

##### Share on other sites
Thanks, that seems to be what I'm looking for.

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 9
• 10
• 13
• 19
• 14
• ### Forum Statistics

• Total Topics
632943
• Total Posts
3009353
• ### Who's Online (See full list)

There are no registered users currently online

×