Sign in to follow this  

32 bit - 4*8 bit

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Osulator
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.


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 this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this