Depth of Field

Effect of the Feature

The depth-of-field feature simulates the effect of a non-infinitesimal small aperture of a camera. This leads to an effect that blurs objects both before and after the focal point. To demonstrate and validate the effect of the feature, we create a new scene with a different objects at different distances from the camera. We place one of the objects exactly at the distance of the set focus distance, such that it should appear in focus (unless specified otherwise). In our case, this is the purple cone, prominently visible in the middle of the scene. For the example scene, we include environment map lighting which has been implemented as part of the environment map feature.

Disabled Enabled

Technical Implementation

The technical implementation of the feature is relatively simple. The sampleRay method of the perspective does already come with a apertureSample which can be converted to a point on the aperture using Warp::squareToUniformDisk, multiplied by our apertureRadius. Instead of shooting the ray from the (0,0,0) point, we now use this sampled point on the origin to shoot a ray. The direction of the ray is now towards the focal point for the given ray. The focal point is the point that lies in distance focalDistance in the direction of the original ray. Using this sampling procedure, we now get realistic depth-of-field.

Validation

We compare our depth-of-field implementation against the same feature in PBRT-v3. For validation, we use again the test scene described above. We perform three different comparisons, with 128 samples per pixel for both PBRT and our Nori-implementation. The rendering resolution is 1024x1024 and all Nori-parameters are matched as closely as possible using their PBRT-equivalents. The field of view is 65mm for all images. To reproduce the results, please use the following two files with the corresponding parameters changed:

  • Nori: cg-project-2022/nori/verification/dof/doftest/dof_testscene.xml
  • PBRT: cg-project-2022/nori/verification/dof/doftest/dof_testscene.pbrt

Comparison 1

  • Focal distance: 45 m
  • Aperture diameter: 0.2 mm
PBRT Mine (Nori)

Comparison 2

  • Focal distance: 45 m
  • Aperture diameter: 0.05 mm
PBRT Mine (Nori)

Comparison 3

  • Focal distance: 15 m
  • Aperture diameter: 0.2 mm
PBRT Mine (Nori)

Conclusion: All renders are matching closely. There is slightly more noise in our version, but nothing of concern. The results for the two different parameters match closely and we see the feature as validated.

Code Coordinates

The feature is purely implemented in the file src/perspective.cpp in the second half. It can be used using the keyword dofcamera in the XML-scene description (i.e. <camera type="dofcamera">).