Focal blur with the targa averager

(This text is also in the documentation of the program)

You can make also focal blur with the targa averager.

You may say "Hey! There is focal blur in povray already."
That's right. But you may have noticed that focal blurred images made with povray are grainy, with random and annoying noise, no matter how many blur samples you use. I don't know exactly why this happens, but I suppose that it's because povray shoots the blur samples at random, with different random values from pixel to pixel. This seems to produce that random noise.
The focal blurred images made by averaging are a lot smoother.
There is also another advantage of using the averager: with the focal blur of povray you can't turn antialiasing on. This results in sharp pixelation at the sharpest zone of the image (the focal_point). When you just average images there's no such limit.

Let's see an example:

Povray default focal blur, 100 blur samples Focal blur made by averaging 100 frames
[Image1] [Image2]
The two images look similar, but if you look closely (specially if you can view them at a low resolution like 640x480) you will see that the image at the left is grainy and noisy. There is also visible pixelation in the borders of the shadow of the chair in the middle of the image.

The big disadvantage of averaging images is the big calculation time. You need lots of images the get good results, but I think the result is worth of it.

How to do it?
The trick is to alter slightly the location of the camera while keeping the look_at point fixed. This look_at point will be the point of sharpness in the image (equivalent to the focal_point in povray). The camera should be placed evenly inside a circle (which is perpendicular to the location-look_at vector) from frame to frame.
You can use a code like this:

#declare Aperture=.2
#declare Laps=20
#declare Ind=1-pow(1-clock,1.2)
#declare PosX=cos(2*pi*Laps*Ind)*Aperture*Ind;
#declare PosY=sin(2*pi*Laps*Ind)*Aperture*Ind;
{ location <PosX,PosY,-Distance_from_lookat>
  look_at 0
  angle Cam_angle
  rotate Angle_around_lookat
  translate Cam_lookat

This algorithm is not perfect, but it gives rather good results (it doesn't place the camera perfectly evenly in the circle, but it's good enough anyways). If you know a better algorithm, let me know.
Bigger Aperture values give more blurred images.
When the Distance_from_lookat is 10, the Aperture value of 0.2 is approximately the same as the aperture value of 0.8 in the normal focal blurred camera of povray.
More frames give better result, but it's slower, of course.
After calculating the frames, just average them to one single file.

Back to the targa averager page.