PDA

View Full Version : Texturing a Sphere with a Tile Map


Viridian
05-11-2006, 12:16 PM
I'm working on my second game, a space-opera RPG called Star Revolution. I'm taking games like Starflight and Star Control II as my inspiration. Thus, I'm going to have a bunch of planets for the player to visit and explore, and the player will be able to travel all over any planet he visits (instead of the planet simply being abstracted to menus like in Privateer or Elite).

So I need spinning globes for the planets in the outer-space, 3D view. This is my first 3D game, and while I'm not completely unfamiliar with 3D concepts, this is the first time I've tried to implement them.

But when the player lands, the planet will be presented in a more traditional, top-down "tiled" RPG view.

What I am trying to do is use the same texture for the 3D and the 2D surface view. Why am I trying to do this?

Back in the mid-Eighties when I played Starflight, I was very impressed with its landing sequence. Starflight presented a planet as a rotating sphere, but when you landed, the view shifted and you saw the patch of planet you were landing on as a heightfield. If you looked very carefully at how the heightfield was colored, when you actually emerged onto the surface of the planet (now presented in 2D) you'd notice that the pattern of height colors was exactly the same, proving that the game used the same data for its 2D and 3D views. That really added to the verisimilitude of the game to me, and I want to do the same in Star Revolution.

I understand that textures designed for use on spheres typically have to be stretched (http://astronomy.swin.edu.au/~pbourke/opengl/sphere/earth.gif) at the top and bottom to compensate for the "pinching" at the poles of a traditional banana-peel sphere (http://astronomy.swin.edu.au/~pbourke/opengl/sphere/quads.gif). I don't want to have to do this, since I want the 2D view to effectively be the same texture, only now mapped on a grid instead of a sphere.

I was thinking hard about this problem when I remembered the icosahedron, or 20-sided figure. I had seen planetary maps in RPGs like GURPS Space and Megatraveller represented by icosahedron shapes that had been flattened (http://upload.wikimedia.org/wikipedia/en/8/83/Icosahedron_flat.png). I think with some clever UV coordinate jiggering I might be able to make that work...I would have some parts of the texture that were "dead" or unused in the 3D view but if I work around that limitation I might get the look I am working towards.

I have two problems:

1. An icosahedron doesn't have enough sides. I want a spherical shape composed of equilateral triangles, like an icosahedron, but with more sides so that it approximates a sphere better. I'd need the this shape in a 3D format that includes both the vertices and their normals, of course. Number of 3D modelling programs I have == zero.

2. Once I had such a shape, I'd have to find a way to "unwind" it so that I can properly map the UV coordinates, and I have no idea how to do that.

Basically, what I'm asking is, has anyone here ever done ANYTHING like this before, and if so, could you give me some tips?

Sybixsus
05-11-2006, 01:05 PM
Well you're on the right track, I think. For 1) I would definitely go with an icosaherdron. As for it lacking detail, just subdivide it. Ultimate Unwrap, for example, will let you create an Icosahedron ( one of several spherical-type shapes it classes as GeoSpheres ) and let you choose the number of subdivisions.

I'm useless at UV mapping, so no real advice for 2) except that Ultimate Unwrap is an excellent tool designed primarily for UV mapping, so it's probably a good tool for you to investigate further.

Viridian
05-11-2006, 01:51 PM
That looks like exactly what I need! Except:

"The demo is fully functional (except for saving)..."

Crud. Well, how much is it?

$50. For something I'll probably only use once. Crap.

And now that I'm trying it, it's not exactly what I need, because it doesn't unwrap geospheres to equilateral triangles.

Well, thanks for the suggestion anyway.

Sybixsus
05-11-2006, 02:38 PM
Well it doesn't UV map them in the way you want by default, no. But there are a lot of options for automatic UV generation, and then there are tools to do it manually. Presumably this is something you're only ever going to need to do once, so if you don't find something which does it with one-click, it still might be worth looking at this.

Yes, it's $50, but it's a supremely useful tool. It's one of my best purchases, as it's useful for tweaking, converting between a myriad of formats and - of course - unwrapping.

Fost
05-11-2006, 02:42 PM
Fixing shere maps is dead easy, I'm always shocked how often I see that pinched texture effect at the poles of planets - even on mainstream games!

Open your texture in photoshop
Filter>distort>polar coordinates: rectangular to polar
Fix the pinching with the clone stamper or your tool of choice
Run the polar coordinates filter again, but this time in polar to rectangualr mode.
*Note - it helps to do this with a higher resolution source map and then scale down, as you lose some clarity in the 2 coordinate changes.


Another option is to use 'spherical cubes' - I'm not exactly sure what the proper terminology is for them - in fact, there may not be any term for them.

Hard to explain, but a picture says a thousand words:

http://www.moonpod.com/board/images/misc/CubicSphere.gif

Essentially a cube warped into a sphere - so you can apply cube maps directly to it. Has much, much better pixel coverage than a spherical map - in fact I think it may be about 4x. Might also work ok with tile maps - as you are still working with a grid, albeit warped.

impossible
05-11-2006, 04:36 PM
I would go with the cube in this case. According to a post of one of the developers of Spore on GD-Algorithms, that game uses a similar technique. Also it should be very easy to turn cube faces into tile maps.

Applewood
05-16-2006, 03:41 PM
I'd approach this a little differently as it's actually mathematically impossible to map a rectangle onto a sphere. Some programs can get you close by mungeing the image, but the below can get you right there and you'll have more flexibility to boot.

Generate your game maps procedurally. There's oodles of samples out there - look for plasma terrain, fractal terrain, and tectonic fault distribution (looks the crappiest in every demo I've seen but it actually better for modelling random terrains imo).

You can reference the tectonic generator from polar coordinates and build a sphere that looks very similar to the 2D view. If you can be arsed, you could even morph from one to the other as your dropship passes through a "cloud layer" (read, bit of slight of hand to hide the cracks :)

I implemented something from hugo eliases demo once and it looked shit hot. Never actually got used though.

http://freespace.virgin.net/hugo.elias/models/m_landsp.htm