Jump to content
  • Advertisement
Sign in to follow this  
Koiby25

8-bit floats in Direct3D shaders

This topic is 3564 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

If you pass a texture (for example, of format D3DFMT_A8R8G8B8) to a pixel shader, each color channel is represented by a float normalized to the range [0.0, 1.0]. I was just wondering... how exactly is this implemented using 8 bits per channel?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Koiby25
If you pass a texture (for example, of format D3DFMT_A8R8G8B8) to a pixel shader, each color channel is represented by a float normalized to the range [0.0, 1.0]. I was just wondering... how exactly is this implemented using 8 bits per channel?
8 bits gives you a range of 0..255. So to get that to 0..1, you just divide by 255 - which is what the GPU does; 0 -> 0, 255 -> 1.0, 128 -> 0.50196, etc.

Share this post


Link to post
Share on other sites
Not necessarily.

Shader 1.x gives about 9 bits precision, plus a sign, not full 32 bits. I don't remember if the extra bit allowed for values between 1 and 2 without overflowing, or if it was an extra lower value bit.

Shader 2.x and 3.x support both floatN and halfN, where float should be a full 32 bit float, and half should be a 16 bit float. nVidia 5xxx cards perform full 32 bit float operations slowly, and it was common to recommend using half unless you really needed the extra precision. In practice, all non 1.1 shaders were too slow on these 5xxx cards, and it's just easier to pretend they're limited to the fixed pipeline. ATI cards of the same era ignored what you asked for and performed all operations as a 24-bit float, which is why the ATI 9800 card held the performance crown until nVidia's next gen reclaimed it.

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!