title: How to calculate gl_FragCoord in glsl
body: <p>Ok, in my GLSL fragment shader I want to be able to calculate the distance of the fragment from a particular line in space.</p>
  
  <p>The result of this is that I am first trying to use a varying vec2 set in my vertex shader to mirror what ends up in <code>gl_FragCoord</code>:</p>
  
  <pre><code>varying vec2 fake_frag_coord;
  //in vertex shader:
  gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  fake_frag_coord=(gl_ModelViewProjectionMatrix * gl_Vertex).xy;
  </code></pre>
  
  <p>Now in the fragment shader I expect:</p>
  
  <pre><code>gl_FragCoord.xy==fake_frag_coord
  </code></pre>
  
  <p>But it does not. What operation does the pipeline do on <code>gl_Position</code> to turn it into <code>gl_FragCoord</code> that I am neglecting to do on <code>fake_frag_coord</code>?</p>