Task 088: Depth of Field camera

Your task is to implement a Dept of Field camera (ray-generator) into our ray-tracer. You should emulate real camera lens with finite aperture - objects far from a focus plane should be blurred (see bokeh). Implementation approach is "distributed ray-tracing", you simply use more slightly different primary rays instead of the ideal one (as in the pinhole camera model).

DepthOfField extreme depth-of-field

Ideas

Extend the existing ray-tracing by a new camera (ray-generator) and use the builtin antialiasing-controlled sampling mechanism (see the global "thread-specific" variables MT.rank and MT.total). You have to reimplement a ray-generator (interface ICamera) able to jitter rays contributing to one pixel. You can also implement more interesting "blur effects", so called bokehs.

Simulating light rays outside of the camera is sufficient (rays starting from the lens surface), there is no need to simulate interior of the lens system or camera. See the WiKi page about DOF or a slideshow distributedrt.pdf or Diaphragm page.

Basis

Your solution can be based on the 048rtmontecarlo or 048rtmontecarlo-script project from the grcis repository.

Details

Ray generator should be extended for working in the internal sampling context: the anti-aliasing system acts as the primary sample generator. Every pixel has declared number of samples (primary rays) available in the static (thread-local) variable MT.total. Current sample number is available in MT.rank (0 <= MT.rank < MT.total).

You should choose resonable sampling method of the lens surface, e.g. some form of jittering or Mithell's algorithm. See the grcis-rt.pdf (Independent stratified sampling) for more details.
You can expect sufficient number of samples per pixel (MT.total).

What to modify

Extend the source file MonteCarloRT.cs by your own implementation of ray-generator (camera) - recommended inspiration comes from the StaticCamera class, you should especially modify the function bool GetRay ( double x, double y, out Vector3d p0, out Vector3d p1 ). Use your new camera into an apropriate RT scene definition (class CustomScene .. or in a CS-script).

You need to show ability of your implementation by setting reasonable camera parameters (aperture), more than one example will be appreciated. Your demo scenes should appear in the scene list-box (see the InitializeScenes() function .. or you should send more CS-scripts).

What to hand in

You must send the modified file MonteCarloRT.cs. You can include a couple of nice pictures.

In case you will be using 048rtmontecarlo-script project, you must include your scene definition[s] in separate file[s]. Script format: see the data/rtscenes/ directory in the repository.

Deadline

Hand in the assignment before: 1. 7. 2018

Points

Basis: 20 points (functional distribution of rays, reasonable demonstration in a 3D scene),
Bonus points: for more advanced effects on a diaphragm (bokeh), etc.

Project

Visual Studio project: 048rtmontecarlo or 048rtmontecarlo-script

Source file

Modify and hand in the source file: MonteCarloRT.cs
Edit your name in the InitializeScenes() function!
Don't forget the .cs script if you are defining your scene using CS-script.


Copyright (C) 2016-2018 J.Pelikán, last change: 2020-02-17 00:43:03 +0100 (Mon, 17 Feb 2020)