November 22, 2011

GLSL depth of field with bokeh v2.1

This is an update from the previous post on DoF bokeh shader.
The main addition is an option of pentagonal shape bokeh. The technique is hackish, but it works. Still I am looking for a more simpler way to make procedural n-gonal shapes of sampling.

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.

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

shifts the weights of the samples on the bokeh edges

pentagon shape of the bokeh (still needs some work)
edit: i have removed the "scale" factor, it is now automatic.

GLSL frag shader: HERE


  1. Hello Martinsh,
    Excellent work as always.:D
    This one looks spectacular. Hope to see more from you.
    Thanks man!

  2. The colours and effect looks fantastic! Well done good sir!

  3. Hello. Can you show me a dof method that is not heavy on a mobil platform?


  4. Absolutely wonderful!
    This is exactly what i was looking for and so much more!
    Thank you!