This wiki describes how to use the stereo vision or anaglyph images ability of OpenSceneGraph and let you experience the FlightGear world in 3D. Another excellent example and simple application of FlightGear's flexibility and realism.
Important Notice: Even though it might not pose any danger, try avoiding excessive use of different color paired glasses, and after your flying sessions with the glasses or whatever, let your eyes and brain rest for a while before starting to sew, chop meat, drive 160mph, dig the garden etc.
Anaglyph, that weird looking glasses...
As you might know or not, FlightGear migrated graphics functions from PLIB to OSG. FlightGear 1.9.0, released Decemeber 22, 2008, marked the release of the OSG version of FlightGear. As of August 2010, most recent stable version of Flightgear uses OSG. For those who are unaware of OSG, it is an open source high performance 3D graphics toolkit.
Stereo vision exploit the human perception by showing a 3-Dimensional image on a 2-Dimensional surface. To understand stereo vision and human judgement of visual distance (that is how we keep visual separation from the traffic), make the following small experiment. While reading this text, close your left eye and then right eye, open left. When you alternate your view, it'll feel like the monitor is moving to little left when you observe with right eye, and vice versa. This situation gives us two different images. Now imagine you took this two "slightly" different images and match it such that each eye sees what it is supposed to see. There are not so many but quite a few ways to achieve this separation. And OSG is capable of doing all of this. Now apply this to your short final 28R at KSFO!
How to multiply your realism level by 10
For this experience, you will need
- A working copy of FlightGear, of course.
- A pair of Red-Green or Red-Cyan pair of 3D glasses. You might have one at home or if you are a DIY type, check NASA way of doing glasses or Liquid Crystal Shutter Glasses and probably suitable hardware (anyone experienced with or owns one pair of this thing might help developing this page).
The easiest and shortest way for users of FlightGear up to version 2.0.0 to experiment with this is to follow the procedure below (quick start). Later versions (including GIT sources) have native support for setting the relevant properties at runtime from a dialog box at View->Stereoscopic View Options.
- FlightGear launcher
- Start the FlightGear launcher, select your aircraft and select your location.
- On the next screen, click "Advanced" just above the "Run" button.
- On the new window, titled "Advanced Options" highlight the "Environment" from the list on the left
- Now, you will create new environment variables, click "New" and type OSG_STEREO=ON, then again click "New". At this point you should be seeing "OSG_STEREO=ON" on environment list.
- The commands (including the one we just created) that you have to pass to OSG consist of:
The result should be something like shown on the right.
After you entered the last value, click "OK" to quit from the Advanced Options window. Remove your pilot raybans, put your fancy 3D glasses and click "Run".
- Command line
When launching FlightGear from the Command line, the environment variables should be set as follow, in the same Command Prompt window (same batch file if applicable) as the one used for FlightGear.
SET OSG_STEREO=ON SET OSG_STEREO_MODE=ANAGLYPHIC SET OSG_SCREEN_DISTANCE=0.7 SET OSG_EYE_SEPARATION=0.06 SET OSG_SCREEN_HEIGHT=0.19 SET OSG_SCREEN_WIDTH=0.33
Mac OS X
- In the Finder, select the menu item Go > Go to Folder... and enter "~/.MacOSX" without the quotes. You will go to a hidden folder in your user directory.
- You should see a file named "environment.plist". Open it in TextEdit.
- Between the <dict> and </dict> tags, add the following:
<key>OSG_EYE_SEPARATION</key> <real>0.065</real> <key>OSG_SCREEN_DISTANCE</key> <real>0.75</real> <key>OSG_STEREO</key> <string>ON</string> <key>OSG_STEREO_MODE</key> <string>ANAGLYPHIC</string>
Don't disturb anything else in there and save the file. Then log out (Shut Down and Start up, or Restart). Fire up Flightgear and be amazed.
If you don't see environment.plist, you'll need to create it. No problem, just open a new document in TextEdit (or another .xml editor e.g. Taco), enter these lines, and save as environment.plist:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>OSG_EYE_SEPARATION</key> <real>0.065</real> <key>OSG_SCREEN_DISTANCE</key> <real>1</real> <key>OSG_STEREO</key> <string>ON</string> <key>OSG_STEREO_MODE</key> <string>ANAGLYPHIC</string> </dict> </plist>
Tweaking The View/Stopping Nausea
A brief explanation of the values we gave for the environment variables goes like this. This info comes directly from the OSG Stereo Settings page.
OSG_STEREO=ON: is quiet self explanatory...We have to tell OSG to turn on the stereo rendering.
OSG_STEREO_MODE=ANAGLYPHIC: Well, the fanciness level starts here...In our relatively cheap case, we chose anaglyph rendering since we only had red-green or red-cyan glasses to see...So we tell OSG to fit our budget by rendering the scene according to ANAGLYPH method. But on the other hand, OSG provides not only ANAGLYPH (as default), it supplies its user with a wide variety of stereo render options.(Don't get scared by the frame rates shown on the screenshots, enabling stereo view didn't effected the framerates of the old laptop the screenshots were taken).These are;
- ANAGLYPH Use anaglyphic stereo when in stereo (default) (See green-red filtered images).
- QUAD_BUFFER Use quad buffered stereo when in stereo.
- HORIZONTAL_SPLIT Use horizontal split stereo mode when in stereo Starting,Running!, External Stereo View
- VERTICAL_SPLIT Use vertical split stereo mode when in stereo Vertical Separation Cockpit and External View
(Any practical application sample of Vertical Split?)
To understand the red-green images, one can carefully inspect especially the horizontally separated images. If you carefully look at this image, note how the runway markings are appearing in a different perspective in left and right images. This is an exact (but not working in this case) copy of "cross eyed 3D" pictures.What OSG does when you tell to enable the Anaglyph instead of this horizontal stereo, it applies color filters that exactly (not at practice sometimes, within color bandwidth limits) matches with your green and red filters on your glasses. Then it overlaps these filtered images and displays as a single image. Then, your left eye, with a green filter, filters the green image and sees the reddish image and vice versa for the right eye. Thus, giving each eye what they should be seeing in a real cockpit is also assembled by our brain, and perceived as a 3D environment. A small reminder about the Quad Buffered Stereo. It should only be enabled when you have a proper hardware, such as liquid crystal shutter glasses. The author attempted enabling this command on a laptop, resulting in bunch of error log in FlightGear console window and application hang.
OSG_SCREEN_DISTANCE=0.95: is the "distance" to your very own screen in metrics. For a good practice, you'd better measure this distance to your screen and not to make it 0.2 meters or 14.3 meters , since the first one is dangerous to your health and latter one to your flight profile. For multiple display, the measurements (should?) be from your viewpoint to the monitor surface. Contributes to the feeling of the depth on your screen.
OSG_EYE_SEPARATION=0.06: Eye seperation...Funny but is the actual distance between two pupils of your eyes. Measure but don't pop them out for a precision measure with a caliper. Makes significant contributions to the realism of the simulator. Generally 5 to 7 cm (0.05 to 0.07 meters). For imperial units convert 1 inch=25.4mm, 1 meter=3.280 ft.
OSG_SCREEN_HEIGHT=0.19: Is another basic measure. You can omit this and OSG will assign a default value, but of course, every monitor might be slightly different then the rest. This is the actual height of the visible image size on your screen.
OSG_SCREEN_WIDTH=0.33: Similar to the height. If you are really lazy to measure your screen dimensions or stuck in the middle of a desert with a laptop and internet connection, but no ruler and you don't have any idea of your handspan, here's another unlimited service from FlightGear!
|(in)||(cm)||w (cm)||h (cm)||w (cm)||h (cm)|
Eye Separation and Horizontal Distance
The very final part of the OSG stereo view options consists of few variables that accommodate the device specific issues and finally allows you to set straight look or cross-eyed look (not advised) options. OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION: variable adjusts the distance between two horizontally separated view-ports (e.g. right/left screens). If not specified in the environment variables with the OSG_STEREO_MODE=HORIZONTAL_SPLIT set, it takes its default 42 pixels value. This value is probably specific to the 3D LCD glasses (like tiny screens in front of your eyes), to adjust the distances between two images.
OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING: While OSG_STEREO_MODE=HORIZONTAL_SPLIT is set, it can take variables such as LEFT_EYE_LEFT_VIEWPORT or LEFT_EYE_RIGHT_VIEWPORT. LEFT_EYE_LEFT_VIEWPORT obviously set the left eye to render to left viewport, right eye to right viewport as a default if not set in Environment. On the other hand LEFT_EYE_RIGHT_VIEWPORT set the left eye to render to right viewport, right eye to left viewport (kind of cross eyed or again, device specific).
OSG_SPLIT_STEREO_VERTICAL_SEPARATION: theoretically does the same thing as horizontal separation but showing images up/down as opposed to left/right. It can take values similar to HORIZONTAL_SEPARATION in pixels.
OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING works the same way as horizontal mapping, displaying upper and lower images respectively. The string variables are LEFT_EYE_TOP_VIEWPORT and LEFT_EYE_BOTTOM_VIEWPORT, which are quiet self-explanatory.