Seam issue when mapping a texture to a sphere in OpenGL(在 OpenGL 中将纹理映射到球体时出现接缝问题)
问题描述
我正在尝试创建几何图形以在 OpenGL 中表示地球.我有一个或多或少的球体(虽然更接近地球的椭圆大地水准面).我绘制了地球表面的纹理(可能是墨卡托投影或类似的东西).纹理的 UV 坐标对应于几何体的纬度和经度.我有两个我无法解决的问题.我正在使用 OpenSceneGraph,但我认为这是一个通用的 OpenGL/3D 编程问题.
I'm trying to create geometry to represent the Earth in OpenGL. I have what's more or less a sphere (closer to the elliptical geoid that Earth is though). I map a texture of the Earth's surface (that's probably a mercator projection or something similar). The texture's UV coordinates correspond to the geometry's latitude and longitude. I have two issues that I'm unable to solve. I am using OpenSceneGraph but I think this is a general OpenGL / 3D programming question.
有一个非常明显的纹理接缝.我确定会发生这种情况,因为我不知道如何将 UV 坐标映射到出现接缝的 XYZ.我只在环绕之前将 UV 坐标映射到最后一个顶点……您需要将两个不同的 UV 坐标映射到同一个 XYZ 顶点以消除接缝.是否有一个常用的技巧来解决这个问题,还是我做错了?
There's a texture seam that's very apparent. I'm sure this occurs because I don't know how to map the UV coordinates to XYZ where the seam occurs. I only map UV coords up to the last vertex before wrapping around... You'd need to map two different UV coordinates to the same XYZ vertex to eliminate the seam. Is there a commonly used trick to get around this, or am I just doing it wrong?
两极发生了疯狂的漩涡状扭曲.我猜这是因为我在两极映射了一个 UV 点(对于地球,我使用 [0.5,1] 表示北极,使用 [0.5,0] 表示南极).你还会做什么?我可以忍受这个......但它在较低分辨率的网格中非常明显.
There's crazy swirly distortion going on at the poles. I'm guessing this because I map a single UV point at the poles (for Earth, I use [0.5,1] for the North Pole, and [0.5,0] for the South Pole). What else would you do though? I can sort of live with this... but its extremely noticeable at lower resolution meshes.
我附上了一张图片来说明我在说什么.
I've attached an image to show what I'm talking about.
推荐答案
处理这个问题的一般方法是使用 立方体贴图,而不是 2D 纹理.
The general way this is handled is by using a cube map, not a 2D texture.
但是,如果您坚持使用 2D 纹理,则必须在网格拓扑中创建一个中断.你得到那条纵向线的原因是因为你有一个纹理坐标大约为 0.9 的顶点,而它的相邻顶点的纹理坐标为 0.0.您真正想要的是 0.9 与 1.0 纹理坐标相邻.
However, if you insist on using a 2D texture, you have to create a break in your mesh's topology. The reason you get that longitudinal line is because you have one vertex with a texture coordinate of something like 0.9 or so, and its neighboring vertex has a texture coordinate of 0.0. What you really want is that the 0.9 one neighbors a 1.0 texture coordinate.
这样做意味着沿着球体的一条线复制位置.因此,您的数据中使用了两次相同的位置.一个附加到 1.0 的纹理坐标并与 0.9 的纹理坐标相邻.另一个的纹理坐标为 0.0,与 0.1 的顶点相邻.
Doing this means replicating the position down one line of the sphere. So you have the same position used twice in your data. One is attached to a texture coordinate of 1.0 and neighbors a texture coordinate of 0.9. The other has a texture coordinate of 0.0, and neighbors a vertex with 0.1.
从拓扑上讲,您需要在球体上进行纵向切片.
Topologically, you need to take a longitudinal slice down your sphere.
这篇关于在 OpenGL 中将纹理映射到球体时出现接缝问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 OpenGL 中将纹理映射到球体时出现接缝问题
基础教程推荐
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01