A.D.A. Amiga Demoscene Archive

  Welcome guest! Please register a new account or log in




log in with SceneID


Demos Amiga Demoscene Archive Forum / Coding / Mapping a texture to a sphere


Author Message
#1 - Posted: 8 May 2013 18:55
Reply Quote
Hi. I want to know a simple (if possible) algorithm (table lookup maybe?) to map a texture to a sphere to simulate a spherical view (from inside the sphere). Thanks!.
#2 - Posted: 9 May 2013 18:12
Reply Quote

Doing this exactly is impossible as a sphere and a plane are topologically different. Basically what you want to do is to spread a piece of cloth over a ball without making any creases in the cloth. However, there are a lot of different approximations to do this as it is an important problem, think drawing a map of the globe. There is quite a nice article on Wikipedia that might work as a good starting point for this https://en.wikipedia.org/wiki/Map_projection.

Out of curiosity what is it that you want to do? If you want to render a sphere, not all of the sphere will be visible at the same time so as long as you put the "smoothest" part of the cloth towards the camera you should be fine.

Hope this helps.
#3 - Posted: 9 May 2013 18:41
Reply Quote
Thanks for your comments bonkers. What I mean is something like this:

http://farm1.staticflickr.com/18/24013890_7f7d835e fb_o.jpg
#4 - Posted: 11 May 2013 10:41 - Edited
Reply Quote
Not sure I understand you, do you want to have a texture-mapper to the polygons that you see in that image or do you simply want to render that grid-pattern i.e. have the points on the surface on the sphere like the image that you link to (even though I think the green thing is a cube)? The former is Map projection and is as I said a tricky thing, can't be done correctly but there are lots of approximations. Generally if you want to render the sphere you make a ray caster. First specify the sphere,


and compute the intersections between the lines going from the camera centre (if you want the camera in the middle of the sphere that's [x₀,y₀,z₀]) through the view-plane [uᵢ,vᵢ,f] (where f is the focal length of the camera). This will then give you the position of the sphere that is visible at a specific screen coordinate. Now, as you know that you are on the sphere, you have only two degrees of freedom and from this you want to have a lookup-table between the coordinates on a sphere and the coordinates on a rectangular texture, and this information you will find in the wiki document.

If you don't want to texture the thing, then you can just specify a sphere, i.e. the green locations in your image, and then project them into the camera.

Still not sure what you mean but hopefully this goes a little bit towards figuring that out at least ;-).
#5 - Posted: 21 Jun 2013 14:24 - Edited
Reply Quote
You need to be very careful here to avoid patent infringement! ;)


..don't we love the bad joke called software patent? :D

Anyway, I'm assuming you're after "being inside a textured ball" and I'd vote for what bonker described! - ray cast it on a course grid and interpolate the [u,v] between the grid points. A bit more complicated that some magical table approach but in the end I think it'll be easier (and a good algo to have around for other nice things).

The major issue is how achieve a efficient mapping, you can't just bend a paper around a ball, so you either get a mapping with very low resolution towards the poles for example, or you need to "cut" your texture/uv-space into parts. You can see an example of both the technique and the mapping problem in the second screenshot of this one:

Powerline - Repugnance (ADA) **

If you run it, you'll definitely see the issue. I simply mapped the [u,v] along 2 dimensions of the sphere - well egg in my case.

Now, I've been thinking about this lately and I'd say the easiest solution is to simply have several versions of the texture and switch between them depending on the angle. A more complicated approach could be blending the textures. An even more complicated way could be to accurately select the appropriate texture for each pixel. That would require (for example) to identify tiles in the the grid that needs to be subdivided further - those tiles where "a line passes through" with one preferred texture on one side and another on the other.

Btw, If anyone have any ideas on good ways of how to texture a sphere in general (i.e. map texture(s) onto it) I'd be happy to hear them!

**Disclamer: the one who "designed" the textures has requested perpetual anonymity. ;D


  Please register a new account or log in to comment





A.D.A. Amiga Demoscene Archive, Version 3.0