1

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.

4

1 回答 1

2

听起来像是非常接近原点的剪裁平面附近的透视图。在构建透视矩阵时,尝试将近剪裁设置为尽可能远离原点。

于 2013-06-29T18:56:58.140 回答