简体   繁体   中英

Why are my depth values in this freaky range?

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 .

截图

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM