Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Spherical Textures -- what is the mapping?

Prospero Frobozz
Astronerd
Join date: 10 Feb 2006
Posts: 164
01-02-2007 07:13
I want to map a texture to a sphere, and have it be precise so that I know exactly which spot on the texture will go to which spot on the sphere. Is it documented anywhere what the mapping is?

What I'm looing for is the function that will take (x,y) on the texture image to (theta,phi) on the sphere (where theta is "latitude" or the equivalent, and phi is longitude).

I figured out that for Blender, the spherical mapping sppears to be x->phi, y->theta (with perhaps an offset of 90 degrees). This means that the only distortion I need to do to the image is to stretch out things off of the equator, as they will be compressed by a factor of cos(theta) (if theta=0 is the equator). I'ved used one such textured I used in Blender also in SecondLife, but things look wrong up near the poles. I'm wondering if perhaps the theta mapping is different.

If I know the function, I can deal with it on my end to make my mapping the way I want it to be.

Can anybody point me to documentation on this? I've looked around some, but haven't yet been able to find it.

Thanks,

-Rob
Chosen Few
Alpha Channel Slave
Join date: 16 Jan 2004
Posts: 7,496
01-02-2007 07:31
I don't know the exact math, but it's basically just like wrapping a map around a globe. The poles (top and bottom of the texture) get squeezed to a single point, while the equator (midline of the texture) remains unchanged. Everything in between gets compressed to an increasing degree as you approach either pole.

I usually just stretch things by eye to get it to work, as I have yet to find a spherical mapping filter that really works well (most function by removing pieces of your image, which is bad). If you start out with the kind of repeating elliptical pattern typically seen on world maps, it's not that hard to then stretch the sections through the empty parts to meet. It's a bit time-consuming, but I really haven't found a better method.

If your image is not real complicated, then using a 3D painting tool to paint directly onto a real sphere can work very well, but since those programs are never very powerful in terms of tool sets (I've tried a great many of them), working in 2D in Photoshop is most often the only way to go. I really wish Adobe hadn't abandoned their 3D painting projects. It would be soooo nice to have a 3D painter with Photoshop's tools in it.
_____________________
.

Land now available for rent in Indigo. Low rates. Quiet, low-lag mainland sim with good neighbors. IM me in-world if you're interested.
Prospero Frobozz
Astronerd
Join date: 10 Feb 2006
Posts: 164
01-02-2007 11:21
The texture I've used was created under the assumption of what you describe. However, things are appearing stretched north/south near the poles, which suggests to me that those assumptions are not corret.

I'd *really* like to know the underlying transformation functions, if there is anywhere we can get that.

-Rob
Namssor Daguerre
Imitates life
Join date: 18 Feb 2004
Posts: 1,423
01-02-2007 12:29
From: Chosen Few

If your image is not real complicated, then using a 3D painting tool to paint directly onto a real sphere can work very well, but since those programs are never very powerful in terms of tool sets (I've tried a great many of them)...


ZBrush gives me excellent results. I don't know if you are including this in the "many" Chosen, but it's definately worth a look-see. There are even default textures, including a map of the globe, as part of the the standard application that will help with this sort of mapping. The paint tools are fairly robust too.
Prospero Frobozz
Astronerd
Join date: 10 Feb 2006
Posts: 164
I may have my answer....
01-02-2007 13:42
I think I found what I was looking for here:

http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node177.html

This should work *if* SecondLife uses the OpenGL spherical mapping... which I suspect is a good guess.

What I need is the technical specs because I want to *plot* on a sphere. It's not art I'm doing, but science :) This is for a planetarium I'm building, and I want to plot stars in the right place given their catalog locations, and I want to draw a grid. Knowing how to turn (theta,phi) (or, really, for stars, RA, Dec) into (x,y) on a texture map is really what I need.

It seems that the short answer is:

p = sqrt( sin(theta)^2 + (cos(theta)+1)^2 ) = sqrt(2 + 2*cos(theta))

u = cos(theta)*cos(phi) / 2p + 1/2
v = cos(theta)*sin(phi) / 2p + 1/2

where (u,v) are indexes into the texture map image in the range [0,1). (Or maybe [0,1]?)

I have to make sure I've translated all of this right, but I'm going to give it a try.... Of to write some perl to plot the stars in the right place!

-Rob
Nerolus Mosienko
Registered User
Join date: 3 Aug 2006
Posts: 145
01-02-2007 15:23
I think my brain just melted.
Indy Quamar
Registered User
Join date: 16 Sep 2006
Posts: 69
01-02-2007 20:46
Just an opionion but i dont think what you are trying is going to work unless you want to use a huge texture to do it. at the poles the sphere is going to strech the pixels till the stars look like comets. If you use a extreamly high resolution texture you will have to stand in your planetarium for 45 min staring at grey space till SL resolves the texture. Also since the sky rotates, the texture will need to also and SL texture animations are not able to be controled that well i dont belive.
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
01-02-2007 22:00
Just checked by putting a grid texture onto a sphere. At least on the outer surface, the mapping is just the standard (x, y, z) = (cos(theta)sin(phi), sin(theta)sin(phi), cos(phi)).

The inside hollow is the same with a sign flipped somewhere, so the image is reflected.

Incidentally, Chaac Amarula has a number of planetaria set up around SL, see his profile for locations.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Warda Kawabata
Amityville Horror
Join date: 4 Nov 2005
Posts: 1,300
01-02-2007 23:22
The projection is essentially the same as a Mercator projection wrt to longitude, though I'm not sure if it maps as Mercator wrt to latitude.
Chosen Few
Alpha Channel Slave
Join date: 16 Jan 2004
Posts: 7,496
01-03-2007 05:31
From: Namssor Daguerre
ZBrush gives me excellent results. I don't know if you are including this in the "many" Chosen, but it's definately worth a look-see. There are even default textures, including a map of the globe, as part of the the standard application that will help with this sort of mapping. The paint tools are fairly robust too.

Thanks, Nam. I haven't tried ZBrush yet, but I've been meaning to. I keep hearing so many things about it. The 3D painters I have tried are Deep Paint 3D, BodyPaint, Blacksmith 3D, Tattoo, Maya's included painting tools, and maybe a couple others I can't remember off hand. Disappointingly, none of them offer the level of control over the "paint" that you get in Photoshop. I'll definitely have to give ZBrush a try.
_____________________
.

Land now available for rent in Indigo. Low rates. Quiet, low-lag mainland sim with good neighbors. IM me in-world if you're interested.
Chosen Few
Alpha Channel Slave
Join date: 16 Jan 2004
Posts: 7,496
01-03-2007 05:53
From: Indy Quamar
Just an opionion but i dont think what you are trying is going to work unless you want to use a huge texture to do it. at the poles the sphere is going to strech the pixels till the stars look like comets.

Not sure what you mean here. Textures get compressed at the poles, not stretched, and texture size doesn't make any difference as far as that goes.

Incidentally, lots of good looking planetariums have already been made in SL, so it's not like Prospero's trying to do anything outlandish here, Indy. The first one I saw was three years ago, and it looked fantastic. I'm sure in the time before and since then, there must have been hundreds of others.

From: Indy Quamar
If you use a extreamly high resolution texture you will have to stand in your planetarium for 45 min staring at grey space till SL resolves the texture.

Well, since SL has a cap of 1024x1024, there's really no such thing as an "extremely high resolution texture". 1024 is large for real time application, true, but it's still not very big. Having a lot of them in view will bog down your system resources, slowing your frame rate, which is bad, but it still shouldn't take more than a few seconds for them to appear on your screen.

If it's taking you 45 minutes to see ANYTHING in SL, get off of dialup, and get on broadband like you're supposed to.

From: Indy Quamar
Also since the sky rotates, the texture will need to also and SL texture animations are not able to be controled that well i dont belive.

First, I don't think you really need a rotating sky to pull off a convincing planetarium, but if you did want one, it's certainly doable.





By the way, Propspero, here's another idea you might want to try. Instead of fussing with pre-distorting your texture, how about making a faceted dome instead of using a sphere? That way you could put an undistorted texture on each of the facets. With well designed geometry, planar mapping, and good use of repeats and offsets, you can make one texture (or group of textures) span the entire dome seamlessly. The effect can be very convincing, especially with Full Bright turned on, which will eliminate shading, making the facet edges virtually undetectable.

If you don't want to build the dome by hand, check out Cadroe Murphy's shapemaker tool. It can automatically construct a dome for you out of quadrangular facets. You just tell it how may facets you want, and what size the whole thing should be.

This obviously will be a lot prim heavier than just going with a sphere, but the texturing will be easier, and you'll have a lot more flexibility.
_____________________
.

Land now available for rent in Indigo. Low rates. Quiet, low-lag mainland sim with good neighbors. IM me in-world if you're interested.
Robin Sojourner
Registered User
Join date: 16 Sep 2004
Posts: 1,080
01-03-2007 16:14
There is actually a very easy way to do this, assuming that you have access to a polar azimuthal projection star map, (ine that shows the sky as if it were projected onto the inside of a bowl,) and Photoshop.

1. Open one half of your map, say the Northern Hemisphere, and trim away any borders. You need to have just the sky.

2. Select all, and go to Filter > Distort > Polar Coordinates

3. Choose "Polar to Rectangle" from the menu, and click OK.

4. Go to View > New Guide, pick Horizontal, and type in half the image size (ie. 256 for a 512 image.)

5. Enable Snap to Guides (View > Snap, making sure "Snap To" has Guides enabled.)

6. Select All, Transform (Command/ctrl T) and drag the bottom up until it snaps to the guide. The Northern Hemisphere is now finished. You should have it filling the top of the image square, with the bottom empty.

7. Repeat steps 1-3 and 6 for the Southern Hemisphere.

8. While still in Transform, Rotate 180°, and drag the Southern Hemisphere to the bottom of the image.

9. Combine the two images, so you have a single image with the Northern Hemisphere at the top, and the Southern Hemisphere at the bottom. (If you were working on two layers of a single image, skip this step.)

10. Size for SL, save your .tga, and upload.

11. In SL, Create a sphere, and apply the map. You're set. If you want the map on the inside of a bowl or hollowed sphere, you'll need to Flip it. Otherwise, you're good to go at this point.


And that's all there is to it.

Be aware, however, that SL sphere maps split at the poles. There is nothing that can be done about this; but it will mean that your map isn't perfect there. Plotting the exact location, to compensate for the splitting, won't work, I'm afraid, because it will be different depending on the viewer distance, size of the sphere, and the amount of screen the sphere covers. (The same thing you see when disks look round if you are close to them, but turn into octagons from a distance.)

Hope this helps!

Robin
_____________________
Robin (Sojourner) Wood
www.robinwood.com

"Second Life ... is an Internet-based virtual world ... and a libertarian anarchy..." Wikipedia