Tuesday, January 4, 2011

Lens Effect / Bokeh

hi
this time i'm attacking a problem related to lens blur effect or bokeh.
as you know (or don't) real time app such as games mimic lens effects with blur filters that applied on some image (scaled or not, depending or the app)
until now, blur could be done with few methods/filters such as gaussian, poisson disk, bilateral and etc depending on the problem you want to solve.
for example:
1. Gaussian could be used for blurring image that need a smooth look, like lighting and such...
2. Poisson disk blur could be used to smooth shadow mapping as it faster than 1 and basically produces nice result.
3. Bilateral blur could be for smoothing SSAO, because it can take into account few vars (like normal, depth) when doing the blur and reduce bleeding.
ok, those methods used until now and rely on samples count.
more samples means nicer result but takes a lot of power and most of the time it doesn't really worth it...
what we really need is a filter that doesn't rely on the kernal/filter size and mimic real camera lens effects without killing our app and can achieve this:

image taken from wiki under 'bokeh'
Coarse bokeh on a photo shot with an 85mm lens and 70mm aperture, which corresponds to f/1.2

the circle shapes is what we need to achieve! (or any other shape we want).
how we get this in reality: when we use smaller f in our camera, out of focus areas/points blurred into polygonal shape formed by the aperture blades.
somebody did this in real time or what? yes, Futuremark group in their new 3dmark 2011 benchmark (the underwater demo... amazing stuff...) and i think me 8p
lets see screenshots:

original image

increase filter size

and here is the hexagon shape...
note that any shape could be done with no cost!

and a video...

video

real time video of lens effect / bokeh

with the new gpu's features and dx11 we can do it in real time, right?
well... yes, but we don't really need dx11 or 10... ;p
what we really need the heavy duty guns! Fast Fourier Transform or FFT in short...
cya until next time...

4 comments:

pixelmager said...

Have a look at futuremarks 3dmark11 whitepaper.

It seems they use a modernized version of the lost planet dx10-method (render sprite for each pixel on screen, low-res) - while streaks/glare etc. is using FFT.

I believe the issue with using FFT for DOF is that you have to run it on multiple layers. This can be done (e.g. http://www.mpi-inf.mpg.de/~slee/pub/ ) but isn't as fast.

orenk2k said...

hi pixelmager

bloom:
"a procedurally precomputed texture is used as the bloom filter. the filter combines blur, streak, lenticular halo and anamorphic flare effects."

as for lens reflections:
"... as in the bloom effect, the forward and inverse ffts are perform using cs ..."

so no sprite instancing here like used in LP...

as for using fft for DOF, its a bit of a problem as multiple kernel sizes need to be used based on the distance from the camera and such, so it's not very good for that (will be slow), but as you know, there are few games other than metro that using downscale blur image and for that, fft will give better result, otherwise, you should use diffusion dof like used in metro (implementation of pixar paper http://graphics.pixar.com/library/DepthOfField/ )

thanks

orenk2k said...

hi again

they use what you said for the dof bokeh...

MarmAmic said...

Very very nice... Can use this DOF effects.
Also can be used as a nice gameplay feature during the game ;)