OpenGL重复纹理在旋转时导致异常
我有一个纹理被绘制到四边形上。纹理是此屏幕截图左上角的重复图案: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案#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)
好的,那么你要旋转四边形,而不是旋转纹理,对吗?
您可以在着色器中轻松完成此操作(缺少某些部分,例如采样器声明)
顶点着色器:
片段着色器:
更重要的是,您甚至不必提供纹理坐标:它们是在运行时计算的。
如果您没有着色器,另一种可能性较小,即以与顶点着色器中相同的方式重新计算 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 :
Fragment shader :
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...
好吧,不知道您应用的旋转,我们只能假设这是某种刚刚形成的莫尔图案(其中干扰网格是您的纹理和光栅化网格)。
为什么你称之为异常(或者更重要的是,你想要什么结果)?
如果您想要的只是看起来更好,我建议您在纹理上打开三线性过滤。
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.