4

I am rendering scenes using a glm::ortho projection. I want the rendering to include every vertex I draw without adding unnecessary depth (i.e. with minimal depth buffer resolution impact).

I've seen this post for a similar question on perspective projections, but I am looking for both near and far clipping plane values in an orthographic projection.

I can calculate the z values of each vertex using the viewMatrix to transform the vertices into screen coordinates. In pseudo code:

float near;
float far;

for (each glm::vec4 vertex)
{
    glm::vec4 trans = viewMatrix * vertex;
    // invert for z-buffer
    trans.z = -trans.z;
    if (trans.z < near)
        near = trans.z;
    if (trans.z > far)
        far = trans.z;
}

This way, near and far represent the z-values of the nearest and farthest vertices in screen coordinates, respectively.

But when I use these values as zNear and zFar in the glm::ortho matrix, much of the rendering is still clipped. What am I missing?

Community
  • 1
  • 1
Neal Kruis
  • 2,055
  • 3
  • 26
  • 49

0 Answers0