Z-Buffer based Depth Of Field Simulation

This is my first attempt to simulate depth of field by postprocessing a 3D scene. The further an object is away from the camera the blurrier it gets. In theory you just use a gaussian blur algortihm and vary its radius based on the z-buffer data. Unfortunately this does not work as it will cause "bleeding": objects that lie further in the background will pick up the colors of objects in the foreground - this does not happen in reality. It will also create an aura around objects that are completely sharp - because the background that lies in inifinty will grab also the color of these objects.

I've tried to circumvent these side-effects in this version by using a function checks the surrounding area of every pixel for objects that are closer to the camera. Well, this doesn't make this demo any faster - as you see even in this size it's quite slow. But for rendering to disk it could be an option.

Built with Processing

Depth Of Field Sourcecode