This forum contains results from the eponymous seminar from WS2011/2012. Each work from the students contains a summary of their results and the presentations attached (partly in German Language).
Post Reply
thomasdw
Posts: 2
Joined: 27.10.2011, 09:47

Stereoscopy in OpenGL

Post by thomasdw » 01.03.2012, 16:43

1 Introduction
To generate a stereoscopic image on the screen, there are needed two images: One for left
eye and one for the right eye. There are two general approaches to make these images.
The first one is called ”toe-in“ and the second one is called ”off-axis“.


1.1 Toe-In
In the Toe-In approach there are two symmetric frustums and therefore two crossed
projection planes as you can see in figure 1.1. While this approach does produce a working
stereo image, it also has the issue that it makes the viewer feel sick or at least gives them
some sort of headache.
This is it’s main disadvantage, but it is easier to implement as well.

toein.png
toein.png (7.99 KiB) Viewed 21181 times
Figure 1.1: Toe-In approach.


1.2 Off-axis
The Off-axis approach uses two asymmetric frustums. This leads to two parallel projection
planes as one can see in figure 1.2. Of course it produces a working stereoscopic image,
too. While it has the disadvantage that it is more difficult to implement — because it
needs a more complicated frustum — it does not cause any problems like sickness or
headaches as the Toe-In approach does.
This should be the approach to choose when you want to produce stereo images.
offaxis.png
offaxis.png (6.47 KiB) Viewed 21181 times
Figure 1.2: Off-axis approach.


2 Mathematic background
Because the Off-axis approach is the better one, only this approach is explained.
To get the two pictures for the left and right eye, there three steps needed. The first is
transforming the camera or the scene/object, the second is calculating the frustums and
the third is the rendering of the scene.

2.1 Translation
The translation of the scene/object is easily done by the old OpenGL method glTranslate(+/-
(0.5*eye separation), 0.0, 0.0) or an equivalent function for generating a translation
matrix. The translation of the camera can be achieved with the GLEW function glu-
Lookat(...) or again with a equivalent function that generates a look-at and therefore
view matrix.


2.2 Frustum
frustum3.png
frustum3.png (6.44 KiB) Viewed 21181 times
Figure 2.1: Frustum.

For calculating the frustum the following values are needed: Left l, Right r, Bottom b,
Top t, Near near and Far far. The values are used like in figure 2.1 and they are calculated
as follows:
wd2 = near * tan( (pi/180) * (FOVy/2))
b = -wd2
t = wd2

Frustum for the left eye:
l = b * (width/height)
r = b * (width/height) + 0.5 * eye_separation * (near/focaldistance)

Frustum for the right eye:
l = b * (width/height) - 0.5 * eye_separation * (near/focaldistance)
r = b * (width/height)

The values width, height, FOVy, eye seperation, near and focaldistance are constants
given by the environment.
The OpenGL function glFrustum(GLdouble l, GLdouble r, GLdouble b, GLdouble t,
GLdouble near, GLdouble far) can be used with the just calculated values to get the
needed projection matrix and therefore the two frustums that are needed.


2.3 Rendering
To render the stereo images one has to follow these steps:
1. Calculate the Frustum for the left eye
2. Transform scene/camera to the right/left
3. Render the scene
4. Calculate the Frustum for the right eye
5. Transform scene/camera to the left/right
6. Render the scene
One can use different types of stereorendering, like: anaglyph, quadbuffering, Side-by-side
or Top-bottom.


Anaglyph
Generating anaglyph images is easy. The only thing to do is set the right colormasks
before rendering the specific image. For the left eye the colormask has to be: glColor-
Mask(GL TRUE, GL FALSE, GL FALSE, GL FALSE) and for the right eye: glColor-
Mask(GL FALSE, GL TRUE, GL TRUE, GL FALSE).

Quadbuffering
To generate the images for quadbuffering it is neccessary to render the two pictures into
the correct buffers.
First of all you have to activate quadbuffering. In GLUT for example this is done with
the GLUT STEREO flag in the glutInitDisplayMode(...) function (This does only work
if you have a Nvidia Quadro Card or an AMD equivalent). Then you just have to activate
the correct buffer before rendering the two images: glDrawBuffer(GL BACK LEFT) for
the left eye and glDrawBuffer(GL BACK RIGHT) for the right eye. After that you have
to swap buffers as usual.


Side-by-side and Top-bottom
sbs.png
sbs.png (191.2 KiB) Viewed 21181 times
Figure 2.2: A side-by-side stereo image.


Side-by-side and Top-bottom methods are useful for 3D-TVs and 3D-Projectors.
The general approach for both methods is the same. The viewport has to be adjusted so
that it is divided in two halfs as you can see in figure 2.2. This can be achieved by using
the glViewport() function.
For the Side-by-side method you have to adjust the viewport for the left eye like this:
glViewport(0, 0, 0.5*width,height) and the right one like this: glViewport(0.5*width, 0,
0.5*width, height).
The viewports for the Top-bottom method are pretty similar. Left eye: glViewport(0,
0.5*height, width,0.5*height); Right eye: glViewport(0, 0, width, 0.5*height).
After each adjustment of the viewports you have to render the scene of course. It is pos-
sible that this is not correct for every TV/Projector, so you maybe have to invert pictures.


2.4 Molecule Visualization
Molecule Visualization is an important field for stereoscopic rendering, because it is pretty
important that you can diffrentiate single atoms and parts of a molecule. This perception
of depth could also be achieved by a shadow calculation, but this is sometimes pretty
expensive and has not quite the same results as stereo rendering.
You can see a direct comparison of a molecule with and without stereorendering in fig-
ure 2.3 and figure 2.4. Of course you need Red-Cyan-3D-Glasses to view the stereo image
correctly.
molstereo.png
molstereo.png (312.97 KiB) Viewed 21181 times
Figure 2.3: With stereo.
molnonstereo.png
molnonstereo.png (216.06 KiB) Viewed 21181 times
Figure 2.4: Without Stereo.


3 Conclusion
It is recommended that you use the Off-axis approach for rendering stereo images — at
least if you have the opportunity to calculate the frustum an easy way like in OpenGl.
Moleculevisualization is an important field for stereo rendering.


Sources
http://paulbourke.net/miscellaneous/ste ... reorender/
http://www.opengl.org/
• Bachelorarbeit: GPU-Based Molecule Rendering
Attachments
stereoscopy_in_opengl.pdf
Text
(1.37 MiB) Downloaded 1145 times
stereoskopie_in_opengl.pdf
Slides
(649.16 KiB) Downloaded 1095 times

Post Reply