Creating and Viewing Anaglyphs
Written by Paul Bourke
Quartz Composer composition: red_cyan.qtz.zip.
There are many different ways of creating and viewing stereoscopic 3D images but they all rely on independently presenting different images to the left and right eye. The following briefly describes and gives examples of what are known as anaglyphs. For more information on how to correctly create stereo pairs, how to use rendering programs to create stereo pairs, and how to use two cameras to film in stereo, see other articles on this page. While there are many problems/issues with anaglyphs they do have the one big advantage that they can be transmitted/presented using traditional single channel media such as print, film, television, etc.
Anaglyphs are a straightforward way of presenting stereo pair images to the appropriate eye. The glasses have two different colour filters, for example, red on the right eye and blue on the left eye. The image that is destined for the left eye is coloured in shades of blue while the image destined for the right eye is coloured in shades of red. Note: if the glasses have the filters around the other way simply reverse them to view the images on this page.
There are three types of anaglyph glasses in common use, red-blue, red-cyan, and red-green. Click on any of the images on this page for the full size version.
The main advantage of anaglyphs is they can viewed with a minimum of hardware and expense. Cardboard glasses are cheap enough for anyone to own and it is easy to distribute them in magazines or or other media (cereal boxes) for promotional exercises. There have also been a number of successful television shows broadcast using this method. A number of movies were made using anaglyphs, their popularity faded when colour filming became possible, audiences would rather see non-stereo colour movies instead of stereoscopic black and white movies. The main drawback with this form of stereo 3D imagery is that it the images have colour distortion.
Given two stereo pair images, they can readily be combined with PhotoShop by turning each image into greyscale and pasting it into the appropriate "channel" (r,g,b) of a third image. For an optimal effect the colours used should be matched to the exact colour of the display/glasses. Simple calibration charts can be created that allow tuning of television or computer monitors to the colours used in the glasses.OpenGL
Rendering anaglyphs in OpenGL is straightforward with the help of the routine glColorMask(). The basic idea is to create the scene with all the surfaces coloured pure white. Render the scene twice, once for each eye. If designing for glasses with the red filter on the right eye and the blue filter on the left eye then before rendering the right eye, call glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_FALSE); and before rendering the left eye, call glColorMask(GL_FALSE,GL_FALSE,GL_TRUE,GL_FALSE); If your OpenGL hardware supports stereo buffers then the above can be implemented directly, if not then one needs to render the scene twice and use the accumulation buffer to merge them, see later.
There is no reason why animations can't be created as illustrated below for a simple mathematical knot. This is a further illustration of how suited this method is to the WWW, there are only a few colours required to render the red and blue (or green) images which is suited to the maximum 256 colour table using animated gifs. Of course any other animation format can be used in general, such as AVI, MPEG, QuickTime, etc.
Strictly speaking it is possible to have colours in the anaglyph. In particular, the object in the scene that are at or about the focal depth can be in colour since they are seen by both eyes. While colour can be added by carefully designing the image, it is hard to include colour automatically. One algorithm that adds colour and also makes the images "look better" when viewed without glasses involves averaging the non-filter primary. For example for red/blue glasses the left eye contributes the red in the final image, the right eye contributes the right eye of the final image, the green component of the final image is the average of the green channel from the left and right eye image.
Gfinal = (Gleft + Gright) / 2
Bfinal = Bright
Increasingly the standard glasses being used are red/cyan. The mapping commonly used is to take the red channel from the left image and the green/blue channel from the left eye.
Gfinal = Gright
Bfinal = Bright
The same can be accomplished but on a grey scale image.
Gfinal = Greyright
Bfinal = Greyright
Creating Anaglyphs using OpenGLor
A simple example using the OpenGL accumulation buffer
Written by Paul Bourke
Feedback from Michael Callahan
If you're rendering with the hardware red and blue (for example, using colour masks), then the colours do not overlap at all. So if you aren't already using the blend function for something else, the accumulation buffer is unnecessary:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE); // set camera for blue eye, red will be filtered. // draw scene glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE); // set camera for red eye, blue will be filtered. // draw scene
Feedback from Daniel van Vugt
Daniel van Vugt pointed out that the accumulation buffer isn't actually needed resulting in a much faster implementation.
"Because the two images do not overlap in colour space, no kind of blending or accumulation is actually doing anything. Just remember to clear the depth buffer for each image, but don't clear the colour buffer between the two images."New, faster, source code
Contribution by Yann that uses the GLM library to open and display OBJ files. yann.zip