OpenGL ES Frustum 之外的几何体是否也被渲染?
我正在使用 OpenGL ES 作为绘图 API 为 iPhone 开发一款游戏。我在一个绘图元素中绘制了整个大世界。根据截锥体,该对象是可见的。
我想知道物体的其他部分发生了什么,它被绘制了吗?对FPS有影响吗?
I am developing a game for iPhone using OpenGL ES as drawing api. I am drawing a whole big world in a single draw element. The object is visible according to the frustum.
I want to know what happens to the other part of the object, Is it drawn? Does it affect the FPS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于场景的任何顶点,都必须运行顶点着色器,以便将它们的坐标从模型空间转换到剪辑空间。
之后,不包含在裁剪体积中的图元(这意味着在裁剪空间中,它们要么在屏幕之外,要么太远或太近)被裁剪,这样它们就不会被进一步处理,并且像素着色器不会不要为他们而跑。
这对于 OpenGL 和 OpenGL ES 来说是相同的。您可以在 OpenGL ES 规范 中找到详细信息( 2.13 原始裁剪)或在 OpenGL 规范中(相同标题)。
这意味着拥有大量几何体(其中大部分位于截锥体之外)会稍微影响您的渲染时间,但比实际渲染所有几何体的情况要少得多。只需要进行逐顶点变换;不会为它们执行光栅化和每像素操作(片段着色器、实际写入帧缓冲区)。
这也意味着,如果您执行大量的逐顶点操作和较少的逐像素操作,那么为场景编写额外的可见性测试可能更重要。
For any vertex of the scene, the vertex shader has to be ran, so that their coordinates are transformed from model space to clip space.
After that, primitives which aren't contained in the clipping volume (which means that in clip space they're either outside of the screen or too far or too near) are clipped, so that they aren't processed further and pixel shader won't be ran for them.
This is the same for OpenGL and OpenGL ES. You can find the details in the OpenGL ES spec (2.13 Primitive Clipping) or in the OpenGL spec (same headline).
This means that having lots of geometry, of which most is outside of the frustum, will affect your rendering time a bit, but much less than if all the geometry was actually rendered. Only per-vertex transformations need to be done; rasterization and per-pixel operations (fragment shader, actual write to framebuffer) won't be executed for them.
This also implies that if you do many per-vertex operations and less per-pixel operations, then it may be more important to write an additional visibility tests for your scene.
OpenGL 处理您指定要绘制的所有图元。这就是为什么你必须自己决定画什么。这确实是一个难题,因为起点是这个。
OpenGL processes all primitives that you tell to draw. That's why you have to determine what to draw yourself. It is really hard problem, as the starting point read this.
几何管道将顶点坐标转换为窗口坐标;此时,窗口外的多边形可以被丢弃。但是处理了太多不必要的几何图形,并且性能受到影响。
考虑使用某种视锥体剔除:将场景划分为较小的部分或图块,并在绘制之前评估图块是否完全位于视锥体之外,从而仅绘制可以<的图块/em> 位于截锥体内。
即使使用简单的分区,差异也应该很明显。
The geometry pipeline transforms vertex coordinates to window coordinates; at that point out-of-window polygons can be discarded. But too many innecesary geometry is processed, and performance is hit.
Consider using some kind of frustum culling: divide your scene in smaller parts or tiles, and evaluate, before drawing, if the tile is fully outside the view frustum, thus drawing only tiles which could lay inside the frustum.
Even with a simple partition, the difference should be noticeable.