Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Convert a texture to a sphere map...

Author
Message
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Oct 2011 04:17 Edited at: 3rd Oct 2011 04:21
I'm hoping that someone may be able to help me out with this problem, I'm pulling what's left of my hair out again.

In the image below is a texture that's been spherized but the algorithm doesn't map it properly. I've googled day after day and found many sites with information about this, I think is called mercator transformation, but no listed maths or solutions to how it is actually done. The closest I found was some old source code on a blitz basic site but still no joy getting it working.

The input image is tiled, the output image should use some sort of spherical conversion algorithm to make it wrap onto a sphere without the pinching at the poles.



My code is based on this which I found: (absolutely no good)


My full code with the spherize functions at the end: Which is obviously not the correct algorithm.


If anyone has any solutions to this problem, whether it called mercator or transvers mercator, or something else odd and has the formula/algorithm it would be greatly appreciated...

Each of the above functions has basically produced the same result, no corrected wrapping of the input texture...

NB: My code does actually use the perlin noise dll but the same code will also work on an input image of the same size.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Attachments

Login to view attachments
Da_Rhyno
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 3rd Oct 2011 05:10
Is it one of those style spheres where it's pretty much a list of points (akin to a cube) where it's transformed in such a way that all the points are at a set distance from the center (a radius so that it is transformed into a sphere)?
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 3rd Oct 2011 15:35
Its always difficult, but I know that it helps to start with a Geosphere model.

chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Oct 2011 16:26 Edited at: 3rd Oct 2011 16:28
Quote: "In the image below is a texture that's been spherized but the algorithm doesn't map it properly"


I think you not only need to convert you texture spherical but seamless too because the sphere has been textured as a cylinder. just try a seamlees texture to see.


Cheers.

I'm not a grumpy grandpa
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 3rd Oct 2011 16:28
Oh yeah, I just noticed it's not seamless.

WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Oct 2011 16:41 Edited at: 3rd Oct 2011 16:43
The texture itself is seamless (I'm using my own code to produce that) but the algorithm I've been using doesn't map it properly so that it will stay seamless. This link has the correct idea: http://www.blitzbasic.com/Community/posts.php?topic=63686 and there is a way of converting it properly so that it wraps perfect, but finding the actual pseudo code or algorithm has been a nightmare.

So far I'm having no luck but not giving up yet.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Oct 2011 16:46
Yeah, left to right would have to be tileable, then a nicely UV mapped geosphere would give some good results - although I'm not convinced that it's possible to get a perfect map on any sphere, I mean geospheres will still have issues around the poles, it's an affect caused by wrapping a square around a sphere. To combat the poles problem, I would use a planet map that had very little detail at the poles.

If I was making a game with planets, I'd consider using 2 texture maps, one for north and south poles, and one for east and west poles - so the areas that would be distorted in one texture, are in the middle of the other texture. I'm not sure how to adjust the texture strength of a vertex, but the effect could be replicated by making 2 sphere, texturing each with the different texture (NS poles, and EW poles), rotate the second sphere 90 degrees to the right, and alpha fade the poles. I think that would give such nicely detailed results - but it would need some good texture work, 2D texture maps just can't cut it on their own.

Health, Ammo, and bacon and eggs!
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Oct 2011 17:26
I might have to cheat and fool the player when it comes to the planets because I can generate a seamless texture and so long as I don't show the poles then I should get away with it. That means putting the camera directly in front of the planet and hiding the pinching effect at the poles.

The actual algorithms are used by all the big companies so they're not widely available. I know it's something to do with calculating longitude and latitude but then what?

The main problem is that I'm generating billions of planet textures so I can't have a library of planet textures. I'm considering looking into adding the curvature into the texture generation and see if that will solve it.

If I was using 2 textures I'd probably have to use a conic algorithm for solving the pole problem and it also could work just thinking about it. Thanks Van B you've given me some food for though.

2nd thoughts on the double texture idea Van B. I'm going to have an experiment and draw up some ideas before I move on. I'll keep you all posted. I'm thinking of converting the square texture into a diamond one (conic from top to middle and bottom to middle). Hard to explain at the moment.

Definitely trying some other ideas before giving up and cheating.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 3rd Oct 2011 18:22 Edited at: 3rd Oct 2011 18:23
When you say that the actual texture is seamless.. well the one you posted isn't seamless. It has in fact textured to your model perfectly how it has been made.

WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Oct 2011 19:45
The texture in the image is the result after the algorithm has done its damage. The original texture is seamless.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 3rd Oct 2011 21:18
Sorry for my coment about the texture,but I din't know that upper left was the bad result of that algorithm.
Cheers.

I'm not a grumpy grandpa
WLGfx
17
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 3rd Oct 2011 21:31
@chafari - no probs, I'm running out of hair. All this longitude and latitude lark. I'll probably just end up cheating cos the seamless bit looks great...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2025-05-06 04:24:16
Your offset time is: 2025-05-06 04:24:16