Results 1 to 2 of 2

Thread: Spherical UV mapping

  1. #1
    Nov 2009

    Unhappy Spherical UV mapping


    If I posted this question in the wrong section please correct me. I don't really know where I should put it.

    I got the following problem: I have build a ray tracing engine and I'm now working on texture mapping. However I came across a problem when I used the functions defined in the book.

    Let's define some values:

    $\displaystyle o(x, y, z)$ is the origin of my sphere, which is the same as the center of my sphere.
    $\displaystyle p(x, y, z)$ is the intersection point of a ray from the camera that hits the sphere.
    $\displaystyle R$ is the radius of my sphere.

    Let's see what my book has to offer:

    Fundamentals of computer graphics - Google Boeken

    Now I know that I do not like to read pages before I can answer a question so, I will type the formula here:

    $\displaystyle \theta = \arccos{(\frac{p_{z} - o_{z}}{R})}$
    $\displaystyle \phi = arctan2{(p_{y} - o_{y}, p_{x} - o_{x})}$

    So what does this arctan2 do? it returns the arctangent of $\displaystyle a/b$. Because $\displaystyle (\theta, phi) \in [0,\pi] \times [-\pi, \pi]$, we convert $\displaystyle (u, v)$ as follow, after adding $\displaystyle 2 \cdot \pi$ to $\displaystyle \phi$ if $\displaystyle \phi < 0$.

    $\displaystyle u = \frac{\phi}{2 \cdot \pi}$
    $\displaystyle v = \frac{\pi - \theta}{\pi}$

    Now you might wonder, what kind of results does this give us? I will show you a picture what kind of result it should be giving with bilinear interpolation applied.

    Well how does it look for me?

    (Please do not pay attention to the edges, I cut them with Photoshop so you don't have to bother looking at the rest of the image, which contains no spheres at all except the one I'm showing.)

    Now how did I tried to fix this? By fixing it accourding to the image.

    I ended up with the best result given by:

    $\displaystyle \theta = \arccos{(\frac{p_{y} - o_{y}}{R})}$
    $\displaystyle v = \frac{\pi - \theta}{\pi}$

    $\displaystyle \phi = arctan2(o_{x} - p_{x}, o_{z} - p_{z})$
    when $\displaystyle \phi < 0 $ I do $\displaystyle phi + 2 \cdot \pi$.
    $\displaystyle u = \frac{phi}{2 \cdot \pi}$

    My best result:

    Now my question, is there any possible way that I can fix my best result to resemble the correct result?

    If yes how can I do this by only modfying my equations? (please do not tell me to debug my code, but if you have a suggestion where the bug may lie, I will be happy to hear your suggestion.)

    If I remove the devided by $\displaystyle 2 * \pi$ and $\displaystyle \pi$, I will end up having a lot of image tiles in my image, which is a good thing. However when tiling is not needed (the picture is large enough to fit onto the sphere), it will still places replicas of the image onto my sphere . That is not correct. I need equations that only places replicas when the image is too small.

    If you have other methods of doing a spherical uv mapping please tell me. I am very happy to look into it!

    Thanks for your answers
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Nov 2009
    I think it would be impossible to tile one sphere and not tile the others, when calculating the uv coordinates. So I created a patch for this. If anyone disagrees, please state your solution.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. mapping
    Posted in the Advanced Applied Math Forum
    Replies: 1
    Last Post: Apr 10th 2011, 12:14 AM
  2. mapping
    Posted in the Differential Geometry Forum
    Replies: 5
    Last Post: Apr 5th 2011, 06:16 PM
  3. Complex open mapping & conformal mapping problems.
    Posted in the Differential Geometry Forum
    Replies: 1
    Last Post: Feb 22nd 2011, 07:26 AM
  4. Mapping
    Posted in the Differential Geometry Forum
    Replies: 5
    Last Post: Apr 20th 2010, 07:19 AM
  5. mapping
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: Nov 13th 2008, 08:24 PM

Search tags for this page

Click on a term to search for related topics.

Search Tags

/mathhelpforum @mathhelpforum