Saturday, April 7, 2012

Another Bokeh Technique - RM Video

Hi all, just created a quick video of the new vs technique, compare it with the quality of the ps technique from the previous posts and see how good it is, as for the numbers, check out my comment from the prev pos, enjoy:



Another Bokeh Technique

hi all

last post i talked about bokeh effect done inside pixel shader using special bokeh kernel, this time i will talk about more generic technique for doing bokeh.
first lets talk about whats wasn't good in the pixel shader technique.
in my engine i say i have film dof effect, what this means is that i can set almost any size of kernel per pixel! this means i'm not suffering from depth difference and stuff like that.
i can set one pixel to be blurred by radius 5, and the next pixel beside by radius 100, without any artifacts... (as long i will not get crazy with kernel radius)

anyway, because the ps technique is some kind of blur technique, if i will inject it to my engine on top of my dof, it will 'erase' my 'perfect' blur technique, because it is a blur, but not smarter than what i already have.

so if you don't have any dof/blur solution yet, it will probably be good for you, if you have some kind of smart blur, it probably wont.

so is there any thing we can do to add bokeh effect without dx10,11?
yes there is...
on the last post i said few words about a technique to generate bokeh using vertex shader, here i will write some detail about it and show some images from the engine.

this new technique uses the vertex shader to generate bokeh sprites/billboards, the steps to do this is:
* create big vertex shader containing 4 vertices per pixel!, yes you are reading it correct, 4 vertices per pixel...
* inside vs, you generate the quad vertices based on some math, this math will actually use some circle of confusion values and your current image, so you can set bokeh color and size.
* inside ps, you just sample your bokeh texture, can be any shape you like, and use the color you output from the vs, to set its intensity etc.

technique pros:
* very easy to do
* support any bokeh shape
* dx9 hardware (shader model 3)
* work hand by hand with any dof/blur technique
* very fast

technique cons:
* takes lots of vertex memory (depends on your size)
* vertex shader heavy (basically not a problem as we are more ps heave than vs)
* can be slow if you won't filter them in a good way, you don't want to generate bokeh for every pixel in the screen, this can be nasty! i got blur screen on win 7 ;)

here is few screenshots (not compressed) from the engine that's shows it in action, you could also see the film dof effect with very large coc to enhanced the effect (kernel radius of 80 for far pixels)

orignal image (no dof, no bokeh)

film dof (no bokeh)

pentagonal bokeh

hexagonal bokeh

circle bokeh

star bokeh

that's it, very simple and very fast! cya until next time...