My first plugin

My first vfx job was with Smoke & Mirrors in London—I use the word ‘job’ in the loosest sense, as they were actually part-sponsoring my doctorate and part of the deal was that they had to employ me for three months over the three years (it was actually more complicated than that, involving a subsidiary that went bust, but that’s a story for another day).

S&M was your typical Soho post-production boutique; five flame suites and a bunch of crazy people rushing around.  Me, fresh-faced post graduate who’d seen A Bug’s Life and thought he’d like to work in computer graphics, is dumped in front of the engineering flame (i.e. unlicensed), handed the thousand page manual and asked to write a rack defocus plugin so that they didn’t have to buy another copy of a commercial one.

The flame API is actually very simple; you effectively get a buffer of pixels in and some parameters then have to produce a buffer of pixels out.  The hard parts were finding my way around the flame interface and working out what a rack defocus is.

I knew enough about optics and image processing to know that there’s not enough information in the 2d image to do a defocus properly.  So I spent a good while looking at what the commercial plugin did and googling stuff until I hit the in-retrospect obvious key—convolve the image with a kernel the shape of the lens aperture you want to see, and boost the highlights so that they don’t go flat and disappear when they are blurred.

So to get those nice hexagonal, octagonal and circular bokeh effects that people love so much I just needed to write a routine to draw a polygon with the appropriate number of sides into the kernel and then convolve it with the image (after first boosting any pixels above a certain threshold).  For the convolution I converted the image to floating point and used the FFTW library to do a fourier convolution, and believe me on an old SGI Octane it was slow.

Sure it’s simple and everyone knows how to do it, but it was a big deal to me at the time.  And here’s a little animation I found on my old pc, a still photo of Hong Kong with a foreground matte and animated defocus.



Leave a Reply

Your email address will not be published. Required fields are marked *