Question

In my deferred renderer, the depth buffer holds values in the range from about 0.9700 to 1.0000. I found this out by drawing pixels in a given depth range black. This is the shader code I used.

bool inrange(in float position)
{
    float z = texture2D(depth, coord).r;
    return abs(position - z) < 0.0001;
}

void main()
{
    if(inrange(0.970)) image = vec3(0);
    else result = texture2D(image, coord);
}

And this is how it looks like. I tried several depth values. This image is for the depth value 0.998.

screenshot

I use a as texture of the type GL_DEPTH24_STENCIL8 and format GL_FLOAT_32_UNSIGNED_INT_24_8_REV as depth and stencil attachment.

Is there an explanation for my depth values to be in this range? Is it default behavior? I would like them to be in the range of 0.0000 and 1.0000.

Was it helpful?

Solution

Sounds like a perspective near clipping plane very close to the origin. When building the perspective matrix try to set the near clipping as far as possible from the origin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top