How to set orthographic near/far clipping planes to display all vertices

青春壹個敷衍的年華 提交于 2019-12-12 15:14:55

问题


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?

来源:https://stackoverflow.com/questions/21488043/how-to-set-orthographic-near-far-clipping-planes-to-display-all-vertices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!