[Radiance-general] Depth-of-field hack

Mark Stock mstock at umich.edu
Mon Aug 16 19:30:29 CEST 2004


Radiance users,

Recently, I have been playing around with several Radiance
programs that I never would ordinarily use, and I devised a new
way to create depth-of-field blur. My primary motivation is
for creating very large images of very complex scenes. I
want to thank Greg for making time to meet me at SIGGRAPH,
and for getting me started on this line of thinking.

I have been creating images by using -aa 0 with -ps 1 for
over a year now. In a little previous work
(http://mark.technolope.org/radmisc/aa0_ps1_test/final.html)
I found that the fastest renderings could be had with
very low -ad but high oversampling. I wanted to find a
method for depth-of-field blur that worked similarly,
and would be compatible with this method.

I first tried pdfblur, which outputs a series of views, each
of which can be rendered with rpict or created with pinterp.
The pinterp method is definitely faster, but, as expected,
the pixels that were in focus were never recalculated, and,
thus, remained spotty:
http://mark.technolope.org/radiance/dof_tests/img06_30.png
(-ad 4, pdfblur 0.003 0.4 30, reduced 4:1)

Using pdfblur with rpict, though, forced resampling of each
pixel, so it took longer, but I didn't have to reduce the
final image at all to get this:
http://mark.technolope.org/radiance/dof_tests/img03_30.png
(-ad 4, pdfblur 0.003 0.4 30, not reduced)

The problem that I see, though, is that some large images will
need hundreds, if not thousands, of images blurred together
to eliminate the sharp lines in the highly-blurred regions,
while the oversampling technique rarely needs more that 36-64
original pixels to each output one (6-8x oversampling).

That's when I started reading lots of man pages. I wanted a way
to simulate DOF within a single image. What I came up with could
be used as an option to rpict, where it could be implemented more
accurately, I presume, (and which I may just do sometime). It
consists of a rather long command-line using vwrays (to create
each pixels' view ray), vwright (to calculate numerous view
parameters), rcalc (to adjust the view point and direction of
each), and rtrace (to take that information and compute a pixel
value).

My first try only supported aperture specification, but set
the focus distance to infinity. I then added a slightly-
incorrect hack to point the view direction back toward the
original view-at point. This is the script:

vwrays -fd -vf vp -x 512 -y 512 | rcalc -id6 -e 'a:0.003;d:0.4'
-e `vwright i < vp`
-e 'theta=2*PI*rand(2*recno-1);r=0.5*a*sqrt(rand(2*recno))'
-e 'r1=r*cos(theta);r2=r*sin(theta)'
-e 'dx=r1*ihx+r2*ivx;dy=r1*ihy+r2*ivy;dz=r1*ihz+r2*ivz'
-e '$1=ipx+dx;$2=ipy+dy;$3=ipz+dz'
-e '$4=$4-dx/d;$5=$5-dy/d;$6=$6-dz/d'
-od | rtrace -fdc -x 512 -y 512 @opts scene5f.oct > img04.pic

The "a:0.003;d:0.4" line specifies aperture and focus distance.
The "vp" file looks like this:
rview -vta -vp 0.51 0.52 0.34 -vd -0.43427 -0.86854 0.238848 -vu
0 0 1 -vh 70 -vv 70 -vo 0 -va 0 -vs 0 -vl 0
The opts file looks like this:
-ab 2 -ad 4 -aa 0 -as 0 -dj 0.7 -ms 0.03
The resolution gets specified in two places on the command-line.

At 512x512, this produced the following image:
http://mark.technolope.org/radiance/dof_program/img04.png

And at 4096x4096, reduced to 512x512 (aperture was not
halved in radius calculation, thus appears more blurry):
http://mark.technolope.org/radiance/dof_program/img05q.png

And that's what I wanted to share. I hope someone finds it
useful. I especially hope that someone improves on it. Right
now it is less useful to me, as I cannot incorporate it
into an rpiece batch job, or restart it if it dies.

Mark
mstock at umich.edu



More information about the Radiance-general mailing list