OpenGL - 无法绘制完全遮挡的多边形?
假设我们有一组多边形,可以更改相机视角并可以在 3D 环境中平移相机。从某些视角来看,其中一些多边形完全被一个或多个其他多边形遮挡。对于每个绘制的帧,我们知道每个多边形的确切坐标,并且可以按照“增加到相机的距离”或“减少到相机的距离”的顺序迭代它们。
现在我的问题是:
预渲染确定多边形是否被其他多边形完全遮挡的有效方法是什么,以便我们可以在绘制过程中简单地跳过它以提高性能?
Let's say we have a set of polygons, can change the camera view angle and can translate the camera in the 3D environment. From certain view angles some of these polygons are completely occluded by one or several of the other polygons. For each drawn frame we know the exact coordinates for each of these polygons and can iterate through them in the "increasing distance to camera" or "decreasing distance to camera" order.
Now my question:
What is an efficient way to prerender determine whether a polygon is completely occluded by others, so that we could simply skip it in the drawing process to boost performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您所想到的称为遮挡剔除。现代显卡具有您可以调用的函数来准确地告诉您这一点。不过,您必须先渲染遮挡场景。另一种方法是在 CPU 上执行此操作。
但是,无论如何我都不建议你做你想做的事情。显卡可以快速渲染大块静态数据。如果您要修改该数据以删除隐藏的表面,那么无论您的遮挡算法有多快,您都会降低性能。显卡很聪明,如果它们意识到多边形被完全覆盖,它们就会尽早将其从管道中丢弃。
如果您还没有这样做,请将多边形放入静态顶点缓冲区。顶点缓冲区是快速渲染大量多边形的好方法。
What you're thinking of is called Occlusion culling. Modern graphics cards have functions you can call that tell you exactly that. You have to have already rendered the occluding scene first though. The alternative is to do this on the CPU.
However, I would not suggest doing what you are trying to do in any case. Graphics cards are fast at rendering static data in big chunks. If you are modifying that data to remove hidden surfaces, you're going to kill performance no matter how fast your occlusion algorithm is. And graphics cards a smart, if they realise that a polygon is completely covered they'll throw it out the the pipeline early.
If you are not already doing so, put your polygons into a static vertex buffer. Vertex buffers are a great way to rendering a lot of polygons quickly.
您正在寻找的技术称为遮挡剔除,并且是一种相当复杂的任务。
能够以递增的相机距离顺序(从前到后)迭代它们会给您带来一些优势。只需以这种方式渲染它们,您就可以从当今图形硬件的早期 z 测试功能中受益,并且多边形只需经过顶点处理和光栅化,而无需进行片段着色。这也可以在不对多边形进行排序的情况下实现,而是在所谓的深度预通道中渲染它们(以任意顺序),在深度预通道中禁用颜色写入并仅渲染多边形的深度值。现在,在下一个渲染通道(真正的渲染通道)中,您还可以从早期的 z 拒绝中受益。
您还可以使用当今 GPU 的硬件遮挡查询,如这篇 GPU Gems 文章中所述。
但正如 Hannesh 所说,如果遮挡剔除的开销值得的话,就应该对其进行加权。我认为你的情况中从前到后的排序并不是凭空出现的。也许深度预通过是一种不需要排序的可行替代方案。尽管您可以以不需要任何排序的方式使用遮挡查询(如链接中所述),但在这种情况下,它不如从前到后排序有效。
The technique you're looking for is called Occlusion Culling and is a rather complex task.
Being able to iterate through them in increasing camera distance order (front-to-back) gives you some advantages. Just rendering them this way lets you profit from early z-testing features of nowaday's graphics hardware and the polygons only have to go through vertex-processing and rasterization, but need not to be fragment-shaded. This can also be achieved without sorting the polygons but rendering them (in an arbitrary order) in a so-called depth-prepass, where you disable color writes and only render the polygons' depth values. Now in the next rendering pass (the real one) you also profit from early z-rejection.
You might also use hardware occlusion queries of nowaday's GPUs like explained in this GPU Gems article.
But like Hannesh said, it should always be weighted if the overhead of the occlusion culling is worth it. I assume the front-to-back sorting in your case doesn't just come out of nowhere. Maybe the depth-prepass is a viable alternative requiring no sorting. Whereas you can use occlusion queries in a way that doesn't require any sorting (like described in the link), in this case it's not as effective as with front-to-back sorting.