Opengl 来自帧缓冲区的正确depthmap值

Opengl 来自帧缓冲区的正确depthmap值,opengl,depth,Opengl,Depth,我目前从帧缓冲区获取depthmap,但是这些值会停留在0.0或1.0或更高。如何获得介于0.0和1.0之间的深度 此外,我在片段着色器中访问depthmap作为sampler2D modelsDepthTextureId = glGenTextures(); glBindTexture(GL_TEXTURE_2D, modelsDepthTextureId); glTexImage2D( GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT

我目前从帧缓冲区获取depthmap,但是这些值会停留在0.0或1.0或更高。如何获得介于0.0和1.0之间的深度

此外,我在片段着色器中访问depthmap作为sampler2D

    modelsDepthTextureId = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, modelsDepthTextureId);
    glTexImage2D( GL_TEXTURE_2D, 0, GL14.GL_DEPTH_COMPONENT24, screenWidth, screenHeight, 0,
        GL_DEPTH_COMPONENT, GL_INT, (java.nio.ByteBuffer) null);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

深度以指数形式保存在depthtexture中。需要使用适当的近距离值和远距离值对上述代码进行线性化。

这不是一个很好的答案。如果您能提供一些文字来解释这是什么,更重要的是您为什么需要它,我们将不胜感激。
float linearize(float depth) {
    float zNear = 0.1;
    float zFar = 100.0;

    return (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear));
}