Reading the depth buffer with glReadPixels()
Hi there,
I've got a wierd problem with glReadPixels:
I'm using
glReadPixels( x, y, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, buffer );
but the values in buffer are all in the range 0.99-1.0 . If I zoom in really really close to the scene, I start to see variation in these values towards a reasonable 0-1 range. It's as if glReadPixels() is assuming some tiny range for my depth values.
The depth range is 0-1 (as in glDepthRange()), the pixel transfer depth bias and scale are 0 and 1 respectively. Perspective projection matrix is set up with znear of 1 and zfar of 1000. Reading the colour buffer produces correct results, and I know that the depth buffer itself is alright, because I'm getting perfectly fine depth testing.
Hardware-wise, I've got an NVidia Quadro FX 3400 with the latest drivers.
Does anybody have any ideas? Many thanks in advance...
Not far - if I render a model at the origin, with the camera 100 units away, then I get the aforementioned 0.99-1.0 depth. If I zoom the camera to with, say, 1 unit of the model, I start seeing a wider range.
Since the depth buffer has exponential precision I'd say it's reasonable to get that range at a distance of 100. Try reducing your far clip plane to let's say 200 and check your values then.
Heya Lord Evil, thanks for your prompt replies! I did have some joy with changing the z planes - near Z having a far better effect on visible depth range than far (also with the added benefit of increasing z buffer precision). I've pushed it out pretty far (to 5 units), and it's still producing irritatingly washed out near white images, but I guess it'll have to do. It's a shame there isn't a non-linear scale that can be applied to pixel transfers.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement