Is drawing front-to-back necessary for optimizing renders?

后端 未结 2 1215
醉话见心
醉话见心 2021-02-13 15:54

I\'ve seen the occasional article suggest ordering your vertices from nearest to furthest from the camera when sending them to OpenGL (for any of the OpenGL variants). The reaso

2条回答
  •  长情又很酷
    2021-02-13 16:00

    You are confusing a few concepts here. There is no need to re-order vertices (*). But you should draw objects that are opaque front to back. This enables what is called "early z rejection" on the GPU. If the GPU knows that a pixel is not going to be shaded by the z test it does not have to run the shader, do texture fetches etc.. This applies to objects in draw calls though, not to individual objects.

    A simple example: You have a player character and a sky background. If you draw the player first, the GPU will never have to do the texture lookups for the pixels where the player is. If you do it the other way around, you first draw all the sky and then cover it up.

    Transparent geometry needs to draw back to front of course.

    ( * )=vertices can be re-ordered for better performance. But doing early z is much more important and done per object.

提交回复
热议问题