Realtime GPU based depth-of-field & backlight in Processing with GLSL v0.1 (2008)

This is a very early version of a GPU based depth-of-field GLSL shader and sample Processing code. Adjust some parameters and it can also be used to give the scene a nice backlight/glow effect.
This is very early work and I wasn’t intending on releasing it just yet, but it was requested on the processing forums, and maybe someone else can improve on it… and thus it’ll be useful for me too 😛

I’m sure there are better and more generic examples out there, but for my specific needs this works quite well. I wrote it tailored for a particular project and only works under some very specific conditions:
– the scene has a white background
– the objects in the scene are pitch black with no lighting
– the objects are faded to white as they get further away (i.e. white fog)

Luckily, the visual brief on the project was in this direction, and that really simplifies the DOF process – because I can use the render as a depth map as well. If your scene is more complicated (like 99.9% of cases)!, you would need to generate a depth map.

press ‘b’ to toggle the blur on/off
press ‘d’ to toggle depth of field (blur only distance, or blur everything)
press ‘s’ to toggle using a single 2D blur, or 2 passes of 1D blurs
use sliders to adjust blur and threshold (loosely like a fake focal depth – but not completely cos the blur is always from the back and fronts are never blurred – though should be easy to mod the code to accommodate what you need).

having the dephth of field off (blurring whole screen) and threshold less than 1 creates a very nice backlit effect as well which could be quite useful.

written in processing 0135 using controlP5 and GLGraphics 0.8.1 (before the latest radical changes to make it work with processing 0148+)
dof_test.zip

This is a very early version of a GPU based depth-of-field GLSL shader and sample Processing code. Adjust some parameters […]

Related keywords

glsl, open source, tutorial