[Test] Stereoscopic 3D Rendering With Anaglyph Images
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.
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.
[ Subscribe to Geeks3D latest news by email ]