BootCamp: Depth of Field

By Luna Jubilee  //  BootCamp  //  5 Comments

A day or two ago, Express plurked about a commit to the Mesh viewer related to Depth of Field. He was really excited about it, but I didn’t really pay attention to him because he has a habit of geeking about the silliest things.

Unsurprisingly, he did a little more research on his own and suggested we put together a tutorial related to depth of field. Since he did all the hard work himself, I told him I’d post whatever he wrote about it:


First off, what is depth of field?

It’s the portion of an image that is sharp (“in focus”) for any given picture. When a lens focuses on a specific distance, only items at exactly that distance are truly in focus. Everything else around it is technically out of focus, but some other distances may still be reasonably sharp. If that range of distances is small, the image has a small depth of field. If the range is large, the image has a large depth of field.

Another way to think about it is that a large depth of field means most of picture is in focus, while a small depth of field means only the subject is in focus, leaving the rest blurry. Look at the following two examples, cropped from two shots inworld.

Bootcamp: Depth Of Field - F-number

Both are focused on the spray can, but the left image begins to go out of focus before reaching the back of the table. The right image has a much large depth of field, and thus does not blur until much farther back.


Simply put, the DoF feature adds a lens blur to SL, as if using a real camera. It’s probably most useful for machinima, where you can’t just take images into Photoshop and blur there.

One of the funny things that happens with new features is that people tend to futz with sliders and turn on the things that “sound good”. Unfortunately, this can lead to the spread of misinformation. For example, how many tutorials have you seen that tell you to enable “high res snapshots” and then also tell you to choose a custom snapshot size via the snapshot dialog? If you’ve read our last boot camp tutorial, you’d know that the “high resolution snapshot” setting applies only when using the “snapshot to disk” shortcut and does nothing when using the snapshot dialog. While it doesn’t hurt to have the setting on, it doesn’t make your snapshots via dialog any better either.

So, in an effort to get in before any misinformation spreads, I wanted to dig through the new depth of field feature and share what I figure out.


I actually plurked the commit after seeing it on Torley’s twitter. The commit is for the Mesh viewer, so it looked like I’d need to log into the beta grid with the Mesh preview to play with it. I was pleasantly surprised to find out that KirstenLee Cinquetti’s latest S20 build, S20(42) actually has the feature, ready and usable on the main grid (at least for Windows). I saw build 43 for Linux available, which might have this too, but the latest OS X build as of writing was only 41.

Kirsten’s viewer makes it very easy to access experimental viewer features, like shadows and depth of field. They’re all visible via the advanced tab of Graphics preferences. Turning on lighting and shadows automatically turns on depth of field, and there doesn’t seem to be a way to turn of DoF and leave only shadows yet. Either way, the DoF settings are currently on the Misc. tab at the end.

There are three variables:

Camera f-number value for DoF effect
Camera focal length for DoF effect (in millimeters)
Camera circle of confusion for DoF effect (in millimeters)

The descriptions of the settings are taken from commit, and didn’t seem to be visible under the Graphics tab in Kirsten’s viewer. However, if you look up the debug settings, you can see them in the debug settings dialog too.

What Do They Mean?

If you know your way around an SLR, some of these settings will probably be familiar to you. Unsurprisingly, the settings are basically the same as their real life counter parts.


For cameras, the f-number (N) is the ratio of the focal length (f) to the lens aperture diameter (D). In math terms:

N = f/D

When you choose the aperture on a camera, you usually are not choosing a diameter in millimeters but instead choose are choosing an “f-stop”, written as f/N (e.g, f/5.6 or f/8). Surprise, surprise, that comes from reworking the formula above to D = f/N. The aperture of the lens changes to to match the new f-number. In the case of f/8, that means N=8 and that the focal distance is 8 times the aperture diameter.

In SL, we don’t really have a lens (if anything, the entire window is our lens) so it’s a bit harder to determine how changing to a specific f-number directly affects the image. However, the following rule from RL camera work does apply:

Increasing the f-number increases the depth of field

The only difference between the two images above is the CameraFNumber value. The blurry one was shot with CameraFNumber = 0.1, creating the short depth of field. The other was shot with CameraFNumber = 90.

Focal Length

The focal length is the distance at which a lens is able to focus light. A shorter focal length means that a lens is able to bend rays more strongly. This allows for a wider angle in a given shot, and is the basis for wide-angle lenses. The same bending is creates the “fish-eye” distortion at the edge of such images as well. A longer focal length allows for greater magnification at a distance, but comes with the penalty of a smaller angle of view (as in the case of a “telephoto lenses” or any telescope).

If my subject is close to me, I’d use a smaller focal length like in the macro shot below (shot with N=2.8 and f=10). It’s worth noting that focal length is measured in millimeters, not meters. So 10mm is 0.01m, which s the smallest value you can assign for a prim dimension.

Bootcamp: Depth of Field - Macro Shot

Conversely, if the the subject is far away, I’d use a larger focal length instead.

So what does this mean for depth of field? Well, I’ve noticed that wide angle lenses have a greater depth of field than telephoto lenses, so I’m guessing a shorter focal length can increase the depth of field.

However, for use in SL, I’ve found that understanding “Hyperfocal Photography” helped me truly take advantage of the focal length.

Hyperfocal Distance

The “hyperfocal distance” is the distance at which you have focus a lens in order to achieve the maximum depth of field. When a lens is focused at the hyperfocal distance, any objects between half of the hyperfocal distance out to infinity will be acceptably sharp.

The formula for hyperfocal distance is

H = f^2/Nc

where f is focal length and N is the f-number like above, and c is the (surprise surprise) circle of confusion. We’ll get to c later.

Bootcamp: Depth of Field - Hyperfocal Distance

This shot of the spray can is a little farther back from the macro shot above, but still using the same settings (f=10, N=2.8, c=0.05). Plugging those into the formula says that if I’m 15.68 cm away from the can, I can get the can and everything in the background in reasonable focus. The one thing to notice is that we’re trying to maximize average sharpness throughout the image, so neither the foreground nor the background are perfectly sharp unlike the previous image.

The “magic” of hyperfocal distances comes from what happens when you focus at distance shorter than the actual hyperfocal distance. When the you focus at H, the range from H/2 to infinity is “in focus”. When you focus at H/2, the range from H/3 to H is in acceptable focus. Focus at H/3, the range is H/4 to H/2, on and on. So if you want a certain depth of field at a distance, you can use the formula to work backwards to a divider and ultimately a focal distance.

A little warning: what will follow is a bunch of math. If you need some help with the terms and equations, I suggest looking at this Math blog. I’m going highlight the important functions so you don’t have to do as much. To make this example a little easier, I’ll work with an example photo as well. This shot is of a house around 100m away from me, without shadows turned on so DoF hasn’t kicked in.

Bootcamp: Depth of Field - Hyperfocal Magic Before

Lets say d is the distance between me and subject, w is the depth of field, and m is the factor we divide our hyperfocal distance H by. For the example shot, I want a short depth of field 10 meters wide and my subject is 100 meters away from me. That means d = 100 meters and w = 10 meters, now I need to find m.

The two equations are:

H/m = d and H/(m-1) – H/(m+1) = w

A little bit of algebra puts us at:

H = dm and H = w(m^2 – 1)/2

You can plug your values into this link at Wolfram Alpha to find out that m = 20.04.

Or, you can just fudge it (by saying that m^2 – 1 is basically the same as m^2). This gives us the handy dandy formula:

m = 2d/w

In words, we need to divide the hyperfocal distance by twice the ratio of the subject distance to the depth of field. Using our numbers above gives us m = 20, which is close enough the actual 20.04 above. From that we get that H = 100 * 20 = 2000 meters = 2,000,000 millimeters.

This all goes back into the original hyperfocal distance formula, which we can solve for f. I used relatively easy N and c values to make the math even easier (N = 0.1 and c = 0.01).

H * N * c = f^2

simplifies to

f^2 = 2000

From which I get f = 44.72. If your values aren’t as simple, here’s another Wolfram Alpha formula that you can plug your numbers into. SL rounded that up to 45, and voila, I’ve got a picture of a house 100 meters away from me with a 10 meter depth of field around the house (notice the hay bales).

Bootcamp: Depth of Field - Hyperfocal Magic After

One thing to note is that fudge above works better with higher values of m. If your divisor is small, the approximated focal length might be not quite right. You could fudge it or just use Wolfram Alpha. If you’d like to get even more technical (and have more flexibility), there are a lot more formulas on the Depth of Field wikipedia page, which you can use with Wolfram Alpha as well.

Circle of Confusion

So you might be wondering what the circle of confusion (CoC) is all about. The definition of hyperfocal distance ends with the phrase “acceptably sharp”. Who determines what is acceptable?

That’s what CoC is for. As the wikipedia article puts it, it’s the “largest blur spot that will still be perceived by the human eye as a point”. That really depends on what size the final shot is displayed at though (the size of the print and how far away the viewer is).

I tried to see if making the CoC larger would let me take larger snapshots with DoF, but this didn’t seem to be the case. However, DoF and Kirsten’s implementation are both experimental and this setting might be the key to taking larger DoF photos down the road.

In theory, however, a lower CoC shrinks the depth of field by shrinking the range in which objects are “acceptably sharp.”

When I raised the CoC in the macro shot above to 0.5 (instead of 0.05), the background actually ended up looking similar to the hyperfocal shot. I didn’t include the image in this tutorial to avoid confusion. However, if you’re taking a shot and you find portions of your subject are a little blurry, you can bump CoC up a bit to make that go away.

Is it Over?

The last thing I wanted to mention was that anti-aliasing with depth of field (or possibly just with shadows) does not seem to work in Kirsten’s S20 (42). Unfortunately, I found out that attempting to compensate for lack of AA with size ends up weakening the DoF affect in the snapshot. As mentioned above, trying to use CoC to compensate didn’t seem to work either. As a result, I took all the pictures in this tutorial at 1600×1200 or smaller, basically 1:1 with what I see in the viewer.

Also, while I was trying to find Torley’s tumblr post, I came across the Depth of Field page on the SL wiki. It contains some of the information mentioned here as well as some video tutorials and other links.

I’m hoping this guide will help people make better sense of the new depth of field settings. Feel free to leave questions in the comments and I’ll try to answer them to the best of my knowledge.

Happy shooting.

– Express

P.S. All of the shots in this tutorial were taken at A.M. Radio’s amazing installation Surface, at IDIA Laboratories (137,110,2058)</a.

5 Comments to “BootCamp: Depth of Field”

  • I saw this the other day on Kirsten’s blog and got terribly excited and confused at the same time. This is amazing and I hope to try it out soon. Thank you both!

  • Hi Cerrie – I was confused at first too. After Express wrote this, I followed along step by step and got really nice photos. Hopefully this write up will help you too. If not, you can always reach out to Express to get your questions answered. He’s a great teacher! <3

  • […] tutorial.For other photography related questions like how to take high-resolution photos or depth of field, check out my Blog Boot Camp. Its full of different tutorials for bloggers and photographers.Also, […]

  • […] the beta SL viewer’s Depth of Field. A few months back I did a Blog Boot Camp tutorial on this topic for another viewer. I like how these pictures turned […]

  • […] also JUST learned that Luna Jubilee did a DOF Tutorial as well. Now that you’ve read mine, go read hers as it’s probably better! Share […]

Leave a comment


Enter your email address to subscribe to and receive notifications of new posts by email.


Roy Tanck's Flickr Widget requires Flash Player 9 or better.

Get this widget at