PDA

View Full Version : Convert GL_UNSIGNED_INT_24_8 packed depth stencil to float depth



RealtimeSlave
10-31-2017, 10:01 AM
Hello,

I want to get the depth values of the FBO's depth-stencil texture attachment as float.

First I read the values with their original packed integer format (GL_UNSIGNED_INT_24_8):
unsigned int values[CubeMapSize];
glBindTexture(GL_TEXTURE_CUBE_MAP, CubeMapHandle);
glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X /*reading one cube map side only*/, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, values);

Now I want to convert one value (here the first) to float-depth:

float depth = DoSomeConversion(values[0]);

Anybody knows how the correct conversion has to look like?
Maybe just take the upper or lower 24 bits and divide by 2^24 or something like that?

Help is really appreciated!

GClements
10-31-2017, 12:20 PM
Maybe just take the upper or lower 24 bits and divide by 2^24 or something like that?

Upper 24 bits. And divide by 224-1. So:


float f = (i>>8)/16777215.0f;

or


float f = (i&~0xFFU)/4294967040.0f;

RealtimeSlave
11-05-2017, 07:37 AM
Thanks! The values look reasonable.