Author Topic: Anaglyphs  (Read 2735 times)

0 Members and 1 Guest are viewing this topic.

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
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).

 

Offline Aardwolf

  • 211
  • Posts: 16,384
    • Minecraft
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.
« Last Edit: June 29, 2008, 04:58:59 pm by Aardwolf »

 

Offline phreak

  • Gun Phreak
  • 211
  • -1
Can a mod please move this to the programming board?
Offically approved by Ebola Virus Man :wtf:
phreakscp - gtalk
phreak317#7583 - discord

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
he wants to put anaglyph stereo in freespace.

i have some edimensional glasses id rather use, but stupid nvidia wont release modern stereo drivers.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline phreak

  • Gun Phreak
  • 211
  • -1
what's an anaglyph?
Offically approved by Ebola Virus Man :wtf:
phreakscp - gtalk
phreak317#7583 - discord

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
thats stereoscopy with red/blue lenses.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Cobra

  • 212
  • Snake on a Cain
    • Minecraft
    • Skype
    • Steam
    • Twitter
Basically 3D support?
To consider the Earth as the only populated world in infinite space is as absurd as to assert that in an entire field of millet, only one grain will grow. - Metrodorus of Chios
I wept. Mysterious forces beyond my ken had reached into my beautiful mission and energized its pilots with inhuman bomb-firing abilities. I could only imagine the GTVA warriors giving a mighty KIAAIIIIIII shout as they worked their triggers, their biceps bulging with sinew after years of Ivan Drago-esque steroid therapy and weight training. - General Battuta

 

Offline Topgun

  • 210
Freespace 3d!!!!
too bad I don't have 3d glasses.

 

Offline Herra Tohtori

  • The Academic
  • 211
  • Bad command or file name
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.
There are three things that last forever: Abort, Retry, Fail - and the greatest of these is Fail.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
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.
-C

 
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.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
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.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Deimos

  • 23
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.

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
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.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN