2

I am creating a virtual reality app for android and I would like to generate a Sphere in openGL for my purposes. In a first step, I found this thread(Draw Sphere - order of vertices) where in the first answer there is a good tutorial of how to offline render the sphere. In that same answer, there is a sample code of a sphere(http://pastebin.com/4esQdVPP) that I used for my app, and then I successfully mapped a 2D texture onto the sphere.

However, that sample sphere has a poor resolution and I would like to generate a better one, so I proceeded to follow some blender tutorials to generate the sphere and then export the .obj file and simply take the point coordinates and index and parse them into java code.

The problem when doing this is that when the texture is added it looks broken at the poles of the sphere, while it looks good in the rest of the sphere (please have a look at the following pictures). Picture of south pole North Pole Front view

I don't know what i'm doing wrong since the algorithm for mapping the texture should be the same, so I guess that maybe the problem is in the index of the points generated. This is the algorithm im using for mapping the texture: https://en.wikipedia.org/wiki/UV_mapping#Finding_UV_on_a_sphere

This is the .obj file autogenerated with blender: http://pastebin.com/uP3ndM2d

And from there, we extract the index and the coordinates: This is the point index: http://pastebin.com/rt1QjcaX

And this is the point coordinates: http://pastebin.com/h1hGwNfx

Could you give me some advice? Is there anything I am doing wrong?

Community
  • 1
  • 1
Jorge S
  • 81
  • 1
  • 9

2 Answers2

2

First of all, determining the texture coordinates at (or even near) the poles needs to be handled with care. Using the UV-algorithm suggested for the s-coordinate at the pole will not give you what you want with the tessellation you chose (e.g., s = 0.5 + arctan2(1,0)/(2*pi) will be used for all points on the north pole). In the image below the M+1 vertices on the top row all represent the same vertex at the north pole -- each of these will have the same t-value but must have different s-values for the texture coordinates:

enter image description here

Second of all, using this type of tessellation will yield aliasing problems near the poles since the small distance between neighboring fragments generate large difference between s-values. You should mitigate the aliasing as much as possible using a mipmap filter. The following images show a mercator projection of the earth and vertical red stripes textured on the sphere (the stripes are a good test case):

enter image description here enter image description hereenter image description here

A better sphere tessellation is to subdivide an icosahedron which will yield nearly equilaterial triangles. Here is an example of a normal mapped sphere that avoids these aliasing problems:

enter image description hereenter image description here

wcochran
  • 10,089
  • 6
  • 61
  • 69
  • Thank you for your answer. I appreciate it. However, I don't quite get your point or see how it could solve my problem. I mean, you are suggesting that the UV algorithm that im using will not work with the tesellation im using, however, it is indeed working for the sample sphere that I copied from here http://pastebin.com/4esQdVPP. I have a working app where the texture is perfectly mapped around that sphere, and I am just changing the sphere(leaving everything else as it is). I am not sure but i think that some tessels are wrongly generated, joining some points from north and south pole. – Jorge S Nov 20 '15 at 10:51
  • The UV-algo works fine everywhere except for the *s* values at the poles -- I added a clarification. – wcochran Nov 20 '15 at 17:13
1

Ok, the problem is solved now. The textures were not working properly because the generated point indices start at 1 instead of 0. By substracting 1 to all indices the problem is solved... :)

Jorge S
  • 81
  • 1
  • 9