December 9, 2011

GLSL depth of field with bokeh v2.3

This is a major update for my depth of field w. bokeh shader.
I have added a python lens control file which gets focus distance from an object, adds control of "f-stop" variable, which controls "aperture" value for the shader.

list all of the new features:

• new and physically more accurate DoF, using real lens equations
• two extra input variables - focal length (in mm), aperture iris diameter (in mm)
• added a debug visualization of focus point and focal range (red line = focal point, green area = focal range)

separate python file:
• sets focus distance from an object
• added slow adaptive focusing for natural feel
• option to control aperture diameter with f-stop values (range: f/1, f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, ..... f/256)
• focal length control (default range from 6mm to 600mm)

Shader is HERE
lens control file HERE (made for Blender)
Blend is HERE

debug focal plane and depth range visualization:

v2.2 was done yesterday and I just did not had the time to post it here.


  1. hello when trying to implement this newer version of depth of field shader i get all brown. I'm not sure why this is. i am readying all the unform's in correctly. could you tell me if there is a what potentially could be the problem. thanks

    1. hello Jeremy, It is hard to tell. It could be hardware thing like ATI incompatibility, depth map, uniform value etc.
      Are you using it in Blender or other software?

    2. I actually suggest you to look at version 2.4 here: