如何在OpenGL(ES)中正确渲染重合多边形 [英] How to correctly render coincident polygons in OpenGL (ES)

查看:213
本文介绍了如何在OpenGL(ES)中正确渲染重合多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到,通过在OpenGL ES中设置深度功能,可以控制在3D场景中如何渲染重叠的几何图形.我在代码中使用了gl.depthFunc(gl.LEQUAL)(webgl).

I understand that by setting the depth function in OpenGL ES one can control how overlapping geometries are rendered in a 3D scene. I use gl.depthFunc(gl.LEQUAL) (webgl) in my code.

但是,当两组多边形重合并且具有不同的颜色时,结果表面将变为两种颜色的任意混合图案(随着相机位置的变化而变化,从而导致闪烁).看一下这张图片:

However when two sets of polygons are coincident and are of different color, the resulting surface turns out to be an arbitrary mixed pattern of the two colors (which changes as the camera location changes, hence leads to flickering). Take a look at this image:

我该如何解决?我尝试了不同的depthFunc值,但是没有一个可以解决此问题.我希望重合的多边形只有一种颜色,哪一个都没关系.

How can I fix this? I have tried different depthFunc values, but none of them solves this problem. I would like the coincident polygons to have single color, it doesn't matter which one.

推荐答案

这称为 z-fighting ,并且与在同一深度渲染两个对象有关,但是舍入误差(和深度缓冲精度)有时会在另一个对象之前弹出.您可以使用的一种解决方案是使用glPolygonOffset函数:

This is called z-fighting, and is related to two objects being rendered at the same depth, but rounding errors (and depth buffer precision) occasionally popping one in front of the other. One solution available to you is to use the glPolygonOffset function:

http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPolygonOffset.xml

您可以在此页底部看到正在使用的示例:

You can see an example of it in use at the bottom of this page:

http://www.glprogramming.com/red/chapter06.html

这篇关于如何在OpenGL(ES)中正确渲染重合多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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