No announcement yet.

Cheap Anaglyph 3D

  • Filter
  • Time
  • Show
Clear All
new posts

    Cheap Anaglyph 3D

    Hello everyone,

    I have created a cheap analgyph 3D post processing effect for UDK.
    This effect will most likely not be of any value for the PC, as there are numerous 3D options available, but it might be of some use in iPhone development.
    I study Computer Sciences and one day I came across two students working on anaglyph 3D techniques in OpenGL/Cg, they told me they were somehow creating those images using only one scene render.
    I asked myself how they could have created that technique, so today I devoted myself to recreating this effect.

    First of all, for those of you interested in how you can create an anaglyph image (assuming the use of red/cyan glasses):
    1. You need two images, a normal image and a right-shifted image.
    2. Take the normal image and add full red to it.
    3. Take the right-shifted image and add full cyan (full green and full blue) to it.
    4. Multiply the two images.
    Formula: (img1's RGB + full R) * (img2's RGB + full G B)

    It's that easy. However, you can manipulate the images further to minimize some artifacts caused by this technique.

    Porting it to UDK:

    How do we make this effect cheap?
    Apply it after rendering as a post processing effect.

    How do we create the shifted image?
    Sample the SceneTexture again and shift it's UV values using the depth of the scene (via SceneDepth in the material editor).

    How do we put it all together?
    Apply the formula mentioned above.

    What does it look like?
    Well at first... it didn't look like anything because I forgot to normalize the SceneDepth. It didn't look any better afterwards, as the normalized SceneDepth didn't work out as I had planned.
    So I divided it by one percent of the MaxZ value, because I wanted the image to be shifted up to one percent of the screen. <-- Wrong explanation, I made an error when setting up the material, it's (SceneDepth / MaxZ) * 100.
    After that I added it to the UV coords and put that into the UV value of the second sample.
    Then it looked like this:

    I'll keep this updated, because I'm not entirely satisfied with it yet, so stay tuned.
    If I can find the time to do so, I'll quickly put a mutator together for UT3.

    A few notes:
    The effect is most convincing in small environments, the images are too wide apart when further away.
    This is effect is not entirely real anaglyphic 3D, it's quite convincing, but you'd need two seperate scene renders with a seperate right shifted camera to do the real thing. That's why there are some cases in which the effect fails to simulate it convincingly.
    Other than that it's quite convincing.

    Haha great job that looks good though, cant wait to see more : P


      Download available: (Compiled on UDK-2011-04)
      Wrapped a mutator around it, nothing else has changed since yesterday.
      I'm still bothered by the fact that normalizing didn't work, so I'll look into that.

      I think I somehow got my own wires crossed when setting up the material...
      Divide SceneDepth by MaxZ and multiply by 100. (lower values cause artifacts in the sky)
      Much cleaner and more understandable.


        One thing I forgot to mention by the way is that you may need to swap the red and cyan additions (annotated "Enhance <color>") for your type of glasses if you think the effect isn't as it should be or if you feel that the effect works correctly if you put on your glasses rotated 180 degrees.
        That said, the students whom I got this idea from published their paper a few days ago, so if you're looking for this kind of info, go ahead and look it up here
        under projects -> reprojection 3D

        A few things I noticed between my implementation and their implementation is that first of all their implementation goes beyond just Anaglyph imaging and contains many, many more features.
        Another thing is that instead of laying the focal point on the near plane they make it possible to shove it back and forth into the scene.

        Still, if you need it quick and (VERY) dirty or already in UDK, go ahead and use my implementation.