对视锥体剔除感到困惑
我是 OpenGL 新手。我将它与 JOGL 一起使用。
我正在阅读有关视锥体剔除的内容:
http://www.lighthouse3d.com/opengl/viewfrustum/
http://www.crownandcutlass.com/features/technicaldetails/frustum.html
我不确定它到底应该做什么。 OpenGL 不会自动剔除屏幕外的对象吗? (这种剔除是否比一开始就不发送对象要慢得多?)
从我所读到的内容来看,这似乎无法避免绘制被另一个对象遮挡但位于视锥体内的对象。这是否意味着唯一的好处是避免将屏幕外对象发送到 OpenGL?
I'm new to OpenGL. I'm using it with JOGL.
I'm reading about frustum culling:
http://www.lighthouse3d.com/opengl/viewfrustum/
http://www.crownandcutlass.com/features/technicaldetails/frustum.html
I'm not sure exactly what it's supposed to do. Doesn't OpenGL cull off-screen objects automatically? (Is this culling significantly slower than just not sending the objects in the first place?)
From what I'm reading, it doesn't look like this will handle avoiding drawing objects that are obscured behind another but are within the viewing frustum. Does that mean that the only benefit is avoid sending off-screen objects to OpenGL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,你基本上是对的。视锥体剔除会切除相机金字塔外部的对象。 OpenGL 在渲染场景时当然也会这样做,但是以每个顶点为基础的。视锥体剔除适用于每个对象,因此其性能提升潜力要高得多。
瓶颈之一是 CPU 和 GPU 之间的数据传输。例如,如果您需要传输室外场景中所有对象/顶点的 1/4,则视锥体剔除可以带来不错的性能提升。
Yes, you are basically right. Frustum culling cuts off objects that are outside the camera pyramid. OpenGL, when rendering a scene, of course does this as well but on a per vertex basis. Frustum culling works per object and its performance boost potential is therefore much higher.
One of the bottlenecks is transferring the data between CPU and GPU. If you need to transfer for example only 1/4 of all the objects/vertices in an outdoor scene, frustum culling can yield a nice performance boost.
最快的对象是您根本不需要绘制的对象。
一般来说,对于还不是非常简单的对象,您将提供一个简化的、保守的边界体积。这样,您就可以进行视锥体剔除,而无需处理复杂对象中的每个三角形。
避免绘制彼此遮挡的对象称为遮挡剔除。遮挡剔除通常比视锥体剔除更复杂;但是,请注意,它仍然可以使用相同的简化包围盒。
The fastest object is the one you don't have to draw at all.
In general, for objects that are not dead simple already, you will provide a simplified, conservative bounding volume. That way, you can do frustum culling without dealing with every triangle in a complex object..
Avoiding drawing objects that are obscured behind each other is called occlusion culling. Occlusion culling is generally more complex than frustum culling; however, note that it can still use the same simplified bounding volume.
是的——视锥体剔除只是删除完全位于视锥体之外的对象。没什么更多或更少。是的,您可以潜在地提高 OpenGL 本身的性能,特别是如果您可以一次剔除大量项目(例如,视图图库可能能够相当快地砍掉图的整个分支)。
还有面剔除,它会删除背向观察者的三角形(或其他任何东西),但这与视锥体剔除不同。
有几种方法可以处理被其他对象遮挡的对象。遮挡剔除是最简单的,但 OpenGL 没有直接支持它(尽管某些硬件作为扩展)。另一个是深度缓冲区——OpenGL 直接支持它。不同之处在于,遮挡剔除会查看整个对象,如果它完全被遮挡,则根本不会渲染它。深度缓冲区在逐个片段的基础上工作,因此它仅在(几乎)完全渲染对象后发生。因此,根据您要处理的对象数量(等),进行自己的遮挡剔除可以是一个相当大的胜利(因为它可以避免在深度缓冲区执行其操作之前进行大量渲染)。
Yes -- frustum culling just removes objects that lie entirely outside the viewing frustum. Nothing more or less. Yes, you can potentially improve performance over OpenGL itself, especially if you can cull a larger number of items at once (e.g., a viewgraph library may be able to chop off entire branches of the graph fairly quickly).
There is also face culling that removes triangles (or whatever) that are facing away from the viewer, but that's separate from frustum culling.
There are a couple of ways of handling objects that are obscured by other objects. Occlusion culling is the simplest, but OpenGL does nothing to support it directly (though some hardware does as an extension). The other is the depth buffer -- which OpenGL does support directly. The difference is that occlusion culling looks at an entire object, and doesn't render it at all if it's completely obscured. The depth buffer works on a fragment-by-fragment basis, so it only takes place after you've (almost) fully rendered an object. Depending on how many objects you're dealing with (and such) doing your own occlusion culling can, therefore, be a pretty big win (since it can avoid doing a lot of rendering that's needed before the depth buffer can do its thing).
当您在代码中进行视锥体检查时,您可以使用包围正在绘制的对象的简单几何图形来完成此操作。这比卡片尝试剔除每个三角形要快得多。
When you do you frustum checks in code, you do it using simple geometry that encases the object being draw. This can be done much faster than the card trying to cull each triangle.