title: gl_FragCoord.x, y, z being 1 for all pixels and w being the depth
body: <p>I'm using THREE.js with shader. I'm trying to get the zbuffer information.</p>
  
  <p>Vertex shader:</p>
  
  <pre><code>// switch on high precision floats
  #ifdef GL_ES
  precision highp float;
  #endif
  
  void main()
  {
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  }
  </code></pre>
  
  <p>Fragment shader:</p>
  
  <pre><code>#ifdef GL_ES
  precision highp float;
  #endif
  
  void main()
  {
      gl_FragColor = vec4(gl_FragCoord.x, gl_FragCoord.y, gl_FragCoord.z, 1.0);
  }
  </code></pre>
  
  <p>There are objects with different position in the scene, thus the values in zbuffer should vary. </p>
  
  <p>It's strange that <code>gl_FragCoord.x</code>, <code>gl_FragCoord.y</code> and <code>gl_FragCoord.z</code> seems to be <code>1.0</code> for all fragments, while <code>gl_FragCoord.w</code> seems to vary for different fragments.</p>
  
  <p>If I use <code>gl_FragCoord.w</code>:</p>
  
  <pre><code>#ifdef GL_ES
  precision highp float;
  #endif
  
  void main()
  {
      float zbuffer = gl_FragCoord.w * 500.0;
      gl_FragColor = vec4(zbuffer, zbuffer, zbuffer, 1.0);
  }
  </code></pre>
  
  <p>It seems to be the zbuffer image:</p>
  
  <p><img src="https://i.stack.imgur.com/TsitA.jpg" alt="enter image description here"></p>
  
  <p>So why would <code>gl_FragCoord.w</code> be representing depth information while <code>gl_FragCoord.z</code> is always <code>1.0</code> for all fragments?</p>