The depth buffer is setup as 24bits.
What I am not sure of is the precision of the copied data. Are there any extensions I need to use to get the full 24bit precision.
I am using the float texture in a fragment shader.
glCopyTexSubImage() does only copy the color framebuffer… or is there a way to make it copy the depth buffer?
glReadPixels() doesn’t support DEPTH_COMPONENT24
ARB_depth_texture, that’s what I was looking for. I overlooked it because it is always mentioned with shadow casting, and thats not what I need it for…
Thanks.
I don’t get any errors but the texture still ends up with 8 bit precision in my fragment shader…
this is from the NVSDK shadow map demo:
when creating the texture, use:
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24_ARB, TEX_SIZE, TEX_SIZE, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
when copy the data out, use:
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, lightshaper.width, lightshaper.height);
note that the texture isn’t really in float format, and you’ll have to use the third component(this is also why depth texture doesn’t support cubemap) of the texcoord to get the binary result(in or not in shadow). There’s no way to get the real depth value through depth texture, AFAIK.
This way I get 3 bytes representing an integer as GBR data in my shader which I can reassemble into a 24bit integer value there.
The glReadPixels conversion into GL_UNSIGNED_INT takes twice as long as when using GL_FLOAT, but I don’t know how to reassemble the float.
Is there a way to reassemble a float from 4 bytes? I guess that would be a shader question then…
Just disabling shadow compare (as cass pointed out) will give you the depth value. I discovered an issue with that tough, you have to disable linear filtering or you will get an 8 bit value. (Using nearest filtering gives you the proper high precision values) I guess the card (nvidia 6800 in my case) doesn’t have 24bit interpolation hardware.
I would expect so. Note that you can’t do the COMPARE function with cube maps, but you should be able to create a DEPTH_COMPONENT cube map and index into it.
Let me know if you run into any problems with this.