# 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.

## 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 on other sites
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 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).

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 17
• 46