OpenGLES 2.0(GLKit、iPhone):多边形部分遮挡线框线
我正在尝试为 iOS 创建一个 3D 函数绘图仪。我已经成功地使用三角形条来渲染图形,并且还实现了通过线条绘制线框。但是,如果我使用 24 位(或 16 位无关紧要)深度缓冲区同时渲染两者,则线条会被多边形部分遮挡,使它们显得非常细或完全消失。关闭 4xMSAA 并不能解决问题。请参阅下图的示例。
仅绘制线条效果很好 - 线条的粗细恰到好处。如果我禁用线条的深度缓冲,它们也会正确绘制,但它们当然会出现在所有多边形之上(即确实被多边形隐藏的线条)。我还尝试降低多边形的透明度,但无济于事。稍微增加线条的 y 坐标使它看起来更好,只要您从上面看它们,那么它们确实位于多边形的前面。
为了获得最佳性能,我在渲染之前将所有顶点数据和索引静态存储到顶点数组中。因此,我的渲染循环非常短:
- (void)drawRect:(CGRect)rect
{
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self.effect prepareToDraw];
for (NSUInteger i = 0; i < _nVertexArrays; i ++)
{
glBindVertexArrayOES(_vertexArrays[i].vertexArray);
glDrawElements(_vertexArrays[i].mode, _vertexArrays[i].indexCount, GL_UNSIGNED_INT, NULL);
}
}
如何同时正确显示多边形和线框?我还想过将线条移近一点,靠近相机现在所在的位置,但我不知道如何在 OpenGL ES 中做到这一点,而且我不确定这是否会影响性能,因为这种转变取决于相机的当前位置。是否可以在绘制线条之前动态对其应用变换?
I am trying to create a 3D function plotter for iOS. I have succeeded to render the graph using triangle strips and also implemented drawing a wireframe via lines. But if I render both at the same time using a 24-bit (or 16-bit doesn't matter) depth buffer the lines get partially obscured by the polygons, making them appear very thin or disappear entirely. Turning off 4xMSAA doesn't solve the issue. See the image below for an example.
Drawing just lines works just fine - the lines have just the proper thickness. If I disable depth-buffering for the lines they get drawn correctly as well, but they of course appear above all the polygons (i.e. lines that are indeed hidden by polygons). I have also tried to reduce the polygons' transparency, to no avail. Slightly increasing the lines' y-coordinates makes it look better, as long as you are looking at them from above, so that they indeed are in front of the polygons then.
For optimum performance, I statically store all vertex data and indices into vertex arrays prior to rendering. Thus, my rendering loop is quite short:
- (void)drawRect:(CGRect)rect
{
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
[self.effect prepareToDraw];
for (NSUInteger i = 0; i < _nVertexArrays; i ++)
{
glBindVertexArrayOES(_vertexArrays[i].vertexArray);
glDrawElements(_vertexArrays[i].mode, _vertexArrays[i].indexCount, GL_UNSIGNED_INT, NULL);
}
}
How can I display polygons and wireframes properly at the same time? I also thought of just moving the lines a bit nearer to wherever the camera happens to be right now, but I don't know how to do that in OpenGL ES, and I'm not sure if it might impact performance, as this shift is dependent on the current position of the camera. Is it possible to dynamically apply a transformation to the lines just before drawing them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 glPolygonOffset。它是专门为此用途而制造的。
Check out glPolygonOffset. It is made specifically for this use.