简体   繁体   English

OpenGL二十面体纹理映射

[英]OpenGL Icosahedron Texture Mapping

I've got currently no solution for texture mapping an icosahedron without a seam from pole to pole. 我目前还没有解决纹理映射的二十面体没有从极到极的接缝。 The texture mapping of this primitive seems to be a common problem, which is not completely solved yet. 这个原语的纹理映射似乎是一个常见问题,尚未完全解决。 I've made a lot of research and I've tried a lot of different approaches for generating the uv coordinates, the most nearby ( and smallest ) approach is this: 我做了很多研究,我已经尝试了很多不同的方法来生成紫外坐标,最近(和最小)的方法是这样的:

GLfloat u = 0.5f * ( 1.0f + atan2( z , x ) * ( 1 / M_PI ));  
GLfloat v = acos( y ) * ( 1 / M_PI );

An icosahedron or geosphere is part of various open-source frameworks, such as jMonkeyEngine or Geist3D but none of the implementations seems to work correctly. 二十面体或地球圈是各种开源框架的一部分,例如jMonkeyEngine或Geist3D,但没有一个实现似乎正常工作。 It should be not impossible to map an unfolded rectangular texture or am I wrong? 映射展开的矩形纹理应该不是不可能,或者我错了吗? Every code snippet is welcome. 每个代码段都是受欢迎的。

I've uploaded the Xcode project here which is built with openFrameworks 0.61 for iPhone. 我已经在这里上传了Xcode项目该项目是使用openFrameworks 0.61 for iPhone构建的。 There are also two PNG files inside, each of them shows another seam variation. 里面还有两个PNG文件,每个文件都显示另一个接缝变化。

You need to change your texture image, the texture image you have is a distortion of the sphere where the pole is stretched into a line, you will never be able to map this properly to an icosahedron, in order to do so you would need a division more like the longitude and latitude system which such a distortion comes from. 你需要改变你的纹理图像,你拥有的纹理图像是一个球体的扭曲,其中杆被拉伸成一条线,你永远无法将它正确地映射到二十面体上,为了做到这一点,你需要一个分裂更像是经度和纬度系统,这种扭曲来自于此。 Instead you need a texture image where the pole is broken up into several distinct points. 相反,你需要一个纹理图像,其中杆被分解成几个不同的点。 You can see this on some world maps where they try to minimize the distortion from mapping a sphere onto a flat surface. 你可以在一些世界地图上看到这一点,他们试图最小化将球体映射到平面上的失真。 eg http://www.planetaryvisions.com/Project.php?pid=2236 例如http://www.planetaryvisions.com/Project.php?pid=2236

You can find some good info on different ways to texture a sphere at http://www.vterrain.org/Textures/spherical.html 您可以在http://www.vterrain.org/Textures/spherical.html上找到有关纹理球体的不同方法的一些好信息

Surface of icosahedron has a topology of a sphere. 二十面体的表面具有球体的拓扑结构。 Surface of a 2D texture has a topology of a plane. 2D纹理的表面具有平面的拓扑。 There exist no diffeomorphism between sphere and plane. 球面与平面之间不存在微分同胚。 That is, there is no mapping without stretches and tears between 2D texture and icosahedron surface. 也就是说,在2D纹理和二十面体表面之间没有拉伸和撕裂的情况下没有映射。

However, there is a mapping between a cubemap and an icosahedron. 但是,立方体贴图和二十面体之间存在映射。

I realize this question is old, but since nobody mentioned the following solution, I thought I'd reply. 我意识到这个问题已经过时了,但由于没有人提到以下解决方案,我以为我会回复。

Two possible solutions: 两种可能的解决方

  1. When constructing the mesh, detect if a triangle sits on the seam. 构造网格时,检测三角形是否位于接缝上。 If so, adjust the texture coordinates by using x + 1 for each vertex on the far side of the seam. 如果是这样,请使用x + 1为接缝远端的每个顶点调整纹理坐标。 Set your texture to wrap horizontally and you will get rid of the seam, at least for most of your polygons. 将纹理设置为水平包裹,您将摆脱接缝,至少对于大多数多边形而言。
  2. Even better: calculate the texture coordinate in your fragment shader, based on the surface normal. 更好的是:根据曲面法线计算片段着色器中的纹理坐标。 This will get rid of the seam completely. 这将彻底摆脱缝隙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM