Depth of Field

Another distributed ray tracing effect added to our project is the implementation of a finite depth-of-field. In order to properly parametrize this setting, a new command was added to the parser.

dof focal_distance aperture_size sample_rays

The three parameters are a floating-point distance to the focal plane, a floating point “aperture size”, which is the scale factor for the blur in the lens plane, and an integer number of sample rays to generate per pixel.

The fundamental principle works by superposing many images, as with a true camera. The process begins with the generation of the original ray (per pixel or sub-pixel). The point that the original ray will arrive at after traveling to the focal plane is calculated. Then, a number of stochastic rays are generated for that pixel; the degree of sampling comes from number of rays specified for “sample_rays.”

For each sample ray, the position is translated along the direction of the ray to the lens plane, which is (center – eye) away. Then, the position is perturbed according to a random distribution in the lens plane (the basis vectors of which are stored in the ray generator) that is scaled by the aperture size parameter. Finally, this ray has its direction adjusted so it will reach its original aim point.

Interesting images can be obtained with some manipulation of the parameters.

Aperture size 0.2, focal plane at 0.5, 128 rays per pixel

Aperture size 0.2, focal plane at 0.5, 128 rays per pixel

Aperture size 0.2, focal plane at 0.5, 256 rays per pixel

Aperture size 0.2, focal plane at 0.5, 256 rays per pixel

Aperture 0.35, focal plane at 0.5, 256 rays per pixel

Aperture 0.35, focal plane at 0.5, 256 rays per pixel

Distant background sphere

Distant background sphere