Note: I understand the basic math. I understand that the typical perspective
function in various math libraries produces a matrix that converts z values from -z
The reason is, that not only gl_Position
gets divided by the homogeneous coordinate, but also all other interpolated varyings. This is called perspective correct interpolation which requires the division to be after the interpolation (and thus after the rasterization). So doing the division in the vertex shader would simply not work. See also this post.