"Congress is so strange. A man gets up to speak and says nothing. Nobody listens - and then everybody disagrees."
- Boris Marshalov

Framework 3 (Last updated: February 6, 2017)
Framework 2 (Last updated: October 8, 2006)
Framework (Last updated: October 8, 2006)
Libraries (Last updated: September 16, 2004)
Really old framework (Last updated: September 16, 2004)
Depth of field
Tuesday, November 19, 2002 | Permalink

Source code
DepthOfField.zip (381 KB)

This demo shows a way to do depth of field with a fragment program. The technique is simple, unfortunately the result follows accordingly. What I've done is render the scene into a texture. At the same time I put the radial distance into the alpha channel. I let the hardware generate the mipmaps with GL_SGIS_generate_mipmap. Then in the fragment shader I can on a per-fragment basis select the LOD. I pass a focus distance to the fragment program and use LOD = const * abs(dist - focusDist).
What I meant with the "result follows accordingly" comment is that it didn't quite look as good as I had hoped. The mipmap lod with a linear filter gives quite a blocky apperance of out-of-focus parts of the scene. For limited blur it works fine though.
Oh, and don't mind the simple texturing and lack of lighting in this demo. Didn't bother to do something serious on that side of things.

You can move the focus spot with you + and - keys.

This demo will run on Radeon 9700 only at this time.