Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Aardwolf on June 29, 2008, 04:48:05 pm

Title: Anaglyphs
Post by: Aardwolf on June 29, 2008, 04:48:05 pm
Ok, I saw an interesting thread by some guy who was doing renders as anaglyphs and I tried it in my own game and it's pretty cool. I tried to code it in myself, but couldn't figure out how to do so, so I figured I should share:




OpenGL Pseudocode:

glColorMask(true, false, false, true); //red

Draw the scene with a camera off in one direction

glClear(GL_DEPTH_BUFFER_BIT);

glColorMask(false, true, true, true); //cyan

Draw the scene from the same distance in the opposite direction

glColorMask(true, true, true, true);

Draw 2D Hud stuff




In theory it should work. Make sure that the color buffer isn't cleared when drawing the scene from each camera (unless it turns out that that doesn't matter).
Title: Re: Anaglyphs
Post by: Aardwolf on June 29, 2008, 04:55:31 pm
I just discovered this algorithm may not work perfectly (I'm looking into a bug with my own game that uses this technique). I'm not saying it definitely doesn't work, just that something is wrong with my own project.

Edit: I figured out what was wrong. glClear(GL_DEPTH_BUFFER_BIT) only works when glDepthMask(true) is set.
Title: Re: Anaglyphs
Post by: phreak on June 29, 2008, 05:27:02 pm
Can a mod please move this to the programming board?
Title: Re: Anaglyphs
Post by: Nuke on June 29, 2008, 05:52:29 pm
he wants to put anaglyph stereo in freespace.

i have some edimensional glasses id rather use, but stupid nvidia wont release modern stereo drivers.
Title: Re: Anaglyphs
Post by: phreak on June 29, 2008, 07:19:10 pm
what's an anaglyph?
Title: Re: Anaglyphs
Post by: Nuke on June 30, 2008, 05:11:02 am
thats stereoscopy with red/blue lenses.
Title: Re: Anaglyphs
Post by: Cobra on June 30, 2008, 01:26:47 pm
Basically 3D support?
Title: Re: Anaglyphs
Post by: Topgun on June 30, 2008, 03:25:27 pm
Freespace 3d!!!!
too bad I don't have 3d glasses.
Title: Re: Anaglyphs
Post by: Herra Tohtori on June 30, 2008, 03:52:02 pm
Freespace 3d!!!!
too bad I don't have 3d glasses.

Anaglyph glasses aren't exactly hard to come by.

Also, for the record - if this kind of option is at some point included in the code, it should have user-adjustable lense hue settings, so that the user can look at what kind of glasses he possesses (red/blue, red/green, red/cyan perhaps most common) and input the colours for left and right lense accordingly.

Of course, anaglyphing the image basically makes it grayscale, but IMO it would be worth it.

Another interesting option is to have two windows rendered next to each other - one for left eyepoint, one for right eyepoint. It would only be somewhat feasible on widescreen displays, though, but it would offer 3D (for those who can look at the image cross-eyed for long enough) while preserving colours accurately.
Title: Re: Anaglyphs
Post by: WMCoolmon on July 01, 2008, 12:30:47 am
A feature that makes people look cross-eyed at the screen really doesn't seem like a good idea. First of all, it wouldn't be widely used, second of all, it shouldn't be widely used, unless I'm wrong in thinking that looking cross-eyed for a long time can cause eyestrain.
Title: Re: Anaglyphs
Post by: Darklord42 on July 01, 2008, 08:50:58 am
It doesn't make you look cross-eyed, but It does give you a bit of a headache after a bit.  I don't know if you ever played Trackmania Nations Forever (which is free) but that game has 3-d glasses support and adjustable stereography which is good as some settings are better for your glasses. But I can't really use it for all that long.
Title: Re: Anaglyphs
Post by: Nuke on July 01, 2008, 12:56:42 pm
ive played quake in stereo, its pretty nauseating. anaglyph is supported at the driver level on some versions of nvidia stereo drivers. unfortunately they haven't updated them in awhile so fat chance finding them for a new video card.
Title: Re: Anaglyphs
Post by: Deimos on July 02, 2008, 10:33:32 am
If you want to see how games look in anaglyph mode, do a search for IZ3D driver - it's a driver for a stereoscopic monitor (used with special polarized glasses), but it also supports anaglyph output mode and works with most direct3D programs (only some OpenGL software is supported). It should with most video cards, since it's independent from videocard driver and unlike nvidia implementation, it's actively developed.

Quote
Of course, anaglyphing the image basically makes it grayscale, but IMO it would be worth it.
Not necessarily - with only one color information missing from each eye, the brain is still able to reconstruct most color information. It takes a bit time to get used to but you can use anaglyph with color pictures. If you have some glasses around, have a look at this:
http://www.youtube.com/watch?v=PoBfGw7u_Gc
http://www.youtube.com/watch?v=dSJ4Rw4b_4I
The there are some problems with red and cyan objects - these are seen only by one eye, so they lack depth and generally look ugly ;) But if you wish to, you can enable a "optimized anaglyph" mode in the iz3d driver that will change picture colors a bit to prevent from displaying red or cyan objects (at the cost of all other colors looking a bit washed out).

Oh, and by the way, when using anaglyph glasses with a monitor, it helps to increase the brightness a bit.
Title: Re: Anaglyphs
Post by: Nuke on July 02, 2008, 06:00:14 pm
id use yellow-purple lenses myself. since neither are a primary color for an rgb color system. they would cause the least interruption to color information.

anyway i do own shudder glasses but ive never got them to work on anything but an antiquated computer. you got to crank up the brightness with any kind of glasses, mine are darker than some sun glasses. so they take out quite abit of the light. polarized lenses are the least dark, but are used to recieve both eye images at once.

anaglyph images are easy to make. render something from 2 different cameras which are right next to each other and pointed at the object. then put the images in photoshop. add a fill layer of a color close to first lens color, on top of the first image, and set its blend mode to multiply. then do the same thing with the other image (using the color for the other lens). flatten both images then cut one and place it as a new layer ontop of the other image. set opacity to 50. flatten again. now the image should pop out at you once your using the proper glasses.

for the same thing to work in freespace you need to alter the camera location possibly with scripting, alternating between two points essentially. then at the end of the render we need to multiply the whole frame buffer by our lens color. then just alternate eyes and colors each frame. doesnt sound complex but that doesnt mean its not.

i thought about trying to hack my 3dimentional glasses to flip when a little black or white square of the corner of the monitor changes color based on which eye to use, then do a scripted camera flip. all id need is to use an optical transistor or a photocell to pick up the color and send out an led blip every time the square changes color. so long as i use vsync it should work. the glasses just seem to detect a steady blip (i used an ir signal analyzer) and flip accordingly. usually the signals would be detected from the monitor cable, get processed and an attached led emitter would blink off the signal. shouldnt be hard to duplicate.