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.
Rendering using extreme angles:
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.