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

查看:17
本文介绍了如何在 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天全站免登陆