如何线性化对数深度缓冲区?
片段着色器中线性深度缓冲区的可视化
float n = 1.0; // camera z near
float f = 27000000.0; // camera z far
float z = texture( DepthTex, TexCoord ).x;
float d = (2.0 * n) / (f + n - z * (f - n));
FragColor=vec4(d,d,d,1);
球体顶点着色器
vec4 ClipCoords(vec3 position,mat4 matrix)
{
vec4 clip = matrix * vec4(position,1.0f);
clip.z =((2.0f * log(1.0f * clip.z + 1.0f) / log(1.0f * 27000000.0f + 1.0f)) - 1.0f) * clip.w;
return clip;
}
gl_Position = ClipCoords(position,matrix);
左边部分显示对数深度缓冲区线性化或更确切地说它的缺乏,而右边显示线性化而不log
只是 gl_Position = matrix * vec4(position,1.0f);