GLSL depth of field with bokeh v2.4 (update)

Hi,
I am really lazy so I will just paste the text from my dev-blog here:

This is my second attempt to create a depth of field shader with bokeh. the first one is here:
http://artmartinsh.blogspot.com/2010/02/glsl-lens-blur-filter-with-bokeh.html
And I am really glad that it got popular quite fast. It has been even used in Google Chrome’s ROME “3 DREAMS OF BLACK” hehe.

This one is much more flexible and I have added few new features.

• variable sample count to increase quality/performance
• option to blur depth buffer to reduce hard edges
• option to dither the samples with noise or pattern
• bokeh chromatic aberration/fringing
• bokeh bias to bring out bokeh edges
• image thresholding to bring out highlights when image is out of focus
• pentagonal bokeh shape (experimental)

yet to do

• add multi-shape bokeh (does anyone knows how to make procedural pentagon or hexagon?)
• bokeh vignetting at screen edges

The shader is made on 2006 iMac with Mobility Radeon card so it should work on any hardware supporting OpenGL.

Screenshots are captured with high sample count, but the point is to show the features and capabilities of the shader.

some of the main features explained with images:

threshold & gain:
brings out highlights by “threshold” value and enhances them with “gain”
as you can see this is the main part that makes the distinct look of the bokeh blur. Without bringing out highlights, the blur looks like just a regular circular blur.

http://dl.dropbox.com/u/11542084/highlights0.jpg
http://dl.dropbox.com/u/11542084/highlights1.jpg
http://dl.dropbox.com/u/11542084/highlights2.jpg
http://dl.dropbox.com/u/11542084/highlights3.jpg

fringe:
adds chromatic aberration for the blur (small overlay image shows r,g,b color offset of the sample)

http://dl.dropbox.com/u/11542084/fringe.jpg

bias:
shifts the weights of the samples on the bokeh edges

http://dl.dropbox.com/u/11542084/bias1.jpg
http://dl.dropbox.com/u/11542084/bias2.jpg

pentagon:
pentagon shape of the bokeh (still needs some work)

http://dl.dropbox.com/u/11542084/penta1.jpg
http://dl.dropbox.com/u/11542084/penta2.jpg

and the GLSL 2D Filter is HERE
version 2.2 is HERE
version 2.4 is HERE (newest!)
I am trying to comment it as simple as I can so anyone can understand it.

and blend is HERE
new blend (2.4) is HERE
I will be glad if you guys will find this useful. I would also like to know how it works for you.

:smiley:

That’s really, quite good. Very much so in fact… EXCELLENT.

Great!
One question : Is there any way to achieve Distance Blur?

Thanks, SolarLune!

BlendingBGE - distance blur? like a blur that blurs the scene only in specified distance?

Thanks Martinsh, screenshots looks great! :slight_smile:

Wow, those bokeh blur look beautiful!

Ooh, pretty!

That is just fantastic! Typical of Martinsh work.:yes:

Yes.
The blur should appear on a specified distance.

Excellent work indeed!

Thank you for the nice replies.

here you go. it should be really easy to use. You have to specify the distance where the blur starts and the distance how far it fades in. All the distances are in Blender Units.
http://dl.dropbox.com/u/11542084/distance_blur

amazing Martinsh! Thank you. Very nice!

This is awesome. When you make the blend, please make a version that works the same as your old DoF ( just centring to the screen so it can be used for a moving camera). Also, is it possible to make the chromatic aberration affect the objects?

Thanks for sharing this script :slight_smile:

I forgot to add: it seems pretty noisy even at 512 samples :frowning:

1 Like

Amazing as usual thanks for share this!

Martinsh I was playing with the DOf with the bokeh effects and its amazing what we can do here is a little presentation with your filter, thanks!

martinsh, as always, awesome !!!

I don’t know why… but if I add a filter as a 2d filter actuator, it never works for me, unless I download the pre-made .blend sample.

What am I doing wrong?

Some filters have properties that are floating values and those need to be replicated in order to them to work, for example, the vignette need the vigneting size or something like that and a valuefrom -1, to 1 ( at least on the one that Im using, but it was modificated) so you need to set it up. Other filters may need a auxiliar python script in order to make them work, like the HDR that need the get light script or the DOF that needs an auxiliar like autofocus or manual focus for example.

And there are other things that may differ from scene to scene, the size for example every scene needs an Z-far and a Z-near for the SSAO to work properly, but all the filters have specific configurations that need to be changed in order to make them work, the templates that martinsh share with us are the best for the scene that cames with the blender but they need to be changed if you want better results for your scene.

I hope that it helps!

leonnn is right,
My shaders are lacking a detailed documentation how to properly set them up, but I try to fix that with the new shaders.
Shaders that uses depth texture input as SSAO and DoF are very dependent to camera range so also for scene scaling . I usually use 1 BlenderUnit = 1meter and camera depth range from 0.1 --> 100.0. Well 100meters is not much, especially for outdoors scenes, but the values can be cleverly tweaked to work for large scale areas. The reason is the depth texture precision on older ATI/AMD cards with large scene sizes, they tend to produce artifacts that looks like stripes.
Thankfully the shaders are very customizable :), it is a matter of tweaking to acquire the best results for your needs.

Here is a blend file and with that - a major shader update.
blend: http://dl.dropbox.com/u/11542084/DoF_playground.blend
the new shader v2.2: http://dl.dropbox.com/u/11542084/DoF_bokeh_2.2

controls:
•WASD+mouse = move&look
•1 - enable depth of field shader
•left mouse button = set focal target
•spacebar toggles a debug visualization of focus point and focal range (red line = focal point, green area = focal range)

http://dl.dropbox.com/u/11542084/focus1.jpg
debug focus visualization enabled:
http://dl.dropbox.com/u/11542084/focus2.jpg