How to render depth linearly in modern OpenGL with gl_FragCoord.z in fragment shader?

but I still don’t know whether or not the gl_FragCoord.z is linear. Whether gl_FragCoord.z is linear or not depends on, the projection matrix. While for Orthographic Projection gl_FragCoord.z is linear, for Perspective Projection it is not linear. In general, the depth (gl_FragCoord.z and gl_FragDepth) is calculated as follows (see GLSL gl_FragCoord.z Calculation and Setting gl_FragDepth): … Read more