Original Post
I'm trying to do a deferred render system that works using only RGB8 render targets. The only problem for now was saving the depth in a way that I could use it later for position reconstruction.
But of course, 8 bits would only allow 255 different Z values, and visualizing the depth buffer shows this, lots of banding.

The depth is stored as
float z = (gl_FragCoord.z/gl_FragCoord.w) / zFar;
Reducing the zFar from 1000 to 100 produced better results, but there should be better solutions.
For the depth reconstruction I need (gl_FragCoord.z/gl_FragCoord.w), as I use the inverted projection matrix method.
But this division yields values in the [0.99 , 1.0] most of the time, and when this is stored to the depth buffer, everything is mapped to 255.
I still have one more G-buffer channel, so what I need is a way to encode (Z/W) in two different channels. This is where I'm blocked. If it were integer values, I would know how to pack a 16-bit value into two 8-bits, but with floating point values, I don't have an idea, anyone knows?
But of course, 8 bits would only allow 255 different Z values, and visualizing the depth buffer shows this, lots of banding.

The depth is stored as
float z = (gl_FragCoord.z/gl_FragCoord.w) / zFar;
Reducing the zFar from 1000 to 100 produced better results, but there should be better solutions.
For the depth reconstruction I need (gl_FragCoord.z/gl_FragCoord.w), as I use the inverted projection matrix method.
But this division yields values in the [0.99 , 1.0] most of the time, and when this is stored to the depth buffer, everything is mapped to 255.
I still have one more G-buffer channel, so what I need is a way to encode (Z/W) in two different channels. This is where I'm blocked. If it were integer values, I would know how to pack a 16-bit value into two 8-bits, but with floating point values, I don't have an idea, anyone knows?