2.26.2010

Adding the 3rd D

before:

Now that you know how 3D works by reading the primer, I wanted to write a post about the technique we use to create the 3D images for Robots! in 3D. Click the jump to geek out over all the technical details of how we add the 3rd to Robots!


Most modern 3D images uses two cameras to capture two images of a three dimensional space (both real and digitally rendered). Robots however we are creating the 3D space completely from a 2D image. We do this by essentially breaking down our 2D image into elements and duplicating/manipulating each element to create a right and left image.

Our current pipeline is basically export Layer Comps from Photoshop and then do the final compositing and anaglyph effect in Shake. At first I built the shake networks by hand, which got very complicated as well as time consuming. I realized there was a good opportunity for some good old fashioned scripting.

The Basic Shake Network I needed to create looked like this:

Essentially each element (Leonard and the background) gets split into two Pans which offsets the element left and right. The left Pans are then put Over each other and the right Pans over each other. This creates the left and right images. These images are multiplied by cyan and red and then added to one another. The resulting image looks like:

 The simple example I showed above looks like this in shake code:

// Input nodes

LeftColor = Color(2100, 3150, 1, 0, 1, 1, 1, 0);
RightColor = Color(2100, 3150, 1, 1, 0, 0, 1, 0);
SFileInBG = SFileIn("//Thetreefort/Robotsin3D/comp/assets/0105/r3d_0105_panel5Farmhousefront.tif", 
    "Auto", 0, 0, "v1.1", "0", "");
SFileInLeonard = SFileIn("//Thetreefort/Robotsin3D/comp/assets/0105/r3d_0105_panel5Farmer.tif", 
    "Auto", 0, 0, "v1.1", "0", "");

// Processing nodes

PanBGLeft = Pan(SFileInBG, -PanBGRight.xPan, 0, 0, 0.5, 0);
PanBGRight = Pan(SFileInBG, 0, 20, 0, 0.5, 0);
PanLeonardLeft = Pan(SFileInLeonard, 0, 0, 0, 0.5, 0);
PanLeonardRight = Pan(SFileInLeonard, 0, 0, 0, 0.5, 0);
OverLeft = Over(PanLeonardLeft, PanBGLeft, 1, 0, 0);
OverRight = Over(PanLeonardRight, PanBGRight, 1, 0, 0);
IMultColorLeft = IMult(LeftColor, OverLeft, 1, 100, 0);
IMultColorRight = IMult(OverRight, RightColor, 1, 100, 0);
IAddLeftRight = IAdd(IMultColorLeft, IMultColorRight, 1, 100);

The 20 in PanBGRight is defines the depth for the 3D effect. The larger the number the further back in depth the object will appear, 0 is at the screen plane and negative numbers will make the object appear in front of the screen. 

So I wrote a tcl script that would generate a shake script that created the base network and grouped them. The script takes in an .r3d configuation file and a render directory and outputs a shake script. The .r3d configuration file defines the paths and orders of the input images as well as their depth (offset). It is a tab separated flat text file that looks like this:
r3d_0105_panel1SFX.tif        -3
r3d_0105_panel1Leaves.tif        -5
r3d_0105_panel1Border.tif        0
r3d_0105_panel1Windmill.tif        9
r3d_0105_panel1Truck.tif        8
r3d_0105_panel1House.tif        10
r3d_0105_panel1FGhills.tif        15
r3d_0105_panel1Fields.tif        20
r3d_0105_panel1Fartrees.tif        25
r3d_0105_panel1BG.tif                30

Currently we have to hand build these files which takes a bit of time but it's pretty much reordering a ls > file.r3d and adding the depth numbers. The resulting shake network still needs to be tweaked and manipulated for more complex 3D effects but it gives a clean network with all the objects put over each other with depth.

after

While there is definitely room for refinement with this system it does a pretty good job giving us a quick 3D image to work off of.

To see the results of this handy work don't forget to check out Robots! in 3D. A new page is released every friday so put on your 3D spex and enjoy!

No comments:

Post a Comment