title: near/far planes and z in orthographic rasterization
body: <p>Ive coded tons of shaders but Ive stumbled into something I never realized before.</p>
  
  <p>I needed a vertex + fragment shader with a simple orthographic projection, with no depth test.</p>
  
  <p>The camera is Z-aligned with the origin.</p>
  
  <p>I disabled GL_DEPTH_TEST, and masked depth writes. It was so simple infact, that I decided I didnt even need a projection matrix. In my complete ignorance and ingenuity, I thought that for any triangle vertex, the vertex shader would simply pass x,y(,z = <code>&lt;whatever&gt;</code>,w = 1) to the fragment shader.</p>
  
  <p>I actually thought the fragment shader would just need x,y coordinates, because since we're talking about orthographic projection, w = 1 (no perspective division), and since depth buffer is useless, and depth writes disabled, z could literally be <em>anything</em>, doesnt matter.</p>
  
  <p>Of course I was wrong. I quickly found that the z component is quite used by the rasterizer, infact, I have tons of triangles that simply dont get rasterized.</p>
  
  <p>I also found that tweaking the z component would dramatically change the rendered triangles. So I implemented a regular orthographic projection matrix, and that of course solved the issue, now everything is properly rasterized.</p>
  
  <p>Now, out of pure curiosity, I started playing with a orthographic projection matrix and see what really produced for different input vectors, with different values for near and far clipping planes, and I really cant understand. Ok, x,y and w are all as expected, but I get completely different z values based on my near/far clip planes.</p>
  
  <p>The question is: the fragment shader doesnt know anything about clip planes and projection matrices, it just gets a bunch of x,y,z,w... what is the role of the z component in the rasterization process? how does it know if something is inside the viewing frustrum or not?</p>
  
  <p>I mean, for any given near/far plane in the orthographic projection matrix, I get z values that are valid for a given projection matrix, and invalid for others. Since the fragment shader has no way to know which planes were used in the matrix, how can it discards fragments? Is there a relationship between every vertex of the same primitive?</p>
  
  <p>PS: I know the fragment shader is not even invoked, as I setup a SSBO + Atomic Counter and checked both are unchanged.</p>