优化渲染是否需要从前到后绘制? [英] Is drawing front-to-back necessary for optimizing renders?

查看:24
本文介绍了优化渲染是否需要从前到后绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶尔看到一篇文章,建议在将顶点发送到 OpenGL(对于任何 OpenGL 变体)时,从离相机最近到最远的顺序进行排序.这样做的原因是如果顶点位于另一个已经渲染的顶点之后,OpenGL 将不会完全处理/渲染顶点.

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 reason suggested by this is that OpenGL will not fully process/render a vertex if it is behind another vertex already rendered.

由于按深度对顶点进行排序是任何项目的昂贵组成部分,因为这种排序通常会经常更改,因此这种设计有多常见或必要?

Since ordering vertices by depth is a costly component of any project, as typically this ordering frequently changes, how common or necessary is such design?

我以前认为 OpenGL 会查看"所有提交的顶点并在它们上处理自己的深度缓冲,而不管它们的顺序如何,在渲染整个批次之前.但如果实际上一个顶点在另一个顶点之前被渲染到屏幕上,那么我可以看到排序如何提高性能.

I had previously thought that OpenGL would "look" at all the vertices submitted and process its own depth buffering on them, regardless of their order, before rendering the entire batch. But if in fact a vertex gets rendered to the screen before another, then I can see how ordering might benefit performance.

优化渲染是否需要从前到后绘制?

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

推荐答案

一旦一个图元被光栅化,它的 z 值就可以被用来做一个early z kill",跳过运行片段着色器.这是从前到后渲染的主要原因.提示:当您有透明(alpha 纹理)多边形时,您必须从后到前渲染.

Once a primitive is rasterized, its z value can be used to do an "early z kill", which skips running the fragment shader. That's the main reason to render front-to-back. Tip: When you have transparent (alpha textured) polygons, you must render back-to-front.

OpenGL 规范定义了一个状态机,并没有指定渲染实际发生的顺序,只是结果应该是正确的(在一定的容差范围内).

The OpenGL spec defines a state machine and does not specify in what order the rendering actually happens, only that the results should be correct (within certain tolerances).

为清楚起见进行我上面想说的是硬件可以做任何它想做的事情,只要基元看起来已按顺序处理

Edit for clarity: What I'm trying to say above is that the hardware can do whatever it wants, as long as the primitives appear to have been processed in order

然而,大多数 GPU 是流处理器,它们的 OpenGL 驱动程序不会批量处理"几何图形,除非出于性能原因(最小 DMA 大小等).如果先输入多边形 A,然后输入多边形 B,则它们将一个接一个地输入管道,并彼此独立(大部分)进行处理.如果 A 和 B 之间有足够数量的 poly,那么 A 很有可能在 B 之前完成,如果 B 在 A 之后,它的碎片将通过early z kill"被丢弃.

However, most GPUs are streaming processors and their OpenGL drivers do not "batch up" geometry, except perhaps for performance reasons (minimum DMA size, etc). If you feed in polygon A followed by polygon B, then they are fed into the pipeline one after the other and are processed independently (for the most part) of each other. If there are a sufficient number of polys between A and B, then there's a good chance A completes before B, and if B was behind A, its fragments will be discarded via "early z kill".

为清楚起见进行我上面想说的是,由于 hw 不会批量处理"几何图形,因此它无法自动进行从前到后的排序.

这篇关于优化渲染是否需要从前到后绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆