Focal Blur

Focal blur helps bring the viewer’s attention to the subject of the image by making it appear sharply in focus. Objects that are too far from—or too near to—the camera will appear out of focus. Here’s an example:

images/next/focal-blur.png

The focus here is on the three balls in the foreground; the smaller balls in the background and the reflections on the walls are blurred to emphasize their distance and lack of importance.

To make this work, you need to simulate a camera with a larger aperture—the hole through which light enters the camera. By default, your ray tracer mimics a pinhole camera, with a hole exactly large enough for a single ray of light. This allows the entire scene to appear crisply in focus. By making the aperture larger, light can arrive from multiple points at once, blurring the picture at those places.

To implement this you need to specify the size of the aperture and the focal length of the camera. Anything situated at the camera’s focal length will be in focus, so you generally put the subject of the picture there. And the wider the aperture, the blurrier things get.

In Implementing a Camera, you set your canvas 1 unit in front of the camera. This effectively hard-coded your focal length to 1. Changing the focal length basically positions your canvas that distance from the camera. Once you’ve got your canvas situated, you cast multiple rays for each pixel, and the more, the better. Instead of casting them all from a single point at the origin, you’ll place your aperture at the origin and choose several points on its surface. Then, for each of those points, construct a ray that passes from the point through the current pixel on the canvas and out into the scene. Average the colors for each of the rays you cast per pixel, and there’s your focal blur!

We can summarize:

  1. Choose a size for the aperture.
  2. Choose a distance for the canvas.
  3. Cast multiple rays from random points on the aperture, through the pixel on the canvas.
  4. Set the pixel to the average of all rays cast through it.

Casting multiple rays per pixel like this is computationally expensive, though, working a lot harder for each pixel. Still, it’s a versatile technique that can create a variety of effects. Read on for another one!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.230.107