I am using THREE.js with a shader. I am trying to get zbuffer info.
Vertex shader:
// switch on high precision floats
Fragment Shader:
#ifdef GL_ES precision highp float; #endif void main() { gl_FragColor = vec4(gl_FragCoord.x, gl_FragCoord.y, gl_FragCoord.z, 1.0); }
There are objects in the scene with different positions, so the values ββin zbuffer must change.
It is strange that gl_FragCoord.x , gl_FragCoord.y and gl_FragCoord.z for all 1.0 fragments, and gl_FragCoord.w seems to change for different fragments.
If I use gl_FragCoord.w :
#ifdef GL_ES precision highp float; #endif void main() { float zbuffer = gl_FragCoord.w * 500.0; gl_FragColor = vec4(zbuffer, zbuffer, zbuffer, 1.0); }
This seems to be a zbuffer image:

So, why gl_FragCoord.w present depth information, and gl_FragCoord.z always 1.0 for all fragments?
source share