I am working on a complicated WebGL program where I have to recover depth in fragment shader.
However, the value of gl_FragCoord.z is always 0.5, quite strange.
// I use this method to verify the value of gl_FragCoord.z
if (gl_FragCoord.z == 0.5) {
fragColor= vec4(1.0, 0.0, 0.0, 0.5);
}
else {
fragColor= vec4(0.0, 0.0, 1.0, 0.5);
}
The depth test is turned on with
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.ALWAYS);
I have seen many similar problems with gl_FragCoord.z valued zero, which is always caused by disable depth test. So I wonder what might cause my problem? Or is there any other way to recover depth of fragment without gl_FragCoord.z?
Thanks!
I have launched a issue of the original project I was working on.