Anaglyph 3D in GeeXLab
Few days ago, the guys at binocularity.org have updated their stereoscopic 3D demo (in Python and C++). So I decided to test stereoscopic 3D rendering with GeeXLab using anaglyph images:
Anaglyph images are used to provide a stereoscopic 3D effect, when viewed with 2 color glasses (each lens a chromatically opposite color, usually red and cyan). Images are made up of two color layers, superimposed, but offset with respect to each other to produce a depth effect. Usually the main subject is in the center, while the foreground and background are shifted laterally in opposite directions. The picture contains two differently filtered colored images, one for each eye. When viewed through the “color coded” “anaglyph glasses”, they reveal an integrated stereoscopic image. The visual cortex of the brain fuses this into perception of a three dimensional scene or composition.
To validate the results, I used the red/cyan glasses I got with Zotac’s GT 240:
That said, let’s quickly see how anaglyph images can be generated with GeeXlab. I use a post direct rendering script to render the images. A post direct rendering script is a type of script where you can directly use rendering calls: OpenGL with PyOpenGL or GeeXLab HYP_Renderer lib. A post direct rendering script is executed after the main scene rendering and just before post processing effects.
Here is how to generate anaglyph images (pseudo-code):
1/ Render the left eye:
Enable_Additive_Color_Blending() Clear_Depth_Buffer() pos_cam_x = -2 pos_cam_y = 0 pos_cam_z = 250 Init_Persp_Camera(pos_cam_x, pos_cam_y, pos_cam_z) Apply_Light_Red() Render_Scene_Objects()
2/ Render the right eye:
Clear_Depth_Buffer() pos_cam_x = 2 pos_cam_y = 0 pos_cam_z = 250 Init_Persp_Camera(pos_cam_x, pos_cam_y, pos_cam_z) Apply_Light_Cyan() Render_Scene_Objects()
If you look at the demo source code, this is exactly what I did in the post direct rendering script.
I must say that the result is much convincing. The true 3D effect is really there!
This technique is based on color blending and then depending on camera viewing angle, objects must be sorted (back to front) before the rendering. In the GeeXLab demo, objects are not sorted.
Demo download
The demo is included in the code samples pack in the Anaglyph_Stereoscopic_3D/ folder. There are two demos: the first based on Lua and the second based on Python.
This demo requires GeeXLab 0.2.4 or a higher version.
This is cool!
However, there is one improvement that would improve the stereo effect considerably (depending on the scene).
You currently use something called “toed-in” stereo, which is not optimal.
Look for “Asymmetric frustum parallel axis projection stereo” in the following link for the correct math to do S3D:
http://www.orthostereo.com/geometryopengl.html
Thanks for the link Michael.
I’ll try to test asymmetric frustum parallel axis projection in a new GeeXLab demo.
He JeGX,
The asymmetric frustum code is built into the binocularity.org analgyph demo – so you should be able to use it really easily.
Good to see you having fun with 3D !
bw
Nick
I would recommend you a performance optimization idea:
Instead of coloring the results and additively blending them together, you should rather use glColorMask to mask only for red or cyan.
This way no need for blending which will (at least slightly) improve performance.
Take a look at vpython.org, which makes it very easy to write navigable 3D animations using Python. Adding a single statement to the program makes it true stereo. For example, for red-cyan glasses, the magic statement is
scene.stereo = ‘redcyan’
It’s wrong.
Toe-in
“In this projection the camera has a fixed and symmetric aperture, each camera is pointed at a single focal point. Images created using the “toe-in” method will still appear stereoscopic but the vertical parallax it introduces will cause increased discomfort levels. The introduced vertical parallax increases out from the center of the projection plane and is more important as the camera aperture increases.”
…
Please read http://local.wasp.uwa.edu.au/~pbourke/miscellaneous/stereographics/stereorender/
Take care about users eyes 😉