Anaglyphic 3D in GLSL

I’ve been playing around with getting some red/cyan stereoscopic 3D working of late, and it’s all turned out rather well – take a look… (Red/Blue or Red/Cyan glasses are required for the effect to work):

Anaglyphic 3D in GLSL
Click for bigger version.

If you’ve got suitable glasses you should definitely see a 3D effect, although I don’t think me rescaling the image has done it any favours – so click the image to see the full sized version for the full effect.

The trick to this has been to render the scene twice to two separate FBO textures, then sample from the left and right textures to draw a fullscreen quad with a combined version as follows:

In the code itself, the torus’ spin around on the spot and look pretty good, although there’s no anti-aliasing as yet as I need to create some multisample buffers instead of straight/normal buffers for the FBO, but it’s not decided to play ball just yet – not to worry though, the hard part’s done and I’m sure multisampling will be sorted in a day or so. After that, I might give ColorCode3D (TM)(R)(C)(Blah) a go, as it seems to give a better colour representation whilst still allowing the same amount of depth as traditional anaglyphic techniques. Also, I’ve got to start using asymmetric frustums for the projection to minimise the likelihood of eye-strain, but I don’t see that as being too much of a problem.

Good times! =D

10 thoughts on “Anaglyphic 3D in GLSL”

  1. After trying out various anaglyph glasses, I believe red-cyan are the best. Colorcode try to retain more color, but I find the extreme difference in brightness levels between the left and right eyes very tiring.

    1. I never had any ColorCode glasses to try it out with, although I did try with Green/Magenta TrioScopic glasses – and, well, it works – but I wouldn’t have been able to call one over the other, they were just different. Which reminds me that I should prolly post up a final multisampling buffer version with anaglyph cycling options… But regardless, I guess colour reproduction is always going to be dreadful with any anaglyphic method.

      Thanks for your anaglyph post, btw – I found it really useful in getting my own stuff up and running. Much appreciated.

    1. The non-anti-aliased code works fine so I could post that up, but the multisample buffer version complains at one point (even though it works and runs as expected) – lemme take a look this evening and I’ll post something up, even if it’s just the non-AA version.

      1. Alright – try this: ORIG-Anaglyphic-GLSL-with-AA.zip.

        It’s a Code::Blocks project and I’ve fixed it so that it doesn’t moan about allocating multisampled buffer storage – keys are W/A/S/D and mouse to move around and F1 to maximise/restore window size.You’ll also need red/cyan 3D glasses ;)

        This project is in desperate need of refactoring into classes – as it stands it’s all just mashed together so I could get something up and running in the quickest time possible. Unfortunately, I just don’t have the time to refactor it at the moment, but when/if I do I’ll post an updated version. Also, it doesn’t use asymmetric frustums so it’s quite likely to cause some eye-strain if used for long periods – so use at your own risk!

        The best thing to play around with is probably the eyeSeparation value defined on line 54 of main.cpp – larger values increase the separation to increase the 3D effect and make objects appear infront of the screen (up to a certain point where your brain just won’t gel the two images together anymore) , but even small values where the “front” is at the physical screen’s location look pretty good!

        Have fun…

  2. hey friend! I have a question… what are the combinations for the left and right frags if i want to make this work for:
    red/blue
    red/green
    as I can see, the one in your code works fine for red/cyan… but what about this other 2?
    sorry for my english, thak you.

    1. I’ve used the following for trioscopic 3D (green/magenta):

      And I believe the following will work for ColorCode 3D:

      There’s a good article which shows how do do all this and also remove/minimise the ghosting effect here:
      http://iaian7.com/quartz/AnaglyphCompositing.

Leave a Reply

Your email address will not be published.