0

How do you map the points on a normalized sphere (radius of 0.5, center of 0,0,0) to a fish eye texture image? I am using the C# language and OpenGL. The results should be UV coordinates for the image. The sphere is simply a list of 3D coordinates for each vertice of the sphere, so each of these would get a UV coordinate in to the image.

The end results would be a full sphere with the fish eye image wrapping all the way around 360 degrees when textured on to the sphere.

Example fish eye image:

enter image description here

1 Answer 1

0

There isn't a single way to map to a sphere. The texture in your post looks like the seam would be up in a nominated world plane. Compare that to a typical skydome type texture, where the sphere usually joins at the bottom (where the camera cant see the join). You might use shader code like this to map a point based on UV:

float3 PointOnSphere(float phi, float theta, float radius)
{
    float3 pos = float3(0, 0, 0);

    pos.x = radius * cos(phi) * sin(theta);
    pos.y = radius * sin(phi) * sin(theta);
    pos.z = radius * cos(theta);

    return pos;
}

Or reverse that to get UV from a point on the surface:

float2 AngleFromPoint(float3 pos)
{
    float phi = atan(pos.y / pos.x);
    float theta = atan(pos.y / pos.z / sin(phi));
    return(float2(phi, theta));
}

Which way is up and where the seam joins is something you'll have to workout yourself. If the texture looks compressed because it is non linear you may need to try something like:

texcoord = pow(texcoord, 0.5f);

Edit: and obviously, normalise the angles to 0 - 1 for texture coordinates

2
  • I've plugged in AngleFromPoint but get a very distorted image. Is the input to AngleFromPoint simply one of the vertices on the sphere?
    – jjxtra
    Apr 18, 2016 at 13:27
  • AngleFromPoint will return the angle in radians. If you just set the output color you can confirm the coordinates: color = float4(phi, theta, 0, 1); It should show even red to green to yellow and not big swathes of black or yellow
    – tim
    Apr 19, 2016 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.