OpenGL重复纹理在旋转时导致异常

发布于 2024-09-18 06:38:13 字数 644 浏览 3 评论 0原文

我有一个纹理被绘制到四边形上。纹理是此屏幕截图左上角的重复图案: http:// img828.imageshack.us/img828/3305/blahpv.png opengl 纹理只有 3px x 9px,我传递的纹理坐标非常大,并且它使用 GL_REPEAT 在 3x9 纹理上循环。对于屏幕截图中看到的奇怪干涉图案有什么解释吗?当四边形完全垂直于相机时,纹理看起来很好(完美重复)...屏幕截图是四边形旋转了几度。当四边形改变与相机的距离或旋转变化时,异常似乎会发生变化,所以我认为它与纹理采样和浮点舍入有关,但我不确定如何修复它。

更新#1:

我没有使用着色器,但这就是我目前在 python 中为每个顶点执行的操作:

(x0, y0, z0) = gluProject(vert[0].x, vert[0].y, 0.0)
x0 /= maskTextureWidth # 3.0
y0 /= maskTextureHeight # 9.0
glMultiTexCoord2f(GL_TEXTURE1_ARB, x0, y0)
glVertex2f(vert[0].x, vert[0].y)

I have a texture being drawn to a quad. The texture is the repeating pattern in the top-left corner of this screenshot: http://img828.imageshack.us/img828/3305/blahpv.png
The opengl texture is only 3px by 9px and the texture coordinates I'm passing are very large numbers and it loops over the 3x9 texture by using GL_REPEAT. Any explanation for the weird interference pattern seen in the screenshot? The texture looks fine (repeating perfectly) when the quad is exactly perpendicular to the camera... the screenshot is with the quad rotated by a couple degrees. The anomalies seem to change as the quad changes its distance to the camera or when the rotation changes, so I think it has something to do with texture sampling and floating point roundoff, but I'm not sure how to fix it.

Update #1:

I'm not using shaders but this is how I'm currently doing it in python for each vertex:

(x0, y0, z0) = gluProject(vert[0].x, vert[0].y, 0.0)
x0 /= maskTextureWidth # 3.0
y0 /= maskTextureHeight # 9.0
glMultiTexCoord2f(GL_TEXTURE1_ARB, x0, y0)
glVertex2f(vert[0].x, vert[0].y)

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

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

发布评论

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

评论(3

乞讨 2024-09-25 06:38:22

答案#2:

使用glTexGen

http:// /www.dei.isep.ipp.pt/~matos/cg/docs/manual/glTexGen.3G.html

带有参数(GL_S,GL_T),GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR(我认为;如果是的话,可以使用该值不正确)

Answer #2 :

use glTexGen

http://www.dei.isep.ipp.pt/~matos/cg/docs/manual/glTexGen.3G.html

with arguments (GL_S, GL_T), GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR (I think; playaround with the value if it's not correct)

爱已欠费 2024-09-25 06:38:19

好的,那么你要旋转四边形,而不是旋转纹理,对吗?

您可以在着色器中轻松完成此操作(缺少某些部分,例如采样器声明)

顶点着色器:

 out vec2 UV;
 main(){
     gl_Position = MVP * Position;
     UV = gl_Position.xy / gl_Position.w;
 }

片段着色器:

in vec2 UV;
main(){
    outColor = texture(sampler, UV);
}

更重要的是,您甚至不必提供纹理坐标:它们是在运行时计算的。

如果您没有着色器,另一种可能性较小,即以与顶点着色器中相同的方式重新计算 UV。

另一种可能性是 glBitmap,但这是一些非常的 API...

Ok, so what you what is to rotate the quad, but not the texture, right ?

You can do this easily in your shaders (some parts are missing, like the sampler declaration)

Vertex shader :

 out vec2 UV;
 main(){
     gl_Position = MVP * Position;
     UV = gl_Position.xy / gl_Position.w;
 }

Fragment shader :

in vec2 UV;
main(){
    outColor = texture(sampler, UV);
}

What's more, you don't even have to provide texture coordinates : they are computed at run-time.

Another possibility, less invasive if you don't have shaders, is to re-compute your UVs so the same way as in the vertex shader.

Yet another possibility is glBitmap, but this is some very old piece of API...

把人绕傻吧 2024-09-25 06:38:17

好吧,不知道您应用的旋转,我们只能假设这是某种刚刚形成的莫尔图案(其中干扰网格是您的纹理和光栅化网格)。

为什么你称之为异常(或者更重要的是,你想要什么结果)?

如果您想要的只是看起来更好,我建议您在纹理上打开三线性过滤。

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

Well, not knowing the rotation you applied, we can only assume this is some sort of Moire pattern barely forming (where the interfering grids are your texture and the rasterization grid).

Why do you call this anomalies (or more to the point, what do you want as a result) ?

If all you want is something that just looks better, I'd suggest turning on trilinear filtering on your texture.

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