Yesterday I read a
post on mashable.com about YouTube's new 3D video feature
and I read about all the new 3D technologies that were in CES 2010, so I
decided I should try implementing something like this on XNA.
Ofcourse the easiest way to display 3D images is using the
cross-eyed stereoscopic approach where the output is 2 images displayed side by side
and you cross your eyes so that your right eye sees tha left image and your
left eye sees the right image, so you see a 3D image floating between your
eyes and your screen as a result of these 2 images combined and interpreted
by your brain.
To be able to do this in XNA, I used 2 cameras for my scene instead of one,
both looking at the same point but their positions are slightly different,
there is an angle of 0.08 radians between the 2 cameras, then I rendered the
scene twice (once for each camera) and took the output of each and displayed
them side by side, and the result was Great !
The only problem is that it's not easy for everybody to cross their eyes and
it's quite tiring for the eyes, so I decided to implement another way for
displaying 3D images, I chose the Red-Cyan Anaglyph approach were the output
is an image with some parts tinted in Red or Cyan and you wear special 3D
Glasses where (usually) the left eye is covered with a red filter and the
right eye covered with a cyan filter, and when you look at the image with
these color filtering glasses you see a 3D image parts of it appear to pop
out of the screen and others appear to be behind the screen.
To implement this I made some research to know how exactly the 2 images are
filtered and how they are blended together, I kept reading stuff from
Wikipedia and
other
places then try to impement them on XNA until it was 5am when I was
finally able to get the required output, I put on the 3D glasses (actually I
used 2 light filters infront of my eyes cause I don't have the glasses, but
it's the same thing) and I saw a satisfying 3D result !
The only problem is, sometimes the colors of the 3D result of a Red-Cyan
Anaglyph looks messed up, that's because your left eye sees only the Red
Component of the light coming from your screen and the right eye sees only
the Green and Blue Components, and your brain tries hard to combine these
components to get the color, but for some colors it's just too hard for your
brain to interpret from their components, so the result are far from
perfect.
Why didn't I implement other better ways, like the one used in the 3D
version of the movie "Avatar", simply because they require psecial hardware,
for example "Avatar" in 3D was made with a polarization approach were the 2
images are displayed from 2 different cinema projectors, one emits
horizontally polarized light and the other vertically polarized light, and
the 3D glasses you wear are made in such a way that each side filters
polarization and permits the other so your eyes see 2 different images
without any color filtering.
Ofcourse this approach is impossible to implement on the PC since I have no
control over the polarization of the light coming from my computer screen, I
even discovered that my laptop screen already emits polarized light, I put
on the glasses I got when I watched "Avatar" and I saw the laptop screen
with only one eye, the other just sees black !
The only way to get very nice 3D images from your computer is to use
NVIDIA's new technology it showed off at CES 2010, but it requires a special
Graphics card and a screen with a very high refresh rate and special (and
expensive) glasses that you connect to the Graphics card, so lets' just hope
that it gets popular, cheaper and available to everybody soon :)
Click on the image in this post to enlarge it, it's a screenshot of the
Red-Cyan Anaglyph output, if you have a Red-Cyan 3D glass, put them on and
look at the enlarged picture.
You can find below a link to a zip archive containing the XNA project that I
made.
NB: you can switch between Red-Cyan mode and Steroescopic mode by pressing
the space-bar.
If you just wanna run the sample without compiling any code, here's a zip
archive with only the exe, the 3D model and the XNA dlls, but you'll need
dotNet framework 3.5 to run it (I think it comes with Windows 7).