Jump to content
  • Advertisement
Sign in to follow this  
Osulator

32 bit - 4*8 bit

This topic is 4813 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!