片段非线性深度值变换为线性

#version 330 core
out vec4 FragColor;

float near = 0.1; 
float far  = 100.0; 

float LinearizeDepth(float depth) 
{
    float z = depth * 2.0 - 1.0; // back to NDC 
    return (2.0 * near * far) / (far + near - z * (far - near));    
}

void main()
{             
    float depth = LinearizeDepth(gl_FragCoord.z) / far; // 为了演示除以 far
    FragColor = vec4(vec3(depth), 1.0);
}
--------------------- 
作者:cqltbe131421 
来源:CSDN 
原文:https://blog.csdn.net/cqltbe131421/article/details/82906652 
版权声明:本文为博主原创文章,转载请附上博文链接!
原文地址:https://www.cnblogs.com/coolbear/p/11303005.html