title: Mapping a fish eye to a sphere - 360 degree view
body: <p>I am attempting to map a fisheye image to a 360 degree view using a sky sphere in Unity. The scene is inside the sphere. I am very close but I am seeing some slight distortion. I am calculating UV coordinates as follows:</p>
  
  <pre><code>Vector3 v = currentVertice; // unit vector from edge of sphere, -1, -1, -1 to 1, 1, 1
  float r = Mathf.Atan2(Mathf.Sqrt(v.x * v.x + v.y * v.y), v.z) / (Mathf.PI * 2.0f);
  float phi = Mathf.Atan2(v.y, v.x);
  textureCoordinates.x = (r * Mathf.Cos(phi)) + 0.5f;
  textureCoordinates.y = (r * Mathf.Sin(phi)) + 0.5f;
  </code></pre>
  
  <p>Here is the distortion and triangles:</p>
  
  <p><a href="https://i.stack.imgur.com/EEx3O.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EEx3O.jpg" alt="enter image description here"></a></p>
  
  <p>The rest of the entire sphere looks great, it's just at this one spot that I get the distortion.</p>
  
  <p>Here is the source fish eye image:</p>
  
  <p><a href="https://i.stack.imgur.com/q2bOQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q2bOQ.jpg" alt="enter image description here"></a></p>
  
  <p>And the same sphere with a UV test texture over the top showing the same distortion area. Full UV test texture is on the right, and is a square although stretched into a rectangle on the right for purposes of my screenshot.</p>
  
  <p><a href="https://i.stack.imgur.com/iTHBI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iTHBI.jpg" alt="enter image description here"></a></p>
  
  <p>The distortion above is using sphere mapping rather than fish eye mapping. Here is the UV texture using fish eye mapping:</p>
  
  <p><a href="https://i.stack.imgur.com/ImeoG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ImeoG.jpg" alt="enter image description here"></a></p>
  
  <p>Math isn't my strong point, am I doing anything wrong here or is this kind of mapping simply not 100% possible?</p>