title: Linear depth buffer
body: <p>Many people use usual perspective matrix with third line like this:</p>
  
  <pre><code>(0  0  (n+f)/(n-f) 2*n*f/(n-f))
  </code></pre>
  
  <p>But it has problem with float precision near far clipping surface. The result is z-fighting.
  What about to use linear transformation of z? Let's change the matrix third line to this:</p>
  
  <pre><code>(0  0  -2/(f-n) (-f-n)/(f-n))
  </code></pre>
  
  <p>It will be linear transformation z from [-n, -f] to [-1, 1]. Then, we will add the line in vertex shader:</p>
  
  <pre><code>gl_Position.z *= gl_Position.w;
  </code></pre>
  
  <p>After perspective divide the z value will be restored. </p>
  
  <p>Why don't it used everywhere? I found a lot of articles in internet. All of them used a usual matrix. 
  Is linear transformation described by me has problems what I don't see? </p>
  
  <p><strong>Update</strong>: This is not a duplicate of <a href="https://stackoverflow.com/questions/42509883/how-to-correctly-linearize-depth-in-opengl-es-in-ios">this</a>. My question is not about how to do linear depth buffer. In my case, the buffer is already linear. I don't understand, why is this method not used? Are there traps in the inner webgl pipeline?</p>