blog
Anaglyphs With Pixel Bender & Depth Map

Pixel Bender and displacement maps were so much fun to develop that my next experiment led me to create some more advanced effects. Do you know anaglyphs? Anaglyph images are used to provide a stereoscopic 3D effect, when viewed with 2 color glasses. There are multiple types of glasses (colors), but the most comon is red-cyan combination. So, I have created this simple pixel bender kernel that makes anaglyph images based on original image and its depth map (just like those used in displacement maps)
Take on your red cyan glasses and lets see the result:
forked from: Pixel Bender Displacement Map Fakes 3D Effect – wonderfl build flash online
I have been asked to make it also work for other types of glasses, so I made left/right glass matrices dynamic, now you can define any values you like (based on your glass color). The default matrices are:
shader.data.matrixLeft = [0.0, 0.0, 0.0, 0.7, 0.0, 0.0, 0.3, 0.0, 0.0];
shader.data.matrixRight = [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];… these values are taken from optimized method for red cyan combination. There are some more for this color combination.
There is also the zBase parameter that takes values from 0.0 to 1.0. Defaul value is 0.5. With 0.0, the scene appears to be in front of monitor, with 1.0 depth goes behind the monitor. With 0.5 closer objects appears to be before monitor, distatnt ones behind:
shader.data.zBase = [0.5];Take care so your head will not explode Download pixel bender kernel (.pbk) file for anaglyphs here.
Where to go from here:
Filippo — 2010-11-22: Many thanks Jozef for sharing but I am looking for a realtime solution. My goal is not only for a stereoscopic 3D effect but I would like to find out the most distant objects and those closest. http://www.pages.drexel.edu/~nk752/depthMapTut.html
Jozef Chúťka — 2010-11-22: Filippo, I do not know about any realtime AS3 attempts. Well maybe will be interested in http://kinecthacks.net/
filippo — 2010-11-22: Hi Jozef, thanks for your prompt response. A kind of Kinect system is what I would like to create. If I/we built a fast system in Pixel Bander to get a depth map it’s easy after to choose the objects in the environment we want to consider for the interaction. We can get an image with only the closest making transparent the others. If you can help me obtaning a Pixel Bander solution using two images, taken from two cameras separated by a distance of a few centimeters, as input and getting a depth map as output I can make it in realtime.
Jozef Chúťka — 2010-11-22: filippo, now I can see what you are up to… I am affraid you will not be able to use pixel bender while there are no loops in current version. I can see some algorithm public available http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=algorithm+two+image+depth+maps … I am briefly reading http://cvlab.epfl.ch/publications/publications/1993/Fua93.pdf , I guess that is the way to go, anyway I believe it would not be fast enough to run realtime (as you could see with photosculpt) … however I think this is an interesting idea. Let me know how else could I help you
Brmm — 2010-11-23: This is really nice, Have you ever tried making multiple instances of the shader in one displayObject? Like if you just need simple 3D, as an alternative to Papervision where you don’t need that much panning, like for top view flash games. Or is that just impossible to due flash performance? Great work.
filippo — 2010-11-23: Hi Joseph, probably I have found a better documentation that can help to understand how to implement it. In this document it’s also great the idea of the deph map for augmented reality. 😉 http://campwww.informatik.tu-muenchen.de/3DPVT2010/data/media/e-proceeding/poster-session1.html (GPU Accelerated Realtime Stereo for Augmented Reality –> .pdf) There are also on internet other examples using openCV. https://sites.google.com/site/elsamuko/c-cpp/opencv-depthmap
Jozef Chúťka — 2010-11-23: Brmm, I never did, however you can. This effect works best with smooth depth changes, if there is something too far next to too close it may result choppy… use drawTriangles method from http://3ddm.yoz.sk/
Jozef Chúťka — 2010-11-23: filippo, great source, now if you could find C sources and compile it into alchemy, you should get really close to some good results 🙂
Jozef Chúťka — 2010-11-30: filippo check out also DAISY method “An Efficient Dense Descriptor Applied for Wide Baseline Stereo” http://cvlab.epfl.ch/research/surface/daisy/
Booney — 2011-08-25: ALso there is a cool software which converts your 2d video files and plays them is snsglyph on the fly! convert-to-3d.com