Jump to content
  • Advertisement
Sign in to follow this  
superpig

Mapping from 24 bits to 8 bits...

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

...when you can only access 8 bits at a time. I've got a 24-bit number spread across three byte-sized channels (pixel shader). I have no bitshifting functions; everything is floating point. How can I scale down my 24-bit distributed number to an 8-bit one? 0xffffff to 0xff, etc. (I know that I lose precision, but that's acceptable).

Share this post


Link to post
Share on other sites
Advertisement
Decide on a scaling scheme first. 323? 332? x222? 222x?

Once you've done that, you're going to want to condense each 8-bit value into is bitsize appropriate representation (scaling 8 bits down to 2 or 3). You're then going to combine all three values using multiplication, since you don't have access to bitshifting.

The big problem here, of course, is the floating-point part of the equation. As I'm sure you know, FP values are stored in a mantissa-exponent format, which means that byte-wise extraction will yield gibberish. The technique above is only useful for 24-bit integer values.

I don't know anything about shaders since I've never had the hardware to support them (though I'm tempted to splurge). I'd recommend providing an overview of your objective so that some shader guru passer-by will be able to provide insightful assistance.

Good luck.

Share this post


Link to post
Share on other sites
Cheers.

I'm going for 233.

What I'm actually trying to do here is apply a full-screen fog effect to my scene. It's being done in screenspace, post-rendering; which means I'm trying to do it by pulling the depth buffer back in as a texture, and reading from it while rendering a full-screen quad.

Because the process of getting the depth buffer bound to a texture includes fooling D3D into thinking that it's an RGBA color texture, my 24-bits of depth information are accessed through the pixel shader's RGB components.

(I've spent the past week working on other ways to achieve this without doing a seperate full-screen pass - trust me, I wouldn't be attempting it if there were other viable options).

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!