Depth of Field

by Emily Guerra

Description


In photography, depth of field refers to the difference between the closest and farthest objects in view that appear sharp or in focus. Photographers can change their camera's aperture, or the opening that let's light in, to change the depth of field. A smaller f-stop means a larger opening for light, resulting in a shallower depth of field. "Bokeh" is the Japanese word for the blurred effects created when using a shallow depth of field.

Technology


To simulate depth of field I used the accumulation buffer in OpenGL. With the accumulation buffer you can draw a scene with slight alterations over itself multiple times. In this case, I essentially translated the components of my scene in a circle about their center points by changing eye location in my lookAt function. I calculated the radius of the bokeh based on the object's distance to my set look at point, using the camera's u axis and the upVector. In order to create a blurred effect, I changed the fragment buffer to make all of the shapes translucent, and implemented a single pass of a Gaussian blur to make the blending even smoother.

Controls


Viewers can look around and explore a scene filled with trees, bunnies, flowers, and grass, with mountains in the background. They can also use the keybaord to adjust the size of the bokeh in order to increase or decrease the amount of blurring.

The scene with no depth of field or blurring. Everything is sharp.

The scene with medium depth of field, showing a sharp tree in the foreground, a slightly blurred bunny in the middle ground, and a very blurred tree and flowers farther away.

The scene with an extremely large bokeh radius, showing how the depth of field blurring is taking place.

Issues


With this method, all of my objects are translucent and they must be manually ordered by depth. In the future I might try a different method instead.


References