Generating stereoscopic images with parallax occlusion mapping

I rarely do experimental programming, but I had an idea today that I wanted to try. Maybe it’s not a new idea but at least I thought of it on my own.

Stereoscopic images are usually photos taken by two seperate cameras aimed at the same object but a small distance apart from eachother. The difference in position will let one camera see the object at a slightly different angle than the other. By looking at the two images side by side and crossing your eyes you will experience a 3D effect. Other than the eye-strain it’s a neat effect.

I liked the idea and thought about ways to generate a steroscopic image from a single flat image. The idea I came up with was to fake depth in the original image and then render two snapshots of it from slightly different angles. There’s a popular method employed by game developers for faking depth in otherwise flat textures called Parallax Occlusion Mapping. The idea is to use a heightmap and some clever math to make parts of the image “pop out”.

The implementation was really straight forward. I just found a parallax mapping shader online, converted the code to C++ and threw some sample images at it.

See my results after the break.

The theory:
parallax.jpg
The result: 

stereoscopic.jpg 

 

3d.gif

 

Rendering using extreme angles:

stereowide.jpg

Painting the heightmap was probably the hardest part in this experiment. It would look more convincing if you used a depth render from Maya or similar.

I only implemented the essential algorithms and could probably build an interface around it to make a proper tool. Maybe I could use DirectX to let users edit and preview the heightmap in realtime (the software rendering is quite slow). This experiment proved to me the concept works at least.

Here are some more renders I made using images I found on google (with accurate depth maps). The first one clearly shows a side effect from the parallax mapping.

 

screws.png 
3d_screws.gif

 

 

blue.png 
3d_blue.gif

 

3 Responses to “Generating stereoscopic images with parallax occlusion mapping”

  1. Andrew said:

    Apr 23, 08 at 17:40

    Very cool technology. Are you doing 3d game development with this?

  2. Jeckle said:

    Apr 23, 08 at 18:00

    Nice job,
    Since you can access a depth map in kjAPI, it would be interesting to see how you use this to generate 3D screenshots :) (maybe a module in Planet level editor ;) )
    Ced

  3. Erik Benerdal said:

    Apr 25, 08 at 12:02

    Andrew: No this was just an idea I had one afternoon and I spent my evening implementing it. I have some further ideas though. First of all I should run it on the GPU to get better performance. Once that’s done I imagine adding a pan/zoom. Currently the effect is limited to the size of the image (I can only cross my eyes so far), but if I instead of having two images I had two viewports that I could pan and zoom around in I think that could make for a really cool effect, as well as enable high resolution images.


Leave a Reply