Hey guys, hope you’re all doing well! I’ve recently been working on a project in an attempt to create some procedurally generated planets using a subdivided icosahedron. I’ve managed to get the subdivision working fine and I’ve calculated my normals but I’m trying to get a naive render of a texture onto my sphere it comes out like the sphere on the left here -
On the left is the result as mentioned above while the right is a default sphere from the engine with the desired texture. I ended up calculating my normals with a formula I found researching and ended up with something like this -
I still sort of new to the concept of UV mapping so I’m unsure of exactly what’s going wrong I was wondering if anybody had a similar experience. If any more code is required feel free to let me know and thanks any help or time in advance!
With UV mapping, you want to project the surface of your 3D-object onto a 2D-plane so you can use a texture (since they are a 2D-image). UV-maps contain 2D-coordinates, ranging from 0 to 1, for each vertex.
Therefore you preferably would take a point like Vector(sphere_radius, 0, 0) as the center of the UV-map (for a sphere). This means, the UV.X coordinates correspond to the rotation around the z-axis (viewing from above, a clockwise rotation from 0…PI being on the left half of the UV.map [UV.X <= 0.5], a counterclockwise rotation from 0…PI being on the right half [UV.X >= 0.5]). This rotation angle is calculated by atan2(y, x). The UV.Y coordinates correspond to the elevation angle = asin(z).
Your code is iterating over the triangles, not the vertices. I suggest the following:
Normalization is only required for asin(z). The center point / offset Vector2D is (0.5f, 0.5f). Subtract atan2(y, x) and asin(z) from the offset so that your texture is not mirrored.
With this code, you will get a vertical line of blurred texturing. Depending on your requirements, the solution for this may vary. You can read the following for two suggestions.