Sign in to follow this  
blueshogun96

How are sphere maps created?

Recommended Posts

I've been doing some google searching, but no answers have come up so far (probably because sphere mapping is a dying/dead visual technique).  How does one create/generate a sphere map from existing images using photoshop or GIMP?  I use GIMP because I can't afford photoshop.  Now, just in case you aren't sure what I mean, I'm talking about a texture that's basically used for reflective purposes, like this one:

 

mountains_sphere.jpg

 

To me, sphere maps seem cheaper than cube maps and are reasonable for those moments where you need to add a cheap reflection to something.  Any info is appreciated.

 

Shogun.

Share this post


Link to post
Share on other sites

A genuine spherical environment texture map contains all the degrees of spherical visual information present in that distorted image. You can read more about it here:

http://www.pauldebevec.com/ReflectionMapping/

 

If you have a single square image you can distort that image from the center to the edges relative to a sine function and it should work as a spherical environment texture map, but it will lose detail. If it were a cubemap, it would be like starting with only the front face and stretching it to cover the other faces.

You can use the Spherize filter in Photoshop to do this, or any other image editing trick such as ImageMagick:

- http://www.imagemagick.org/Usage/mapping/#spherical

- http://www.fmwconcepts.com/imagemagick/bubblewarp/index.php

 

GIMP does not have a "spherize" filter. The Polar Coordinates filter is not a replacement for this, it does something else. It's possible to write a GIMP Python-Fu script to do a "sine warp" as explained in that "bubblewarp" page.

A reference GIMP Python-Fu script is the following. It's unrelated to this task, but it's a template that you can use and replace the pixel-manipulation logic with anything you want, such as that sine warping: 

http://paulbourke.net/texture_colour/tiling/polarCorrection.py

 

Let me just say that Python-Fu has terrible documentation (it's better to [url=http://registry.gimp.org/node/28124]read the code samples[/url]), and that Python itself can be very frustrating if you're used to languages that don't enforce any formatting restrictions, like C++. A single blank space can stop GIMP from executing your Python script because it breaks indentation.

 

Some further reading:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb147401(v=vs.85).aspx

http://paulbourke.net/texture_colour/tiling/ (At the bottom)

Share this post


Link to post
Share on other sites

A genuine spherical environment texture map contains all the degrees of spherical visual information present in that distorted image. You can read more about it here:

http://www.pauldebevec.com/ReflectionMapping/

 

If you have a single square image you can distort that image from the center to the edges relative to a sine function and it should work as a spherical environment texture map, but it will lose detail. If it were a cubemap, it would be like starting with only the front face and stretching it to cover the other faces.

You can use the Spherize filter in Photoshop to do this, or any other image editing trick such as ImageMagick:

- http://www.imagemagick.org/Usage/mapping/#spherical

- http://www.fmwconcepts.com/imagemagick/bubblewarp/index.php

 

GIMP does not have a "spherize" filter. The Polar Coordinates filter is not a replacement for this, it does something else. It's possible to write a GIMP Python-Fu script to do a "sine warp" as explained in that "bubblewarp" page.

A reference GIMP Python-Fu script is the following. It's unrelated to this task, but it's a template that you can use and replace the pixel-manipulation logic with anything you want, such as that sine warping: 

http://paulbourke.net/texture_colour/tiling/polarCorrection.py

 

Let me just say that Python-Fu has terrible documentation (it's better to read the code samples), and that Python itself can be very frustrating if you're used to languages that don't enforce any formatting restrictions, like C++. A single blank space can stop GIMP from executing your Python script because it breaks indentation.

 

Some further reading:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb147401(v=vs.85).aspx

http://paulbourke.net/texture_colour/tiling/ (At the bottom)

Ah, I get it.  Very interesting.  I'll explain why I asked about spheremaps in a moment.

 

 

I'd start with a cube map, then write a shader that does a reverse spheremap lookup (UV -> 3D direction) and use that to copy the cubemap to a 2D spheremap texture.

In this case, I think I should just stick with the cube map.  The reason I was looking into spheremaps because I had an idea for dynamic spheremap generation as a faster replacement for dynamic cube maps for reflections.  If it requires cube maps to begin with, then the technique would be too expensive, as dynamic cube maps are expensive enough as it is.

 

Shogun.

Share this post


Link to post
Share on other sites
You COULD render straight to a spheremap, but, its hard because it's a curved projection and the HW can only draw triangles with straight lines.

If you haven't heard of them, check out dual-paraboloid maps - these are similar, but consist of a front/back hemisphere map.
They face the same issues from curved geometry, but not quite as badly because they're not as extremely distorted as the edge of a spheremap has. Sometimes people just put up with the artefacts, or you can use tesellation to minimize them.

Share this post


Link to post
Share on other sites

As in that MSDN article, the formula used for spherical environment mapping is this:

 

IC511482.png

 

The UV values of a vertex are derived from the normal vector of that vertex.

If you render a scene to the backbuffer (without the reflective objects), grab that as a texture and use it as a spherical environment texture and render the reflective objects with it, it should convey the effect. 

Parts of the object facing left will sample from the left parts of the texture, the bottom parts of the object will sample the bottom parts of the texture etc.

The result is this:

 

Bitmap_118.jpg

 

This is only an illusion, the object isn't really a mirror because out-of-screen objects won't be reflected. The object will only reflect what's already on the screen.

If you use cube maps (which are five times more expensive to render), then the object can truly reflect things not on the screen like a mirror.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this