Depth of Field Simulation

Hi, can anyone point me to an example of how to create a DOF effect with Radiance?
I tried reading the pdf/pinterp docs but am still not clear as to how the process works.

Thanks

You start with a view file with a single view in it, whose -vd direction vector length is the focus distance of the subject. You then pass this “viewfile” to pdfblur and pinterp like so:

pdfblur 0.05 50 viewfile | pinterp -vf viewfile -x xres -y yres -B render.hdr render.zbf > blurred.hdr

In this example, I am using a lens aperture of “0.05” in world units, whatever they are. You can also generate a depth-of-field blur using rpict directly:

rpict -vf viewfile -pd 0.05 -x 3000 -y 3000 [other options] scene.oct | pfilt -1 -x /3 -y /3 -r .6 > blurred.hdr

Rendering at a higher resolution and downsampling with pfilt greatly improves the quality of the results. You can also combine these methods, putting a little bit of noisy depth-of-field blur in with rpict then applying the faster pinterp method for the rest:

rpict -vf viewfile -pd 0.02 -x 2000 -y 2000 [other options] -o slightblur.hdr -z slightblur.zbf scene.oct
pdfblur 0.03 50 viewfile | pinterp -vf viewfile -x 2000 -y 2000 -B slightblur.hdr slightblur.zbf | pfilt -1 -x /2 -y /2 -r .6 > blurred.hdr

An important note about computing the aperture used by Radiance is given in the ranimate(1) manpage, which can perform the above operations as part of managing an animation:

To simulate a particular camera
aperture, divide the focal length of the lens by  the  f-number, 
then  convert  to  the  corresponding  world coordinate
units.  For example, if you wish to simulate a 50mm  lens  at
f/2.0  in  a scene modeled in meters, then you divide 50mm by
2.0 to get 25mm, which corresponds to an  effective  aperture
of  0.025  meters.

-Greg

What should I do if my image is created using rtrace, so there’s no defined view file? The reason is I’m also trying to simulate realistic lens distortion effect.

The view parameters can be approximate. You will need to add them to your rtrace output using getinfo -a, e.g.:

getinfo -a "VIEW= -vtv -vh 90 -vv 50 -vp 10 19 25 -vd -5 -3 -1.5" < rtrace_out.hdr > withview.hdr

Thanks for you answer.

I’m concerned about how well of an approximation that will be, but I’ll try it out.

I think it might be a nice feature to be able to interpolate by directly feeding rays into pinterp rather than view files, in order to allow arbitrary views.

Thanks