Progress Report

Latest

PRIMITIVE Inverse Lighting

Ok, this is really cool! (This post is a bit technical, but I tried my best to make it accessible to everyone. If something is not clear, please post a question in the comments.)

The Problem

Unfortunately, the bald cap is wrinkling in most shots and has to be completely replaced with a cleaned up CG version. Here’s an example of the wrinkling:

We are going to track the head geometry (based on a 3D scan of Bill Oberst, Jr.) per frame relative to the camera. (The actual head tracking is done by a custom geometry tracker written especially for PRIMITIVE. I will describe it in a future post.) Here’s a screenshot of what the head tracking looks like in Maya:

So all we have do now is render out the clean CG bald cap and comp it over the original, right? Well, almost. Even though we have the camera and the head geometry, we still don’t know what the lighting is! In order to match the lighting in the original shot, I could take one of the following approaches:

  1. Match the lighting manually by placing lights around the CG bald cap and adjusting their colors. This would be a very labor intensive process.
  2. I actually took still Low Dynamic Range images of a chrome ball on the day of the shoot. Even though these are not true High Dynamic Range images, they could still be used for Image Based Lighting, especially if the clipped highlights are expanded. The only problem is that these images are now so far back in my pipeline that I would have to go digging through old hard drives to find them all. Boring.
  3. Write a tool which will estimate the lighting for me.

Guess which one I did?

Image Based Lighting

The tool I wrote is based around the idea of Image Based Lighting (IBL). For the uninitiated, here’s a very short explanation. IBL was introduced by my boss, Dr. Paul Debevec, in a Siggraph 98 paper called Rendering Synthetic Objects into Real Scenes. (I graduated high school that year!) The general idea is that if you’ve captured a High Dynamic Range panoramic environment of your scene, then you can use this environment as a spherical light source in an IBL capable renderer. Here’s an example environment (image from HDRLabs.com):

In IBL, we take this environment image and map it onto the inside of a giant sphere. We can then render objects placed inside this sphere using the environment map as a light source. Here’s an example of Bill’s head geometry lit by this environment:

You can actually see the blue light on his cheek coming from the TV screen.

Reflectance Fields

Reflectance fields were also introduced by Paul Debevec in a Siggraph 2000 paper called Acquiring the Reflectance Field of a Human Face. There’s an excellent explanation of reflectance fields in this short video:

http://people.ict.usc.edu/~debevec/Research/LS/debevec-imagebasedlighting-s2000.mov

The idea is that if you’ve captured or rendered your subject from all possible lighting directions, then it is possible to arbitrarily relight the subject by adding the images together in different proportions. In my case, the reflectance field (also known as a lighting basis) is one of the inputs to my program. I used a simple grid lighting basis, 16×8 pixels, for a total of 128 lighting conditions. Here’s the lighting basis I used:

 

I literally mapped this sequence of images onto a large sphere and rendered my object with IBL settings turned on in Mental Ray. Here’s the result:

As you can see, this produces 128 images, one image for each pixel in the 16×8 grid. Now let’s take our original environment of the room with the TV and scale it down to 16×8 pixels. Let’s call this the target lightmap.

Now let’s multiply each basis render with it’s corresponding pixel:

Now if we add up all these images together, we will get Bill’s face lit by the room’s environment. Simple, right? Let’s call this the target image:

Inverse Lighting

In the above case, the lighting (the image we called target lightmap) is known. But in the case of the bald cap, the lighting is unknown. Luckily, it is possible to reverse engineer the lighting through a process known as Inverse Lighting. Here’s a good paper about Inverse Lighting:

http://graphics.stanford.edu/~srm/publications/CIC97-invlig.pdf

My tool is simply an implementation of this paper in Python/Numpy. The tool takes as input the target image and the 128 basis renders. Assuming that the lighting in the target image can be reproduced by some combination of the basis images added together in different proportions, all we need to know is what those proportions are. The proportions (coefficients) are, in fact, the colors of the pixels in the estimated lightmap! My tool solves the coefficients (per channel) using a least squares solver and outputs an estimated lightmap, like this one:

As you can see, this lightmap is very close to our target lightmap, especially in areas where we have data, like the front of the face. Areas where we don’t have any data, like the back of the head, are not close, but that doesn’t matter because we will only be rendering from one point of view!

Now let’s compare the original target image rendered by the known ground truth target lightmap:

With the result image rendered by the estimated lightmap produced by my tool:

As you can see, they are almost identical!

Now of course, this test data set is synthetic and therefore these results are ideal. In the real world case of the bald cap there will be error. For example, the target image will be a still of the bald cap (masked out of course) and the 128 basis renders will be of the CG bald cap, which may not be the exact same shape or color as Bill’s head. This will introduce some error, but we can be confident that the tool will produce the best possible lightmap approximation while trying to minimize the error.

So in summary, I just saved myself countless hours of work, if I were to try matching the lighting manually. I’m considering selling this tool. If you’re interested, please contact me.

I’m not sure if this will impress Paul Debevec. But considering that I failed Algebra twice, this will impress my mom. :)

PRIMITIVE Progress

I know it’s been ages since I’ve posted anything about PRIMITIVE. But that’s because I’ve been too busy making progress! In the past 6 months I’ve completed two critical milestones:

  • I fixed most of the vertical parallax issues in my stereo footage.
  • I finished the alpha cleanup on all the shots.

Vertical Parallax Fix

You may remember that PRIMITIVE was shot with the wrong beam splitter rig. This was my fault. I originally bought the cheaper version of the beam splitter rig from 3dfilmfactory, because I never imagined that I could later afford shooting with 2 RED cameras. The beam splitter rig that I got was never designed to hold 2 REDs, but somehow my DP managed to shove 2 REDs in there anyway. The result was a vertically misaligned 3D camera. So, I knew going in that I was gonna have vertical parallax problems. What I didn’t know was how big a deal it would be to fix this in post.

Here’s an example shot with really severe vertical parallax problems. Not all shots were this bad. The red lines connect corresponding points in the left and right images. Ideally, these lines are supposed to be completely horizontal. Notice that the problem can’t be fixed with a simple 2D shift because the vertical parallax is different for points close to the camera and points far from the camera. Looking at this image in 3D would give you a major headache because in order to achieve stereopsis your eyes would have to diverge vertically!

Here is the same shot with my vertical parallax fix applied. Notice how the same lines are almost horizontal now, which means that viewing this shot in 3D will be a pleasant experience.

So how does it work? Well, I tried several different “obvious” approaches, all of which failed. I became discouraged by the possibility that I would have to fall back to making the film in 2D. Then I said: “Let me try one last thing. If this doesn’t work, nothing will.” The idea I came up with was to convert each frame of the film into a low res 3D scan, like an animated “rubber sheet”. Then rerender the left view from a corrected position. Here’s a screenshot revealing the magic trick.

I won’t go into the highly technical implementation details. Needless to say, it took me months to write the custom computer vision software required for this to work. Luckily, it did work and the film is still going forward in 3D! And by the way, lesson learned. Next time I’ll get it right in camera!

Alpha Cleanup

Whereas fixing the vertical parallax was a creative challenge, cleaning up the alpha channels was a monotonous, never-ending hell. The task was commonplace: isolate the subject from the background using a combination of chroma key, paint, and rotoscoping. Here’s an example shot.

And here is the cleaned up alpha channel. Having this alpha channel allows us to composite the kids over a new background, like a sky.

Most of the shots were easy because all I had to do was chroma key the blue screen. Sometimes the chroma key had a few holes in it which I filled with a paint brush. But sometimes there would be severe blue spill from the cliff onto the Neanderthal’s body. Or sometimes the Neanderthal’s fingers would go outside the blue screen. In such cases I had to resort to my new mortal enemy: rotoscoping. Here’s an example of a particularly evil roto shot. This shot alone took me weeks to complete.

The thing is, I fully anticipated having to do this kind of work even before shooting. But I highly underestimated how long roto actually takes. And I overestimated how much free help I would get from others. I ended up doing most of this work myself, with some help from two other people. So, another hard lesson learned: next time allocate money in the budget for roto! In fact, I would recommend this to any independent filmmaker: Allocate money in the budget for all non-creative tasks. I’m just glad it’s over.

Next Steps

The next steps are as follows:

  • 3D track the Neanderthal’s head geometry. This will allow us to warp Bill Oberst’s head to Neanderthal proportions. This head warping effect will be what makes or breaks this film, and it could still go either way! We’ve developed a badass custom pipeline for the head tracking and I can’t wait to use it.
  • Fix the bald cap wrinkling issues. The head tracking will help with that, too.
  • Model, animate, and render props, like the nest and a more menacing branch.
  • Finish 3D environments. This is already progressing nicely.
  • Finish sound design. Can be completed in parallel with the VFX work.
  • Composite all the elements!
It’s clear that I will not finish all this work by the end of 2011, like I originally wanted to. But I can finally see the light at the end of the tunnel. It may be just a speck, but it’s there.

Games with a Purpose

Don’t miss this excellent lecture about human computation by Luis Von Ahn! You can also play the games here. ESP game is my favorite :)

 

PRIMITIVE ADR

This weekend we recorded all the ADR (automated dialog replacement) for PRIMITIVE. The recording took place in the spacious sound studio at Puget Sound, owned by supervising sound editor, Joe Milner. We recorded all 3 actors in one day: Bill Oberst Jr. in the morning and the boys, Brendon Eggertsen and Christopher Mastandrea, in the afternoon. The material has now been sent to my very talented sound designer, Ken Showler, who will edit the ADR.

This was my first ADR session as a director and I learned a lot! Big thanks to everyone who made this session possible!

PRIMITIVE Environments Progress

Check out the latest progress from Salvador Cueto, the Environment Lead on PRIMITIVE! From what I understand, there are several 4K textures on this model of the cliff. The grass is fur, I think. Rendered in Mental Ray.

History of Easter Island

Here’s a sobering System Dynamics lesson from history. Read it and weep.

http://www.hartford-hwp.com/archives/24/042.html

And here is a related TED talk on why societies collapse by Jared Diamond:

Related: Earth 2100. A possible near future featuring interviews with some very credible people. This show has high production value and is not what you might expect from a typical doomsday scenario show. It even offers a glimmer of hope at the end. Watch all 9 parts:

http://www.youtube.com/watch?v=bISCbOUozMk

PRIMITIVE 3D Monitor Setup

PRIMITIVE is a stereoscopic film. But up until now I haven’t been able to view any of my work in 3D. Sure, there’s anaglyph (red/cyan), but that’s bullshit. The mirror method is much better, but a bit awkward. So, after much research, I finally invested in my 3D monitor setup.

  1. NVidia 3D Vision Kit. One pair of active shutter glasses and infrared emitter. $200.
  2. Samsung SyncMaster 2233RZ 120Hz LCD monitor. $200 on Ebay.
  3. Stereoscopic Player software. Free trial allows up to 5 minutes of playback at a time, which is long enough to check shots.

To check a shot in 3D, all you have to do is render out a jpg sequence in the over/under format, with the left view on top and the right view on the bottom. (The shot has already been converged, usually on the subject’s eyes.) Like this:

Then convert the jpg sequence into an avi using ffmpeg. Like this:

ffmpeg -i F:\SUNSET_0100_N\topBottom2048.%04d.jpg -y -qscale 1 -r 24 F:\SUNSET_0100_N\topBottom2048.avi

Finally, open the avi in the Stereoscopic Player, set the viewing method to NVIDIA 3D Vision, and go to full screen mode. Put on your 3D glasses and enjoy!

There are a couple of other nice things about this setup:

  • I can play any PC game in 3D! Nothing beats climbing the rooftops of Jerusalem in Assassin’s Creed in 3D.
  • The Stereoscopic Player supports the Fujifilm FinePix W1 MPO format, which means I can view all the pictures I’ve taken with the W1 in 3D.

So, after having seen my shots in 3D, do I still think it was worth the trouble to make PRIMITIVE in 3D? Fuck yeah!

PRIMITIVE Prop Scans

I’ve decided to 3D scan all my props during the Winter break. Like the big rock, the nest and egg, and the branch. I’ve set up a homemade 3D scanning pipeline using the Bundler Photogrammetry Package. (Watch the tutorial video on that page.)

http://blog.neonascent.net/archives/bundler-photogrammetry-package/

I’ve been getting some really great results so I’m excited to share the process with you! Let’s take the big rock scan as an example.

The beauty of this pipeline is that it doesn’t require any special hardware. If you have a camera, you have a 3D scanner. If your subject is static (such as a prop or a building), you only need one camera. If your subject is alive, you’ll need lots of cameras for simultaneous capture.

The idea of “structure from motion” is to take lots of pictures of your subject from many different angles. I found that for props it is easier to have a static camera on a tripod and rotate the object in front of a greenscreen, rather than move the camera around the object. Here are some of the pictures I took of the big rock. I took 108 pictures with flash using my Fujifilm FinePix W1. The W1 is perfect for this because each picture is actually 2 pictures with a parallax. The scan probably would have worked with less than a 108 images, but I found that it’s better to take lots of  images. Also, I found that for the entire object to be solved from all angles, it is a good idea to find a “path” from one camera to the next. In other words, random camera angles are not as good as planned/consistent/efficient ones.

I keyed out the greenscreen in Nuke and made the background black. One caveat when saving images out of Nuke is that it doesn’t preserve the Exif data, which is necessary for the next step. So I wrote a small Python script to copy the Exif data from the original images to the ones saved out of Nuke.

Now things get interesting. I ran the sparseRecon64.bat utility on all these images. This utility runs bundler.exe and solves a sparse point cloud of the automatically detected features and also solves the cameras. Only someone who has done image-based modeling manually (for example, manually clicking points in Autodesk ImageModeler) can appreciate how cool this step is. You can check the .ply file in MeshLab to make sure all cameras got solved.

Now things get even more exciting. After the sparse point cloud and cameras have been solved, I ran denseRecon.vbs. This compares each image with every other image pixel by pixel and generates a dense point cloud of the object! The dense reconstruction algorithm likes objects with lots of random texture (so the rock is perfect). It also doesn’t like really shiny objects because the highlights move from one image to the next.

In MeshLab, I used Poisson Surface Reconstruction to generate a mesh from the dense point cloud. Then I used Quadric Edge Collapse Decimation to reduce the poly count to 10,000 triangles.

Now we’ve got the geometry, and that’s how far the default Bundler Photogrammetry Package will take you. But what about the textures? Well, stay with me my friends, because I wrote a couple of MEL scripts to get high res textures onto the model. The first script I wrote imports the Bundler cameras and sparse point cloud into Maya. It also assigns the images as camera image planes. (Contact me, and I’ll probably give you this script.)

The second script projects the images from multiple cameras onto the model and automatically blends them into a single texture. (Contact me, and I’ll probably give you this script.) A UV set with non-overlapping UVs is required. (I just did a quick Unfold UVs in Maya.) I picked a subset of 6 cameras to project.

Here is what the texture looks like.

And here is a quick render of the rock with the texture applied as both diffuse and bump map. I think it looks pretty damn good considering I only spent about 2 hours on this scan, with NO manual work.

Finally, if you don’t like command line programs, I found this Bunder GUI. I haven’t tried it, but in theory it should get you pretty far. However, it’s not free, and certainly not as nuanced as my pipeline.

http://www.agisoft.ru/products/photoscan/standard/

(Arnold accent) Come on! Do it! Do it now! Try Bundler! Adjust the little rays of light!

Game Design with Will Wright

Another great talk by game designer Will Wright. Highly recommended. Almost 2 hours long!

And another talk about augmented reality!

More Will Wright talks here.