消除 OpenGL 纹理伪影

发布于 2024-08-01 16:26:25 字数 942 浏览 5 评论 0原文

我正在创建一个简单的 opengl 应用程序,其中显然包含一些 3d 对象和纹理。 然而,我的问题是每个纹理上都会出现伪影。 它们的边缘呈三角形。

我注意到,当我将视点移近它完美渲染的纹理时,它就会消失。 因此我怀疑它与 mipmap 或 z 缓冲区有关。 请注意,所有纹理坐标均从 .3ds 文件加载,并且所有纹理坐标均经过验证位于 0-1 范围内。

这是我的问题的图片:

图片 1

纹理是这样加载的:

//Texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//Define the 2d texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array);

//Create 2d mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, array);

I am creating a simple opengl application which obviously includes some 3d-objects and textures. My problem is however that artifacts appear on every texture. These come in the form of triangles along the edges.

I have noticed that it disappears as soon as I move the view-point closer to texture it renders perfectly. Therefore I have a suspicion that it has something to do, either with the mipmapping or the z-buffer.
Please note that all texture-coordinates are loaded from a .3ds-file and all of them are verified to be within the range of 0-1.

Here are a picture of my problem:

Picture 1

The textures are loaded like this:

//Texture parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//Define the 2d texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, array);

//Create 2d mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, array);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燕归巢 2024-08-08 16:26:25

当我使用 DirectX 进行编程时,近平面/远平面距离比会导致边缘出现伪影。

在我的例子中,如果近平面距“相机”1 个单位,远平面距“相机”10000 个单位,则比率为 1/10000,这就产生了问题。 如果我将近平面设置为 10 或 100,则比率会变大。 它解决了锯齿状边缘问题。

我不知道它是否/如何适用于 OpenGL,但你可能想检查一下。

When I was programming using DirectX, the near plane / far plane distance ratio caused artifacts in the edges.

In my case, if near plane was 1 unit away from 'camera' and far plane was 10000 units away, the ratio is 1/10000 and it created problems. If i set the near plane to 10 or 100, the ratio becomes bigger. It solved the jagged edges problem.

I don't know if/how it is applicable in OpenGL, but you might want to check it out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文